ffi-hydrogen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +30 -0
  5. data/.travis.yml +10 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +72 -0
  9. data/Rakefile +46 -0
  10. data/bench/both.rb +86 -0
  11. data/bench/encode.rb +57 -0
  12. data/bench/encrypt.rb +80 -0
  13. data/bench/init.rb +5 -0
  14. data/bin/console +14 -0
  15. data/bin/setup +8 -0
  16. data/ffi-hydrogen.gemspec +31 -0
  17. data/lib/ffi/hydrogen.rb +216 -0
  18. data/vendor/.clang-format +2 -0
  19. data/vendor/.gitignore +3 -0
  20. data/vendor/README.md +2 -0
  21. data/vendor/libhydrogen/.clang-format +95 -0
  22. data/vendor/libhydrogen/.gitignore +32 -0
  23. data/vendor/libhydrogen/.travis.yml +22 -0
  24. data/vendor/libhydrogen/LICENSE +18 -0
  25. data/vendor/libhydrogen/Makefile +61 -0
  26. data/vendor/libhydrogen/Makefile.arduino +51 -0
  27. data/vendor/libhydrogen/README.md +29 -0
  28. data/vendor/libhydrogen/hydrogen.c +18 -0
  29. data/vendor/libhydrogen/hydrogen.h +317 -0
  30. data/vendor/libhydrogen/impl/common.h +316 -0
  31. data/vendor/libhydrogen/impl/core.h +220 -0
  32. data/vendor/libhydrogen/impl/gimli-core/portable.h +39 -0
  33. data/vendor/libhydrogen/impl/gimli-core/sse2.h +97 -0
  34. data/vendor/libhydrogen/impl/gimli-core.h +25 -0
  35. data/vendor/libhydrogen/impl/hash.h +138 -0
  36. data/vendor/libhydrogen/impl/hydrogen_p.h +83 -0
  37. data/vendor/libhydrogen/impl/kdf.h +20 -0
  38. data/vendor/libhydrogen/impl/kx.h +441 -0
  39. data/vendor/libhydrogen/impl/pwhash.h +281 -0
  40. data/vendor/libhydrogen/impl/random.h +376 -0
  41. data/vendor/libhydrogen/impl/secretbox.h +236 -0
  42. data/vendor/libhydrogen/impl/sign.h +207 -0
  43. data/vendor/libhydrogen/impl/x25519.h +383 -0
  44. data/vendor/libhydrogen/library.properties +10 -0
  45. data/vendor/libhydrogen/logo.png +0 -0
  46. data/vendor/libhydrogen/tests/tests.c +431 -0
  47. data/vendor/main.c +140 -0
  48. data/vendor/stringencoders/.gitignore +25 -0
  49. data/vendor/stringencoders/.travis.yml +13 -0
  50. data/vendor/stringencoders/AUTHORS +1 -0
  51. data/vendor/stringencoders/COPYING +2 -0
  52. data/vendor/stringencoders/ChangeLog +170 -0
  53. data/vendor/stringencoders/Doxyfile +276 -0
  54. data/vendor/stringencoders/INSTALL +119 -0
  55. data/vendor/stringencoders/LICENSE +22 -0
  56. data/vendor/stringencoders/Makefile.am +3 -0
  57. data/vendor/stringencoders/NEWS +3 -0
  58. data/vendor/stringencoders/README +2 -0
  59. data/vendor/stringencoders/README.md +32 -0
  60. data/vendor/stringencoders/bootstrap.sh +3 -0
  61. data/vendor/stringencoders/configure-gcc-hardened.sh +16 -0
  62. data/vendor/stringencoders/configure.ac +44 -0
  63. data/vendor/stringencoders/doxy/footer.html +34 -0
  64. data/vendor/stringencoders/doxy/header.html +85 -0
  65. data/vendor/stringencoders/indent.sh +9 -0
  66. data/vendor/stringencoders/javascript/base64-speed.html +43 -0
  67. data/vendor/stringencoders/javascript/base64-test.html +209 -0
  68. data/vendor/stringencoders/javascript/base64.html +18 -0
  69. data/vendor/stringencoders/javascript/base64.js +176 -0
  70. data/vendor/stringencoders/javascript/qunit.css +119 -0
  71. data/vendor/stringencoders/javascript/qunit.js +1062 -0
  72. data/vendor/stringencoders/javascript/urlparse-test.html +367 -0
  73. data/vendor/stringencoders/javascript/urlparse.js +328 -0
  74. data/vendor/stringencoders/make-ci.sh +13 -0
  75. data/vendor/stringencoders/makerelease.sh +16 -0
  76. data/vendor/stringencoders/python/b85.py +176 -0
  77. data/vendor/stringencoders/src/Makefile.am +134 -0
  78. data/vendor/stringencoders/src/arraytoc.c +85 -0
  79. data/vendor/stringencoders/src/arraytoc.h +43 -0
  80. data/vendor/stringencoders/src/extern_c_begin.h +3 -0
  81. data/vendor/stringencoders/src/extern_c_end.h +3 -0
  82. data/vendor/stringencoders/src/html_named_entities_generator.py +203 -0
  83. data/vendor/stringencoders/src/modp_ascii.c +159 -0
  84. data/vendor/stringencoders/src/modp_ascii.h +162 -0
  85. data/vendor/stringencoders/src/modp_ascii_data.h +84 -0
  86. data/vendor/stringencoders/src/modp_ascii_gen.c +55 -0
  87. data/vendor/stringencoders/src/modp_b16.c +125 -0
  88. data/vendor/stringencoders/src/modp_b16.h +148 -0
  89. data/vendor/stringencoders/src/modp_b16_data.h +104 -0
  90. data/vendor/stringencoders/src/modp_b16_gen.c +65 -0
  91. data/vendor/stringencoders/src/modp_b2.c +69 -0
  92. data/vendor/stringencoders/src/modp_b2.h +130 -0
  93. data/vendor/stringencoders/src/modp_b2_data.h +44 -0
  94. data/vendor/stringencoders/src/modp_b2_gen.c +36 -0
  95. data/vendor/stringencoders/src/modp_b36.c +108 -0
  96. data/vendor/stringencoders/src/modp_b36.h +170 -0
  97. data/vendor/stringencoders/src/modp_b64.c +254 -0
  98. data/vendor/stringencoders/src/modp_b64.h +236 -0
  99. data/vendor/stringencoders/src/modp_b64_data.h +477 -0
  100. data/vendor/stringencoders/src/modp_b64_gen.c +168 -0
  101. data/vendor/stringencoders/src/modp_b64r.c +254 -0
  102. data/vendor/stringencoders/src/modp_b64r.h +242 -0
  103. data/vendor/stringencoders/src/modp_b64r_data.h +477 -0
  104. data/vendor/stringencoders/src/modp_b64w.c +254 -0
  105. data/vendor/stringencoders/src/modp_b64w.h +231 -0
  106. data/vendor/stringencoders/src/modp_b64w_data.h +477 -0
  107. data/vendor/stringencoders/src/modp_b85.c +109 -0
  108. data/vendor/stringencoders/src/modp_b85.h +171 -0
  109. data/vendor/stringencoders/src/modp_b85_data.h +36 -0
  110. data/vendor/stringencoders/src/modp_b85_gen.c +65 -0
  111. data/vendor/stringencoders/src/modp_bjavascript.c +65 -0
  112. data/vendor/stringencoders/src/modp_bjavascript.h +105 -0
  113. data/vendor/stringencoders/src/modp_bjavascript_data.h +84 -0
  114. data/vendor/stringencoders/src/modp_bjavascript_gen.c +58 -0
  115. data/vendor/stringencoders/src/modp_burl.c +228 -0
  116. data/vendor/stringencoders/src/modp_burl.h +259 -0
  117. data/vendor/stringencoders/src/modp_burl_data.h +136 -0
  118. data/vendor/stringencoders/src/modp_burl_gen.c +121 -0
  119. data/vendor/stringencoders/src/modp_html.c +128 -0
  120. data/vendor/stringencoders/src/modp_html.h +53 -0
  121. data/vendor/stringencoders/src/modp_html_named_entities.h +9910 -0
  122. data/vendor/stringencoders/src/modp_json.c +315 -0
  123. data/vendor/stringencoders/src/modp_json.h +103 -0
  124. data/vendor/stringencoders/src/modp_json_data.h +57 -0
  125. data/vendor/stringencoders/src/modp_json_gen.py +60 -0
  126. data/vendor/stringencoders/src/modp_mainpage.h +120 -0
  127. data/vendor/stringencoders/src/modp_numtoa.c +350 -0
  128. data/vendor/stringencoders/src/modp_numtoa.h +100 -0
  129. data/vendor/stringencoders/src/modp_qsiter.c +76 -0
  130. data/vendor/stringencoders/src/modp_qsiter.h +71 -0
  131. data/vendor/stringencoders/src/modp_stdint.h +43 -0
  132. data/vendor/stringencoders/src/modp_utf8.c +88 -0
  133. data/vendor/stringencoders/src/modp_utf8.h +38 -0
  134. data/vendor/stringencoders/src/modp_xml.c +311 -0
  135. data/vendor/stringencoders/src/modp_xml.h +166 -0
  136. data/vendor/stringencoders/src/stringencoders.pc +10 -0
  137. data/vendor/stringencoders/src/stringencoders.pc.in +10 -0
  138. data/vendor/stringencoders/test/Makefile.am +113 -0
  139. data/vendor/stringencoders/test/apr_base64.c +262 -0
  140. data/vendor/stringencoders/test/apr_base64.h +120 -0
  141. data/vendor/stringencoders/test/cxx_test.cc +482 -0
  142. data/vendor/stringencoders/test/minunit.h +82 -0
  143. data/vendor/stringencoders/test/modp_ascii_test.c +281 -0
  144. data/vendor/stringencoders/test/modp_b16_test.c +288 -0
  145. data/vendor/stringencoders/test/modp_b2_test.c +250 -0
  146. data/vendor/stringencoders/test/modp_b64_test.c +266 -0
  147. data/vendor/stringencoders/test/modp_b85_test.c +130 -0
  148. data/vendor/stringencoders/test/modp_bjavascript_test.c +137 -0
  149. data/vendor/stringencoders/test/modp_burl_test.c +423 -0
  150. data/vendor/stringencoders/test/modp_html_test.c +296 -0
  151. data/vendor/stringencoders/test/modp_json_test.c +336 -0
  152. data/vendor/stringencoders/test/modp_numtoa_test.c +545 -0
  153. data/vendor/stringencoders/test/modp_qsiter_test.c +280 -0
  154. data/vendor/stringencoders/test/modp_utf8_test.c +188 -0
  155. data/vendor/stringencoders/test/modp_xml_test.c +339 -0
  156. data/vendor/stringencoders/test/speedtest.c +241 -0
  157. data/vendor/stringencoders/test/speedtest_ascii.c +345 -0
  158. data/vendor/stringencoders/test/speedtest_msg.c +78 -0
  159. data/vendor/stringencoders/test/speedtest_numtoa.c +276 -0
  160. metadata +314 -0
@@ -0,0 +1,482 @@
1
+ /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2
+ /* vi: set expandtab shiftwidth=4 tabstop=4: */
3
+
4
+ #include <cstdlib>
5
+ #include <string>
6
+ using std::string;
7
+
8
+ #include <iostream>
9
+ using std::cerr;
10
+
11
+ #include "modp_b2.h"
12
+ #include "modp_b16.h"
13
+ #include "modp_b85.h"
14
+ #include "modp_b64.h"
15
+ #include "modp_b64w.h"
16
+ #include "modp_burl.h"
17
+ #include "modp_bjavascript.h"
18
+ #include "modp_ascii.h"
19
+
20
+ using namespace modp;
21
+
22
+ #define WHERE(A) A << "[" << __FILE__ << ":" << __LINE__ << "] "
23
+
24
+ static void test_b2()
25
+ {
26
+ string orig("this is a test");
27
+ string s(orig);
28
+ b2_encode(s);
29
+ b2_decode(s);
30
+ if (s != orig) {
31
+ WHERE(cerr) << "Expected " << orig << ", received " << s << "\n";
32
+ exit(1);
33
+ }
34
+
35
+ s = "1";
36
+ b2_decode(s);
37
+ if (!s.empty()) {
38
+ WHERE(cerr) << "Expected decode to be empty\n";
39
+ exit(1);
40
+ }
41
+ }
42
+
43
+ static void test_b2_const()
44
+ {
45
+ const string orig("this is a test");
46
+ const string s(b2_encode(orig));
47
+ string result = b2_decode(s);
48
+ if (result != orig) {
49
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
50
+ exit(1);
51
+ }
52
+
53
+ const string badstr("1");
54
+ result = b2_decode(badstr);
55
+ if (!result.empty()) {
56
+ WHERE(cerr) << "Expected decode to be empty\n";
57
+ exit(1);
58
+ }
59
+ }
60
+
61
+ static void test_b16()
62
+ {
63
+ string orig("this is a test");
64
+ string expected("7468697320697320612074657374");
65
+ string s(orig);
66
+ b16_encode(s);
67
+ if (s.size() != expected.size()) {
68
+ WHERE(cerr) << "Bad Size. Expected " << expected.size() << ", received " << s.size() << "\n";
69
+ exit(1);
70
+ }
71
+ if (s != expected) {
72
+ WHERE(cerr) << "Expected " << expected << ", received " << s << "\n";
73
+ exit(1);
74
+ }
75
+ b16_decode(s);
76
+ if (s != orig) {
77
+ WHERE(cerr) << "Expected " << orig << ", received '" << s << "'\n";
78
+ exit(1);
79
+ }
80
+
81
+ // test bad input
82
+ s = "1";
83
+ b16_decode(s);
84
+ if (!s.empty()) {
85
+ WHERE(cerr) << "Expected decode to be empty\n";
86
+ exit(1);
87
+ }
88
+ }
89
+
90
+ static void test_b16_const()
91
+ {
92
+ const string orig("this is a test");
93
+ const string s(b16_encode(orig));
94
+ string result = b16_decode(s);
95
+ if (result != orig) {
96
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
97
+ exit(1);
98
+ }
99
+
100
+ // test bad input
101
+ const string badstr("1");
102
+ result = b16_decode(badstr);
103
+ if (!result.empty()) {
104
+ WHERE(cerr) << "Expected decode to be empty\n";
105
+ exit(1);
106
+ }
107
+ }
108
+
109
+ static void test_b64()
110
+ {
111
+ string orig("this is a test");
112
+ string s(orig);
113
+ b64_encode(s);
114
+ if (s == orig) {
115
+ WHERE(cerr) << "something wrong\n";
116
+ exit(1);
117
+ }
118
+
119
+ b64_decode(s);
120
+ if (s != orig) {
121
+ WHERE(cerr) << "Expected " << orig << ", received " << s << "\n";
122
+ exit(1);
123
+ }
124
+
125
+ // test bad decode length
126
+ s = "a";
127
+ b64_decode(s);
128
+ if (!s.empty()) {
129
+ WHERE(cerr) << "Expected decode output to be empty\n";
130
+ exit(1);
131
+ }
132
+ }
133
+
134
+ static void test_b64w()
135
+ {
136
+ string orig("this is a test");
137
+ string s(orig);
138
+ b64w_encode(s);
139
+ if (s == orig) {
140
+ WHERE(cerr) << "something wrong\n";
141
+ exit(1);
142
+ }
143
+
144
+ b64w_decode(s);
145
+ if (s != orig) {
146
+ WHERE(cerr) << "Expected " << orig << ", received " << s << "\n";
147
+ exit(1);
148
+ }
149
+
150
+ // test bad decode length
151
+ s = "a";
152
+ b64w_decode(s);
153
+ if (!s.empty()) {
154
+ WHERE(cerr) << "Expected decode output to be empty\n";
155
+ exit(1);
156
+ }
157
+ }
158
+
159
+ static void test_b64_const()
160
+ {
161
+ const string orig("this is a test");
162
+ const string s(b64_encode(orig));
163
+ string result = b64_decode(s);
164
+ if (result != orig) {
165
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
166
+ exit(1);
167
+ }
168
+
169
+ const string badstr("a");
170
+ result = b64_decode(badstr);
171
+ if (!result.empty()) {
172
+ WHERE(cerr) << "Expected decode output to be empty\n";
173
+ exit(1);
174
+ }
175
+ }
176
+
177
+ static void test_b64w_const()
178
+ {
179
+ const string orig("this is a test");
180
+ const string s(b64w_encode(orig));
181
+ string result = b64w_decode(s);
182
+ if (result != orig) {
183
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
184
+ exit(1);
185
+ }
186
+
187
+ const string badstr("a");
188
+ result = b64w_decode(badstr);
189
+ if (!result.empty()) {
190
+ WHERE(cerr) << "Expected decode output to be empty\n";
191
+ exit(1);
192
+ }
193
+ }
194
+
195
+ static void test_b64_cstr()
196
+ {
197
+ const char* orig = "this is a test";
198
+ const string s(b64_encode(orig));
199
+ string result = b64_decode(s);
200
+
201
+ if (result != orig) {
202
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
203
+ exit(1);
204
+ }
205
+ result = b64_decode(s.data(), s.size());
206
+ if (result != orig) {
207
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
208
+ exit(1);
209
+ }
210
+ result = b64_decode(s.c_str());
211
+ if (result != orig) {
212
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
213
+ exit(1);
214
+ }
215
+ }
216
+
217
+ static void test_b64w_cstr()
218
+ {
219
+ const char* orig = "this is a test";
220
+ const string s(b64w_encode(orig));
221
+ string result = b64w_decode(s);
222
+
223
+ if (result != orig) {
224
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
225
+ exit(1);
226
+ }
227
+ result = b64w_decode(s.data(), s.size());
228
+ if (result != orig) {
229
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
230
+ exit(1);
231
+ }
232
+ result = b64w_decode(s.c_str());
233
+ if (result != orig) {
234
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
235
+ exit(1);
236
+ }
237
+ }
238
+ static void test_b85()
239
+ {
240
+ // must be multiple of 4
241
+ string orig("this is a test!!");
242
+ string s(orig);
243
+ b85_encode(s);
244
+ if (s == orig) {
245
+ WHERE(cerr) << "something wrong\n";
246
+ exit(1);
247
+ }
248
+ b85_decode(s);
249
+ if (s != orig) {
250
+ WHERE(cerr) << "Expected " << orig << ", received " << s << "\n";
251
+ exit(1);
252
+ }
253
+
254
+ // test non-multiple for decode
255
+ string badstr;
256
+
257
+ badstr = "abcd";
258
+ b85_decode(badstr);
259
+ if (!badstr.empty()) {
260
+ WHERE(cerr) << "Expected decode output to be empty\n";
261
+ exit(1);
262
+ }
263
+
264
+ badstr = "abcdef";
265
+ b85_encode(badstr);
266
+ if (!badstr.empty()) {
267
+ WHERE(cerr) << "Expected encode output to be empty\n";
268
+ exit(1);
269
+ }
270
+ }
271
+
272
+ static void test_b85_const()
273
+ {
274
+ const string orig("this is a test!!"); // must be multiple of 4
275
+ const string s(b85_encode(orig));
276
+ string result = b85_decode(s);
277
+ if (result != orig) {
278
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
279
+ exit(1);
280
+ }
281
+
282
+ const string badstr("abcdef");
283
+ result = b85_encode(badstr);
284
+ if (!result.empty()) {
285
+ WHERE(cerr) << "Expected " << orig << ", received " << result << "\n";
286
+ exit(1);
287
+ }
288
+ }
289
+
290
+ static void test_url()
291
+ {
292
+ string orig("this is a test");
293
+ string expected("this+is+a+test");
294
+ string s(orig);
295
+ url_encode(s);
296
+ if (s != expected) {
297
+ WHERE(cerr) << "Expected " << expected << ", received " << s << "\n";
298
+ exit(1);
299
+ }
300
+
301
+ url_decode(s);
302
+ if (s != orig) {
303
+ WHERE(cerr) << "Expected " << orig << ", received " << s << "\n";
304
+ exit(1);
305
+ }
306
+
307
+ s = "bad\n";
308
+ url_decode(s);
309
+ if (s.empty()) {
310
+ WHERE(cerr) << "Expected empty decode\n";
311
+ exit(1);
312
+ }
313
+
314
+ }
315
+
316
+ static void test_url_const()
317
+ {
318
+ const string orig("this is a test");
319
+ const string expected("this+is+a+test");
320
+ const string s1(url_encode(orig));
321
+ if (s1 != expected) {
322
+ WHERE(cerr) << "Expected " << expected << ", received " << s1 << "\n";
323
+ exit(1);
324
+ }
325
+
326
+ const string s2(url_decode(s1));
327
+ if (s2 != orig) {
328
+ WHERE(cerr) << "Expected " << orig << ", received " << s2 << "\n";
329
+ exit(1);
330
+ }
331
+
332
+ const string s3("bad\n");
333
+ const string r3(url_decode(s3));
334
+ if (r3.empty()) {
335
+ WHERE(cerr) << "Expected empty decode\n";
336
+ exit(1);
337
+ }
338
+ }
339
+
340
+ static void test_url_cstr()
341
+ {
342
+ const char* data = "this+is+a%20test";
343
+ const string expected("this is a test");
344
+
345
+ const string s1(url_decode(data));
346
+ if (s1 != expected) {
347
+ WHERE(cerr) << "Expected " << expected << ", received " << s1 << "\n";
348
+ exit(1);
349
+ }
350
+
351
+ const string s2(url_decode(data, strlen(data)));
352
+ if (s2 != expected) {
353
+ WHERE(cerr) << "Expected " << expected << ", received " << s2 << "\n";
354
+ exit(1);
355
+ }
356
+ }
357
+
358
+ static void test_javascript()
359
+ {
360
+ string orig("this \"is\' a test\n");
361
+ string expected("this \\\"is\\' a test\\n");
362
+ javascript_encode(orig);
363
+ if (orig != expected) {
364
+ WHERE(cerr) << "Expected: " << expected << "Received: " << orig << "\n";
365
+ exit(1);
366
+ }
367
+ }
368
+ static void test_javascript_const()
369
+ {
370
+ const string orig("this \"is\' a test\n");
371
+ const string expected("this \\\"is\\' a test\\n");
372
+ string result = javascript_encode(orig);
373
+ if (result != expected) {
374
+ WHERE(cerr) << "Expected: " << expected << "Received: " << result << "\n";
375
+ exit(1);
376
+ }
377
+ }
378
+
379
+ static void test_ascii_inline()
380
+ {
381
+ string orig;
382
+
383
+ orig = "abcd123";
384
+ toupper(orig);
385
+ if (orig != "ABCD123") {
386
+ WHERE(cerr) << "to upper failed: " << orig << " (size=" << orig.size() << ")\n";
387
+ exit(1);
388
+ }
389
+
390
+ orig = "ABCD123";
391
+ tolower(orig);
392
+ if (orig != "abcd123") {
393
+ WHERE(cerr) << "to lower failed: " << orig << " (size=" << orig.size() << ")\n";
394
+ exit(1);
395
+ }
396
+
397
+ orig = "ABCD\n123";
398
+ toprint(orig);
399
+ if (orig != "ABCD?123") {
400
+ WHERE(cerr) << "to print failed: " << orig << " (size=" << orig.size() << ")\n";
401
+ exit(1);
402
+ }
403
+ }
404
+
405
+ static void test_ascii_copy()
406
+ {
407
+
408
+ /**
409
+ * Test of toupper
410
+ */
411
+ const char* orig_c = "abcd123";
412
+ const string orig(orig_c);
413
+
414
+ string news(toupper(orig));
415
+ if (news != "ABCD123") {
416
+ WHERE(cerr) << "toupper copy failed: got " << news << " (size=" << news.size() << ")\n";
417
+ exit(1);
418
+ }
419
+ if (orig != orig_c) {
420
+ WHERE(cerr) << "toupper copy modified original string! Got: " << orig << ", expected " << orig_c << "\n";
421
+ exit(1);
422
+ }
423
+
424
+
425
+ /**
426
+ * Test of tolower
427
+ */
428
+ const char* orig2_c = "ABCD123";
429
+ const string orig2(orig2_c);
430
+
431
+ string news2(tolower(orig2));
432
+ if (news2 != "abcd123") {
433
+ WHERE(cerr) << "tolower copy failed: " << news2 << " (size=" << news2.size() << ")\n";
434
+ exit(1);
435
+ }
436
+ if (orig2 != orig2_c) {
437
+ WHERE(cerr) << "tolower copy modified original string! Got: " << orig2 << ", expected " << orig2_c << "\n";
438
+ exit(1);
439
+ }
440
+
441
+ /**
442
+ * Test of toprint
443
+ */
444
+ const char* orig3_c= "ABCD\n123";
445
+ const string orig3(orig3_c);
446
+
447
+ string news3(toprint(orig3));
448
+ if (news3 != "ABCD?123") {
449
+ WHERE(cerr) << "toprint copy failed: " << orig3 << " (size=" << orig3.size() << ")\n";
450
+ exit(1);
451
+ }
452
+ if (orig3 != orig3_c) {
453
+ WHERE(cerr) << "toprint copy modified original string! Got: " << orig3 << ", expected " << orig3_c << "\n";
454
+ exit(1);
455
+ }
456
+
457
+ }
458
+
459
+ int main()
460
+ {
461
+ test_b2();
462
+ test_b2_const();
463
+ test_b16();
464
+ test_b16_const();
465
+ test_b64();
466
+ test_b64_const();
467
+ test_b64_cstr();
468
+ test_b64w();
469
+ test_b64w_const();
470
+ test_b64w_cstr();
471
+ test_b85();
472
+ test_b85_const();
473
+ test_url();
474
+ test_url_const();
475
+ test_url_cstr();
476
+ test_javascript();
477
+ test_javascript_const();
478
+ test_ascii_inline();
479
+ test_ascii_copy();
480
+
481
+ return 0;
482
+ }
@@ -0,0 +1,82 @@
1
+
2
+ #ifndef MINUNIT_H
3
+ #define MINUNIT_H
4
+
5
+ /* http://www.jera.com/techinfo/jtns/jtn002.html */
6
+
7
+ #define mu_assert(test) \
8
+ do { \
9
+ if (!(test)) { \
10
+ snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s:%d", __FILE__, __LINE__); \
11
+ return mu_buf; \
12
+ } \
13
+ } while (0)
14
+
15
+ #define mu_assert_msg(msg, test) \
16
+ do { \
17
+ if (!(test)) { \
18
+ snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s %s:%d", msg, __FILE__, __LINE__); \
19
+ return mu_buf; \
20
+ } \
21
+ } while (0)
22
+
23
+ #define mu_assert_int_equals(lhs, rhs) \
24
+ do { \
25
+ if ((int)lhs != (int)rhs) { \
26
+ snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s:%d", __FILE__, __LINE__); \
27
+ return mu_buf; \
28
+ } \
29
+ } while (0)
30
+
31
+ #define mu_assert_str_equals(lhs, rhs) \
32
+ do { \
33
+ if (strcmp(lhs, rhs) != 0) { \
34
+ snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s:%d %s != %s", __FILE__, __LINE__, lhs, rhs); \
35
+ return mu_buf; \
36
+ } \
37
+ } while (0)
38
+
39
+ #define mu_assert_str_equals_msg(msg, lhs, rhs) \
40
+ do { \
41
+ if (strcmp(lhs, rhs) != 0) { \
42
+ snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s %s:%d %s != %s", msg, __FILE__, __LINE__, lhs, rhs); \
43
+ return mu_buf; \
44
+ } \
45
+ } while (0)
46
+
47
+ #define mu_assert_int_equals_msg(msg, lhs, rhs) \
48
+ do { \
49
+ if (lhs != rhs) { \
50
+ snprintf(mu_buf, sizeof(mu_buf), "ASSERTION FAILED: %s %s:%d", msg, __FILE__, __LINE__); \
51
+ return mu_buf; \
52
+ } \
53
+ } while (0)
54
+
55
+ #define mu_run_test(test) \
56
+ do { \
57
+ printf("."); \
58
+ fflush(stdout); \
59
+ char* message = test(); \
60
+ tests_run++; \
61
+ if (message) \
62
+ return message; \
63
+ } while (0)
64
+
65
+ #define UNITTESTS \
66
+ int main(void) \
67
+ { \
68
+ printf("%s ", __FILE__); \
69
+ fflush(stdout); \
70
+ char* result = all_tests(); \
71
+ if (result != 0) { \
72
+ printf("%s\n", result); \
73
+ } else { \
74
+ printf("OK (%d tests)\n", tests_run); \
75
+ } \
76
+ return result != 0; \
77
+ }
78
+
79
+ static int tests_run = 0;
80
+ static char mu_buf[1024];
81
+
82
+ #endif