test_routerset.c 47 KB

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