]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2020 Gerhard Sittig <gerhard.sittig@gmx.net> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include <config.h> | |
21 | #include <check.h> | |
22 | #include <libsigrok/libsigrok.h> | |
23 | #include <stdlib.h> | |
24 | #include <string.h> | |
25 | #include "lib.h" | |
26 | #include "libsigrok-internal.h" | |
27 | ||
28 | static const uint8_t buff1234[] = { | |
29 | 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, | |
30 | }; | |
31 | ||
32 | START_TEST(test_endian_macro) | |
33 | { | |
34 | const uint8_t *p8; | |
35 | const uint16_t *p16; | |
36 | const uint32_t *p32; | |
37 | ||
38 | p8 = (const void *)&buff1234[0]; | |
39 | fail_unless(R8(&p8[0]) == 0x11); | |
40 | fail_unless(R8(&p8[1]) == 0x22); | |
41 | fail_unless(R8(&p8[2]) == 0x33); | |
42 | fail_unless(R8(&p8[3]) == 0x44); | |
43 | ||
44 | p16 = (const void *)&buff1234[0]; | |
45 | fail_unless(RB16(&p16[0]) == 0x1122); | |
46 | fail_unless(RB16(&p16[1]) == 0x3344); | |
47 | ||
48 | p16 = (const void *)&buff1234[0]; | |
49 | fail_unless(RL16(&p16[0]) == 0x2211); | |
50 | fail_unless(RL16(&p16[1]) == 0x4433); | |
51 | ||
52 | p32 = (const void *)&buff1234[0]; | |
53 | fail_unless(RB32(&p32[0]) == 0x11223344); | |
54 | fail_unless(RB32(&p32[1]) == 0x55667788); | |
55 | ||
56 | p32 = (const void *)&buff1234[0]; | |
57 | fail_unless(RL32(&p32[0]) == 0x44332211); | |
58 | fail_unless(RL32(&p32[1]) == 0x88776655); | |
59 | ||
60 | p16 = (const void *)&buff1234[0]; | |
61 | fail_unless(RB16(p16++) == 0x1122); | |
62 | fail_unless(RB16(p16++) == 0x3344); | |
63 | } | |
64 | END_TEST | |
65 | ||
66 | Suite *suite_conv(void) | |
67 | { | |
68 | Suite *s; | |
69 | TCase *tc; | |
70 | ||
71 | s = suite_create("conv"); | |
72 | ||
73 | tc = tcase_create("endian"); | |
74 | tcase_add_test(tc, test_endian_macro); | |
75 | suite_add_tcase(s, tc); | |
76 | ||
77 | return s; | |
78 | } |