test_routerset.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224
  1. /* Copyright (c) 2014-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define ROUTERSET_PRIVATE
  4. #include "or.h"
  5. #include "geoip.h"
  6. #include "routerset.h"
  7. #include "routerparse.h"
  8. #include "policies.h"
  9. #include "nodelist.h"
  10. #include "test.h"
  11. #define NS_MODULE routerset
  12. #define NS_SUBMODULE routerset_new
  13. /*
  14. * Functional (blackbox) test to determine that each member of the routerset
  15. * is non-NULL
  16. */
  17. static void
  18. NS(test_main)(void *arg)
  19. {
  20. routerset_t *rs;
  21. (void)arg;
  22. rs = routerset_new();
  23. tt_ptr_op(rs, OP_NE, NULL);
  24. tt_ptr_op(rs->list, OP_NE, NULL);
  25. tt_ptr_op(rs->names, OP_NE, NULL);
  26. tt_ptr_op(rs->digests, OP_NE, NULL);
  27. tt_ptr_op(rs->policies, OP_NE, NULL);
  28. tt_ptr_op(rs->country_names, OP_NE, NULL);
  29. done:
  30. routerset_free(rs);
  31. }
  32. #undef NS_SUBMODULE
  33. #define NS_SUBMODULE routerset_get_countryname
  34. /*
  35. * Functional test to strip the braces from a "{xx}" country code string.
  36. */
  37. static void
  38. NS(test_main)(void *arg)
  39. {
  40. const char *input;
  41. char *name;
  42. (void)arg;
  43. /* strlen(c) < 4 */
  44. input = "xxx";
  45. name = routerset_get_countryname(input);
  46. tt_ptr_op(name, OP_EQ, NULL);
  47. tor_free(name);
  48. /* c[0] != '{' */
  49. input = "xxx}";
  50. name = routerset_get_countryname(input);
  51. tt_ptr_op(name, OP_EQ, NULL);
  52. tor_free(name);
  53. /* c[3] != '}' */
  54. input = "{xxx";
  55. name = routerset_get_countryname(input);
  56. tt_ptr_op(name, OP_EQ, NULL);
  57. tor_free(name);
  58. /* tor_strlower */
  59. input = "{XX}";
  60. name = routerset_get_countryname(input);
  61. tt_str_op(name, OP_EQ, "xx");
  62. tor_free(name);
  63. input = "{xx}";
  64. name = routerset_get_countryname(input);
  65. tt_str_op(name, OP_EQ, "xx");
  66. done:
  67. tor_free(name);
  68. }
  69. #undef NS_SUBMODULE
  70. #define NS_SUBMODULE ASPECT(routerset_refresh_counties, geoip_not_loaded)
  71. /*
  72. * Structural (whitebox) test for routerset_refresh_counties, when the GeoIP DB
  73. * is not loaded.
  74. */
  75. NS_DECL(int, geoip_is_loaded, (sa_family_t family));
  76. NS_DECL(int, geoip_get_n_countries, (void));
  77. static void
  78. NS(test_main)(void *arg)
  79. {
  80. routerset_t *set = routerset_new();
  81. (void)arg;
  82. NS_MOCK(geoip_is_loaded);
  83. NS_MOCK(geoip_get_n_countries);
  84. routerset_refresh_countries(set);
  85. tt_ptr_op(set->countries, OP_EQ, NULL);
  86. tt_int_op(set->n_countries, OP_EQ, 0);
  87. tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1);
  88. tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 0);
  89. done:
  90. NS_UNMOCK(geoip_is_loaded);
  91. NS_UNMOCK(geoip_get_n_countries);
  92. routerset_free(set);
  93. }
  94. static int
  95. NS(geoip_is_loaded)(sa_family_t family)
  96. {
  97. (void)family;
  98. CALLED(geoip_is_loaded)++;
  99. return 0;
  100. }
  101. static int
  102. NS(geoip_get_n_countries)(void)
  103. {
  104. CALLED(geoip_get_n_countries)++;
  105. return 0;
  106. }
  107. #undef NS_SUBMODULE
  108. #define NS_SUBMODULE ASPECT(routerset_refresh_counties, no_countries)
  109. /*
  110. * Structural test for routerset_refresh_counties, when there are no countries.
  111. */
  112. NS_DECL(int, geoip_is_loaded, (sa_family_t family));
  113. NS_DECL(int, geoip_get_n_countries, (void));
  114. NS_DECL(country_t, geoip_get_country, (const char *country));
  115. static void
  116. NS(test_main)(void *arg)
  117. {
  118. routerset_t *set = routerset_new();
  119. (void)arg;
  120. NS_MOCK(geoip_is_loaded);
  121. NS_MOCK(geoip_get_n_countries);
  122. NS_MOCK(geoip_get_country);
  123. routerset_refresh_countries(set);
  124. tt_ptr_op(set->countries, OP_NE, NULL);
  125. tt_int_op(set->n_countries, OP_EQ, 1);
  126. tt_int_op((unsigned int)(*set->countries), OP_EQ, 0);
  127. tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1);
  128. tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 1);
  129. tt_int_op(CALLED(geoip_get_country), OP_EQ, 0);
  130. done:
  131. NS_UNMOCK(geoip_is_loaded);
  132. NS_UNMOCK(geoip_get_n_countries);
  133. NS_UNMOCK(geoip_get_country);
  134. routerset_free(set);
  135. }
  136. static int
  137. NS(geoip_is_loaded)(sa_family_t family)
  138. {
  139. (void)family;
  140. CALLED(geoip_is_loaded)++;
  141. return 1;
  142. }
  143. static int
  144. NS(geoip_get_n_countries)(void)
  145. {
  146. CALLED(geoip_get_n_countries)++;
  147. return 1;
  148. }
  149. static country_t
  150. NS(geoip_get_country)(const char *countrycode)
  151. {
  152. (void)countrycode;
  153. CALLED(geoip_get_country)++;
  154. return 1;
  155. }
  156. #undef NS_SUBMODULE
  157. #define NS_SUBMODULE ASPECT(routerset_refresh_counties, one_valid_country)
  158. /*
  159. * Structural test for routerset_refresh_counties, with one valid country.
  160. */
  161. NS_DECL(int, geoip_is_loaded, (sa_family_t family));
  162. NS_DECL(int, geoip_get_n_countries, (void));
  163. NS_DECL(country_t, geoip_get_country, (const char *country));
  164. static void
  165. NS(test_main)(void *arg)
  166. {
  167. routerset_t *set = routerset_new();
  168. (void)arg;
  169. NS_MOCK(geoip_is_loaded);
  170. NS_MOCK(geoip_get_n_countries);
  171. NS_MOCK(geoip_get_country);
  172. smartlist_add(set->country_names, tor_strndup("foo", 3));
  173. routerset_refresh_countries(set);
  174. tt_ptr_op(set->countries, OP_NE, NULL);
  175. tt_int_op(set->n_countries, OP_EQ, 2);
  176. tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1);
  177. tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 1);
  178. tt_int_op(CALLED(geoip_get_country), OP_EQ, 1);
  179. tt_int_op((unsigned int)(*set->countries), OP_NE, 0);
  180. done:
  181. NS_UNMOCK(geoip_is_loaded);
  182. NS_UNMOCK(geoip_get_n_countries);
  183. NS_UNMOCK(geoip_get_country);
  184. routerset_free(set);
  185. }
  186. static int
  187. NS(geoip_is_loaded)(sa_family_t family)
  188. {
  189. (void)family;
  190. CALLED(geoip_is_loaded)++;
  191. return 1;
  192. }
  193. static int
  194. NS(geoip_get_n_countries)(void)
  195. {
  196. CALLED(geoip_get_n_countries)++;
  197. return 2;
  198. }
  199. static country_t
  200. NS(geoip_get_country)(const char *countrycode)
  201. {
  202. (void)countrycode;
  203. CALLED(geoip_get_country)++;
  204. return 1;
  205. }
  206. #undef NS_SUBMODULE
  207. #define NS_SUBMODULE ASPECT(routerset_refresh_counties, one_invalid_country)
  208. /*
  209. * Structural test for routerset_refresh_counties, with one invalid
  210. * country code..
  211. */
  212. NS_DECL(int, geoip_is_loaded, (sa_family_t family));
  213. NS_DECL(int, geoip_get_n_countries, (void));
  214. NS_DECL(country_t, geoip_get_country, (const char *country));
  215. static void
  216. NS(test_main)(void *arg)
  217. {
  218. routerset_t *set = routerset_new();
  219. (void)arg;
  220. NS_MOCK(geoip_is_loaded);
  221. NS_MOCK(geoip_get_n_countries);
  222. NS_MOCK(geoip_get_country);
  223. smartlist_add(set->country_names, tor_strndup("foo", 3));
  224. routerset_refresh_countries(set);
  225. tt_ptr_op(set->countries, OP_NE, NULL);
  226. tt_int_op(set->n_countries, OP_EQ, 2);
  227. tt_int_op(CALLED(geoip_is_loaded), OP_EQ, 1);
  228. tt_int_op(CALLED(geoip_get_n_countries), OP_EQ, 1);
  229. tt_int_op(CALLED(geoip_get_country), OP_EQ, 1);
  230. tt_int_op((unsigned int)(*set->countries), OP_EQ, 0);
  231. done:
  232. NS_UNMOCK(geoip_is_loaded);
  233. NS_UNMOCK(geoip_get_n_countries);
  234. NS_UNMOCK(geoip_get_country);
  235. routerset_free(set);
  236. }
  237. static int
  238. NS(geoip_is_loaded)(sa_family_t family)
  239. {
  240. (void)family;
  241. CALLED(geoip_is_loaded)++;
  242. return 1;
  243. }
  244. static int
  245. NS(geoip_get_n_countries)(void)
  246. {
  247. CALLED(geoip_get_n_countries)++;
  248. return 2;
  249. }
  250. static country_t
  251. NS(geoip_get_country)(const char *countrycode)
  252. {
  253. (void)countrycode;
  254. CALLED(geoip_get_country)++;
  255. return -1;
  256. }
  257. #undef NS_SUBMODULE
  258. #define NS_SUBMODULE ASPECT(routerset_parse, malformed)
  259. /*
  260. * Functional test, with a malformed string to parse.
  261. */
  262. static void
  263. NS(test_main)(void *arg)
  264. {
  265. routerset_t *set = routerset_new();
  266. const char *s = "_";
  267. int r;
  268. (void)arg;
  269. r = routerset_parse(set, s, "");
  270. tt_int_op(r, OP_EQ, -1);
  271. done:
  272. routerset_free(set);
  273. }
  274. #undef NS_SUBMODULE
  275. #define NS_SUBMODULE ASPECT(routerset_parse, valid_hexdigest)
  276. /*
  277. * Functional test for routerset_parse, that routerset_parse returns 0
  278. * on a valid hexdigest entry.
  279. */
  280. static void
  281. NS(test_main)(void *arg)
  282. {
  283. routerset_t *set;
  284. const char *s;
  285. int r;
  286. (void)arg;
  287. set = routerset_new();
  288. s = "$0000000000000000000000000000000000000000";
  289. r = routerset_parse(set, s, "");
  290. tt_int_op(r, OP_EQ, 0);
  291. tt_int_op(digestmap_isempty(set->digests), OP_NE, 1);
  292. done:
  293. routerset_free(set);
  294. }
  295. #undef NS_SUBMODULE
  296. #define NS_SUBMODULE ASPECT(routerset_parse, valid_nickname)
  297. /*
  298. * Functional test for routerset_parse, when given a valid nickname as input.
  299. */
  300. static void
  301. NS(test_main)(void *arg)
  302. {
  303. routerset_t *set;
  304. const char *s;
  305. int r;
  306. (void)arg;
  307. set = routerset_new();
  308. s = "fred";
  309. r = routerset_parse(set, s, "");
  310. tt_int_op(r, OP_EQ, 0);
  311. tt_int_op(strmap_isempty(set->names), OP_NE, 1);
  312. done:
  313. routerset_free(set);
  314. }
  315. #undef NS_SUBMODULE
  316. #define NS_SUBMODULE ASPECT(routerset_parse, get_countryname)
  317. /*
  318. * Functional test for routerset_parse, when given a valid countryname.
  319. */
  320. static void
  321. NS(test_main)(void *arg)
  322. {
  323. routerset_t *set;
  324. const char *s;
  325. int r;
  326. (void)arg;
  327. set = routerset_new();
  328. s = "{cc}";
  329. r = routerset_parse(set, s, "");
  330. tt_int_op(r, OP_EQ, 0);
  331. tt_int_op(smartlist_len(set->country_names), OP_NE, 0);
  332. done:
  333. routerset_free(set);
  334. }
  335. #undef NS_SUBMODULE
  336. #define NS_SUBMODULE ASPECT(routerset_parse, policy_wildcard)
  337. /*
  338. * Structural test for routerset_parse, when given a valid wildcard policy.
  339. */
  340. NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
  341. (const char *s, int assume_action, int *malformed_list));
  342. static addr_policy_t *NS(mock_addr_policy);
  343. static void
  344. NS(test_main)(void *arg)
  345. {
  346. routerset_t *set;
  347. const char *s;
  348. int r;
  349. (void)arg;
  350. NS_MOCK(router_parse_addr_policy_item_from_string);
  351. NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t));
  352. set = routerset_new();
  353. s = "*";
  354. r = routerset_parse(set, s, "");
  355. tt_int_op(r, OP_EQ, 0);
  356. tt_int_op(smartlist_len(set->policies), OP_NE, 0);
  357. tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1);
  358. done:
  359. routerset_free(set);
  360. }
  361. addr_policy_t *
  362. NS(router_parse_addr_policy_item_from_string)(const char *s,
  363. int assume_action,
  364. int *malformed_list)
  365. {
  366. (void)s;
  367. (void)assume_action;
  368. (void)malformed_list;
  369. CALLED(router_parse_addr_policy_item_from_string)++;
  370. return NS(mock_addr_policy);
  371. }
  372. #undef NS_SUBMODULE
  373. #define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv4)
  374. /*
  375. * Structural test for routerset_parse, when given a valid IPv4 address
  376. * literal policy.
  377. */
  378. NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
  379. (const char *s, int assume_action, int *bogus));
  380. static addr_policy_t *NS(mock_addr_policy);
  381. static void
  382. NS(test_main)(void *arg)
  383. {
  384. routerset_t *set;
  385. const char *s;
  386. int r;
  387. (void)arg;
  388. NS_MOCK(router_parse_addr_policy_item_from_string);
  389. NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t));
  390. set = routerset_new();
  391. s = "127.0.0.1";
  392. r = routerset_parse(set, s, "");
  393. tt_int_op(r, OP_EQ, 0);
  394. tt_int_op(smartlist_len(set->policies), OP_NE, 0);
  395. tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1);
  396. done:
  397. routerset_free(set);
  398. }
  399. addr_policy_t *
  400. NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action,
  401. int *bogus)
  402. {
  403. (void)s;
  404. (void)assume_action;
  405. CALLED(router_parse_addr_policy_item_from_string)++;
  406. *bogus = 0;
  407. return NS(mock_addr_policy);
  408. }
  409. #undef NS_SUBMODULE
  410. #define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv6)
  411. /*
  412. * Structural test for routerset_parse, when given a valid IPv6 address
  413. * literal policy.
  414. */
  415. NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string,
  416. (const char *s, int assume_action, int *bad));
  417. static addr_policy_t *NS(mock_addr_policy);
  418. static void
  419. NS(test_main)(void *arg)
  420. {
  421. routerset_t *set;
  422. const char *s;
  423. int r;
  424. (void)arg;
  425. NS_MOCK(router_parse_addr_policy_item_from_string);
  426. NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t));
  427. set = routerset_new();
  428. s = "::1";
  429. r = routerset_parse(set, s, "");
  430. tt_int_op(r, OP_EQ, 0);
  431. tt_int_op(smartlist_len(set->policies), OP_NE, 0);
  432. tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1);
  433. done:
  434. routerset_free(set);
  435. }
  436. addr_policy_t *
  437. NS(router_parse_addr_policy_item_from_string)(const char *s,
  438. int assume_action, int *bad)
  439. {
  440. (void)s;
  441. (void)assume_action;
  442. CALLED(router_parse_addr_policy_item_from_string)++;
  443. *bad = 0;
  444. return NS(mock_addr_policy);
  445. }
  446. #undef NS_SUBMODULE
  447. #define NS_SUBMODULE ASPECT(routerset_union, source_bad)
  448. /*
  449. * Structural test for routerset_union, when given a bad source argument.
  450. */
  451. NS_DECL(smartlist_t *, smartlist_new, (void));
  452. static void
  453. NS(test_main)(void *arg)
  454. {
  455. routerset_t *set, *bad_set;
  456. (void)arg;
  457. set = routerset_new();
  458. bad_set = routerset_new();
  459. smartlist_free(bad_set->list);
  460. bad_set->list = NULL;
  461. NS_MOCK(smartlist_new);
  462. routerset_union(set, NULL);
  463. tt_int_op(CALLED(smartlist_new), OP_EQ, 0);
  464. routerset_union(set, bad_set);
  465. tt_int_op(CALLED(smartlist_new), OP_EQ, 0);
  466. done:
  467. NS_UNMOCK(smartlist_new);
  468. routerset_free(set);
  469. /* Just recreate list, so we can simply use routerset_free. */
  470. bad_set->list = smartlist_new();
  471. routerset_free(bad_set);
  472. }
  473. static smartlist_t *
  474. NS(smartlist_new)(void)
  475. {
  476. CALLED(smartlist_new)++;
  477. return NULL;
  478. }
  479. #undef NS_SUBMODULE
  480. #define NS_SUBMODULE ASPECT(routerset_union, one)
  481. /*
  482. * Functional test for routerset_union.
  483. */
  484. static void
  485. NS(test_main)(void *arg)
  486. {
  487. routerset_t *src = routerset_new();
  488. routerset_t *tgt;
  489. (void)arg;
  490. tgt = routerset_new();
  491. smartlist_add_strdup(src->list, "{xx}");
  492. routerset_union(tgt, src);
  493. tt_int_op(smartlist_len(tgt->list), OP_NE, 0);
  494. done:
  495. routerset_free(src);
  496. routerset_free(tgt);
  497. }
  498. #undef NS_SUBMODULE
  499. #define NS_SUBMODULE routerset_is_list
  500. /*
  501. * Functional tests for routerset_is_list.
  502. */
  503. static void
  504. NS(test_main)(void *arg)
  505. {
  506. routerset_t *set;
  507. addr_policy_t *policy;
  508. int is_list;
  509. (void)arg;
  510. /* len(set->country_names) == 0, len(set->policies) == 0 */
  511. set = routerset_new();
  512. is_list = routerset_is_list(set);
  513. routerset_free(set);
  514. set = NULL;
  515. tt_int_op(is_list, OP_NE, 0);
  516. /* len(set->country_names) != 0, len(set->policies) == 0 */
  517. set = routerset_new();
  518. smartlist_add(set->country_names, tor_strndup("foo", 3));
  519. is_list = routerset_is_list(set);
  520. routerset_free(set);
  521. set = NULL;
  522. tt_int_op(is_list, OP_EQ, 0);
  523. /* len(set->country_names) == 0, len(set->policies) != 0 */
  524. set = routerset_new();
  525. policy = tor_malloc_zero(sizeof(addr_policy_t));
  526. smartlist_add(set->policies, (void *)policy);
  527. is_list = routerset_is_list(set);
  528. routerset_free(set);
  529. set = NULL;
  530. tt_int_op(is_list, OP_EQ, 0);
  531. /* len(set->country_names) != 0, len(set->policies) != 0 */
  532. set = routerset_new();
  533. smartlist_add(set->country_names, tor_strndup("foo", 3));
  534. policy = tor_malloc_zero(sizeof(addr_policy_t));
  535. smartlist_add(set->policies, (void *)policy);
  536. is_list = routerset_is_list(set);
  537. routerset_free(set);
  538. set = NULL;
  539. tt_int_op(is_list, OP_EQ, 0);
  540. done:
  541. ;
  542. }
  543. #undef NS_SUBMODULE
  544. #define NS_SUBMODULE routerset_needs_geoip
  545. /*
  546. * Functional tests for routerset_needs_geoip.
  547. */
  548. static void
  549. NS(test_main)(void *arg)
  550. {
  551. const routerset_t *set;
  552. int needs_geoip;
  553. (void)arg;
  554. set = NULL;
  555. needs_geoip = routerset_needs_geoip(set);
  556. tt_int_op(needs_geoip, OP_EQ, 0);
  557. set = routerset_new();
  558. needs_geoip = routerset_needs_geoip(set);
  559. routerset_free((routerset_t *)set);
  560. tt_int_op(needs_geoip, OP_EQ, 0);
  561. set = NULL;
  562. set = routerset_new();
  563. smartlist_add(set->country_names, tor_strndup("xx", 2));
  564. needs_geoip = routerset_needs_geoip(set);
  565. routerset_free((routerset_t *)set);
  566. set = NULL;
  567. tt_int_op(needs_geoip, OP_NE, 0);
  568. done:
  569. ;
  570. }
  571. #undef NS_SUBMODULE
  572. #define NS_SUBMODULE routerset_is_empty
  573. /*
  574. * Functional tests for routerset_is_empty.
  575. */
  576. static void
  577. NS(test_main)(void *arg)
  578. {
  579. routerset_t *set = NULL;
  580. int is_empty;
  581. (void)arg;
  582. is_empty = routerset_is_empty(set);
  583. tt_int_op(is_empty, OP_NE, 0);
  584. set = routerset_new();
  585. is_empty = routerset_is_empty(set);
  586. routerset_free(set);
  587. set = NULL;
  588. tt_int_op(is_empty, OP_NE, 0);
  589. set = routerset_new();
  590. smartlist_add_strdup(set->list, "{xx}");
  591. is_empty = routerset_is_empty(set);
  592. routerset_free(set);
  593. set = NULL;
  594. tt_int_op(is_empty, OP_EQ, 0);
  595. done:
  596. ;
  597. }
  598. #undef NS_SUBMODULE
  599. #define NS_SUBMODULE ASPECT(routerset_contains, null_set_or_null_set_list)
  600. /*
  601. * Functional test for routerset_contains, when given a NULL set or the
  602. * set has a NULL list.
  603. */
  604. static void
  605. NS(test_main)(void *arg)
  606. {
  607. routerset_t *set = NULL;
  608. int contains;
  609. (void)arg;
  610. contains = routerset_contains(set, NULL, 0, NULL, NULL, 0);
  611. tt_int_op(contains, OP_EQ, 0);
  612. set = tor_malloc_zero(sizeof(routerset_t));
  613. set->list = NULL;
  614. contains = routerset_contains(set, NULL, 0, NULL, NULL, 0);
  615. tor_free(set);
  616. tt_int_op(contains, OP_EQ, 0);
  617. done:
  618. ;
  619. }
  620. #undef NS_SUBMODULE
  621. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_null_nickname)
  622. /*
  623. * Functional test for routerset_contains, when given a valid routerset but a
  624. * NULL nickname.
  625. */
  626. static void
  627. NS(test_main)(void *arg)
  628. {
  629. routerset_t *set = routerset_new();
  630. char *nickname = NULL;
  631. int contains;
  632. (void)arg;
  633. contains = routerset_contains(set, NULL, 0, nickname, NULL, 0);
  634. routerset_free(set);
  635. tt_int_op(contains, OP_EQ, 0);
  636. done:
  637. ;
  638. }
  639. #undef NS_SUBMODULE
  640. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_nickname)
  641. /*
  642. * Functional test for routerset_contains, when given a valid routerset
  643. * and the nickname is in the routerset.
  644. */
  645. static void
  646. NS(test_main)(void *arg)
  647. {
  648. routerset_t *set = routerset_new();
  649. const char *nickname;
  650. int contains;
  651. (void)arg;
  652. nickname = "Foo"; /* This tests the lowercase comparison as well. */
  653. strmap_set_lc(set->names, nickname, (void *)1);
  654. contains = routerset_contains(set, NULL, 0, nickname, NULL, 0);
  655. routerset_free(set);
  656. tt_int_op(contains, OP_EQ, 4);
  657. done:
  658. ;
  659. }
  660. #undef NS_SUBMODULE
  661. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_no_nickname)
  662. /*
  663. * Functional test for routerset_contains, when given a valid routerset
  664. * and the nickname is not in the routerset.
  665. */
  666. static void
  667. NS(test_main)(void *arg)
  668. {
  669. routerset_t *set = routerset_new();
  670. int contains;
  671. (void)arg;
  672. strmap_set_lc(set->names, "bar", (void *)1);
  673. contains = routerset_contains(set, NULL, 0, "foo", NULL, 0);
  674. routerset_free(set);
  675. tt_int_op(contains, OP_EQ, 0);
  676. done:
  677. ;
  678. }
  679. #undef NS_SUBMODULE
  680. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_digest)
  681. /*
  682. * Functional test for routerset_contains, when given a valid routerset
  683. * and the digest is contained in the routerset.
  684. */
  685. static void
  686. NS(test_main)(void *arg)
  687. {
  688. routerset_t *set = routerset_new();
  689. int contains;
  690. uint8_t foo[20] = { 2, 3, 4 };
  691. (void)arg;
  692. digestmap_set(set->digests, (const char*)foo, (void *)1);
  693. contains = routerset_contains(set, NULL, 0, NULL, (const char*)foo, 0);
  694. routerset_free(set);
  695. tt_int_op(contains, OP_EQ, 4);
  696. done:
  697. ;
  698. }
  699. #undef NS_SUBMODULE
  700. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_no_digest)
  701. /*
  702. * Functional test for routerset_contains, when given a valid routerset
  703. * and the digest is not contained in the routerset.
  704. */
  705. static void
  706. NS(test_main)(void *arg)
  707. {
  708. routerset_t *set = routerset_new();
  709. int contains;
  710. uint8_t bar[20] = { 9, 10, 11, 55 };
  711. uint8_t foo[20] = { 1, 2, 3, 4};
  712. (void)arg;
  713. digestmap_set(set->digests, (const char*)bar, (void *)1);
  714. contains = routerset_contains(set, NULL, 0, NULL, (const char*)foo, 0);
  715. routerset_free(set);
  716. tt_int_op(contains, OP_EQ, 0);
  717. done:
  718. ;
  719. }
  720. #undef NS_SUBMODULE
  721. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_null_digest)
  722. /*
  723. * Functional test for routerset_contains, when given a valid routerset
  724. * and the digest is NULL.
  725. */
  726. static void
  727. NS(test_main)(void *arg)
  728. {
  729. routerset_t *set = routerset_new();
  730. int contains;
  731. uint8_t bar[20] = { 9, 10, 11, 55 };
  732. (void)arg;
  733. digestmap_set(set->digests, (const char*)bar, (void *)1);
  734. contains = routerset_contains(set, NULL, 0, NULL, NULL, 0);
  735. routerset_free(set);
  736. tt_int_op(contains, OP_EQ, 0);
  737. done:
  738. ;
  739. }
  740. #undef NS_SUBMODULE
  741. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_addr)
  742. /*
  743. * Structural test for routerset_contains, when given a valid routerset
  744. * and the address is rejected by policy.
  745. */
  746. NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy,
  747. (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy));
  748. static tor_addr_t MOCK_TOR_ADDR;
  749. #define MOCK_TOR_ADDR_PTR (&MOCK_TOR_ADDR)
  750. static void
  751. NS(test_main)(void *arg)
  752. {
  753. routerset_t *set = routerset_new();
  754. tor_addr_t *addr = MOCK_TOR_ADDR_PTR;
  755. int contains;
  756. (void)arg;
  757. NS_MOCK(compare_tor_addr_to_addr_policy);
  758. contains = routerset_contains(set, addr, 0, NULL, NULL, 0);
  759. routerset_free(set);
  760. tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1);
  761. tt_int_op(contains, OP_EQ, 3);
  762. done:
  763. ;
  764. }
  765. addr_policy_result_t
  766. NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port,
  767. const smartlist_t *policy)
  768. {
  769. (void)port;
  770. (void)policy;
  771. CALLED(compare_tor_addr_to_addr_policy)++;
  772. tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
  773. return ADDR_POLICY_REJECTED;
  774. done:
  775. return 0;
  776. }
  777. #undef NS_SUBMODULE
  778. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_no_addr)
  779. /*
  780. * Structural test for routerset_contains, when given a valid routerset
  781. * and the address is not rejected by policy.
  782. */
  783. NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy,
  784. (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy));
  785. static void
  786. NS(test_main)(void *arg)
  787. {
  788. routerset_t *set = routerset_new();
  789. tor_addr_t *addr = MOCK_TOR_ADDR_PTR;
  790. int contains;
  791. (void)arg;
  792. NS_MOCK(compare_tor_addr_to_addr_policy);
  793. contains = routerset_contains(set, addr, 0, NULL, NULL, 0);
  794. routerset_free(set);
  795. tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1);
  796. tt_int_op(contains, OP_EQ, 0);
  797. done:
  798. ;
  799. }
  800. addr_policy_result_t
  801. NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port,
  802. const smartlist_t *policy)
  803. {
  804. (void)port;
  805. (void)policy;
  806. CALLED(compare_tor_addr_to_addr_policy)++;
  807. tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
  808. return ADDR_POLICY_ACCEPTED;
  809. done:
  810. return 0;
  811. }
  812. #undef NS_SUBMODULE
  813. #define NS_SUBMODULE ASPECT(routerset_contains, set_and_null_addr)
  814. /*
  815. * Structural test for routerset_contains, when given a valid routerset
  816. * and the address is NULL.
  817. */
  818. NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy,
  819. (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy));
  820. static void
  821. NS(test_main)(void *arg)
  822. {
  823. routerset_t *set = routerset_new();
  824. int contains;
  825. (void)arg;
  826. NS_MOCK(compare_tor_addr_to_addr_policy);
  827. contains = routerset_contains(set, NULL, 0, NULL, NULL, 0);
  828. routerset_free(set);
  829. tt_int_op(contains, OP_EQ, 0);
  830. done:
  831. ;
  832. }
  833. addr_policy_result_t
  834. NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port,
  835. const smartlist_t *policy)
  836. {
  837. (void)port;
  838. (void)policy;
  839. CALLED(compare_tor_addr_to_addr_policy)++;
  840. tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
  841. return ADDR_POLICY_ACCEPTED;
  842. done:
  843. return 0;
  844. }
  845. #undef NS_SUBMODULE
  846. #define NS_SUBMODULE ASPECT(routerset_contains, countries_no_geoip)
  847. /*
  848. * Structural test for routerset_contains, when there is no matching country
  849. * for the address.
  850. */
  851. NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy,
  852. (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy));
  853. NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr));
  854. static void
  855. NS(test_main)(void *arg)
  856. {
  857. routerset_t *set = routerset_new();
  858. int contains = 1;
  859. (void)arg;
  860. NS_MOCK(compare_tor_addr_to_addr_policy);
  861. NS_MOCK(geoip_get_country_by_addr);
  862. set->countries = bitarray_init_zero(1);
  863. bitarray_set(set->countries, 1);
  864. contains = routerset_contains(set, MOCK_TOR_ADDR_PTR, 0, NULL, NULL, -1);
  865. routerset_free(set);
  866. tt_int_op(contains, OP_EQ, 0);
  867. tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1);
  868. tt_int_op(CALLED(geoip_get_country_by_addr), OP_EQ, 1);
  869. done:
  870. ;
  871. }
  872. addr_policy_result_t
  873. NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port,
  874. const smartlist_t *policy)
  875. {
  876. (void)port;
  877. (void)policy;
  878. CALLED(compare_tor_addr_to_addr_policy)++;
  879. tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
  880. done:
  881. return ADDR_POLICY_ACCEPTED;
  882. }
  883. int
  884. NS(geoip_get_country_by_addr)(const tor_addr_t *addr)
  885. {
  886. CALLED(geoip_get_country_by_addr)++;
  887. tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
  888. done:
  889. return -1;
  890. }
  891. #undef NS_SUBMODULE
  892. #define NS_SUBMODULE ASPECT(routerset_contains, countries_geoip)
  893. /*
  894. * Structural test for routerset_contains, when there a matching country
  895. * for the address.
  896. */
  897. NS_DECL(addr_policy_result_t, compare_tor_addr_to_addr_policy,
  898. (const tor_addr_t *addr, uint16_t port, const smartlist_t *policy));
  899. NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr));
  900. static void
  901. NS(test_main)(void *arg)
  902. {
  903. routerset_t *set = routerset_new();
  904. int contains = 1;
  905. (void)arg;
  906. NS_MOCK(compare_tor_addr_to_addr_policy);
  907. NS_MOCK(geoip_get_country_by_addr);
  908. set->n_countries = 2;
  909. set->countries = bitarray_init_zero(1);
  910. bitarray_set(set->countries, 1);
  911. contains = routerset_contains(set, MOCK_TOR_ADDR_PTR, 0, NULL, NULL, -1);
  912. routerset_free(set);
  913. tt_int_op(contains, OP_EQ, 2);
  914. tt_int_op(CALLED(compare_tor_addr_to_addr_policy), OP_EQ, 1);
  915. tt_int_op(CALLED(geoip_get_country_by_addr), OP_EQ, 1);
  916. done:
  917. ;
  918. }
  919. addr_policy_result_t
  920. NS(compare_tor_addr_to_addr_policy)(const tor_addr_t *addr, uint16_t port,
  921. const smartlist_t *policy)
  922. {
  923. (void)port;
  924. (void)policy;
  925. CALLED(compare_tor_addr_to_addr_policy)++;
  926. tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
  927. done:
  928. return ADDR_POLICY_ACCEPTED;
  929. }
  930. int
  931. NS(geoip_get_country_by_addr)(const tor_addr_t *addr)
  932. {
  933. CALLED(geoip_get_country_by_addr)++;
  934. tt_ptr_op(addr, OP_EQ, MOCK_TOR_ADDR_PTR);
  935. done:
  936. return 1;
  937. }
  938. #undef NS_SUBMODULE
  939. #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, only_flag_and_no_ccs)
  940. /*
  941. * Functional test for routerset_add_unknown_ccs, where only_if_some_cc_set
  942. * is set and there are no country names.
  943. */
  944. static void
  945. NS(test_main)(void *arg)
  946. {
  947. routerset_t *set = routerset_new();
  948. routerset_t **setp = &set;
  949. int r;
  950. (void)arg;
  951. r = routerset_add_unknown_ccs(setp, 1);
  952. tt_int_op(r, OP_EQ, 0);
  953. done:
  954. routerset_free(set);
  955. }
  956. #undef NS_SUBMODULE
  957. #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, creates_set)
  958. /*
  959. * Functional test for routerset_add_unknown_ccs, where the set argument
  960. * is created if passed in as NULL.
  961. */
  962. /* The mock is only used to stop the test from asserting erroneously. */
  963. NS_DECL(country_t, geoip_get_country, (const char *country));
  964. static void
  965. NS(test_main)(void *arg)
  966. {
  967. routerset_t *set = NULL;
  968. routerset_t **setp = &set;
  969. int r;
  970. (void)arg;
  971. NS_MOCK(geoip_get_country);
  972. r = routerset_add_unknown_ccs(setp, 0);
  973. tt_ptr_op(*setp, OP_NE, NULL);
  974. tt_int_op(r, OP_EQ, 0);
  975. done:
  976. if (set != NULL)
  977. routerset_free(set);
  978. }
  979. country_t
  980. NS(geoip_get_country)(const char *country)
  981. {
  982. (void)country;
  983. CALLED(geoip_get_country)++;
  984. return -1;
  985. }
  986. #undef NS_SUBMODULE
  987. #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, add_unknown)
  988. /*
  989. * Structural test for routerset_add_unknown_ccs, that the "{??}"
  990. * country code is added to the list.
  991. */
  992. NS_DECL(country_t, geoip_get_country, (const char *country));
  993. NS_DECL(int, geoip_is_loaded, (sa_family_t family));
  994. static void
  995. NS(test_main)(void *arg)
  996. {
  997. routerset_t *set = routerset_new();
  998. routerset_t **setp = &set;
  999. int r;
  1000. (void)arg;
  1001. NS_MOCK(geoip_get_country);
  1002. NS_MOCK(geoip_is_loaded);
  1003. r = routerset_add_unknown_ccs(setp, 0);
  1004. tt_int_op(r, OP_EQ, 1);
  1005. tt_int_op(smartlist_contains_string(set->country_names, "??"), OP_EQ, 1);
  1006. tt_int_op(smartlist_contains_string(set->list, "{??}"), OP_EQ, 1);
  1007. done:
  1008. if (set != NULL)
  1009. routerset_free(set);
  1010. }
  1011. country_t
  1012. NS(geoip_get_country)(const char *country)
  1013. {
  1014. int arg_is_qq, arg_is_a1;
  1015. CALLED(geoip_get_country)++;
  1016. arg_is_qq = !strcmp(country, "??");
  1017. arg_is_a1 = !strcmp(country, "A1");
  1018. tt_int_op(arg_is_qq || arg_is_a1, OP_EQ, 1);
  1019. if (arg_is_qq)
  1020. return 1;
  1021. done:
  1022. return -1;
  1023. }
  1024. int
  1025. NS(geoip_is_loaded)(sa_family_t family)
  1026. {
  1027. CALLED(geoip_is_loaded)++;
  1028. tt_int_op(family, OP_EQ, AF_INET);
  1029. done:
  1030. return 0;
  1031. }
  1032. #undef NS_SUBMODULE
  1033. #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, add_a1)
  1034. /*
  1035. * Structural test for routerset_add_unknown_ccs, that the "{a1}"
  1036. * country code is added to the list.
  1037. */
  1038. NS_DECL(country_t, geoip_get_country, (const char *country));
  1039. NS_DECL(int, geoip_is_loaded, (sa_family_t family));
  1040. static void
  1041. NS(test_main)(void *arg)
  1042. {
  1043. routerset_t *set = routerset_new();
  1044. routerset_t **setp = &set;
  1045. int r;
  1046. (void)arg;
  1047. NS_MOCK(geoip_get_country);
  1048. NS_MOCK(geoip_is_loaded);
  1049. r = routerset_add_unknown_ccs(setp, 0);
  1050. tt_int_op(r, OP_EQ, 1);
  1051. tt_int_op(smartlist_contains_string(set->country_names, "a1"), OP_EQ, 1);
  1052. tt_int_op(smartlist_contains_string(set->list, "{a1}"), OP_EQ, 1);
  1053. done:
  1054. if (set != NULL)
  1055. routerset_free(set);
  1056. }
  1057. country_t
  1058. NS(geoip_get_country)(const char *country)
  1059. {
  1060. int arg_is_qq, arg_is_a1;
  1061. CALLED(geoip_get_country)++;
  1062. arg_is_qq = !strcmp(country, "??");
  1063. arg_is_a1 = !strcmp(country, "A1");
  1064. tt_int_op(arg_is_qq || arg_is_a1, OP_EQ, 1);
  1065. if (arg_is_a1)
  1066. return 1;
  1067. done:
  1068. return -1;
  1069. }
  1070. int
  1071. NS(geoip_is_loaded)(sa_family_t family)
  1072. {
  1073. CALLED(geoip_is_loaded)++;
  1074. tt_int_op(family, OP_EQ, AF_INET);
  1075. done:
  1076. return 0;
  1077. }
  1078. #undef NS_SUBMODULE
  1079. #define NS_SUBMODULE routerset_contains_extendinfo
  1080. /*
  1081. * Functional test for routerset_contains_extendinfo.
  1082. */
  1083. static void
  1084. NS(test_main)(void *arg)
  1085. {
  1086. routerset_t *set = routerset_new();
  1087. extend_info_t ei;
  1088. int r;
  1089. const char *nickname = "foo";
  1090. (void)arg;
  1091. memset(&ei, 0, sizeof(ei));
  1092. strmap_set_lc(set->names, nickname, (void *)1);
  1093. strncpy(ei.nickname, nickname, sizeof(ei.nickname) - 1);
  1094. ei.nickname[sizeof(ei.nickname) - 1] = '\0';
  1095. r = routerset_contains_extendinfo(set, &ei);
  1096. tt_int_op(r, OP_EQ, 4);
  1097. done:
  1098. routerset_free(set);
  1099. }
  1100. #undef NS_SUBMODULE
  1101. #define NS_SUBMODULE routerset_contains_router
  1102. /*
  1103. * Functional test for routerset_contains_router.
  1104. */
  1105. static void
  1106. NS(test_main)(void *arg)
  1107. {
  1108. routerset_t *set = routerset_new();
  1109. routerinfo_t ri;
  1110. country_t country = 1;
  1111. int r;
  1112. const char *nickname = "foo";
  1113. (void)arg;
  1114. memset(&ri, 0, sizeof(ri));
  1115. strmap_set_lc(set->names, nickname, (void *)1);
  1116. ri.nickname = (char *)nickname;
  1117. r = routerset_contains_router(set, &ri, country);
  1118. tt_int_op(r, OP_EQ, 4);
  1119. done:
  1120. routerset_free(set);
  1121. }
  1122. #undef NS_SUBMODULE
  1123. #define NS_SUBMODULE routerset_contains_routerstatus
  1124. /*
  1125. * Functional test for routerset_contains_routerstatus.
  1126. */
  1127. // XXX: This is a bit brief. It only populates and tests the nickname fields
  1128. // ie., enough to make the containment check succeed. Perhaps it should do
  1129. // a bit more or test a bit more.
  1130. static void
  1131. NS(test_main)(void *arg)
  1132. {
  1133. routerset_t *set = routerset_new();
  1134. routerstatus_t rs;
  1135. country_t country = 1;
  1136. int r;
  1137. const char *nickname = "foo";
  1138. (void)arg;
  1139. memset(&rs, 0, sizeof(rs));
  1140. strmap_set_lc(set->names, nickname, (void *)1);
  1141. strncpy(rs.nickname, nickname, sizeof(rs.nickname) - 1);
  1142. rs.nickname[sizeof(rs.nickname) - 1] = '\0';
  1143. r = routerset_contains_routerstatus(set, &rs, country);
  1144. tt_int_op(r, OP_EQ, 4);
  1145. done:
  1146. routerset_free(set);
  1147. }
  1148. #undef NS_SUBMODULE
  1149. #define NS_SUBMODULE ASPECT(routerset_contains_node, none)
  1150. /*
  1151. * Functional test for routerset_contains_node, when the node has no
  1152. * routerset or routerinfo.
  1153. */
  1154. static node_t NS(mock_node);
  1155. static void
  1156. NS(test_main)(void *arg)
  1157. {
  1158. routerset_t *set = routerset_new();
  1159. int r;
  1160. (void)arg;
  1161. NS(mock_node).ri = NULL;
  1162. NS(mock_node).rs = NULL;
  1163. r = routerset_contains_node(set, &NS(mock_node));
  1164. tt_int_op(r, OP_EQ, 0);
  1165. done:
  1166. routerset_free(set);
  1167. }
  1168. #undef NS_SUBMODULE
  1169. #define NS_SUBMODULE ASPECT(routerset_contains_node, routerstatus)
  1170. /*
  1171. * Functional test for routerset_contains_node, when the node has a
  1172. * routerset and no routerinfo.
  1173. */
  1174. static node_t NS(mock_node);
  1175. static void
  1176. NS(test_main)(void *arg)
  1177. {
  1178. routerset_t *set = routerset_new();
  1179. int r;
  1180. const char *nickname = "foo";
  1181. routerstatus_t rs;
  1182. (void)arg;
  1183. strmap_set_lc(set->names, nickname, (void *)1);
  1184. strncpy(rs.nickname, nickname, sizeof(rs.nickname) - 1);
  1185. rs.nickname[sizeof(rs.nickname) - 1] = '\0';
  1186. NS(mock_node).ri = NULL;
  1187. NS(mock_node).rs = &rs;
  1188. r = routerset_contains_node(set, &NS(mock_node));
  1189. tt_int_op(r, OP_EQ, 4);
  1190. done:
  1191. routerset_free(set);
  1192. }
  1193. #undef NS_SUBMODULE
  1194. #define NS_SUBMODULE ASPECT(routerset_contains_node, routerinfo)
  1195. /*
  1196. * Functional test for routerset_contains_node, when the node has no
  1197. * routerset and a routerinfo.
  1198. */
  1199. static void
  1200. NS(test_main)(void *arg)
  1201. {
  1202. routerset_t *set = routerset_new();
  1203. int r;
  1204. const char *nickname = "foo";
  1205. routerinfo_t ri;
  1206. node_t mock_node;
  1207. (void)arg;
  1208. strmap_set_lc(set->names, nickname, (void *)1);
  1209. ri.nickname = (char *)nickname;
  1210. mock_node.ri = &ri;
  1211. mock_node.rs = NULL;
  1212. r = routerset_contains_node(set, &mock_node);
  1213. tt_int_op(r, OP_EQ, 4);
  1214. done:
  1215. routerset_free(set);
  1216. }
  1217. #undef NS_SUBMODULE
  1218. #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, no_routerset)
  1219. /*
  1220. * Functional test for routerset_get_all_nodes, when routerset is NULL or
  1221. * the routerset list is NULL.
  1222. */
  1223. static void
  1224. NS(test_main)(void *arg)
  1225. {
  1226. smartlist_t *out = smartlist_new();
  1227. routerset_t *set = NULL;
  1228. (void)arg;
  1229. tt_int_op(smartlist_len(out), OP_EQ, 0);
  1230. routerset_get_all_nodes(out, NULL, NULL, 0);
  1231. tt_int_op(smartlist_len(out), OP_EQ, 0);
  1232. set = routerset_new();
  1233. smartlist_free(set->list);
  1234. routerset_get_all_nodes(out, NULL, NULL, 0);
  1235. tt_int_op(smartlist_len(out), OP_EQ, 0);
  1236. /* Just recreate list, so we can simply use routerset_free. */
  1237. set->list = smartlist_new();
  1238. done:
  1239. routerset_free(set);
  1240. smartlist_free(out);
  1241. }
  1242. #undef NS_SUBMODULE
  1243. #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, list_with_no_nodes)
  1244. /*
  1245. * Structural test for routerset_get_all_nodes, when the routerset list
  1246. * is empty.
  1247. */
  1248. NS_DECL(const node_t *, node_get_by_nickname,
  1249. (const char *nickname, unsigned flags));
  1250. static const char *NS(mock_nickname);
  1251. static void
  1252. NS(test_main)(void *arg)
  1253. {
  1254. smartlist_t *out = smartlist_new();
  1255. routerset_t *set = routerset_new();
  1256. int out_len;
  1257. (void)arg;
  1258. NS_MOCK(node_get_by_nickname);
  1259. NS(mock_nickname) = "foo";
  1260. smartlist_add_strdup(set->list, NS(mock_nickname));
  1261. routerset_get_all_nodes(out, set, NULL, 0);
  1262. out_len = smartlist_len(out);
  1263. smartlist_free(out);
  1264. routerset_free(set);
  1265. tt_int_op(out_len, OP_EQ, 0);
  1266. tt_int_op(CALLED(node_get_by_nickname), OP_EQ, 1);
  1267. done:
  1268. ;
  1269. }
  1270. const node_t *
  1271. NS(node_get_by_nickname)(const char *nickname, unsigned flags)
  1272. {
  1273. CALLED(node_get_by_nickname)++;
  1274. tt_str_op(nickname, OP_EQ, NS(mock_nickname));
  1275. tt_uint_op(flags, OP_EQ, 0);
  1276. done:
  1277. return NULL;
  1278. }
  1279. #undef NS_SUBMODULE
  1280. #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, list_flag_not_running)
  1281. /*
  1282. * Structural test for routerset_get_all_nodes, with the running_only flag
  1283. * is set but the nodes are not running.
  1284. */
  1285. NS_DECL(const node_t *, node_get_by_nickname,
  1286. (const char *nickname, unsigned flags));
  1287. static const char *NS(mock_nickname);
  1288. static node_t NS(mock_node);
  1289. static void
  1290. NS(test_main)(void *arg)
  1291. {
  1292. smartlist_t *out = smartlist_new();
  1293. routerset_t *set = routerset_new();
  1294. int out_len;
  1295. (void)arg;
  1296. NS_MOCK(node_get_by_nickname);
  1297. NS(mock_node).is_running = 0;
  1298. NS(mock_nickname) = "foo";
  1299. smartlist_add_strdup(set->list, NS(mock_nickname));
  1300. routerset_get_all_nodes(out, set, NULL, 1);
  1301. out_len = smartlist_len(out);
  1302. smartlist_free(out);
  1303. routerset_free(set);
  1304. tt_int_op(out_len, OP_EQ, 0);
  1305. tt_int_op(CALLED(node_get_by_nickname), OP_EQ, 1);
  1306. done:
  1307. ;
  1308. }
  1309. const node_t *
  1310. NS(node_get_by_nickname)(const char *nickname, unsigned flags)
  1311. {
  1312. CALLED(node_get_by_nickname)++;
  1313. tt_str_op(nickname, OP_EQ, NS(mock_nickname));
  1314. tt_int_op(flags, OP_EQ, 0);
  1315. done:
  1316. return &NS(mock_node);
  1317. }
  1318. #undef NS_SUBMODULE
  1319. #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, list)
  1320. /*
  1321. * Structural test for routerset_get_all_nodes.
  1322. */
  1323. NS_DECL(const node_t *, node_get_by_nickname,
  1324. (const char *nickname, unsigned flags));
  1325. static char *NS(mock_nickname);
  1326. static node_t NS(mock_node);
  1327. static void
  1328. NS(test_main)(void *arg)
  1329. {
  1330. smartlist_t *out = smartlist_new();
  1331. routerset_t *set = routerset_new();
  1332. int out_len;
  1333. node_t *ent;
  1334. (void)arg;
  1335. NS_MOCK(node_get_by_nickname);
  1336. NS(mock_nickname) = tor_strdup("foo");
  1337. smartlist_add(set->list, NS(mock_nickname));
  1338. routerset_get_all_nodes(out, set, NULL, 0);
  1339. out_len = smartlist_len(out);
  1340. ent = (node_t *)smartlist_get(out, 0);
  1341. smartlist_free(out);
  1342. routerset_free(set);
  1343. tt_int_op(out_len, OP_EQ, 1);
  1344. tt_ptr_op(ent, OP_EQ, &NS(mock_node));
  1345. tt_int_op(CALLED(node_get_by_nickname), OP_EQ, 1);
  1346. done:
  1347. ;
  1348. }
  1349. const node_t *
  1350. NS(node_get_by_nickname)(const char *nickname, unsigned flags)
  1351. {
  1352. CALLED(node_get_by_nickname)++;
  1353. tt_str_op(nickname, OP_EQ, NS(mock_nickname));
  1354. tt_int_op(flags, OP_EQ, 0);
  1355. done:
  1356. return &NS(mock_node);
  1357. }
  1358. #undef NS_SUBMODULE
  1359. #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, nodelist_with_no_nodes)
  1360. /*
  1361. * Structural test for routerset_get_all_nodes, when the nodelist has no nodes.
  1362. */
  1363. NS_DECL(smartlist_t *, nodelist_get_list, (void));
  1364. static smartlist_t *NS(mock_smartlist);
  1365. static void
  1366. NS(test_main)(void *arg)
  1367. {
  1368. routerset_t *set = routerset_new();
  1369. smartlist_t *out = smartlist_new();
  1370. int r;
  1371. (void)arg;
  1372. NS_MOCK(nodelist_get_list);
  1373. smartlist_add_strdup(set->country_names, "{xx}");
  1374. NS(mock_smartlist) = smartlist_new();
  1375. routerset_get_all_nodes(out, set, NULL, 1);
  1376. r = smartlist_len(out);
  1377. routerset_free(set);
  1378. smartlist_free(out);
  1379. smartlist_free(NS(mock_smartlist));
  1380. tt_int_op(r, OP_EQ, 0);
  1381. tt_int_op(CALLED(nodelist_get_list), OP_EQ, 1);
  1382. done:
  1383. ;
  1384. }
  1385. smartlist_t *
  1386. NS(nodelist_get_list)(void)
  1387. {
  1388. CALLED(nodelist_get_list)++;
  1389. return NS(mock_smartlist);
  1390. }
  1391. #undef NS_SUBMODULE
  1392. #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, nodelist_flag_not_running)
  1393. /*
  1394. * Structural test for routerset_get_all_nodes, with a non-list routerset
  1395. * the running_only flag is set, but the nodes are not running.
  1396. */
  1397. NS_DECL(smartlist_t *, nodelist_get_list, (void));
  1398. static smartlist_t *NS(mock_smartlist);
  1399. static node_t NS(mock_node);
  1400. static void
  1401. NS(test_main)(void *arg)
  1402. {
  1403. routerset_t *set = routerset_new();
  1404. smartlist_t *out = smartlist_new();
  1405. int r;
  1406. (void)arg;
  1407. NS_MOCK(nodelist_get_list);
  1408. smartlist_add_strdup(set->country_names, "{xx}");
  1409. NS(mock_smartlist) = smartlist_new();
  1410. NS(mock_node).is_running = 0;
  1411. smartlist_add(NS(mock_smartlist), (void *)&NS(mock_node));
  1412. routerset_get_all_nodes(out, set, NULL, 1);
  1413. r = smartlist_len(out);
  1414. routerset_free(set);
  1415. smartlist_free(out);
  1416. smartlist_free(NS(mock_smartlist));
  1417. tt_int_op(r, OP_EQ, 0);
  1418. tt_int_op(CALLED(nodelist_get_list), OP_EQ, 1);
  1419. done:
  1420. ;
  1421. }
  1422. smartlist_t *
  1423. NS(nodelist_get_list)(void)
  1424. {
  1425. CALLED(nodelist_get_list)++;
  1426. return NS(mock_smartlist);
  1427. }
  1428. #undef NS_SUBMODULE
  1429. #define NS_SUBMODULE routerset_subtract_nodes
  1430. /*
  1431. * Functional test for routerset_subtract_nodes.
  1432. */
  1433. static void
  1434. NS(test_main)(void *arg)
  1435. {
  1436. routerset_t *set = routerset_new();
  1437. smartlist_t *list = smartlist_new();
  1438. const char *nickname = "foo";
  1439. routerinfo_t ri;
  1440. node_t mock_node;
  1441. (void)arg;
  1442. strmap_set_lc(set->names, nickname, (void *)1);
  1443. ri.nickname = (char *)nickname;
  1444. mock_node.rs = NULL;
  1445. mock_node.ri = &ri;
  1446. smartlist_add(list, (void *)&mock_node);
  1447. tt_int_op(smartlist_len(list), OP_NE, 0);
  1448. routerset_subtract_nodes(list, set);
  1449. tt_int_op(smartlist_len(list), OP_EQ, 0);
  1450. done:
  1451. routerset_free(set);
  1452. smartlist_free(list);
  1453. }
  1454. #undef NS_SUBMODULE
  1455. #define NS_SUBMODULE ASPECT(routerset_subtract_nodes, null_routerset)
  1456. /*
  1457. * Functional test for routerset_subtract_nodes, with a NULL routerset.
  1458. */
  1459. static void
  1460. NS(test_main)(void *arg)
  1461. {
  1462. routerset_t *set = NULL;
  1463. smartlist_t *list = smartlist_new();
  1464. const char *nickname = "foo";
  1465. routerinfo_t ri;
  1466. node_t mock_node;
  1467. (void)arg;
  1468. ri.nickname = (char *)nickname;
  1469. mock_node.ri = &ri;
  1470. smartlist_add(list, (void *)&mock_node);
  1471. tt_int_op(smartlist_len(list), OP_NE, 0);
  1472. routerset_subtract_nodes(list, set);
  1473. tt_int_op(smartlist_len(list), OP_NE, 0);
  1474. done:
  1475. routerset_free(set);
  1476. smartlist_free(list);
  1477. }
  1478. #undef NS_SUBMODULE
  1479. #define NS_SUBMODULE routerset_to_string
  1480. /*
  1481. * Functional test for routerset_to_string.
  1482. */
  1483. static void
  1484. NS(test_main)(void *arg)
  1485. {
  1486. routerset_t *set = NULL;
  1487. char *s = NULL;
  1488. (void)arg;
  1489. set = NULL;
  1490. s = routerset_to_string(set);
  1491. tt_str_op(s, OP_EQ, "");
  1492. tor_free(s);
  1493. set = routerset_new();
  1494. s = routerset_to_string(set);
  1495. tt_str_op(s, OP_EQ, "");
  1496. tor_free(s);
  1497. routerset_free(set); set = NULL;
  1498. set = routerset_new();
  1499. smartlist_add(set->list, tor_strndup("a", 1));
  1500. s = routerset_to_string(set);
  1501. tt_str_op(s, OP_EQ, "a");
  1502. tor_free(s);
  1503. routerset_free(set); set = NULL;
  1504. set = routerset_new();
  1505. smartlist_add(set->list, tor_strndup("a", 1));
  1506. smartlist_add(set->list, tor_strndup("b", 1));
  1507. s = routerset_to_string(set);
  1508. tt_str_op(s, OP_EQ, "a,b");
  1509. tor_free(s);
  1510. routerset_free(set); set = NULL;
  1511. done:
  1512. tor_free(s);
  1513. routerset_free((routerset_t *)set);
  1514. }
  1515. #undef NS_SUBMODULE
  1516. #define NS_SUBMODULE ASPECT(routerset_equal, empty_empty)
  1517. /*
  1518. * Functional test for routerset_equal, with both routersets empty.
  1519. */
  1520. static void
  1521. NS(test_main)(void *arg)
  1522. {
  1523. routerset_t *a = routerset_new(), *b = routerset_new();
  1524. int r;
  1525. (void)arg;
  1526. r = routerset_equal(a, b);
  1527. routerset_free(a);
  1528. routerset_free(b);
  1529. tt_int_op(r, OP_EQ, 1);
  1530. done:
  1531. ;
  1532. }
  1533. #undef NS_SUBMODULE
  1534. #define NS_SUBMODULE ASPECT(routerset_equal, empty_not_empty)
  1535. /*
  1536. * Functional test for routerset_equal, with one routersets empty.
  1537. */
  1538. static void
  1539. NS(test_main)(void *arg)
  1540. {
  1541. routerset_t *a = routerset_new(), *b = routerset_new();
  1542. int r;
  1543. (void)arg;
  1544. smartlist_add_strdup(b->list, "{xx}");
  1545. r = routerset_equal(a, b);
  1546. routerset_free(a);
  1547. routerset_free(b);
  1548. tt_int_op(r, OP_EQ, 0);
  1549. done:
  1550. ;
  1551. }
  1552. #undef NS_SUBMODULE
  1553. #define NS_SUBMODULE ASPECT(routerset_equal, differing_lengths)
  1554. /*
  1555. * Functional test for routerset_equal, with the routersets having
  1556. * differing lengths.
  1557. */
  1558. static void
  1559. NS(test_main)(void *arg)
  1560. {
  1561. routerset_t *a = routerset_new(), *b = routerset_new();
  1562. int r;
  1563. (void)arg;
  1564. smartlist_add_strdup(a->list, "{aa}");
  1565. smartlist_add_strdup(b->list, "{b1}");
  1566. smartlist_add_strdup(b->list, "{b2}");
  1567. r = routerset_equal(a, b);
  1568. routerset_free(a);
  1569. routerset_free(b);
  1570. tt_int_op(r, OP_EQ, 0);
  1571. done:
  1572. ;
  1573. }
  1574. #undef NS_SUBMODULE
  1575. #define NS_SUBMODULE ASPECT(routerset_equal, unequal)
  1576. /*
  1577. * Functional test for routerset_equal, with the routersets being
  1578. * different.
  1579. */
  1580. static void
  1581. NS(test_main)(void *arg)
  1582. {
  1583. routerset_t *a = routerset_new(), *b = routerset_new();
  1584. int r;
  1585. (void)arg;
  1586. smartlist_add_strdup(a->list, "foo");
  1587. smartlist_add_strdup(b->list, "bar");
  1588. r = routerset_equal(a, b);
  1589. routerset_free(a);
  1590. routerset_free(b);
  1591. tt_int_op(r, OP_EQ, 0);
  1592. done:
  1593. ;
  1594. }
  1595. #undef NS_SUBMODULE
  1596. #define NS_SUBMODULE ASPECT(routerset_equal, equal)
  1597. /*
  1598. * Functional test for routerset_equal, with the routersets being
  1599. * equal.
  1600. */
  1601. static void
  1602. NS(test_main)(void *arg)
  1603. {
  1604. routerset_t *a = routerset_new(), *b = routerset_new();
  1605. int r;
  1606. (void)arg;
  1607. smartlist_add_strdup(a->list, "foo");
  1608. smartlist_add_strdup(b->list, "foo");
  1609. r = routerset_equal(a, b);
  1610. routerset_free(a);
  1611. routerset_free(b);
  1612. tt_int_op(r, OP_EQ, 1);
  1613. done:
  1614. ;
  1615. }
  1616. #undef NS_SUBMODULE
  1617. #define NS_SUBMODULE ASPECT(routerset_free, null_routerset)
  1618. /*
  1619. * Structural test for routerset_free, where the routerset is NULL.
  1620. */
  1621. NS_DECL(void, smartlist_free, (smartlist_t *sl));
  1622. static void
  1623. NS(test_main)(void *arg)
  1624. {
  1625. (void)arg;
  1626. NS_MOCK(smartlist_free);
  1627. routerset_free(NULL);
  1628. tt_int_op(CALLED(smartlist_free), OP_EQ, 0);
  1629. done:
  1630. ;
  1631. }
  1632. void
  1633. NS(smartlist_free)(smartlist_t *s)
  1634. {
  1635. (void)s;
  1636. CALLED(smartlist_free)++;
  1637. }
  1638. #undef NS_SUBMODULE
  1639. #define NS_SUBMODULE routerset_free
  1640. /*
  1641. * Structural test for routerset_free.
  1642. */
  1643. NS_DECL(void, smartlist_free, (smartlist_t *sl));
  1644. NS_DECL(void, strmap_free,(strmap_t *map, void (*free_val)(void*)));
  1645. NS_DECL(void, digestmap_free, (digestmap_t *map, void (*free_val)(void*)));
  1646. static void
  1647. NS(test_main)(void *arg)
  1648. {
  1649. routerset_t *routerset = routerset_new();
  1650. (void)arg;
  1651. NS_MOCK(smartlist_free);
  1652. NS_MOCK(strmap_free);
  1653. NS_MOCK(digestmap_free);
  1654. routerset_free(routerset);
  1655. tt_int_op(CALLED(smartlist_free), OP_NE, 0);
  1656. tt_int_op(CALLED(strmap_free), OP_NE, 0);
  1657. tt_int_op(CALLED(digestmap_free), OP_NE, 0);
  1658. done:
  1659. ;
  1660. }
  1661. void
  1662. NS(smartlist_free)(smartlist_t *s)
  1663. {
  1664. CALLED(smartlist_free)++;
  1665. smartlist_free__real(s);
  1666. }
  1667. void
  1668. NS(strmap_free)(strmap_t *map, void (*free_val)(void*))
  1669. {
  1670. CALLED(strmap_free)++;
  1671. strmap_free__real(map, free_val);
  1672. }
  1673. void
  1674. NS(digestmap_free)(digestmap_t *map, void (*free_val)(void*))
  1675. {
  1676. CALLED(digestmap_free)++;
  1677. digestmap_free__real(map, free_val);
  1678. }
  1679. #undef NS_SUBMODULE
  1680. struct testcase_t routerset_tests[] = {
  1681. TEST_CASE(routerset_new),
  1682. TEST_CASE(routerset_get_countryname),
  1683. TEST_CASE(routerset_is_list),
  1684. TEST_CASE(routerset_needs_geoip),
  1685. TEST_CASE(routerset_is_empty),
  1686. TEST_CASE_ASPECT(routerset_contains, null_set_or_null_set_list),
  1687. TEST_CASE_ASPECT(routerset_contains, set_and_nickname),
  1688. TEST_CASE_ASPECT(routerset_contains, set_and_null_nickname),
  1689. TEST_CASE_ASPECT(routerset_contains, set_and_no_nickname),
  1690. TEST_CASE_ASPECT(routerset_contains, set_and_digest),
  1691. TEST_CASE_ASPECT(routerset_contains, set_and_no_digest),
  1692. TEST_CASE_ASPECT(routerset_contains, set_and_null_digest),
  1693. TEST_CASE_ASPECT(routerset_contains, set_and_addr),
  1694. TEST_CASE_ASPECT(routerset_contains, set_and_no_addr),
  1695. TEST_CASE_ASPECT(routerset_contains, set_and_null_addr),
  1696. TEST_CASE_ASPECT(routerset_contains, countries_no_geoip),
  1697. TEST_CASE_ASPECT(routerset_contains, countries_geoip),
  1698. TEST_CASE_ASPECT(routerset_add_unknown_ccs, only_flag_and_no_ccs),
  1699. TEST_CASE_ASPECT(routerset_add_unknown_ccs, creates_set),
  1700. TEST_CASE_ASPECT(routerset_add_unknown_ccs, add_unknown),
  1701. TEST_CASE_ASPECT(routerset_add_unknown_ccs, add_a1),
  1702. TEST_CASE(routerset_contains_extendinfo),
  1703. TEST_CASE(routerset_contains_router),
  1704. TEST_CASE(routerset_contains_routerstatus),
  1705. TEST_CASE_ASPECT(routerset_contains_node, none),
  1706. TEST_CASE_ASPECT(routerset_contains_node, routerinfo),
  1707. TEST_CASE_ASPECT(routerset_contains_node, routerstatus),
  1708. TEST_CASE_ASPECT(routerset_get_all_nodes, no_routerset),
  1709. TEST_CASE_ASPECT(routerset_get_all_nodes, list_with_no_nodes),
  1710. TEST_CASE_ASPECT(routerset_get_all_nodes, list_flag_not_running),
  1711. TEST_CASE_ASPECT(routerset_get_all_nodes, list),
  1712. TEST_CASE_ASPECT(routerset_get_all_nodes, nodelist_with_no_nodes),
  1713. TEST_CASE_ASPECT(routerset_get_all_nodes, nodelist_flag_not_running),
  1714. TEST_CASE_ASPECT(routerset_refresh_counties, geoip_not_loaded),
  1715. TEST_CASE_ASPECT(routerset_refresh_counties, no_countries),
  1716. TEST_CASE_ASPECT(routerset_refresh_counties, one_valid_country),
  1717. TEST_CASE_ASPECT(routerset_refresh_counties, one_invalid_country),
  1718. TEST_CASE_ASPECT(routerset_union, source_bad),
  1719. TEST_CASE_ASPECT(routerset_union, one),
  1720. TEST_CASE_ASPECT(routerset_parse, malformed),
  1721. TEST_CASE_ASPECT(routerset_parse, valid_hexdigest),
  1722. TEST_CASE_ASPECT(routerset_parse, valid_nickname),
  1723. TEST_CASE_ASPECT(routerset_parse, get_countryname),
  1724. TEST_CASE_ASPECT(routerset_parse, policy_wildcard),
  1725. TEST_CASE_ASPECT(routerset_parse, policy_ipv4),
  1726. TEST_CASE_ASPECT(routerset_parse, policy_ipv6),
  1727. TEST_CASE(routerset_subtract_nodes),
  1728. TEST_CASE_ASPECT(routerset_subtract_nodes, null_routerset),
  1729. TEST_CASE(routerset_to_string),
  1730. TEST_CASE_ASPECT(routerset_equal, empty_empty),
  1731. TEST_CASE_ASPECT(routerset_equal, empty_not_empty),
  1732. TEST_CASE_ASPECT(routerset_equal, differing_lengths),
  1733. TEST_CASE_ASPECT(routerset_equal, unequal),
  1734. TEST_CASE_ASPECT(routerset_equal, equal),
  1735. TEST_CASE_ASPECT(routerset_free, null_routerset),
  1736. TEST_CASE(routerset_free),
  1737. END_OF_TESTCASES
  1738. };