Debian Codegraph @

third-party/xxhash/tests/multiInclude.c

raw
1 /*
2 * Multi-include test program
3 * Validates that xxhash.h can be included multiple times and in any order
4 *
5 * Copyright (C) 2020 Yann Collet
6 *
7 * GPL v2 License
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * You can contact the author at:
24 * - xxHash homepage: https://www.xxhash.com
25 * - xxHash source repository: https://github.com/Cyan4973/xxHash
26 */
27
28 #include <stdio.h> /* printf */
29
30 /* Normal include, gives access to public symbols */
31 #include "../xxhash.h"
32
33 /* Multiple consecutive inclusions are handled properly. */
34 #include "../xxhash.h"
35
36 /*
37 * Advanced include, gives access to experimental symbols
38 * This test ensures that xxhash.h can be included multiple times
39 * and in any order. The tested order is more difficult:
40 * without care, the declaration of experimental symbols could be skipped.
41 */
42 #define XXH_STATIC_LINKING_ONLY
43 #include "../xxhash.h"
44
45 /*
46 * Inlining: redefine all identifiers, keep them private to the unit.
47 * Note: Without specific efforts, the identifier names would collide.
48 *
49 * To be linked with and without xxhash.o
50 * to test the symbol's presence and naming collisions.
51 */
52 #define XXH_INLINE_ALL
53 #include "../xxhash.h"
54
55 /*
56 * Multiple consecutive inclusions with XXH_INLINE_ALL are handled properly.
57 */
58 #define XXH_INLINE_ALL
59 #include "../xxhash.h"
60
61
62 void hash_advanced(void)
63 {
64 XXH3_state_t state; /* this type is part of experimental API */
65
66 XXH3_64bits_reset(&state);
67 const char input[] = "Hello World !";
68
69 XXH3_64bits_update(&state, input, sizeof(input));
70
71 XXH64_hash_t const h = XXH3_64bits_digest(&state);
72 printf("hash '%s': %08x%08x \n", input, (unsigned)(h >> 32), (unsigned)h);
73 }
74
75 int main(void)
76 {
77 hash_advanced();
78 }