test_containers.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2013, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #include "orconfig.h"
  6. #include "or.h"
  7. #include "fp_pair.h"
  8. #include "test.h"
  9. /** Helper: return a tristate based on comparing the strings in *<b>a</b> and
  10. * *<b>b</b>. */
  11. static int
  12. compare_strs_(const void **a, const void **b)
  13. {
  14. const char *s1 = *a, *s2 = *b;
  15. return strcmp(s1, s2);
  16. }
  17. /** Helper: return a tristate based on comparing the strings in <b>a</b> and
  18. * *<b>b</b>. */
  19. static int
  20. compare_strs_for_bsearch_(const void *a, const void **b)
  21. {
  22. const char *s1 = a, *s2 = *b;
  23. return strcmp(s1, s2);
  24. }
  25. /** Helper: return a tristate based on comparing the strings in *<b>a</b> and
  26. * *<b>b</b>, excluding a's first character, and ignoring case. */
  27. static int
  28. compare_without_first_ch_(const void *a, const void **b)
  29. {
  30. const char *s1 = a, *s2 = *b;
  31. return strcasecmp(s1+1, s2);
  32. }
  33. /** Run unit tests for basic dynamic-sized array functionality. */
  34. static void
  35. test_container_smartlist_basic(void)
  36. {
  37. smartlist_t *sl;
  38. char *v0 = tor_strdup("v0");
  39. char *v1 = tor_strdup("v1");
  40. char *v2 = tor_strdup("v2");
  41. char *v3 = tor_strdup("v3");
  42. char *v4 = tor_strdup("v4");
  43. char *v22 = tor_strdup("v22");
  44. char *v99 = tor_strdup("v99");
  45. char *v555 = tor_strdup("v555");
  46. /* XXXX test sort_digests, uniq_strings, uniq_digests */
  47. /* Test smartlist add, del_keeporder, insert, get. */
  48. sl = smartlist_new();
  49. smartlist_add(sl, v1);
  50. smartlist_add(sl, v2);
  51. smartlist_add(sl, v3);
  52. smartlist_add(sl, v4);
  53. smartlist_del_keeporder(sl, 1);
  54. smartlist_insert(sl, 1, v22);
  55. smartlist_insert(sl, 0, v0);
  56. smartlist_insert(sl, 5, v555);
  57. test_eq_ptr(v0, smartlist_get(sl,0));
  58. test_eq_ptr(v1, smartlist_get(sl,1));
  59. test_eq_ptr(v22, smartlist_get(sl,2));
  60. test_eq_ptr(v3, smartlist_get(sl,3));
  61. test_eq_ptr(v4, smartlist_get(sl,4));
  62. test_eq_ptr(v555, smartlist_get(sl,5));
  63. /* Try deleting in the middle. */
  64. smartlist_del(sl, 1);
  65. test_eq_ptr(v555, smartlist_get(sl, 1));
  66. /* Try deleting at the end. */
  67. smartlist_del(sl, 4);
  68. test_eq(4, smartlist_len(sl));
  69. /* test isin. */
  70. test_assert(smartlist_contains(sl, v3));
  71. test_assert(!smartlist_contains(sl, v99));
  72. done:
  73. smartlist_free(sl);
  74. tor_free(v0);
  75. tor_free(v1);
  76. tor_free(v2);
  77. tor_free(v3);
  78. tor_free(v4);
  79. tor_free(v22);
  80. tor_free(v99);
  81. tor_free(v555);
  82. }
  83. /** Run unit tests for smartlist-of-strings functionality. */
  84. static void
  85. test_container_smartlist_strings(void)
  86. {
  87. smartlist_t *sl = smartlist_new();
  88. char *cp=NULL, *cp_alloc=NULL;
  89. size_t sz;
  90. /* Test split and join */
  91. test_eq(0, smartlist_len(sl));
  92. smartlist_split_string(sl, "abc", ":", 0, 0);
  93. test_eq(1, smartlist_len(sl));
  94. test_streq("abc", smartlist_get(sl, 0));
  95. smartlist_split_string(sl, "a::bc::", "::", 0, 0);
  96. test_eq(4, smartlist_len(sl));
  97. test_streq("a", smartlist_get(sl, 1));
  98. test_streq("bc", smartlist_get(sl, 2));
  99. test_streq("", smartlist_get(sl, 3));
  100. cp_alloc = smartlist_join_strings(sl, "", 0, NULL);
  101. test_streq(cp_alloc, "abcabc");
  102. tor_free(cp_alloc);
  103. cp_alloc = smartlist_join_strings(sl, "!", 0, NULL);
  104. test_streq(cp_alloc, "abc!a!bc!");
  105. tor_free(cp_alloc);
  106. cp_alloc = smartlist_join_strings(sl, "XY", 0, NULL);
  107. test_streq(cp_alloc, "abcXYaXYbcXY");
  108. tor_free(cp_alloc);
  109. cp_alloc = smartlist_join_strings(sl, "XY", 1, NULL);
  110. test_streq(cp_alloc, "abcXYaXYbcXYXY");
  111. tor_free(cp_alloc);
  112. cp_alloc = smartlist_join_strings(sl, "", 1, NULL);
  113. test_streq(cp_alloc, "abcabc");
  114. tor_free(cp_alloc);
  115. smartlist_split_string(sl, "/def/ /ghijk", "/", 0, 0);
  116. test_eq(8, smartlist_len(sl));
  117. test_streq("", smartlist_get(sl, 4));
  118. test_streq("def", smartlist_get(sl, 5));
  119. test_streq(" ", smartlist_get(sl, 6));
  120. test_streq("ghijk", smartlist_get(sl, 7));
  121. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  122. smartlist_clear(sl);
  123. smartlist_split_string(sl, "a,bbd,cdef", ",", SPLIT_SKIP_SPACE, 0);
  124. test_eq(3, smartlist_len(sl));
  125. test_streq("a", smartlist_get(sl,0));
  126. test_streq("bbd", smartlist_get(sl,1));
  127. test_streq("cdef", smartlist_get(sl,2));
  128. smartlist_split_string(sl, " z <> zhasd <> <> bnud<> ", "<>",
  129. SPLIT_SKIP_SPACE, 0);
  130. test_eq(8, smartlist_len(sl));
  131. test_streq("z", smartlist_get(sl,3));
  132. test_streq("zhasd", smartlist_get(sl,4));
  133. test_streq("", smartlist_get(sl,5));
  134. test_streq("bnud", smartlist_get(sl,6));
  135. test_streq("", smartlist_get(sl,7));
  136. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  137. smartlist_clear(sl);
  138. smartlist_split_string(sl, " ab\tc \td ef ", NULL,
  139. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  140. test_eq(4, smartlist_len(sl));
  141. test_streq("ab", smartlist_get(sl,0));
  142. test_streq("c", smartlist_get(sl,1));
  143. test_streq("d", smartlist_get(sl,2));
  144. test_streq("ef", smartlist_get(sl,3));
  145. smartlist_split_string(sl, "ghi\tj", NULL,
  146. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  147. test_eq(6, smartlist_len(sl));
  148. test_streq("ghi", smartlist_get(sl,4));
  149. test_streq("j", smartlist_get(sl,5));
  150. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  151. smartlist_clear(sl);
  152. cp_alloc = smartlist_join_strings(sl, "XY", 0, NULL);
  153. test_streq(cp_alloc, "");
  154. tor_free(cp_alloc);
  155. cp_alloc = smartlist_join_strings(sl, "XY", 1, NULL);
  156. test_streq(cp_alloc, "XY");
  157. tor_free(cp_alloc);
  158. smartlist_split_string(sl, " z <> zhasd <> <> bnud<> ", "<>",
  159. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  160. test_eq(3, smartlist_len(sl));
  161. test_streq("z", smartlist_get(sl, 0));
  162. test_streq("zhasd", smartlist_get(sl, 1));
  163. test_streq("bnud", smartlist_get(sl, 2));
  164. smartlist_split_string(sl, " z <> zhasd <> <> bnud<> ", "<>",
  165. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
  166. test_eq(5, smartlist_len(sl));
  167. test_streq("z", smartlist_get(sl, 3));
  168. test_streq("zhasd <> <> bnud<>", smartlist_get(sl, 4));
  169. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  170. smartlist_clear(sl);
  171. smartlist_split_string(sl, "abcd\n", "\n",
  172. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  173. test_eq(1, smartlist_len(sl));
  174. test_streq("abcd", smartlist_get(sl, 0));
  175. smartlist_split_string(sl, "efgh", "\n",
  176. SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  177. test_eq(2, smartlist_len(sl));
  178. test_streq("efgh", smartlist_get(sl, 1));
  179. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  180. smartlist_clear(sl);
  181. /* Test swapping, shuffling, and sorting. */
  182. smartlist_split_string(sl, "the,onion,router,by,arma,and,nickm", ",", 0, 0);
  183. test_eq(7, smartlist_len(sl));
  184. smartlist_sort(sl, compare_strs_);
  185. cp_alloc = smartlist_join_strings(sl, ",", 0, NULL);
  186. test_streq(cp_alloc,"and,arma,by,nickm,onion,router,the");
  187. tor_free(cp_alloc);
  188. smartlist_swap(sl, 1, 5);
  189. cp_alloc = smartlist_join_strings(sl, ",", 0, NULL);
  190. test_streq(cp_alloc,"and,router,by,nickm,onion,arma,the");
  191. tor_free(cp_alloc);
  192. smartlist_shuffle(sl);
  193. test_eq(7, smartlist_len(sl));
  194. test_assert(smartlist_contains_string(sl, "and"));
  195. test_assert(smartlist_contains_string(sl, "router"));
  196. test_assert(smartlist_contains_string(sl, "by"));
  197. test_assert(smartlist_contains_string(sl, "nickm"));
  198. test_assert(smartlist_contains_string(sl, "onion"));
  199. test_assert(smartlist_contains_string(sl, "arma"));
  200. test_assert(smartlist_contains_string(sl, "the"));
  201. /* Test bsearch. */
  202. smartlist_sort(sl, compare_strs_);
  203. test_streq("nickm", smartlist_bsearch(sl, "zNicKM",
  204. compare_without_first_ch_));
  205. test_streq("and", smartlist_bsearch(sl, " AND", compare_without_first_ch_));
  206. test_eq_ptr(NULL, smartlist_bsearch(sl, " ANz", compare_without_first_ch_));
  207. /* Test bsearch_idx */
  208. {
  209. int f;
  210. smartlist_t *tmp = NULL;
  211. test_eq(0, smartlist_bsearch_idx(sl," aaa",compare_without_first_ch_,&f));
  212. test_eq(f, 0);
  213. test_eq(0, smartlist_bsearch_idx(sl," and",compare_without_first_ch_,&f));
  214. test_eq(f, 1);
  215. test_eq(1, smartlist_bsearch_idx(sl," arm",compare_without_first_ch_,&f));
  216. test_eq(f, 0);
  217. test_eq(1, smartlist_bsearch_idx(sl," arma",compare_without_first_ch_,&f));
  218. test_eq(f, 1);
  219. test_eq(2, smartlist_bsearch_idx(sl," armb",compare_without_first_ch_,&f));
  220. test_eq(f, 0);
  221. test_eq(7, smartlist_bsearch_idx(sl," zzzz",compare_without_first_ch_,&f));
  222. test_eq(f, 0);
  223. /* Test trivial cases for list of length 0 or 1 */
  224. tmp = smartlist_new();
  225. test_eq(0, smartlist_bsearch_idx(tmp, "foo",
  226. compare_strs_for_bsearch_, &f));
  227. test_eq(f, 0);
  228. smartlist_insert(tmp, 0, (void *)("bar"));
  229. test_eq(1, smartlist_bsearch_idx(tmp, "foo",
  230. compare_strs_for_bsearch_, &f));
  231. test_eq(f, 0);
  232. test_eq(0, smartlist_bsearch_idx(tmp, "aaa",
  233. compare_strs_for_bsearch_, &f));
  234. test_eq(f, 0);
  235. test_eq(0, smartlist_bsearch_idx(tmp, "bar",
  236. compare_strs_for_bsearch_, &f));
  237. test_eq(f, 1);
  238. /* ... and one for length 2 */
  239. smartlist_insert(tmp, 1, (void *)("foo"));
  240. test_eq(1, smartlist_bsearch_idx(tmp, "foo",
  241. compare_strs_for_bsearch_, &f));
  242. test_eq(f, 1);
  243. test_eq(2, smartlist_bsearch_idx(tmp, "goo",
  244. compare_strs_for_bsearch_, &f));
  245. test_eq(f, 0);
  246. smartlist_free(tmp);
  247. }
  248. /* Test reverse() and pop_last() */
  249. smartlist_reverse(sl);
  250. cp_alloc = smartlist_join_strings(sl, ",", 0, NULL);
  251. test_streq(cp_alloc,"the,router,onion,nickm,by,arma,and");
  252. tor_free(cp_alloc);
  253. cp_alloc = smartlist_pop_last(sl);
  254. test_streq(cp_alloc, "and");
  255. tor_free(cp_alloc);
  256. test_eq(smartlist_len(sl), 6);
  257. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  258. smartlist_clear(sl);
  259. cp_alloc = smartlist_pop_last(sl);
  260. test_eq_ptr(cp_alloc, NULL);
  261. /* Test uniq() */
  262. smartlist_split_string(sl,
  263. "50,noon,radar,a,man,a,plan,a,canal,panama,radar,noon,50",
  264. ",", 0, 0);
  265. smartlist_sort(sl, compare_strs_);
  266. smartlist_uniq(sl, compare_strs_, tor_free_);
  267. cp_alloc = smartlist_join_strings(sl, ",", 0, NULL);
  268. test_streq(cp_alloc, "50,a,canal,man,noon,panama,plan,radar");
  269. tor_free(cp_alloc);
  270. /* Test contains_string, contains_string_case and contains_int_as_string */
  271. test_assert(smartlist_contains_string(sl, "noon"));
  272. test_assert(!smartlist_contains_string(sl, "noonoon"));
  273. test_assert(smartlist_contains_string_case(sl, "nOOn"));
  274. test_assert(!smartlist_contains_string_case(sl, "nooNooN"));
  275. test_assert(smartlist_contains_int_as_string(sl, 50));
  276. test_assert(!smartlist_contains_int_as_string(sl, 60));
  277. /* Test smartlist_choose */
  278. {
  279. int i;
  280. int allsame = 1;
  281. int allin = 1;
  282. void *first = smartlist_choose(sl);
  283. test_assert(smartlist_contains(sl, first));
  284. for (i = 0; i < 100; ++i) {
  285. void *second = smartlist_choose(sl);
  286. if (second != first)
  287. allsame = 0;
  288. if (!smartlist_contains(sl, second))
  289. allin = 0;
  290. }
  291. test_assert(!allsame);
  292. test_assert(allin);
  293. }
  294. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  295. smartlist_clear(sl);
  296. /* Test string_remove and remove and join_strings2 */
  297. smartlist_split_string(sl,
  298. "Some say the Earth will end in ice and some in fire",
  299. " ", 0, 0);
  300. cp = smartlist_get(sl, 4);
  301. test_streq(cp, "will");
  302. smartlist_add(sl, cp);
  303. smartlist_remove(sl, cp);
  304. tor_free(cp);
  305. cp_alloc = smartlist_join_strings(sl, ",", 0, NULL);
  306. test_streq(cp_alloc, "Some,say,the,Earth,fire,end,in,ice,and,some,in");
  307. tor_free(cp_alloc);
  308. smartlist_string_remove(sl, "in");
  309. cp_alloc = smartlist_join_strings2(sl, "+XX", 1, 0, &sz);
  310. test_streq(cp_alloc, "Some+say+the+Earth+fire+end+some+ice+and");
  311. test_eq((int)sz, 40);
  312. done:
  313. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  314. smartlist_free(sl);
  315. tor_free(cp_alloc);
  316. }
  317. /** Run unit tests for smartlist set manipulation functions. */
  318. static void
  319. test_container_smartlist_overlap(void)
  320. {
  321. smartlist_t *sl = smartlist_new();
  322. smartlist_t *ints = smartlist_new();
  323. smartlist_t *odds = smartlist_new();
  324. smartlist_t *evens = smartlist_new();
  325. smartlist_t *primes = smartlist_new();
  326. int i;
  327. for (i=1; i < 10; i += 2)
  328. smartlist_add(odds, (void*)(uintptr_t)i);
  329. for (i=0; i < 10; i += 2)
  330. smartlist_add(evens, (void*)(uintptr_t)i);
  331. /* add_all */
  332. smartlist_add_all(ints, odds);
  333. smartlist_add_all(ints, evens);
  334. test_eq(smartlist_len(ints), 10);
  335. smartlist_add(primes, (void*)2);
  336. smartlist_add(primes, (void*)3);
  337. smartlist_add(primes, (void*)5);
  338. smartlist_add(primes, (void*)7);
  339. /* overlap */
  340. test_assert(smartlist_overlap(ints, odds));
  341. test_assert(smartlist_overlap(odds, primes));
  342. test_assert(smartlist_overlap(evens, primes));
  343. test_assert(!smartlist_overlap(odds, evens));
  344. /* intersect */
  345. smartlist_add_all(sl, odds);
  346. smartlist_intersect(sl, primes);
  347. test_eq(smartlist_len(sl), 3);
  348. test_assert(smartlist_contains(sl, (void*)3));
  349. test_assert(smartlist_contains(sl, (void*)5));
  350. test_assert(smartlist_contains(sl, (void*)7));
  351. /* subtract */
  352. smartlist_add_all(sl, primes);
  353. smartlist_subtract(sl, odds);
  354. test_eq(smartlist_len(sl), 1);
  355. test_assert(smartlist_contains(sl, (void*)2));
  356. done:
  357. smartlist_free(odds);
  358. smartlist_free(evens);
  359. smartlist_free(ints);
  360. smartlist_free(primes);
  361. smartlist_free(sl);
  362. }
  363. /** Run unit tests for smartlist-of-digests functions. */
  364. static void
  365. test_container_smartlist_digests(void)
  366. {
  367. smartlist_t *sl = smartlist_new();
  368. /* contains_digest */
  369. smartlist_add(sl, tor_memdup("AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN));
  370. smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
  371. smartlist_add(sl, tor_memdup("\00090AAB2AAAAaasdAAAAA", DIGEST_LEN));
  372. test_eq(0, smartlist_contains_digest(NULL, "AAAAAAAAAAAAAAAAAAAA"));
  373. test_assert(smartlist_contains_digest(sl, "AAAAAAAAAAAAAAAAAAAA"));
  374. test_assert(smartlist_contains_digest(sl, "\00090AAB2AAAAaasdAAAAA"));
  375. test_eq(0, smartlist_contains_digest(sl, "\00090AAB2AAABaasdAAAAA"));
  376. /* sort digests */
  377. smartlist_sort_digests(sl);
  378. test_memeq(smartlist_get(sl, 0), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
  379. test_memeq(smartlist_get(sl, 1), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
  380. test_memeq(smartlist_get(sl, 2), "AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN);
  381. test_eq(3, smartlist_len(sl));
  382. /* uniq_digests */
  383. smartlist_uniq_digests(sl);
  384. test_eq(2, smartlist_len(sl));
  385. test_memeq(smartlist_get(sl, 0), "\00090AAB2AAAAaasdAAAAA", DIGEST_LEN);
  386. test_memeq(smartlist_get(sl, 1), "AAAAAAAAAAAAAAAAAAAA", DIGEST_LEN);
  387. done:
  388. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  389. smartlist_free(sl);
  390. }
  391. /** Run unit tests for concatenate-a-smartlist-of-strings functions. */
  392. static void
  393. test_container_smartlist_join(void)
  394. {
  395. smartlist_t *sl = smartlist_new();
  396. smartlist_t *sl2 = smartlist_new(), *sl3 = smartlist_new(),
  397. *sl4 = smartlist_new();
  398. char *joined=NULL;
  399. /* unique, sorted. */
  400. smartlist_split_string(sl,
  401. "Abashments Ambush Anchorman Bacon Banks Borscht "
  402. "Bunks Inhumane Insurance Knish Know Manners "
  403. "Maraschinos Stamina Sunbonnets Unicorns Wombats",
  404. " ", 0, 0);
  405. /* non-unique, sorted. */
  406. smartlist_split_string(sl2,
  407. "Ambush Anchorman Anchorman Anemias Anemias Bacon "
  408. "Crossbowmen Inhumane Insurance Knish Know Manners "
  409. "Manners Maraschinos Wombats Wombats Work",
  410. " ", 0, 0);
  411. SMARTLIST_FOREACH_JOIN(sl, char *, cp1,
  412. sl2, char *, cp2,
  413. strcmp(cp1,cp2),
  414. smartlist_add(sl3, cp2)) {
  415. test_streq(cp1, cp2);
  416. smartlist_add(sl4, cp1);
  417. } SMARTLIST_FOREACH_JOIN_END(cp1, cp2);
  418. SMARTLIST_FOREACH(sl3, const char *, cp,
  419. test_assert(smartlist_contains(sl2, cp) &&
  420. !smartlist_contains_string(sl, cp)));
  421. SMARTLIST_FOREACH(sl4, const char *, cp,
  422. test_assert(smartlist_contains(sl, cp) &&
  423. smartlist_contains_string(sl2, cp)));
  424. joined = smartlist_join_strings(sl3, ",", 0, NULL);
  425. test_streq(joined, "Anemias,Anemias,Crossbowmen,Work");
  426. tor_free(joined);
  427. joined = smartlist_join_strings(sl4, ",", 0, NULL);
  428. test_streq(joined, "Ambush,Anchorman,Anchorman,Bacon,Inhumane,Insurance,"
  429. "Knish,Know,Manners,Manners,Maraschinos,Wombats,Wombats");
  430. tor_free(joined);
  431. done:
  432. smartlist_free(sl4);
  433. smartlist_free(sl3);
  434. SMARTLIST_FOREACH(sl2, char *, cp, tor_free(cp));
  435. smartlist_free(sl2);
  436. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  437. smartlist_free(sl);
  438. tor_free(joined);
  439. }
  440. static void
  441. test_container_smartlist_ints_eq(void *arg)
  442. {
  443. smartlist_t *sl1 = NULL, *sl2 = NULL;
  444. int x;
  445. (void)arg;
  446. tt_assert(smartlist_ints_eq(NULL, NULL));
  447. sl1 = smartlist_new();
  448. tt_assert(!smartlist_ints_eq(sl1, NULL));
  449. tt_assert(!smartlist_ints_eq(NULL, sl1));
  450. sl2 = smartlist_new();
  451. tt_assert(smartlist_ints_eq(sl1, sl2));
  452. x = 5;
  453. smartlist_add(sl1, tor_memdup(&x, sizeof(int)));
  454. smartlist_add(sl2, tor_memdup(&x, sizeof(int)));
  455. x = 90;
  456. smartlist_add(sl1, tor_memdup(&x, sizeof(int)));
  457. smartlist_add(sl2, tor_memdup(&x, sizeof(int)));
  458. tt_assert(smartlist_ints_eq(sl1, sl2));
  459. x = -50;
  460. smartlist_add(sl1, tor_memdup(&x, sizeof(int)));
  461. tt_assert(! smartlist_ints_eq(sl1, sl2));
  462. tt_assert(! smartlist_ints_eq(sl2, sl1));
  463. smartlist_add(sl2, tor_memdup(&x, sizeof(int)));
  464. tt_assert(smartlist_ints_eq(sl1, sl2));
  465. *(int*)smartlist_get(sl1, 1) = 101010;
  466. tt_assert(! smartlist_ints_eq(sl2, sl1));
  467. *(int*)smartlist_get(sl2, 1) = 101010;
  468. tt_assert(smartlist_ints_eq(sl1, sl2));
  469. done:
  470. if (sl1)
  471. SMARTLIST_FOREACH(sl1, int *, ip, tor_free(ip));
  472. if (sl2)
  473. SMARTLIST_FOREACH(sl2, int *, ip, tor_free(ip));
  474. smartlist_free(sl1);
  475. smartlist_free(sl2);
  476. }
  477. /** Run unit tests for bitarray code */
  478. static void
  479. test_container_bitarray(void)
  480. {
  481. bitarray_t *ba = NULL;
  482. int i, j, ok=1;
  483. ba = bitarray_init_zero(1);
  484. test_assert(ba);
  485. test_assert(! bitarray_is_set(ba, 0));
  486. bitarray_set(ba, 0);
  487. test_assert(bitarray_is_set(ba, 0));
  488. bitarray_clear(ba, 0);
  489. test_assert(! bitarray_is_set(ba, 0));
  490. bitarray_free(ba);
  491. ba = bitarray_init_zero(1023);
  492. for (i = 1; i < 64; ) {
  493. for (j = 0; j < 1023; ++j) {
  494. if (j % i)
  495. bitarray_set(ba, j);
  496. else
  497. bitarray_clear(ba, j);
  498. }
  499. for (j = 0; j < 1023; ++j) {
  500. if (!bool_eq(bitarray_is_set(ba, j), j%i))
  501. ok = 0;
  502. }
  503. test_assert(ok);
  504. if (i < 7)
  505. ++i;
  506. else if (i == 28)
  507. i = 32;
  508. else
  509. i += 7;
  510. }
  511. done:
  512. if (ba)
  513. bitarray_free(ba);
  514. }
  515. /** Run unit tests for digest set code (implemented as a hashtable or as a
  516. * bloom filter) */
  517. static void
  518. test_container_digestset(void)
  519. {
  520. smartlist_t *included = smartlist_new();
  521. char d[DIGEST_LEN];
  522. int i;
  523. int ok = 1;
  524. int false_positives = 0;
  525. digestset_t *set = NULL;
  526. for (i = 0; i < 1000; ++i) {
  527. crypto_rand(d, DIGEST_LEN);
  528. smartlist_add(included, tor_memdup(d, DIGEST_LEN));
  529. }
  530. set = digestset_new(1000);
  531. SMARTLIST_FOREACH(included, const char *, cp,
  532. if (digestset_contains(set, cp))
  533. ok = 0);
  534. test_assert(ok);
  535. SMARTLIST_FOREACH(included, const char *, cp,
  536. digestset_add(set, cp));
  537. SMARTLIST_FOREACH(included, const char *, cp,
  538. if (!digestset_contains(set, cp))
  539. ok = 0);
  540. test_assert(ok);
  541. for (i = 0; i < 1000; ++i) {
  542. crypto_rand(d, DIGEST_LEN);
  543. if (digestset_contains(set, d))
  544. ++false_positives;
  545. }
  546. test_assert(false_positives < 50); /* Should be far lower. */
  547. done:
  548. if (set)
  549. digestset_free(set);
  550. SMARTLIST_FOREACH(included, char *, cp, tor_free(cp));
  551. smartlist_free(included);
  552. }
  553. typedef struct pq_entry_t {
  554. const char *val;
  555. int idx;
  556. } pq_entry_t;
  557. /** Helper: return a tristate based on comparing two pq_entry_t values. */
  558. static int
  559. compare_strings_for_pqueue_(const void *p1, const void *p2)
  560. {
  561. const pq_entry_t *e1=p1, *e2=p2;
  562. return strcmp(e1->val, e2->val);
  563. }
  564. /** Run unit tests for heap-based priority queue functions. */
  565. static void
  566. test_container_pqueue(void)
  567. {
  568. smartlist_t *sl = smartlist_new();
  569. int (*cmp)(const void *, const void*);
  570. const int offset = STRUCT_OFFSET(pq_entry_t, idx);
  571. #define ENTRY(s) pq_entry_t s = { #s, -1 }
  572. ENTRY(cows);
  573. ENTRY(zebras);
  574. ENTRY(fish);
  575. ENTRY(frogs);
  576. ENTRY(apples);
  577. ENTRY(squid);
  578. ENTRY(daschunds);
  579. ENTRY(eggplants);
  580. ENTRY(weissbier);
  581. ENTRY(lobsters);
  582. ENTRY(roquefort);
  583. ENTRY(chinchillas);
  584. ENTRY(fireflies);
  585. #define OK() smartlist_pqueue_assert_ok(sl, cmp, offset)
  586. cmp = compare_strings_for_pqueue_;
  587. smartlist_pqueue_add(sl, cmp, offset, &cows);
  588. smartlist_pqueue_add(sl, cmp, offset, &zebras);
  589. smartlist_pqueue_add(sl, cmp, offset, &fish);
  590. smartlist_pqueue_add(sl, cmp, offset, &frogs);
  591. smartlist_pqueue_add(sl, cmp, offset, &apples);
  592. smartlist_pqueue_add(sl, cmp, offset, &squid);
  593. smartlist_pqueue_add(sl, cmp, offset, &daschunds);
  594. smartlist_pqueue_add(sl, cmp, offset, &eggplants);
  595. smartlist_pqueue_add(sl, cmp, offset, &weissbier);
  596. smartlist_pqueue_add(sl, cmp, offset, &lobsters);
  597. smartlist_pqueue_add(sl, cmp, offset, &roquefort);
  598. OK();
  599. test_eq(smartlist_len(sl), 11);
  600. test_eq_ptr(smartlist_get(sl, 0), &apples);
  601. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &apples);
  602. test_eq(smartlist_len(sl), 10);
  603. OK();
  604. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &cows);
  605. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &daschunds);
  606. smartlist_pqueue_add(sl, cmp, offset, &chinchillas);
  607. OK();
  608. smartlist_pqueue_add(sl, cmp, offset, &fireflies);
  609. OK();
  610. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &chinchillas);
  611. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &eggplants);
  612. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &fireflies);
  613. OK();
  614. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &fish);
  615. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &frogs);
  616. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &lobsters);
  617. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &roquefort);
  618. OK();
  619. test_eq(smartlist_len(sl), 3);
  620. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &squid);
  621. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &weissbier);
  622. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &zebras);
  623. test_eq(smartlist_len(sl), 0);
  624. OK();
  625. /* Now test remove. */
  626. smartlist_pqueue_add(sl, cmp, offset, &cows);
  627. smartlist_pqueue_add(sl, cmp, offset, &fish);
  628. smartlist_pqueue_add(sl, cmp, offset, &frogs);
  629. smartlist_pqueue_add(sl, cmp, offset, &apples);
  630. smartlist_pqueue_add(sl, cmp, offset, &squid);
  631. smartlist_pqueue_add(sl, cmp, offset, &zebras);
  632. test_eq(smartlist_len(sl), 6);
  633. OK();
  634. smartlist_pqueue_remove(sl, cmp, offset, &zebras);
  635. test_eq(smartlist_len(sl), 5);
  636. OK();
  637. smartlist_pqueue_remove(sl, cmp, offset, &cows);
  638. test_eq(smartlist_len(sl), 4);
  639. OK();
  640. smartlist_pqueue_remove(sl, cmp, offset, &apples);
  641. test_eq(smartlist_len(sl), 3);
  642. OK();
  643. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &fish);
  644. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &frogs);
  645. test_eq_ptr(smartlist_pqueue_pop(sl, cmp, offset), &squid);
  646. test_eq(smartlist_len(sl), 0);
  647. OK();
  648. #undef OK
  649. done:
  650. smartlist_free(sl);
  651. }
  652. /** Run unit tests for string-to-void* map functions */
  653. static void
  654. test_container_strmap(void)
  655. {
  656. strmap_t *map;
  657. strmap_iter_t *iter;
  658. const char *k;
  659. void *v;
  660. char *visited = NULL;
  661. smartlist_t *found_keys = NULL;
  662. char *v1 = tor_strdup("v1");
  663. char *v99 = tor_strdup("v99");
  664. char *v100 = tor_strdup("v100");
  665. char *v101 = tor_strdup("v101");
  666. char *v102 = tor_strdup("v102");
  667. char *v103 = tor_strdup("v103");
  668. char *v104 = tor_strdup("v104");
  669. char *v105 = tor_strdup("v105");
  670. map = strmap_new();
  671. test_assert(map);
  672. test_eq(strmap_size(map), 0);
  673. test_assert(strmap_isempty(map));
  674. v = strmap_set(map, "K1", v99);
  675. test_eq_ptr(v, NULL);
  676. test_assert(!strmap_isempty(map));
  677. v = strmap_set(map, "K2", v101);
  678. test_eq_ptr(v, NULL);
  679. v = strmap_set(map, "K1", v100);
  680. test_eq_ptr(v, v99);
  681. test_eq_ptr(strmap_get(map,"K1"), v100);
  682. test_eq_ptr(strmap_get(map,"K2"), v101);
  683. test_eq_ptr(strmap_get(map,"K-not-there"), NULL);
  684. strmap_assert_ok(map);
  685. v = strmap_remove(map,"K2");
  686. strmap_assert_ok(map);
  687. test_eq_ptr(v, v101);
  688. test_eq_ptr(strmap_get(map,"K2"), NULL);
  689. test_eq_ptr(strmap_remove(map,"K2"), NULL);
  690. strmap_set(map, "K2", v101);
  691. strmap_set(map, "K3", v102);
  692. strmap_set(map, "K4", v103);
  693. test_eq(strmap_size(map), 4);
  694. strmap_assert_ok(map);
  695. strmap_set(map, "K5", v104);
  696. strmap_set(map, "K6", v105);
  697. strmap_assert_ok(map);
  698. /* Test iterator. */
  699. iter = strmap_iter_init(map);
  700. found_keys = smartlist_new();
  701. while (!strmap_iter_done(iter)) {
  702. strmap_iter_get(iter,&k,&v);
  703. smartlist_add(found_keys, tor_strdup(k));
  704. test_eq_ptr(v, strmap_get(map, k));
  705. if (!strcmp(k, "K2")) {
  706. iter = strmap_iter_next_rmv(map,iter);
  707. } else {
  708. iter = strmap_iter_next(map,iter);
  709. }
  710. }
  711. /* Make sure we removed K2, but not the others. */
  712. test_eq_ptr(strmap_get(map, "K2"), NULL);
  713. test_eq_ptr(strmap_get(map, "K5"), v104);
  714. /* Make sure we visited everyone once */
  715. smartlist_sort_strings(found_keys);
  716. visited = smartlist_join_strings(found_keys, ":", 0, NULL);
  717. test_streq(visited, "K1:K2:K3:K4:K5:K6");
  718. strmap_assert_ok(map);
  719. /* Clean up after ourselves. */
  720. strmap_free(map, NULL);
  721. map = NULL;
  722. /* Now try some lc functions. */
  723. map = strmap_new();
  724. strmap_set_lc(map,"Ab.C", v1);
  725. test_eq_ptr(strmap_get(map,"ab.c"), v1);
  726. strmap_assert_ok(map);
  727. test_eq_ptr(strmap_get_lc(map,"AB.C"), v1);
  728. test_eq_ptr(strmap_get(map,"AB.C"), NULL);
  729. test_eq_ptr(strmap_remove_lc(map,"aB.C"), v1);
  730. strmap_assert_ok(map);
  731. test_eq_ptr(strmap_get_lc(map,"AB.C"), NULL);
  732. done:
  733. if (map)
  734. strmap_free(map,NULL);
  735. if (found_keys) {
  736. SMARTLIST_FOREACH(found_keys, char *, cp, tor_free(cp));
  737. smartlist_free(found_keys);
  738. }
  739. tor_free(visited);
  740. tor_free(v1);
  741. tor_free(v99);
  742. tor_free(v100);
  743. tor_free(v101);
  744. tor_free(v102);
  745. tor_free(v103);
  746. tor_free(v104);
  747. tor_free(v105);
  748. }
  749. /** Run unit tests for getting the median of a list. */
  750. static void
  751. test_container_order_functions(void)
  752. {
  753. int lst[25], n = 0;
  754. unsigned int lst2[25];
  755. // int a=12,b=24,c=25,d=60,e=77;
  756. #define median() median_int(lst, n)
  757. lst[n++] = 12;
  758. test_eq(12, median()); /* 12 */
  759. lst[n++] = 77;
  760. //smartlist_shuffle(sl);
  761. test_eq(12, median()); /* 12, 77 */
  762. lst[n++] = 77;
  763. //smartlist_shuffle(sl);
  764. test_eq(77, median()); /* 12, 77, 77 */
  765. lst[n++] = 24;
  766. test_eq(24, median()); /* 12,24,77,77 */
  767. lst[n++] = 60;
  768. lst[n++] = 12;
  769. lst[n++] = 25;
  770. //smartlist_shuffle(sl);
  771. test_eq(25, median()); /* 12,12,24,25,60,77,77 */
  772. #undef median
  773. #define third_quartile() third_quartile_uint32(lst2, n)
  774. n = 0;
  775. lst2[n++] = 1;
  776. test_eq(1, third_quartile()); /* ~1~ */
  777. lst2[n++] = 2;
  778. test_eq(2, third_quartile()); /* 1, ~2~ */
  779. lst2[n++] = 3;
  780. lst2[n++] = 4;
  781. lst2[n++] = 5;
  782. test_eq(4, third_quartile()); /* 1, 2, 3, ~4~, 5 */
  783. lst2[n++] = 6;
  784. lst2[n++] = 7;
  785. lst2[n++] = 8;
  786. lst2[n++] = 9;
  787. test_eq(7, third_quartile()); /* 1, 2, 3, 4, 5, 6, ~7~, 8, 9 */
  788. lst2[n++] = 10;
  789. lst2[n++] = 11;
  790. test_eq(9, third_quartile()); /* 1, 2, 3, 4, 5, 6, 7, 8, ~9~, 10, 11 */
  791. #undef third_quartile
  792. done:
  793. ;
  794. }
  795. static void
  796. test_container_di_map(void *arg)
  797. {
  798. di_digest256_map_t *map = NULL;
  799. const uint8_t key1[] = "In view of the fact that it was ";
  800. const uint8_t key2[] = "superficially convincing, being ";
  801. const uint8_t key3[] = "properly enciphered in a one-tim";
  802. const uint8_t key4[] = "e cipher scheduled for use today";
  803. char *v1 = tor_strdup(", it came close to causing a disaster...");
  804. char *v2 = tor_strdup("I regret to have to advise you that the mission");
  805. char *v3 = tor_strdup("was actually initiated...");
  806. /* -- John Brunner, _The Shockwave Rider_ */
  807. (void)arg;
  808. /* Try searching on an empty map. */
  809. tt_ptr_op(NULL, ==, dimap_search(map, key1, NULL));
  810. tt_ptr_op(NULL, ==, dimap_search(map, key2, NULL));
  811. tt_ptr_op(v3, ==, dimap_search(map, key2, v3));
  812. dimap_free(map, NULL);
  813. map = NULL;
  814. /* Add a single entry. */
  815. dimap_add_entry(&map, key1, v1);
  816. tt_ptr_op(NULL, ==, dimap_search(map, key2, NULL));
  817. tt_ptr_op(v3, ==, dimap_search(map, key2, v3));
  818. tt_ptr_op(v1, ==, dimap_search(map, key1, NULL));
  819. /* Now try it with three entries in the map. */
  820. dimap_add_entry(&map, key2, v2);
  821. dimap_add_entry(&map, key3, v3);
  822. tt_ptr_op(v1, ==, dimap_search(map, key1, NULL));
  823. tt_ptr_op(v2, ==, dimap_search(map, key2, NULL));
  824. tt_ptr_op(v3, ==, dimap_search(map, key3, NULL));
  825. tt_ptr_op(NULL, ==, dimap_search(map, key4, NULL));
  826. tt_ptr_op(v1, ==, dimap_search(map, key4, v1));
  827. done:
  828. tor_free(v1);
  829. tor_free(v2);
  830. tor_free(v3);
  831. dimap_free(map, NULL);
  832. }
  833. /** Run unit tests for fp_pair-to-void* map functions */
  834. static void
  835. test_container_fp_pair_map(void)
  836. {
  837. fp_pair_map_t *map;
  838. fp_pair_t fp1, fp2, fp3, fp4, fp5, fp6;
  839. void *v;
  840. fp_pair_map_iter_t *iter;
  841. fp_pair_t k;
  842. char *v99 = tor_strdup("99");
  843. char *v100 = tor_strdup("v100");
  844. char *v101 = tor_strdup("v101");
  845. char *v102 = tor_strdup("v102");
  846. char *v103 = tor_strdup("v103");
  847. char *v104 = tor_strdup("v104");
  848. char *v105 = tor_strdup("v105");
  849. map = fp_pair_map_new();
  850. test_assert(map);
  851. test_eq(fp_pair_map_size(map), 0);
  852. test_assert(fp_pair_map_isempty(map));
  853. memset(fp1.first, 0x11, DIGEST_LEN);
  854. memset(fp1.second, 0x12, DIGEST_LEN);
  855. memset(fp2.first, 0x21, DIGEST_LEN);
  856. memset(fp2.second, 0x22, DIGEST_LEN);
  857. memset(fp3.first, 0x31, DIGEST_LEN);
  858. memset(fp3.second, 0x32, DIGEST_LEN);
  859. memset(fp4.first, 0x41, DIGEST_LEN);
  860. memset(fp4.second, 0x42, DIGEST_LEN);
  861. memset(fp5.first, 0x51, DIGEST_LEN);
  862. memset(fp5.second, 0x52, DIGEST_LEN);
  863. memset(fp6.first, 0x61, DIGEST_LEN);
  864. memset(fp6.second, 0x62, DIGEST_LEN);
  865. v = fp_pair_map_set(map, &fp1, v99);
  866. tt_ptr_op(v, ==, NULL);
  867. test_assert(!fp_pair_map_isempty(map));
  868. v = fp_pair_map_set(map, &fp2, v101);
  869. tt_ptr_op(v, ==, NULL);
  870. v = fp_pair_map_set(map, &fp1, v100);
  871. tt_ptr_op(v, ==, v99);
  872. test_eq_ptr(fp_pair_map_get(map, &fp1), v100);
  873. test_eq_ptr(fp_pair_map_get(map, &fp2), v101);
  874. test_eq_ptr(fp_pair_map_get(map, &fp3), NULL);
  875. fp_pair_map_assert_ok(map);
  876. v = fp_pair_map_remove(map, &fp2);
  877. fp_pair_map_assert_ok(map);
  878. test_eq_ptr(v, v101);
  879. test_eq_ptr(fp_pair_map_get(map, &fp2), NULL);
  880. test_eq_ptr(fp_pair_map_remove(map, &fp2), NULL);
  881. fp_pair_map_set(map, &fp2, v101);
  882. fp_pair_map_set(map, &fp3, v102);
  883. fp_pair_map_set(map, &fp4, v103);
  884. test_eq(fp_pair_map_size(map), 4);
  885. fp_pair_map_assert_ok(map);
  886. fp_pair_map_set(map, &fp5, v104);
  887. fp_pair_map_set(map, &fp6, v105);
  888. fp_pair_map_assert_ok(map);
  889. /* Test iterator. */
  890. iter = fp_pair_map_iter_init(map);
  891. while (!fp_pair_map_iter_done(iter)) {
  892. fp_pair_map_iter_get(iter, &k, &v);
  893. test_eq_ptr(v, fp_pair_map_get(map, &k));
  894. if (tor_memeq(&fp2, &k, sizeof(fp2))) {
  895. iter = fp_pair_map_iter_next_rmv(map, iter);
  896. } else {
  897. iter = fp_pair_map_iter_next(map, iter);
  898. }
  899. }
  900. /* Make sure we removed fp2, but not the others. */
  901. test_eq_ptr(fp_pair_map_get(map, &fp2), NULL);
  902. test_eq_ptr(fp_pair_map_get(map, &fp5), v104);
  903. fp_pair_map_assert_ok(map);
  904. /* Clean up after ourselves. */
  905. fp_pair_map_free(map, NULL);
  906. map = NULL;
  907. done:
  908. if (map)
  909. fp_pair_map_free(map, NULL);
  910. tor_free(v99);
  911. tor_free(v100);
  912. tor_free(v101);
  913. tor_free(v102);
  914. tor_free(v103);
  915. tor_free(v104);
  916. tor_free(v105);
  917. }
  918. #define CONTAINER_LEGACY(name) \
  919. { #name, legacy_test_helper, 0, &legacy_setup, test_container_ ## name }
  920. #define CONTAINER(name, flags) \
  921. { #name, test_container_ ## name, (flags), NULL, NULL }
  922. struct testcase_t container_tests[] = {
  923. CONTAINER_LEGACY(smartlist_basic),
  924. CONTAINER_LEGACY(smartlist_strings),
  925. CONTAINER_LEGACY(smartlist_overlap),
  926. CONTAINER_LEGACY(smartlist_digests),
  927. CONTAINER_LEGACY(smartlist_join),
  928. CONTAINER(smartlist_ints_eq, 0),
  929. CONTAINER_LEGACY(bitarray),
  930. CONTAINER_LEGACY(digestset),
  931. CONTAINER_LEGACY(strmap),
  932. CONTAINER_LEGACY(pqueue),
  933. CONTAINER_LEGACY(order_functions),
  934. CONTAINER(di_map, 0),
  935. CONTAINER_LEGACY(fp_pair_map),
  936. END_OF_TESTCASES
  937. };