geoip2_c 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ubuntu.yml +33 -0
  3. data/.github/workflows/windows.yml +52 -0
  4. data/README.md +22 -10
  5. data/docker-compose.yml +22 -1
  6. data/dockerfiles/{Dockerfile-ruby2.3 → Dockerfile-ruby2.5} +1 -1
  7. data/dockerfiles/{Dockerfile-ruby2.1 → Dockerfile-ruby2.6} +1 -1
  8. data/dockerfiles/{Dockerfile-ruby2.2 → Dockerfile-ruby2.7} +1 -1
  9. data/ext/geoip2/extconf.rb +11 -4
  10. data/ext/geoip2/geoip2.c +63 -18
  11. data/ext/geoip2/libmaxminddb/.gitignore +3 -0
  12. data/ext/geoip2/libmaxminddb/.travis.yml +24 -2
  13. data/ext/geoip2/libmaxminddb/Changes.md +39 -0
  14. data/ext/geoip2/libmaxminddb/README.dev.md +41 -30
  15. data/ext/geoip2/libmaxminddb/README.md +3 -3
  16. data/ext/geoip2/libmaxminddb/bin/Makefile.am +5 -0
  17. data/ext/geoip2/libmaxminddb/bin/mmdblookup.c +333 -15
  18. data/ext/geoip2/libmaxminddb/configure.ac +5 -5
  19. data/ext/geoip2/libmaxminddb/dev-bin/ppa-release.sh +8 -5
  20. data/ext/geoip2/libmaxminddb/dev-bin/release.sh +7 -0
  21. data/ext/geoip2/libmaxminddb/dev-bin/valgrind-all.pl +10 -3
  22. data/ext/geoip2/libmaxminddb/include/maxminddb.h +11 -2
  23. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj +3 -1
  24. data/ext/geoip2/libmaxminddb/projects/VS12/libmaxminddb.vcxproj.filters +7 -1
  25. data/ext/geoip2/libmaxminddb/src/Makefile.am +18 -2
  26. data/ext/geoip2/libmaxminddb/src/data-pool.c +180 -0
  27. data/ext/geoip2/libmaxminddb/src/data-pool.h +52 -0
  28. data/ext/geoip2/libmaxminddb/src/maxminddb.c +58 -48
  29. data/ext/geoip2/libmaxminddb/t/Makefile.am +6 -2
  30. data/ext/geoip2/libmaxminddb/t/bad_databases_t.c +1 -0
  31. data/ext/geoip2/libmaxminddb/t/basic_lookup_t.c +35 -0
  32. data/ext/geoip2/libmaxminddb/t/data-pool-t.c +374 -0
  33. data/ext/geoip2/libmaxminddb/t/external_symbols_t.pl +106 -0
  34. data/ext/geoip2/libmaxminddb/t/libtap/.gitignore +13 -0
  35. data/ext/geoip2/libmaxminddb/t/libtap/.travis.yml +13 -0
  36. data/ext/geoip2/libmaxminddb/t/libtap/COPYING +165 -0
  37. data/ext/geoip2/libmaxminddb/t/libtap/INSTALL +41 -0
  38. data/ext/geoip2/libmaxminddb/t/libtap/Makefile +72 -0
  39. data/ext/geoip2/libmaxminddb/t/libtap/Makefile.win +37 -0
  40. data/ext/geoip2/libmaxminddb/t/libtap/README.md +268 -0
  41. data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.c +20 -0
  42. data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.expected +28 -0
  43. data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.c +16 -0
  44. data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.expected +37 -0
  45. data/ext/geoip2/libmaxminddb/t/libtap/t/diag.c +10 -0
  46. data/ext/geoip2/libmaxminddb/t/libtap/t/diag.expected +2 -0
  47. data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.c +14 -0
  48. data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.expected +6 -0
  49. data/ext/geoip2/libmaxminddb/t/libtap/t/is.c +24 -0
  50. data/ext/geoip2/libmaxminddb/t/libtap/t/is.expected +58 -0
  51. data/ext/geoip2/libmaxminddb/t/libtap/t/like.c +10 -0
  52. data/ext/geoip2/libmaxminddb/t/libtap/t/like.expected +4 -0
  53. data/ext/geoip2/libmaxminddb/t/libtap/t/simple.c +31 -0
  54. data/ext/geoip2/libmaxminddb/t/libtap/t/simple.expected +32 -0
  55. data/ext/geoip2/libmaxminddb/t/libtap/t/skip.c +23 -0
  56. data/ext/geoip2/libmaxminddb/t/libtap/t/skip.expected +9 -0
  57. data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.c +13 -0
  58. data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.expected +9 -0
  59. data/ext/geoip2/libmaxminddb/t/libtap/t/test.c +28 -0
  60. data/ext/geoip2/libmaxminddb/t/libtap/t/todo.c +17 -0
  61. data/ext/geoip2/libmaxminddb/t/libtap/t/todo.expected +11 -0
  62. data/ext/geoip2/libmaxminddb/t/libtap/tap.c +354 -0
  63. data/ext/geoip2/libmaxminddb/t/libtap/tap.h +115 -0
  64. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitattributes +1 -0
  65. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitconfig +2 -0
  66. data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitignore +2 -0
  67. data/ext/geoip2/libmaxminddb/t/maxmind-db/.perltidyallrc +11 -0
  68. data/ext/geoip2/libmaxminddb/t/maxmind-db/.tidyallrc +7 -0
  69. data/ext/geoip2/libmaxminddb/t/maxmind-db/LICENSE +4 -0
  70. data/ext/geoip2/libmaxminddb/t/maxmind-db/MaxMind-DB-spec.md +558 -0
  71. data/ext/geoip2/libmaxminddb/t/maxmind-db/README.md +4 -0
  72. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/README.md +7 -0
  73. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb +0 -0
  74. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/cyclic-data-structure.mmdb +0 -0
  75. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-bytes-length.mmdb +1 -0
  76. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb +0 -0
  77. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-map-key-length.mmdb +0 -0
  78. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-string-length.mmdb +1 -0
  79. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb +1 -0
  80. data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/unexpected-bytes.mmdb +0 -0
  81. data/ext/geoip2/libmaxminddb/t/maxmind-db/perltidyrc +12 -0
  82. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Anonymous-IP-Test.json +32 -0
  83. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-City-Test.json +12616 -0
  84. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Connection-Type-Test.json +102 -0
  85. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Country-Test.json +10975 -0
  86. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-DensityIncome-Test.json +14 -0
  87. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Domain-Test.json +452 -0
  88. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Enterprise-Test.json +666 -0
  89. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-ISP-Test.json +12585 -0
  90. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Precision-Enterprise-Test.json +1035 -0
  91. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoLite2-ASN-Test.json +37 -0
  92. data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/README +13 -0
  93. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
  94. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
  95. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
  96. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test.mmdb +0 -0
  97. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
  98. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Country-Test.mmdb +0 -0
  99. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
  100. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Domain-Test.mmdb +0 -0
  101. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
  102. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-ISP-Test.mmdb +0 -0
  103. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
  104. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoLite2-ASN-Test.mmdb +0 -0
  105. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
  106. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
  107. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
  108. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
  109. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
  110. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
  111. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
  112. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
  113. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
  114. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
  115. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
  116. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
  117. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
  118. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
  119. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
  120. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-nested.mmdb +0 -0
  121. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/README.md +26 -0
  122. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/maps-with-pointers.raw +0 -0
  123. data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/write-test-data.pl +614 -0
  124. data/ext/geoip2/libmaxminddb/t/maxmind-db/tidyall.ini +5 -0
  125. data/geoip2_c.gemspec +2 -3
  126. data/lib/geoip2/database.rb +4 -0
  127. data/lib/geoip2/version.rb +1 -1
  128. metadata +114 -22
  129. data/.travis.yml +0 -31
  130. data/Appraisals +0 -7
  131. data/gemfiles/ruby_2.1.gemfile +0 -7
  132. data/gemfiles/ruby_2.2.gemfile +0 -7
@@ -0,0 +1,32 @@
1
+ 1..24
2
+ ok 1
3
+ ok 2
4
+ ok 3
5
+ not ok 4
6
+ # Failed test at t/simple.c line 8.
7
+ ok 5 - foo
8
+ ok 6 - bar
9
+ ok 7 - baz
10
+ ok 8 - quux
11
+ ok 9 - thud
12
+ ok 10 - wombat
13
+ ok 11 - blurgle
14
+ ok 12 - frob
15
+ not ok 13 - frobnicate
16
+ # Failed test 'frobnicate'
17
+ # at t/simple.c line 17.
18
+ ok 14 - eek
19
+ ok 15 - ook
20
+ ok 16 - frodo
21
+ ok 17 - bilbo
22
+ ok 18 - wubble
23
+ ok 19 - flarp
24
+ ok 20 - fnord
25
+ ok 21
26
+ not ok 22
27
+ # Failed test at t/simple.c line 26.
28
+ ok 23 - good
29
+ not ok 24 - bad
30
+ # Failed test 'bad'
31
+ # at t/simple.c line 28.
32
+ # Looks like you failed 4 tests of 24 run.
@@ -0,0 +1,23 @@
1
+ #include "tap.h"
2
+
3
+ int main () {
4
+ plan(8);
5
+ skip(0, 3, "%s cannot fork", "windows");
6
+ ok(1, "quux");
7
+ ok(1, "thud");
8
+ ok(1, "wombat");
9
+ end_skip;
10
+ skip(1, 1, "need to be on windows");
11
+ ok(0, "blurgle");
12
+ end_skip;
13
+ skip(0, 3);
14
+ ok(1, "quux");
15
+ ok(1, "thud");
16
+ ok(1, "wombat");
17
+ end_skip;
18
+ skip(1, 1);
19
+ ok(0, "blurgle");
20
+ end_skip;
21
+ done_testing();
22
+ }
23
+
@@ -0,0 +1,9 @@
1
+ 1..8
2
+ ok 1 - quux
3
+ ok 2 - thud
4
+ ok 3 - wombat
5
+ ok 4 # skip need to be on windows
6
+ ok 5 - quux
7
+ ok 6 - thud
8
+ ok 7 - wombat
9
+ ok 8 # skip
@@ -0,0 +1,13 @@
1
+ #include "tap.h"
2
+
3
+ int main () {
4
+ plan(5);
5
+ int bronze = 1, silver = 2, gold = 3;
6
+ ok(bronze < silver, "bronze is less than silver");
7
+ ok(bronze > silver, "not quite");
8
+ is("gold", "gold", "gold is gold");
9
+ cmp_ok(silver, "<", gold, "%d <= %d", silver, gold);
10
+ like("platinum", ".*inum", "platinum matches .*inum");
11
+ done_testing();
12
+ }
13
+
@@ -0,0 +1,9 @@
1
+ 1..5
2
+ ok 1 - bronze is less than silver
3
+ not ok 2 - not quite
4
+ # Failed test 'not quite'
5
+ # at t/synopsis.c line 7.
6
+ ok 3 - gold is gold
7
+ ok 4 - 2 <= 3
8
+ ok 5 - platinum matches .*inum
9
+ # Looks like you failed 1 test of 5 run.
@@ -0,0 +1,28 @@
1
+ #include "tap.h"
2
+ #include <stdio.h>
3
+ #include <dirent.h>
4
+ #include <stdlib.h>
5
+ #include <string.h>
6
+
7
+ int main () {
8
+ DIR *dp = opendir("t");
9
+ if (!dp) {
10
+ perror("opendir");
11
+ exit(1);
12
+ }
13
+ struct dirent *ep;
14
+ while ((ep = readdir(dp))) {
15
+ char *name = ep->d_name;
16
+ if (strchr(name, '.') || !strcmp(name, "test"))
17
+ continue;
18
+ char command[1024];
19
+ snprintf(command, 1024, "./t/%s >t/%s.got 2>&1", name, name);
20
+ system(command);
21
+ snprintf(command, 1024, "diff -up t/%s.expected t/%s.got", name, name);
22
+ int retval = system(command);
23
+ ok(!(retval >> 8), name);
24
+ }
25
+ closedir(dp);
26
+ done_testing();
27
+ }
28
+
@@ -0,0 +1,17 @@
1
+ #include "tap.h"
2
+
3
+ int main () {
4
+ plan(6);
5
+ todo();
6
+ ok(0, "foo");
7
+ ok(1, "bar");
8
+ ok(1, "baz");
9
+ end_todo;
10
+ todo("im not ready");
11
+ ok(0, "quux");
12
+ ok(1, "thud");
13
+ ok(1, "wombat");
14
+ end_todo;
15
+ done_testing();
16
+ }
17
+
@@ -0,0 +1,11 @@
1
+ 1..6
2
+ not ok 1 - foo # TODO
3
+ # Failed (TODO) test 'foo'
4
+ # at t/todo.c line 6.
5
+ ok 2 - bar # TODO
6
+ ok 3 - baz # TODO
7
+ not ok 4 - quux # TODO im not ready
8
+ # Failed (TODO) test 'quux'
9
+ # at t/todo.c line 11.
10
+ ok 5 - thud # TODO im not ready
11
+ ok 6 - wombat # TODO im not ready
@@ -0,0 +1,354 @@
1
+ /*
2
+ libtap - Write tests in C
3
+ Copyright 2012 Jake Gelbman <gelbman@gmail.com>
4
+ This file is licensed under the LGPL
5
+ */
6
+
7
+ #define _DEFAULT_SOURCE 1
8
+
9
+ #include <stdio.h>
10
+ #include <stdlib.h>
11
+ #include <stdarg.h>
12
+ #include <string.h>
13
+ #include "tap.h"
14
+
15
+ static int expected_tests = NO_PLAN;
16
+ static int failed_tests;
17
+ static int current_test;
18
+ static char *todo_mesg;
19
+
20
+ static char *
21
+ vstrdupf (const char *fmt, va_list args) {
22
+ char *str;
23
+ int size;
24
+ va_list args2;
25
+ va_copy(args2, args);
26
+ if (!fmt)
27
+ fmt = "";
28
+ size = vsnprintf(NULL, 0, fmt, args2) + 2;
29
+ str = malloc(size);
30
+ if (!str) {
31
+ perror("malloc error");
32
+ exit(1);
33
+ }
34
+ vsprintf(str, fmt, args);
35
+ va_end(args2);
36
+ return str;
37
+ }
38
+
39
+ void
40
+ tap_plan (int tests, const char *fmt, ...) {
41
+ expected_tests = tests;
42
+ if (tests == SKIP_ALL) {
43
+ char *why;
44
+ va_list args;
45
+ va_start(args, fmt);
46
+ why = vstrdupf(fmt, args);
47
+ va_end(args);
48
+ printf("1..0 ");
49
+ diag("SKIP %s\n", why);
50
+ exit(0);
51
+ }
52
+ if (tests != NO_PLAN) {
53
+ printf("1..%d\n", tests);
54
+ }
55
+ }
56
+
57
+ int
58
+ vok_at_loc (const char *file, int line, int test, const char *fmt,
59
+ va_list args)
60
+ {
61
+ char *name = vstrdupf(fmt, args);
62
+ if (!test) {
63
+ printf("not ");
64
+ }
65
+ printf("ok %d", ++current_test);
66
+ if (*name)
67
+ printf(" - %s", name);
68
+ if (todo_mesg) {
69
+ printf(" # TODO");
70
+ if (*todo_mesg)
71
+ printf(" %s", todo_mesg);
72
+ }
73
+ printf("\n");
74
+ if (!test) {
75
+ printf("# Failed ");
76
+ if (todo_mesg)
77
+ printf("(TODO) ");
78
+ printf("test ");
79
+ if (*name)
80
+ printf("'%s'\n# ", name);
81
+ printf("at %s line %d.\n", file, line);
82
+ if (!todo_mesg)
83
+ failed_tests++;
84
+ }
85
+ free(name);
86
+ return test;
87
+ }
88
+
89
+ int
90
+ ok_at_loc (const char *file, int line, int test, const char *fmt, ...) {
91
+ va_list args;
92
+ va_start(args, fmt);
93
+ vok_at_loc(file, line, test, fmt, args);
94
+ va_end(args);
95
+ return test;
96
+ }
97
+
98
+ static int
99
+ mystrcmp (const char *a, const char *b) {
100
+ return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
101
+ }
102
+
103
+ #define eq(a, b) (!mystrcmp(a, b))
104
+ #define ne(a, b) (mystrcmp(a, b))
105
+
106
+ int
107
+ is_at_loc (const char *file, int line, const char *got, const char *expected,
108
+ const char *fmt, ...)
109
+ {
110
+ int test = eq(got, expected);
111
+ va_list args;
112
+ va_start(args, fmt);
113
+ vok_at_loc(file, line, test, fmt, args);
114
+ va_end(args);
115
+ if (!test) {
116
+ diag(" got: '%s'", got);
117
+ diag(" expected: '%s'", expected);
118
+ }
119
+ return test;
120
+ }
121
+
122
+ int
123
+ isnt_at_loc (const char *file, int line, const char *got, const char *expected,
124
+ const char *fmt, ...)
125
+ {
126
+ int test = ne(got, expected);
127
+ va_list args;
128
+ va_start(args, fmt);
129
+ vok_at_loc(file, line, test, fmt, args);
130
+ va_end(args);
131
+ if (!test) {
132
+ diag(" got: '%s'", got);
133
+ diag(" expected: anything else");
134
+ }
135
+ return test;
136
+ }
137
+
138
+ int
139
+ cmp_ok_at_loc (const char *file, int line, int a, const char *op, int b,
140
+ const char *fmt, ...)
141
+ {
142
+ int test = eq(op, "||") ? a || b
143
+ : eq(op, "&&") ? a && b
144
+ : eq(op, "|") ? a | b
145
+ : eq(op, "^") ? a ^ b
146
+ : eq(op, "&") ? a & b
147
+ : eq(op, "==") ? a == b
148
+ : eq(op, "!=") ? a != b
149
+ : eq(op, "<") ? a < b
150
+ : eq(op, ">") ? a > b
151
+ : eq(op, "<=") ? a <= b
152
+ : eq(op, ">=") ? a >= b
153
+ : eq(op, "<<") ? a << b
154
+ : eq(op, ">>") ? a >> b
155
+ : eq(op, "+") ? a + b
156
+ : eq(op, "-") ? a - b
157
+ : eq(op, "*") ? a * b
158
+ : eq(op, "/") ? a / b
159
+ : eq(op, "%") ? a % b
160
+ : diag("unrecognized operator '%s'", op);
161
+ va_list args;
162
+ va_start(args, fmt);
163
+ vok_at_loc(file, line, test, fmt, args);
164
+ va_end(args);
165
+ if (!test) {
166
+ diag(" %d", a);
167
+ diag(" %s", op);
168
+ diag(" %d", b);
169
+ }
170
+ return test;
171
+ }
172
+
173
+ static int
174
+ find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
175
+ size_t i;
176
+ if (a == b)
177
+ return 0;
178
+ if (!a || !b)
179
+ return 2;
180
+ for (i = 0; i < n; i++) {
181
+ if (a[i] != b[i]) {
182
+ *offset = i;
183
+ return 1;
184
+ }
185
+ }
186
+ return 0;
187
+ }
188
+
189
+ int
190
+ cmp_mem_at_loc (const char *file, int line, const void *got,
191
+ const void *expected, size_t n, const char *fmt, ...)
192
+ {
193
+ size_t offset;
194
+ int diff = find_mem_diff(got, expected, n, &offset);
195
+ va_list args;
196
+ va_start(args, fmt);
197
+ vok_at_loc(file, line, !diff, fmt, args);
198
+ va_end(args);
199
+ if (diff == 1) {
200
+ diag(" Difference starts at offset %d", offset);
201
+ diag(" got: 0x%02x", ((unsigned char *)got)[offset]);
202
+ diag(" expected: 0x%02x", ((unsigned char *)expected)[offset]);
203
+ }
204
+ else if (diff == 2) {
205
+ diag(" got: %s", got ? "not NULL" : "NULL");
206
+ diag(" expected: %s", expected ? "not NULL" : "NULL");
207
+ }
208
+ return !diff;
209
+ }
210
+
211
+ int
212
+ diag (const char *fmt, ...) {
213
+ va_list args;
214
+ char *mesg, *line;
215
+ int i;
216
+ va_start(args, fmt);
217
+ if (!fmt)
218
+ return 0;
219
+ mesg = vstrdupf(fmt, args);
220
+ line = mesg;
221
+ for (i = 0; *line; i++) {
222
+ char c = mesg[i];
223
+ if (!c || c == '\n') {
224
+ mesg[i] = '\0';
225
+ printf("# %s\n", line);
226
+ if (!c)
227
+ break;
228
+ mesg[i] = c;
229
+ line = mesg + i + 1;
230
+ }
231
+ }
232
+ free(mesg);
233
+ va_end(args);
234
+ return 0;
235
+ }
236
+
237
+ int
238
+ exit_status () {
239
+ int retval = 0;
240
+ if (expected_tests == NO_PLAN) {
241
+ printf("1..%d\n", current_test);
242
+ }
243
+ else if (current_test != expected_tests) {
244
+ diag("Looks like you planned %d test%s but ran %d.",
245
+ expected_tests, expected_tests > 1 ? "s" : "", current_test);
246
+ retval = 2;
247
+ }
248
+ if (failed_tests) {
249
+ diag("Looks like you failed %d test%s of %d run.",
250
+ failed_tests, failed_tests > 1 ? "s" : "", current_test);
251
+ retval = 1;
252
+ }
253
+ return retval;
254
+ }
255
+
256
+ int
257
+ bail_out (int ignore, const char *fmt, ...) {
258
+ va_list args;
259
+ va_start(args, fmt);
260
+ printf("Bail out! ");
261
+ vprintf(fmt, args);
262
+ printf("\n");
263
+ va_end(args);
264
+ exit(255);
265
+ return 0;
266
+ }
267
+
268
+ void
269
+ tap_skip (int n, const char *fmt, ...) {
270
+ char *why;
271
+ va_list args;
272
+ va_start(args, fmt);
273
+ why = vstrdupf(fmt, args);
274
+ va_end(args);
275
+ while (n --> 0) {
276
+ printf("ok %d ", ++current_test);
277
+ diag("skip %s\n", why);
278
+ }
279
+ free(why);
280
+ }
281
+
282
+ void
283
+ tap_todo (int ignore, const char *fmt, ...) {
284
+ va_list args;
285
+ va_start(args, fmt);
286
+ todo_mesg = vstrdupf(fmt, args);
287
+ va_end(args);
288
+ }
289
+
290
+ void
291
+ tap_end_todo () {
292
+ free(todo_mesg);
293
+ todo_mesg = NULL;
294
+ }
295
+
296
+ #ifndef _WIN32
297
+ #include <sys/mman.h>
298
+ #include <sys/param.h>
299
+ #include <regex.h>
300
+
301
+ #if defined __APPLE__ || defined BSD
302
+ #define MAP_ANONYMOUS MAP_ANON
303
+ #endif
304
+
305
+ /* Create a shared memory int to keep track of whether a piece of code executed
306
+ dies. to be used in the dies_ok and lives_ok macros. */
307
+ int
308
+ tap_test_died (int status) {
309
+ static int *test_died = NULL;
310
+ int prev;
311
+ if (!test_died) {
312
+ test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
313
+ MAP_SHARED | MAP_ANONYMOUS, -1, 0);
314
+ *test_died = 0;
315
+ }
316
+ prev = *test_died;
317
+ *test_died = status;
318
+ return prev;
319
+ }
320
+
321
+ int
322
+ like_at_loc (int for_match, const char *file, int line, const char *got,
323
+ const char *expected, const char *fmt, ...)
324
+ {
325
+ int test;
326
+ regex_t re;
327
+ va_list args;
328
+ int err = regcomp(&re, expected, REG_EXTENDED);
329
+ if (err) {
330
+ char errbuf[256];
331
+ regerror(err, &re, errbuf, sizeof errbuf);
332
+ fprintf(stderr, "Unable to compile regex '%s': %s at %s line %d\n",
333
+ expected, errbuf, file, line);
334
+ exit(255);
335
+ }
336
+ err = regexec(&re, got, 0, NULL, 0);
337
+ regfree(&re);
338
+ test = for_match ? !err : err;
339
+ va_start(args, fmt);
340
+ vok_at_loc(file, line, test, fmt, args);
341
+ va_end(args);
342
+ if (!test) {
343
+ if (for_match) {
344
+ diag(" '%s'", got);
345
+ diag(" doesn't match: '%s'", expected);
346
+ }
347
+ else {
348
+ diag(" '%s'", got);
349
+ diag(" matches: '%s'", expected);
350
+ }
351
+ }
352
+ return test;
353
+ }
354
+ #endif
@@ -0,0 +1,115 @@
1
+ /*
2
+ libtap - Write tests in C
3
+ Copyright 2012 Jake Gelbman <gelbman@gmail.com>
4
+ This file is licensed under the LGPL
5
+ */
6
+
7
+ #ifndef __TAP_H__
8
+ #define __TAP_H__
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ #ifndef va_copy
15
+ #ifdef __va_copy
16
+ #define va_copy __va_copy
17
+ #else
18
+ #define va_copy(d, s) ((d) = (s))
19
+ #endif
20
+ #endif
21
+
22
+ #include <stdio.h>
23
+ #include <stdlib.h>
24
+ #include <stdarg.h>
25
+
26
+ int vok_at_loc (const char *file, int line, int test, const char *fmt,
27
+ va_list args);
28
+ int ok_at_loc (const char *file, int line, int test, const char *fmt,
29
+ ...);
30
+ int is_at_loc (const char *file, int line, const char *got,
31
+ const char *expected, const char *fmt, ...);
32
+ int isnt_at_loc (const char *file, int line, const char *got,
33
+ const char *expected, const char *fmt, ...);
34
+ int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
35
+ int b, const char *fmt, ...);
36
+ int cmp_mem_at_loc (const char *file, int line, const void *got,
37
+ const void *expected, size_t n, const char *fmt, ...);
38
+ int bail_out (int ignore, const char *fmt, ...);
39
+ void tap_plan (int tests, const char *fmt, ...);
40
+ int diag (const char *fmt, ...);
41
+ int exit_status (void);
42
+ void tap_skip (int n, const char *fmt, ...);
43
+ void tap_todo (int ignore, const char *fmt, ...);
44
+ void tap_end_todo (void);
45
+
46
+ #define NO_PLAN -1
47
+ #define SKIP_ALL -2
48
+ #define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
49
+ #define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
50
+ #define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
51
+ #define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
52
+ #define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
53
+ #define plan(...) tap_plan(__VA_ARGS__, NULL)
54
+ #define done_testing() return exit_status()
55
+ #define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
56
+ #define pass(...) ok(1, "" __VA_ARGS__)
57
+ #define fail(...) ok(0, "" __VA_ARGS__)
58
+
59
+ #define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
60
+ #define end_skip } while (0)
61
+
62
+ #define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
63
+ #define end_todo tap_end_todo()
64
+
65
+ #define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
66
+ #define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
67
+
68
+ #ifdef _WIN32
69
+ #define like(...) tap_skip(1, "like is not implemented on Windows")
70
+ #define unlike tap_skip(1, "unlike is not implemented on Windows")
71
+ #define dies_ok_common(...) \
72
+ tap_skip(1, "Death detection is not supported on Windows")
73
+ #else
74
+ #define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
75
+ #define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
76
+ int like_at_loc (int for_match, const char *file, int line,
77
+ const char *got, const char *expected,
78
+ const char *fmt, ...);
79
+ #include <unistd.h>
80
+ #include <sys/types.h>
81
+ #include <sys/wait.h>
82
+ int tap_test_died (int status);
83
+ #define dies_ok_common(for_death, code, ...) \
84
+ do { \
85
+ int cpid; \
86
+ int it_died; \
87
+ tap_test_died(1); \
88
+ cpid = fork(); \
89
+ switch (cpid) { \
90
+ case -1: \
91
+ perror("fork error"); \
92
+ exit(1); \
93
+ case 0: \
94
+ close(1); \
95
+ close(2); \
96
+ code \
97
+ tap_test_died(0); \
98
+ exit(0); \
99
+ } \
100
+ if (waitpid(cpid, NULL, 0) < 0) { \
101
+ perror("waitpid error"); \
102
+ exit(1); \
103
+ } \
104
+ it_died = tap_test_died(0); \
105
+ if (!it_died) \
106
+ {code} \
107
+ ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
108
+ } while (0)
109
+ #endif
110
+
111
+ #ifdef __cplusplus
112
+ }
113
+ #endif
114
+
115
+ #endif
@@ -0,0 +1 @@
1
+ *.mmdb diff=mmdb
@@ -0,0 +1,2 @@
1
+ [diff "mmdb"]
2
+ textconv = hexdump -v -C
@@ -0,0 +1,2 @@
1
+ /_site
2
+ .tidyall.d
@@ -0,0 +1,11 @@
1
+ --blank-lines-before-packages=0
2
+ --iterations=2
3
+ --no-outdent-long-comments
4
+ -bar
5
+ -boc
6
+ -ci=4
7
+ -i=4
8
+ -l=78
9
+ -nolq
10
+ -se
11
+ -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
@@ -0,0 +1,7 @@
1
+ [PerlTidy]
2
+ select = **/*.{pl,pm,t,psgi}
3
+ ignore = blib/**/*
4
+ argv = --profile=$ROOT/.perltidyallrc
5
+
6
+ [JSON]
7
+ select = **/*.json
@@ -0,0 +1,4 @@
1
+ This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
2
+ Unported License. To view a copy of this license, visit
3
+ http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
4
+ Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.