Commit | Line | Data |
---|---|---|
cfe4f77b SK |
1 | -module(x_plane_data_SUITE). |
2 | ||
3 | -include_lib("x_plane_data.hrl"). | |
4 | ||
5 | %% CT callbacks | |
6 | -export( | |
7 | [ all/0 | |
8 | , groups/0 | |
9 | ]). | |
10 | ||
11 | %% Test cases | |
12 | -export( | |
13 | [ t_basic_sanity_check/1 | |
14 | ]). | |
15 | ||
16 | -define(GROUP, x_plane_data). | |
17 | ||
18 | %% ============================================================================ | |
19 | %% CT callbacks | |
20 | %% ============================================================================ | |
21 | ||
22 | all() -> | |
23 | [ {group, ?GROUP} | |
24 | ]. | |
25 | ||
26 | groups() -> | |
27 | Tests = | |
28 | [ t_basic_sanity_check | |
29 | ], | |
30 | Properties = [parallel], | |
31 | [ {?GROUP, Properties, Tests} | |
32 | ]. | |
33 | ||
34 | ||
35 | %% ============================================================================= | |
36 | %% Test cases | |
37 | %% ============================================================================= | |
38 | ||
39 | t_basic_sanity_check(_Cfg) -> | |
40 | Test = | |
41 | fun (PacketBase64) -> | |
42 | Packet = base64:decode(PacketBase64), | |
43 | MaxIndex = 133, | |
44 | BadIndex = MaxIndex + 1, | |
45 | FakeBlockData = list_to_binary(lists:seq(1, 32)), | |
46 | FakeBlockOk = <<MaxIndex:32/little-integer, FakeBlockData/binary>>, | |
47 | FakeBlockBadIndex = <<BadIndex:32/little-integer, FakeBlockData/binary>>, | |
48 | {error, {block_index_byte_out_of_range, {BadIndex,_,_,_,_,_,_,_,_}}} = | |
49 | x_plane_data:of_bin(<<Packet/binary, FakeBlockBadIndex/binary>>), | |
50 | {error, packet_unrecognized} = | |
51 | x_plane_data:of_bin(<<"bad-header", Packet/binary>>), | |
52 | {error, packet_length_invalid} = | |
53 | x_plane_data:of_bin(<<Packet/binary, "extra-stuff">>), | |
54 | {ok, Data} = | |
55 | x_plane_data:of_bin(<<Packet/binary, FakeBlockOk/binary>>), | |
56 | {some, #x_plane_datum_speeds{}} = | |
57 | hope_kv_list:get(Data, speeds), | |
58 | {some, #x_plane_datum_pitch_roll_heading{}} = | |
59 | hope_kv_list:get(Data, pitch_roll_heading), | |
60 | {some, #x_plane_datum_lat_lon_alt{}} = | |
61 | hope_kv_list:get(Data, lat_lon_alt), | |
62 | {some, {MaxIndex,_,_,_,_,_,_,_,_}} = | |
63 | hope_kv_list:get(Data, MaxIndex), | |
64 | ok | |
65 | end, | |
66 | lists:foreach(Test, sample_packets_base64_encoded()). | |
67 | ||
68 | ||
69 | ||
70 | %% ============================================================================= | |
71 | %% Sample data | |
72 | %% ============================================================================= | |
73 | ||
74 | sample_packets_base64_encoded() -> | |
75 | [ <<"REFUQUADAAAAbcpGQLt81EBfZNlATnUoNwDAecSow2RAnCv6QLrbQTcRAAAA3i8VQFL3ZT6dPfFCx4IFQwDAecQAwHnEAMB5xADAecQUAAAA1ZciQg6ik8JGBv9AdDxoPgAAgD9G/o3CAAAgQgAAlsI=">> | |
76 | ]. |