geoip2_c 0.3.4 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +23 -0
  3. data/.github/workflows/ubuntu.yml +17 -8
  4. data/.github/workflows/windows.yml +18 -8
  5. data/.gitmodules +0 -3
  6. data/ext/geoip2/extconf.rb +9 -25
  7. data/ext/geoip2/geoip2.c +82 -32
  8. data/geoip2_c.gemspec +1 -0
  9. data/lib/geoip2/version.rb +1 -1
  10. metadata +18 -182
  11. data/ext/geoip2/libmaxminddb/.gitignore +0 -38
  12. data/ext/geoip2/libmaxminddb/.gitmodules +0 -9
  13. data/ext/geoip2/libmaxminddb/.perltidyrc +0 -11
  14. data/ext/geoip2/libmaxminddb/.travis.yml +0 -70
  15. data/ext/geoip2/libmaxminddb/.uncrustify.cfg +0 -78
  16. data/ext/geoip2/libmaxminddb/AUTHORS +0 -0
  17. data/ext/geoip2/libmaxminddb/Changes.md +0 -277
  18. data/ext/geoip2/libmaxminddb/LICENSE +0 -202
  19. data/ext/geoip2/libmaxminddb/Makefile.am +0 -41
  20. data/ext/geoip2/libmaxminddb/NOTICE +0 -13
  21. data/ext/geoip2/libmaxminddb/README.dev.md +0 -69
  22. data/ext/geoip2/libmaxminddb/README.md +0 -122
  23. data/ext/geoip2/libmaxminddb/appveyor.yml +0 -33
  24. data/ext/geoip2/libmaxminddb/bin/Makefile.am +0 -10
  25. data/ext/geoip2/libmaxminddb/bin/mmdblookup.c +0 -715
  26. data/ext/geoip2/libmaxminddb/bootstrap +0 -21
  27. data/ext/geoip2/libmaxminddb/common.mk +0 -7
  28. data/ext/geoip2/libmaxminddb/configure.ac +0 -132
  29. data/ext/geoip2/libmaxminddb/dev-bin/make-man-pages.pl +0 -76
  30. data/ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh +0 -53
  31. data/ext/geoip2/libmaxminddb/dev-bin/regen-prototypes.pl +0 -136
  32. data/ext/geoip2/libmaxminddb/dev-bin/regen-win32-test-projs.pl +0 -54
  33. data/ext/geoip2/libmaxminddb/dev-bin/release.sh +0 -113
  34. data/ext/geoip2/libmaxminddb/dev-bin/uncrustify-all.sh +0 -21
  35. data/ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl +0 -53
  36. data/ext/geoip2/libmaxminddb/doc/libmaxminddb.md +0 -889
  37. data/ext/geoip2/libmaxminddb/doc/mmdblookup.md +0 -103
  38. data/ext/geoip2/libmaxminddb/include/maxminddb.h +0 -241
  39. data/ext/geoip2/libmaxminddb/include/maxminddb_config.h.in +0 -14
  40. data/ext/geoip2/libmaxminddb/projects/VS12/README.md +0 -59
  41. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-release.props +0 -32
  42. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb-x64.props +0 -14
  43. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.props +0 -32
  44. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.sln +0 -150
  45. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj +0 -143
  46. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters +0 -32
  47. data/ext/geoip2/libmaxminddb/projects/VS12/maxminddb_config.h +0 -14
  48. data/ext/geoip2/libmaxminddb/projects/VS12-tests/bad_pointers.vcxproj +0 -105
  49. data/ext/geoip2/libmaxminddb/projects/VS12-tests/basic_lookup.vcxproj +0 -105
  50. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_entry_list.vcxproj +0 -105
  51. data/ext/geoip2/libmaxminddb/projects/VS12-tests/data_types.vcxproj +0 -105
  52. data/ext/geoip2/libmaxminddb/projects/VS12-tests/dump.vcxproj +0 -105
  53. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value.vcxproj +0 -105
  54. data/ext/geoip2/libmaxminddb/projects/VS12-tests/get_value_pointer_bug.vcxproj +0 -105
  55. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv4_start_cache.vcxproj +0 -105
  56. data/ext/geoip2/libmaxminddb/projects/VS12-tests/ipv6_lookup_in_ipv4.vcxproj +0 -105
  57. data/ext/geoip2/libmaxminddb/projects/VS12-tests/libtap.vcxproj +0 -85
  58. data/ext/geoip2/libmaxminddb/projects/VS12-tests/maxminddb_test_helper.vcxproj +0 -107
  59. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata.vcxproj +0 -105
  60. data/ext/geoip2/libmaxminddb/projects/VS12-tests/metadata_pointers.vcxproj +0 -105
  61. data/ext/geoip2/libmaxminddb/projects/VS12-tests/no_map_get_value.vcxproj +0 -105
  62. data/ext/geoip2/libmaxminddb/projects/VS12-tests/read_node.vcxproj +0 -105
  63. data/ext/geoip2/libmaxminddb/projects/VS12-tests/shared.vcxproj +0 -104
  64. data/ext/geoip2/libmaxminddb/projects/VS12-tests/threads.vcxproj +0 -103
  65. data/ext/geoip2/libmaxminddb/projects/VS12-tests/version.vcxproj +0 -105
  66. data/ext/geoip2/libmaxminddb/projects/test.vcxproj.template +0 -105
  67. data/ext/geoip2/libmaxminddb/src/Makefile.am +0 -25
  68. data/ext/geoip2/libmaxminddb/src/data-pool.c +0 -180
  69. data/ext/geoip2/libmaxminddb/src/data-pool.h +0 -52
  70. data/ext/geoip2/libmaxminddb/src/libmaxminddb.pc.in +0 -11
  71. data/ext/geoip2/libmaxminddb/src/maxminddb-compat-util.h +0 -167
  72. data/ext/geoip2/libmaxminddb/src/maxminddb.c +0 -2181
  73. data/ext/geoip2/libmaxminddb/t/Makefile.am +0 -27
  74. data/ext/geoip2/libmaxminddb/t/bad_databases_t.c +0 -67
  75. data/ext/geoip2/libmaxminddb/t/bad_pointers_t.c +0 -53
  76. data/ext/geoip2/libmaxminddb/t/basic_lookup_t.c +0 -207
  77. data/ext/geoip2/libmaxminddb/t/compile_c++_t.pl +0 -107
  78. data/ext/geoip2/libmaxminddb/t/data-pool-t.c +0 -374
  79. data/ext/geoip2/libmaxminddb/t/data_entry_list_t.c +0 -353
  80. data/ext/geoip2/libmaxminddb/t/data_types_t.c +0 -439
  81. data/ext/geoip2/libmaxminddb/t/dump_t.c +0 -103
  82. data/ext/geoip2/libmaxminddb/t/external_symbols_t.pl +0 -106
  83. data/ext/geoip2/libmaxminddb/t/get_value_pointer_bug_t.c +0 -66
  84. data/ext/geoip2/libmaxminddb/t/get_value_t.c +0 -249
  85. data/ext/geoip2/libmaxminddb/t/ipv4_start_cache_t.c +0 -36
  86. data/ext/geoip2/libmaxminddb/t/ipv6_lookup_in_ipv4_t.c +0 -48
  87. data/ext/geoip2/libmaxminddb/t/libtap/.gitignore +0 -13
  88. data/ext/geoip2/libmaxminddb/t/libtap/.travis.yml +0 -13
  89. data/ext/geoip2/libmaxminddb/t/libtap/COPYING +0 -165
  90. data/ext/geoip2/libmaxminddb/t/libtap/INSTALL +0 -41
  91. data/ext/geoip2/libmaxminddb/t/libtap/Makefile +0 -72
  92. data/ext/geoip2/libmaxminddb/t/libtap/Makefile.win +0 -37
  93. data/ext/geoip2/libmaxminddb/t/libtap/README.md +0 -268
  94. data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.c +0 -20
  95. data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.expected +0 -28
  96. data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.c +0 -16
  97. data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.expected +0 -37
  98. data/ext/geoip2/libmaxminddb/t/libtap/t/diag.c +0 -10
  99. data/ext/geoip2/libmaxminddb/t/libtap/t/diag.expected +0 -2
  100. data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.c +0 -14
  101. data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.expected +0 -6
  102. data/ext/geoip2/libmaxminddb/t/libtap/t/is.c +0 -24
  103. data/ext/geoip2/libmaxminddb/t/libtap/t/is.expected +0 -58
  104. data/ext/geoip2/libmaxminddb/t/libtap/t/like.c +0 -10
  105. data/ext/geoip2/libmaxminddb/t/libtap/t/like.expected +0 -4
  106. data/ext/geoip2/libmaxminddb/t/libtap/t/simple.c +0 -31
  107. data/ext/geoip2/libmaxminddb/t/libtap/t/simple.expected +0 -32
  108. data/ext/geoip2/libmaxminddb/t/libtap/t/skip.c +0 -23
  109. data/ext/geoip2/libmaxminddb/t/libtap/t/skip.expected +0 -9
  110. data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.c +0 -13
  111. data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.expected +0 -9
  112. data/ext/geoip2/libmaxminddb/t/libtap/t/test.c +0 -28
  113. data/ext/geoip2/libmaxminddb/t/libtap/t/todo.c +0 -17
  114. data/ext/geoip2/libmaxminddb/t/libtap/t/todo.expected +0 -11
  115. data/ext/geoip2/libmaxminddb/t/libtap/tap.c +0 -354
  116. data/ext/geoip2/libmaxminddb/t/libtap/tap.h +0 -115
  117. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitattributes +0 -1
  118. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitconfig +0 -2
  119. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitignore +0 -2
  120. data/ext/geoip2/libmaxminddb/t/maxmind-db/.perltidyallrc +0 -11
  121. data/ext/geoip2/libmaxminddb/t/maxmind-db/.tidyallrc +0 -7
  122. data/ext/geoip2/libmaxminddb/t/maxmind-db/LICENSE +0 -4
  123. data/ext/geoip2/libmaxminddb/t/maxmind-db/MaxMind-DB-spec.md +0 -558
  124. data/ext/geoip2/libmaxminddb/t/maxmind-db/README.md +0 -4
  125. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/README.md +0 -7
  126. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb +0 -0
  127. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/cyclic-data-structure.mmdb +0 -0
  128. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-bytes-length.mmdb +0 -1
  129. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb +0 -0
  130. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-map-key-length.mmdb +0 -0
  131. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-string-length.mmdb +0 -1
  132. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb +0 -1
  133. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/unexpected-bytes.mmdb +0 -0
  134. data/ext/geoip2/libmaxminddb/t/maxmind-db/perltidyrc +0 -12
  135. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Anonymous-IP-Test.json +0 -32
  136. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-City-Test.json +0 -12616
  137. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Connection-Type-Test.json +0 -102
  138. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Country-Test.json +0 -10975
  139. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-DensityIncome-Test.json +0 -14
  140. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Domain-Test.json +0 -452
  141. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Enterprise-Test.json +0 -666
  142. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-ISP-Test.json +0 -12585
  143. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Precision-Enterprise-Test.json +0 -1035
  144. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoLite2-ASN-Test.json +0 -37
  145. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/README +0 -13
  146. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  147. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  148. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  149. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test.mmdb +0 -0
  150. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  151. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Country-Test.mmdb +0 -0
  152. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  153. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  154. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  155. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  156. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  157. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  158. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  159. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  160. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  161. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  162. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  163. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  164. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  165. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  166. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  167. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  168. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  169. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  170. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  171. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  172. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  173. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  174. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/README.md +0 -26
  175. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/maps-with-pointers.raw +0 -0
  176. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/write-test-data.pl +0 -614
  177. data/ext/geoip2/libmaxminddb/t/maxmind-db/tidyall.ini +0 -5
  178. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.c +0 -255
  179. data/ext/geoip2/libmaxminddb/t/maxminddb_test_helper.h +0 -69
  180. data/ext/geoip2/libmaxminddb/t/metadata_pointers_t.c +0 -32
  181. data/ext/geoip2/libmaxminddb/t/metadata_t.c +0 -226
  182. data/ext/geoip2/libmaxminddb/t/mmdblookup_t.pl +0 -158
  183. data/ext/geoip2/libmaxminddb/t/no_map_get_value_t.c +0 -32
  184. data/ext/geoip2/libmaxminddb/t/read_node_t.c +0 -157
  185. data/ext/geoip2/libmaxminddb/t/threads_t.c +0 -196
  186. data/ext/geoip2/libmaxminddb/t/version_t.c +0 -10
@@ -1,374 +0,0 @@
1
- #include <assert.h>
2
- #include <data-pool.h>
3
- #include <inttypes.h>
4
- #include "libtap/tap.h"
5
- #include <math.h>
6
- #include "maxminddb_test_helper.h"
7
-
8
- static void test_data_pool_new(void);
9
- static void test_data_pool_destroy(void);
10
- static void test_data_pool_alloc(void);
11
- static void test_data_pool_to_list(void);
12
- static bool create_and_check_list(size_t const,
13
- size_t const);
14
- static void check_block_count(MMDB_entry_data_list_s const *const,
15
- size_t const);
16
-
17
- int main(void)
18
- {
19
- plan(NO_PLAN);
20
- test_data_pool_new();
21
- test_data_pool_destroy();
22
- test_data_pool_alloc();
23
- test_data_pool_to_list();
24
- done_testing();
25
- }
26
-
27
- static void test_data_pool_new(void)
28
- {
29
- {
30
- MMDB_data_pool_s *const pool = data_pool_new(0);
31
- ok(!pool, "size 0 is not valid");
32
- }
33
-
34
- {
35
- MMDB_data_pool_s *const pool = data_pool_new(SIZE_MAX - 10);
36
- ok(!pool, "very large size is not valid");
37
- }
38
-
39
- {
40
- MMDB_data_pool_s *const pool = data_pool_new(512);
41
- ok(pool != NULL, "size 512 is valid");
42
- cmp_ok(pool->size, "==", 512, "size is 512");
43
- cmp_ok(pool->used, "==", 0, "used size is 0");
44
- data_pool_destroy(pool);
45
- }
46
- }
47
-
48
- static void test_data_pool_destroy(void)
49
- {
50
- {
51
- data_pool_destroy(NULL);
52
- }
53
-
54
- {
55
- MMDB_data_pool_s *const pool = data_pool_new(512);
56
- ok(pool != NULL, "created pool");
57
- data_pool_destroy(pool);
58
- }
59
- }
60
-
61
- static void test_data_pool_alloc(void)
62
- {
63
- {
64
- MMDB_data_pool_s *const pool = data_pool_new(1);
65
- ok(pool != NULL, "created pool");
66
- cmp_ok(pool->used, "==", 0, "used size starts at 0");
67
-
68
- MMDB_entry_data_list_s *const entry1 = data_pool_alloc(pool);
69
- ok(entry1 != NULL, "allocated first entry");
70
- // Arbitrary so that we can recognize it.
71
- entry1->entry_data.offset = (uint32_t)123;
72
-
73
- cmp_ok(pool->size, "==", 1, "size is still 1");
74
- cmp_ok(pool->used, "==", 1, "used size is 1 after taking one");
75
-
76
- MMDB_entry_data_list_s *const entry2 = data_pool_alloc(pool);
77
- ok(entry2 != NULL, "got another entry");
78
- ok(entry1 != entry2, "second entry is different from first entry");
79
-
80
- cmp_ok(pool->size, "==", 2, "size is 2 (new block)");
81
- cmp_ok(pool->used, "==", 1, "used size is 1 in current block");
82
-
83
- ok(entry1->entry_data.offset == 123,
84
- "accessing the original entry's memory is ok");
85
-
86
- data_pool_destroy(pool);
87
- }
88
-
89
- {
90
- size_t const initial_size = 10;
91
- MMDB_data_pool_s *const pool = data_pool_new(initial_size);
92
- ok(pool != NULL, "created pool");
93
-
94
- MMDB_entry_data_list_s *entry1 = NULL;
95
- for (size_t i = 0; i < initial_size; i++) {
96
- MMDB_entry_data_list_s *const entry = data_pool_alloc(pool);
97
- ok(entry != NULL, "got an entry");
98
- // Give each a unique number so we can check it.
99
- entry->entry_data.offset = (uint32_t)i;
100
- if (i == 0) {
101
- entry1 = entry;
102
- }
103
- }
104
-
105
- cmp_ok(pool->size, "==", initial_size, "size is the initial size");
106
- cmp_ok(pool->used, "==", initial_size, "used size is as expected");
107
-
108
- MMDB_entry_data_list_s *const entry = data_pool_alloc(pool);
109
- ok(entry != NULL, "got an entry");
110
- entry->entry_data.offset = (uint32_t)initial_size;
111
-
112
- cmp_ok(pool->size, "==", initial_size * 2,
113
- "size is the initial size*2");
114
- cmp_ok(pool->used, "==", 1, "used size is as expected");
115
-
116
- MMDB_entry_data_list_s *const list = data_pool_to_list(pool);
117
-
118
- MMDB_entry_data_list_s *element = list;
119
- for (size_t i = 0; i < initial_size + 1; i++) {
120
- ok(
121
- element->entry_data.offset == (uint32_t)i,
122
- "found offset %" PRIu32 ", should have %zu",
123
- element->entry_data.offset,
124
- i
125
- );
126
- element = element->next;
127
- }
128
-
129
- ok(entry1->entry_data.offset == (uint32_t)0,
130
- "accessing entry1's original memory is ok after growing the pool");
131
-
132
- data_pool_destroy(pool);
133
- }
134
- }
135
-
136
- static void test_data_pool_to_list(void)
137
- {
138
- {
139
- size_t const initial_size = 16;
140
- MMDB_data_pool_s *const pool = data_pool_new(initial_size);
141
- ok(pool != NULL, "created pool");
142
-
143
- MMDB_entry_data_list_s *const entry1 = data_pool_alloc(pool);
144
- ok(entry1 != NULL, "got an entry");
145
-
146
- MMDB_entry_data_list_s *const list_one_element
147
- = data_pool_to_list(pool);
148
- ok(list_one_element != NULL, "got a list");
149
- ok(list_one_element == entry1,
150
- "list's first element is the first we retrieved");
151
- ok(list_one_element->next == NULL, "list is one element in size");
152
-
153
- MMDB_entry_data_list_s *const entry2 = data_pool_alloc(pool);
154
- ok(entry2 != NULL, "got another entry");
155
-
156
- MMDB_entry_data_list_s *const list_two_elements
157
- = data_pool_to_list(pool);
158
- ok(list_two_elements != NULL, "got a list");
159
- ok(list_two_elements == entry1,
160
- "list's first element is the first we retrieved");
161
- ok(list_two_elements->next != NULL, "list has a second element");
162
-
163
- MMDB_entry_data_list_s *const second_element = list_two_elements->next;
164
- ok(second_element == entry2,
165
- "second item in list is second we retrieved");
166
- ok(second_element->next == NULL, "list ends with the second element");
167
-
168
- data_pool_destroy(pool);
169
- }
170
-
171
- {
172
- size_t const initial_size = 1;
173
- MMDB_data_pool_s *const pool = data_pool_new(initial_size);
174
- ok(pool != NULL, "created pool");
175
-
176
- MMDB_entry_data_list_s *const entry1 = data_pool_alloc(pool);
177
- ok(entry1 != NULL, "got an entry");
178
-
179
- MMDB_entry_data_list_s *const list_one_element
180
- = data_pool_to_list(pool);
181
- ok(list_one_element != NULL, "got a list");
182
- ok(list_one_element == entry1,
183
- "list's first element is the first we retrieved");
184
- ok(list_one_element->next == NULL, "list ends with this element");
185
-
186
- data_pool_destroy(pool);
187
- }
188
-
189
- {
190
- size_t const initial_size = 2;
191
- MMDB_data_pool_s *const pool = data_pool_new(initial_size);
192
- ok(pool != NULL, "created pool");
193
-
194
- MMDB_entry_data_list_s *const entry1 = data_pool_alloc(pool);
195
- ok(entry1 != NULL, "got an entry");
196
-
197
- MMDB_entry_data_list_s *const entry2 = data_pool_alloc(pool);
198
- ok(entry2 != NULL, "got an entry");
199
- ok(entry1 != entry2, "second entry is different from the first");
200
-
201
- MMDB_entry_data_list_s *const list_element1 = data_pool_to_list(pool);
202
- ok(list_element1 != NULL, "got a list");
203
- ok(list_element1 == entry1,
204
- "list's first element is the first we retrieved");
205
-
206
- MMDB_entry_data_list_s *const list_element2 = list_element1->next;
207
- ok(list_element2 == entry2,
208
- "second element is the second we retrieved");
209
- ok(list_element2->next == NULL, "list ends with this element");
210
-
211
- data_pool_destroy(pool);
212
- }
213
-
214
- {
215
- diag("starting test: fill one block save for one spot");
216
- ok(
217
- create_and_check_list(3, 2),
218
- "fill one block save for one spot"
219
- );
220
- }
221
-
222
- {
223
- diag("starting test: fill one block");
224
- ok(
225
- create_and_check_list(3, 3),
226
- "fill one block"
227
- );
228
- }
229
-
230
- {
231
- diag("starting test: fill one block and use one spot in the next block");
232
- ok(
233
- create_and_check_list(3, 3 + 1),
234
- "fill one block and use one spot in the next block"
235
- );
236
- }
237
-
238
- {
239
- diag("starting test: fill two blocks save for one spot");
240
- ok(
241
- create_and_check_list(3, 3 + 3 * 2 - 1),
242
- "fill two blocks save for one spot"
243
- );
244
- }
245
-
246
- {
247
- diag("starting test: fill two blocks");
248
- ok(
249
- create_and_check_list(3, 3 + 3 * 2),
250
- "fill two blocks"
251
- );
252
- }
253
-
254
- {
255
- diag("starting test: fill two blocks and use one spot in the next");
256
- ok(
257
- create_and_check_list(3, 3 + 3 * 2 + 1),
258
- "fill two blocks and use one spot in the next"
259
- );
260
- }
261
-
262
- {
263
- diag("starting test: fill three blocks save for one spot");
264
- ok(
265
- create_and_check_list(3, 3 + 3 * 2 + 3 * 2 * 2 - 1),
266
- "fill three blocks save for one spot"
267
- );
268
- }
269
-
270
- {
271
- diag("starting test: fill three blocks");
272
- ok(
273
- create_and_check_list(3, 3 + 3 * 2 + 3 * 2 * 2),
274
- "fill three blocks"
275
- );
276
- }
277
-
278
- // It would be nice to have a larger number of these, but it's expensive to
279
- // run many. We currently hardcode what this will be anyway, so varying
280
- // this is not very interesting.
281
- size_t const initial_sizes[] = { 1, 2, 32, 64, 128, 256 };
282
-
283
- size_t const max_element_count = 4096;
284
-
285
- for (size_t i = 0; i < sizeof(initial_sizes) / sizeof(initial_sizes[0]);
286
- i++) {
287
- size_t const initial_size = initial_sizes[i];
288
-
289
- for (size_t element_count = 0; element_count < max_element_count;
290
- element_count++) {
291
- assert(create_and_check_list(initial_size, element_count));
292
- }
293
- }
294
- }
295
-
296
- // Use assert() rather than libtap as libtap is significantly slower and we run
297
- // this frequently.
298
- static bool create_and_check_list(size_t const initial_size,
299
- size_t const element_count)
300
- {
301
- MMDB_data_pool_s *const pool = data_pool_new(initial_size);
302
- assert(pool != NULL);
303
-
304
- assert(pool->used == 0);
305
-
306
- // Hold on to the pointers as we initially see them so that we can check
307
- // they are still valid after building the list.
308
- MMDB_entry_data_list_s **const entry_array
309
- = calloc(element_count, sizeof(MMDB_entry_data_list_s *));
310
- assert(entry_array != NULL);
311
-
312
- for (size_t i = 0; i < element_count; i++) {
313
- MMDB_entry_data_list_s *const entry = data_pool_alloc(pool);
314
- assert(entry != NULL);
315
-
316
- entry->entry_data.offset = (uint32_t)i;
317
-
318
- entry_array[i] = entry;
319
- }
320
-
321
- MMDB_entry_data_list_s *const list = data_pool_to_list(pool);
322
-
323
- if (element_count == 0) {
324
- assert(list == NULL);
325
- data_pool_destroy(pool);
326
- free(entry_array);
327
- return true;
328
- }
329
-
330
- assert(list != NULL);
331
-
332
- MMDB_entry_data_list_s *element = list;
333
- for (size_t i = 0; i < element_count; i++) {
334
- assert(element->entry_data.offset == (uint32_t)i);
335
-
336
- assert(element == entry_array[i]);
337
-
338
- element = element->next;
339
- }
340
- assert(element == NULL);
341
-
342
- check_block_count(list, initial_size);
343
-
344
- data_pool_destroy(pool);
345
- free(entry_array);
346
- return true;
347
- }
348
-
349
- // Use assert() rather than libtap as libtap is significantly slower and we run
350
- // this frequently.
351
- static void check_block_count(MMDB_entry_data_list_s const *const list,
352
- size_t const initial_size)
353
- {
354
- size_t got_block_count = 0;
355
- size_t got_element_count = 0;
356
-
357
- MMDB_entry_data_list_s const *element = list;
358
- while (element) {
359
- got_element_count++;
360
-
361
- if (element->pool) {
362
- got_block_count++;
363
- }
364
-
365
- element = element->next;
366
- }
367
-
368
- // Because <number of elements> = <initial size> * 2^(number of blocks)
369
- double const a = ceil((double)got_element_count / (double)initial_size);
370
- double const b = log2(a);
371
- size_t const expected_block_count = ((size_t)b) + 1;
372
-
373
- assert(got_block_count == expected_block_count);
374
- }