testargint.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
  1. /*******************************************************************************
  2. * This file is part of the argtable3 library.
  3. *
  4. * Copyright (C) 2013-2019 Tom G. Huang
  5. * <tomghuang@gmail.com>
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * * Neither the name of STEWART HEITMANN nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
  23. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. ******************************************************************************/
  30. #include <string.h>
  31. #include "CuTest.h"
  32. #include "argtable3.h"
  33. #if defined(_MSC_VER)
  34. #pragma warning(push)
  35. #pragma warning(disable : 4204)
  36. #endif
  37. void test_argint_basic_001(CuTest* tc) {
  38. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  39. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  40. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  41. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  42. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  43. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  44. struct arg_end* end = arg_end(20);
  45. void* argtable[] = {a, b, c, d, e, f, end};
  46. int nerrors;
  47. char* argv[] = {"program", "0", NULL};
  48. int argc = sizeof(argv) / sizeof(char*) - 1;
  49. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  50. nerrors = arg_parse(argc, argv, argtable);
  51. CuAssertTrue(tc, nerrors == 0);
  52. CuAssertTrue(tc, a->count == 1);
  53. CuAssertIntEquals(tc, a->ival[0], 0);
  54. CuAssertTrue(tc, b->count == 0);
  55. CuAssertTrue(tc, c->count == 0);
  56. CuAssertTrue(tc, d->count == 0);
  57. CuAssertTrue(tc, e->count == 0);
  58. CuAssertTrue(tc, f->count == 0);
  59. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  60. }
  61. void test_argint_basic_002(CuTest* tc) {
  62. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  63. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  64. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  65. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  66. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  67. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  68. struct arg_end* end = arg_end(20);
  69. void* argtable[] = {a, b, c, d, e, f, end};
  70. int nerrors;
  71. char* argv[] = {"program", "1", NULL};
  72. int argc = sizeof(argv) / sizeof(char*) - 1;
  73. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  74. nerrors = arg_parse(argc, argv, argtable);
  75. CuAssertTrue(tc, nerrors == 0);
  76. CuAssertTrue(tc, a->count == 1);
  77. CuAssertIntEquals(tc, a->ival[0], 1);
  78. CuAssertTrue(tc, b->count == 0);
  79. CuAssertTrue(tc, c->count == 0);
  80. CuAssertTrue(tc, d->count == 0);
  81. CuAssertTrue(tc, e->count == 0);
  82. CuAssertTrue(tc, f->count == 0);
  83. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  84. }
  85. void test_argint_basic_003(CuTest* tc) {
  86. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  87. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  88. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  89. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  90. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  91. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  92. struct arg_end* end = arg_end(20);
  93. void* argtable[] = {a, b, c, d, e, f, end};
  94. int nerrors;
  95. char* argv[] = {"program", "1", "2", NULL};
  96. int argc = sizeof(argv) / sizeof(char*) - 1;
  97. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  98. nerrors = arg_parse(argc, argv, argtable);
  99. CuAssertTrue(tc, nerrors == 0);
  100. CuAssertTrue(tc, a->count == 1);
  101. CuAssertIntEquals(tc, a->ival[0], 1);
  102. CuAssertTrue(tc, b->count == 1);
  103. CuAssertIntEquals(tc, b->ival[0], 2);
  104. CuAssertTrue(tc, c->count == 0);
  105. CuAssertTrue(tc, d->count == 0);
  106. CuAssertTrue(tc, e->count == 0);
  107. CuAssertTrue(tc, f->count == 0);
  108. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  109. }
  110. void test_argint_basic_004(CuTest* tc) {
  111. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  112. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  113. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  114. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  115. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  116. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  117. struct arg_end* end = arg_end(20);
  118. void* argtable[] = {a, b, c, d, e, f, end};
  119. int nerrors;
  120. char* argv[] = {"program", "5", "7", "9", "-d", "-21", NULL};
  121. int argc = sizeof(argv) / sizeof(char*) - 1;
  122. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  123. nerrors = arg_parse(argc, argv, argtable);
  124. CuAssertTrue(tc, nerrors == 0);
  125. CuAssertTrue(tc, a->count == 1);
  126. CuAssertIntEquals(tc, a->ival[0], 5);
  127. CuAssertTrue(tc, b->count == 1);
  128. CuAssertIntEquals(tc, b->ival[0], 7);
  129. CuAssertTrue(tc, c->count == 1);
  130. CuAssertIntEquals(tc, c->ival[0], 9);
  131. CuAssertTrue(tc, d->count == 1);
  132. CuAssertIntEquals(tc, d->ival[0], -21);
  133. CuAssertTrue(tc, e->count == 0);
  134. CuAssertTrue(tc, f->count == 0);
  135. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  136. }
  137. void test_argint_basic_005(CuTest* tc) {
  138. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  139. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  140. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  141. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  142. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  143. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  144. struct arg_end* end = arg_end(20);
  145. void* argtable[] = {a, b, c, d, e, f, end};
  146. int nerrors;
  147. char* argv[] = {"program", "-d", "1", "-D2", "--delta", "3", NULL};
  148. int argc = sizeof(argv) / sizeof(char*) - 1;
  149. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  150. nerrors = arg_parse(argc, argv, argtable);
  151. CuAssertTrue(tc, nerrors == 1);
  152. CuAssertTrue(tc, a->count == 0);
  153. CuAssertTrue(tc, b->count == 0);
  154. CuAssertTrue(tc, c->count == 0);
  155. CuAssertTrue(tc, d->count == 3);
  156. CuAssertIntEquals(tc, d->ival[0], 1);
  157. CuAssertIntEquals(tc, d->ival[1], 2);
  158. CuAssertIntEquals(tc, d->ival[2], 3);
  159. CuAssertTrue(tc, e->count == 0);
  160. CuAssertTrue(tc, f->count == 0);
  161. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  162. }
  163. void test_argint_basic_006(CuTest* tc) {
  164. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  165. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  166. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  167. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  168. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  169. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  170. struct arg_end* end = arg_end(20);
  171. void* argtable[] = {a, b, c, d, e, f, end};
  172. int nerrors;
  173. char* argv[] = {"program", "1", "2", "4", "--eps", "-7", NULL};
  174. int argc = sizeof(argv) / sizeof(char*) - 1;
  175. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  176. nerrors = arg_parse(argc, argv, argtable);
  177. CuAssertTrue(tc, nerrors == 0);
  178. CuAssertTrue(tc, a->count == 1);
  179. CuAssertIntEquals(tc, a->ival[0], 1);
  180. CuAssertTrue(tc, b->count == 1);
  181. CuAssertIntEquals(tc, b->ival[0], 2);
  182. CuAssertTrue(tc, c->count == 1);
  183. CuAssertIntEquals(tc, c->ival[0], 4);
  184. CuAssertTrue(tc, d->count == 0);
  185. CuAssertTrue(tc, e->count == 1);
  186. CuAssertIntEquals(tc, e->ival[0], -7);
  187. CuAssertTrue(tc, f->count == 0);
  188. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  189. }
  190. void test_argint_basic_007(CuTest* tc) {
  191. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  192. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  193. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  194. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  195. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  196. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  197. struct arg_end* end = arg_end(20);
  198. void* argtable[] = {a, b, c, d, e, f, end};
  199. int nerrors;
  200. char* argv[] = {"program", "1", "2", "4", "--eqn", "-7", NULL};
  201. int argc = sizeof(argv) / sizeof(char*) - 1;
  202. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  203. nerrors = arg_parse(argc, argv, argtable);
  204. CuAssertTrue(tc, nerrors == 0);
  205. CuAssertTrue(tc, a->count == 1);
  206. CuAssertIntEquals(tc, a->ival[0], 1);
  207. CuAssertTrue(tc, b->count == 1);
  208. CuAssertIntEquals(tc, b->ival[0], 2);
  209. CuAssertTrue(tc, c->count == 1);
  210. CuAssertIntEquals(tc, c->ival[0], 4);
  211. CuAssertTrue(tc, d->count == 0);
  212. CuAssertTrue(tc, e->count == 1);
  213. CuAssertIntEquals(tc, e->ival[0], -7);
  214. CuAssertTrue(tc, f->count == 0);
  215. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  216. }
  217. void test_argint_basic_008(CuTest* tc) {
  218. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  219. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  220. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  221. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  222. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  223. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  224. struct arg_end* end = arg_end(20);
  225. void* argtable[] = {a, b, c, d, e, f, end};
  226. int nerrors;
  227. char* argv[] = {"program", "1", "2", "3", "-D4", "--eps", "-10", NULL};
  228. int argc = sizeof(argv) / sizeof(char*) - 1;
  229. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  230. nerrors = arg_parse(argc, argv, argtable);
  231. CuAssertTrue(tc, nerrors == 0);
  232. CuAssertTrue(tc, a->count == 1);
  233. CuAssertIntEquals(tc, a->ival[0], 1);
  234. CuAssertTrue(tc, b->count == 1);
  235. CuAssertIntEquals(tc, b->ival[0], 2);
  236. CuAssertTrue(tc, c->count == 1);
  237. CuAssertIntEquals(tc, c->ival[0], 3);
  238. CuAssertTrue(tc, d->count == 1);
  239. CuAssertIntEquals(tc, d->ival[0], 4);
  240. CuAssertTrue(tc, e->count == 1);
  241. CuAssertIntEquals(tc, e->ival[0], -10);
  242. CuAssertTrue(tc, f->count == 0);
  243. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  244. }
  245. void test_argint_basic_009(CuTest* tc) {
  246. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  247. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  248. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  249. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  250. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  251. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  252. struct arg_end* end = arg_end(20);
  253. void* argtable[] = {a, b, c, d, e, f, end};
  254. int nerrors;
  255. int i;
  256. char* argv[] = {"program", "1", "-f", NULL};
  257. int argc = sizeof(argv) / sizeof(char*) - 1;
  258. /* allow missing argument values for the f argument, and set defaults to -1 */
  259. f->hdr.flag |= ARG_HASOPTVALUE;
  260. for (i = 0; i < f->hdr.maxcount; i++)
  261. f->ival[i] = -1;
  262. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  263. nerrors = arg_parse(argc, argv, argtable);
  264. CuAssertTrue(tc, nerrors == 0);
  265. CuAssertTrue(tc, a->count == 1);
  266. CuAssertTrue(tc, b->count == 0);
  267. CuAssertTrue(tc, c->count == 0);
  268. CuAssertTrue(tc, d->count == 0);
  269. CuAssertTrue(tc, e->count == 0);
  270. CuAssertTrue(tc, f->count == 1);
  271. CuAssertIntEquals(tc, f->ival[0], -1);
  272. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  273. }
  274. void test_argint_basic_010(CuTest* tc) {
  275. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  276. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  277. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  278. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  279. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  280. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  281. struct arg_end* end = arg_end(20);
  282. void* argtable[] = {a, b, c, d, e, f, end};
  283. int nerrors;
  284. int i;
  285. char* argv[] = {"program", "-f", "1", NULL};
  286. int argc = sizeof(argv) / sizeof(char*) - 1;
  287. /* allow missing argument values for the f argument, and set defaults to -1 */
  288. f->hdr.flag |= ARG_HASOPTVALUE;
  289. for (i = 0; i < f->hdr.maxcount; i++)
  290. f->ival[i] = -1;
  291. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  292. nerrors = arg_parse(argc, argv, argtable);
  293. CuAssertIntEquals(tc, nerrors, 0);
  294. CuAssertIntEquals(tc, a->count, 1);
  295. CuAssertIntEquals(tc, a->ival[0], 1);
  296. CuAssertIntEquals(tc, b->count, 0);
  297. CuAssertIntEquals(tc, c->count, 0);
  298. CuAssertIntEquals(tc, d->count, 0);
  299. CuAssertIntEquals(tc, e->count, 0);
  300. CuAssertIntEquals(tc, f->count, 1);
  301. CuAssertIntEquals(tc, f->ival[0], -1);
  302. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  303. }
  304. void test_argint_basic_011(CuTest* tc) {
  305. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  306. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  307. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  308. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  309. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  310. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  311. struct arg_end* end = arg_end(20);
  312. void* argtable[] = {a, b, c, d, e, f, end};
  313. int nerrors;
  314. int i;
  315. char* argv[] = {"program", "-f", "2", "--filler", NULL};
  316. int argc = sizeof(argv) / sizeof(char*) - 1;
  317. /* allow missing argument values for the f argument, and set defaults to -1 */
  318. f->hdr.flag |= ARG_HASOPTVALUE;
  319. for (i = 0; i < f->hdr.maxcount; i++)
  320. f->ival[i] = -1;
  321. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  322. nerrors = arg_parse(argc, argv, argtable);
  323. CuAssertIntEquals(tc, nerrors, 0);
  324. CuAssertIntEquals(tc, a->count, 1);
  325. CuAssertIntEquals(tc, a->ival[0], 2);
  326. CuAssertIntEquals(tc, b->count, 0);
  327. CuAssertIntEquals(tc, c->count, 0);
  328. CuAssertIntEquals(tc, d->count, 0);
  329. CuAssertIntEquals(tc, e->count, 0);
  330. CuAssertIntEquals(tc, f->count, 2);
  331. CuAssertIntEquals(tc, f->ival[0], -1);
  332. CuAssertIntEquals(tc, f->ival[1], -1);
  333. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  334. }
  335. void test_argint_basic_012(CuTest* tc) {
  336. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  337. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  338. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  339. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  340. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  341. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  342. struct arg_end* end = arg_end(20);
  343. void* argtable[] = {a, b, c, d, e, f, end};
  344. int nerrors;
  345. int i;
  346. char* argv[] = {"program", "-f", "1", "--filler=2", "-f", NULL};
  347. int argc = sizeof(argv) / sizeof(char*) - 1;
  348. /* allow missing argument values for the f argument, and set defaults to -1 */
  349. f->hdr.flag |= ARG_HASOPTVALUE;
  350. for (i = 0; i < f->hdr.maxcount; i++)
  351. f->ival[i] = -1;
  352. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  353. nerrors = arg_parse(argc, argv, argtable);
  354. CuAssertIntEquals(tc, nerrors, 0);
  355. CuAssertIntEquals(tc, a->count, 1);
  356. CuAssertIntEquals(tc, a->ival[0], 1);
  357. CuAssertIntEquals(tc, b->count, 0);
  358. CuAssertIntEquals(tc, c->count, 0);
  359. CuAssertIntEquals(tc, d->count, 0);
  360. CuAssertIntEquals(tc, e->count, 0);
  361. CuAssertIntEquals(tc, f->count, 3);
  362. CuAssertIntEquals(tc, f->ival[0], -1);
  363. CuAssertIntEquals(tc, f->ival[1], 2);
  364. CuAssertIntEquals(tc, f->ival[0], -1);
  365. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  366. }
  367. void test_argint_basic_013(CuTest* tc) {
  368. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  369. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  370. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  371. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  372. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  373. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  374. struct arg_end* end = arg_end(20);
  375. void* argtable[] = {a, b, c, d, e, f, end};
  376. int nerrors;
  377. int i;
  378. char* argv[] = {"program", "0x0", NULL};
  379. int argc = sizeof(argv) / sizeof(char*) - 1;
  380. /* allow missing argument values for the f argument, and set defaults to -1 */
  381. f->hdr.flag |= ARG_HASOPTVALUE;
  382. for (i = 0; i < f->hdr.maxcount; i++)
  383. f->ival[i] = -1;
  384. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  385. nerrors = arg_parse(argc, argv, argtable);
  386. CuAssertIntEquals(tc, nerrors, 0);
  387. CuAssertIntEquals(tc, a->count, 1);
  388. CuAssertIntEquals(tc, a->ival[0], 0x0);
  389. CuAssertIntEquals(tc, b->count, 0);
  390. CuAssertIntEquals(tc, c->count, 0);
  391. CuAssertIntEquals(tc, d->count, 0);
  392. CuAssertIntEquals(tc, e->count, 0);
  393. CuAssertIntEquals(tc, f->count, 0);
  394. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  395. }
  396. void test_argint_basic_014(CuTest* tc) {
  397. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  398. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  399. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  400. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  401. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  402. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  403. struct arg_end* end = arg_end(20);
  404. void* argtable[] = {a, b, c, d, e, f, end};
  405. int nerrors;
  406. int i;
  407. char* argv[] = {"program", "0x0", NULL};
  408. int argc = sizeof(argv) / sizeof(char*) - 1;
  409. /* allow missing argument values for the f argument, and set defaults to -1 */
  410. f->hdr.flag |= ARG_HASOPTVALUE;
  411. for (i = 0; i < f->hdr.maxcount; i++)
  412. f->ival[i] = -1;
  413. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  414. nerrors = arg_parse(argc, argv, argtable);
  415. CuAssertIntEquals(tc, nerrors, 0);
  416. CuAssertIntEquals(tc, a->count, 1);
  417. CuAssertIntEquals(tc, a->ival[0], 0x0);
  418. CuAssertIntEquals(tc, b->count, 0);
  419. CuAssertIntEquals(tc, c->count, 0);
  420. CuAssertIntEquals(tc, d->count, 0);
  421. CuAssertIntEquals(tc, e->count, 0);
  422. CuAssertIntEquals(tc, f->count, 0);
  423. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  424. }
  425. void test_argint_basic_015(CuTest* tc) {
  426. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  427. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  428. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  429. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  430. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  431. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  432. struct arg_end* end = arg_end(20);
  433. void* argtable[] = {a, b, c, d, e, f, end};
  434. int nerrors;
  435. int i;
  436. char* argv[] = {"program", "0x10", NULL};
  437. int argc = sizeof(argv) / sizeof(char*) - 1;
  438. /* allow missing argument values for the f argument, and set defaults to -1 */
  439. f->hdr.flag |= ARG_HASOPTVALUE;
  440. for (i = 0; i < f->hdr.maxcount; i++)
  441. f->ival[i] = -1;
  442. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  443. nerrors = arg_parse(argc, argv, argtable);
  444. CuAssertIntEquals(tc, nerrors, 0);
  445. CuAssertIntEquals(tc, a->count, 1);
  446. CuAssertIntEquals(tc, a->ival[0], 0x10);
  447. CuAssertIntEquals(tc, b->count, 0);
  448. CuAssertIntEquals(tc, c->count, 0);
  449. CuAssertIntEquals(tc, d->count, 0);
  450. CuAssertIntEquals(tc, e->count, 0);
  451. CuAssertIntEquals(tc, f->count, 0);
  452. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  453. }
  454. void test_argint_basic_016(CuTest* tc) {
  455. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  456. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  457. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  458. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  459. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  460. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  461. struct arg_end* end = arg_end(20);
  462. void* argtable[] = {a, b, c, d, e, f, end};
  463. int nerrors;
  464. int i;
  465. char* argv[] = {"program", "0x10", "0x32", NULL};
  466. int argc = sizeof(argv) / sizeof(char*) - 1;
  467. /* allow missing argument values for the f argument, and set defaults to -1 */
  468. f->hdr.flag |= ARG_HASOPTVALUE;
  469. for (i = 0; i < f->hdr.maxcount; i++)
  470. f->ival[i] = -1;
  471. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  472. nerrors = arg_parse(argc, argv, argtable);
  473. CuAssertIntEquals(tc, nerrors, 0);
  474. CuAssertIntEquals(tc, a->count, 1);
  475. CuAssertIntEquals(tc, a->ival[0], 0x10);
  476. CuAssertIntEquals(tc, b->count, 1);
  477. CuAssertIntEquals(tc, b->ival[0], 0x32);
  478. CuAssertIntEquals(tc, c->count, 0);
  479. CuAssertIntEquals(tc, d->count, 0);
  480. CuAssertIntEquals(tc, e->count, 0);
  481. CuAssertIntEquals(tc, f->count, 0);
  482. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  483. }
  484. void test_argint_basic_017(CuTest* tc) {
  485. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  486. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  487. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  488. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  489. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  490. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  491. struct arg_end* end = arg_end(20);
  492. void* argtable[] = {a, b, c, d, e, f, end};
  493. int nerrors;
  494. int i;
  495. char* argv[] = {"program", "0x5", "0xA", "0xF", "-d", "-0x1E", NULL};
  496. int argc = sizeof(argv) / sizeof(char*) - 1;
  497. /* allow missing argument values for the f argument, and set defaults to -1 */
  498. f->hdr.flag |= ARG_HASOPTVALUE;
  499. for (i = 0; i < f->hdr.maxcount; i++)
  500. f->ival[i] = -1;
  501. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  502. nerrors = arg_parse(argc, argv, argtable);
  503. CuAssertIntEquals(tc, nerrors, 0);
  504. CuAssertIntEquals(tc, a->count, 1);
  505. CuAssertIntEquals(tc, a->ival[0], 0x5);
  506. CuAssertIntEquals(tc, b->count, 1);
  507. CuAssertIntEquals(tc, b->ival[0], 0xA);
  508. CuAssertIntEquals(tc, c->count, 1);
  509. CuAssertIntEquals(tc, c->ival[0], 0xF);
  510. CuAssertIntEquals(tc, d->count, 1);
  511. CuAssertIntEquals(tc, d->ival[0], -0x1E);
  512. CuAssertIntEquals(tc, e->count, 0);
  513. CuAssertIntEquals(tc, f->count, 0);
  514. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  515. }
  516. void test_argint_basic_018(CuTest* tc) {
  517. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  518. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  519. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  520. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  521. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  522. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  523. struct arg_end* end = arg_end(20);
  524. void* argtable[] = {a, b, c, d, e, f, end};
  525. int nerrors;
  526. int i;
  527. char* argv[] = {"program", "-d", "0xab", "-D0x09", "--delta", "0x02e", NULL};
  528. int argc = sizeof(argv) / sizeof(char*) - 1;
  529. /* allow missing argument values for the f argument, and set defaults to -1 */
  530. f->hdr.flag |= ARG_HASOPTVALUE;
  531. for (i = 0; i < f->hdr.maxcount; i++)
  532. f->ival[i] = -1;
  533. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  534. nerrors = arg_parse(argc, argv, argtable);
  535. CuAssertIntEquals(tc, nerrors, 1);
  536. CuAssertIntEquals(tc, a->count, 0);
  537. CuAssertIntEquals(tc, b->count, 0);
  538. CuAssertIntEquals(tc, c->count, 0);
  539. CuAssertIntEquals(tc, d->count, 3);
  540. CuAssertIntEquals(tc, d->ival[0], 0xab);
  541. CuAssertIntEquals(tc, d->ival[1], 0x09);
  542. CuAssertIntEquals(tc, d->ival[2], 0x02e);
  543. CuAssertIntEquals(tc, e->count, 0);
  544. CuAssertIntEquals(tc, f->count, 0);
  545. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  546. }
  547. void test_argint_basic_019(CuTest* tc) {
  548. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  549. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  550. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  551. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  552. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  553. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  554. struct arg_end* end = arg_end(20);
  555. void* argtable[] = {a, b, c, d, e, f, end};
  556. int nerrors;
  557. int i;
  558. char* argv[] = {"program", "0o0", NULL};
  559. int argc = sizeof(argv) / sizeof(char*) - 1;
  560. /* allow missing argument values for the f argument, and set defaults to -1 */
  561. f->hdr.flag |= ARG_HASOPTVALUE;
  562. for (i = 0; i < f->hdr.maxcount; i++)
  563. f->ival[i] = -1;
  564. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  565. nerrors = arg_parse(argc, argv, argtable);
  566. CuAssertIntEquals(tc, nerrors, 0);
  567. CuAssertIntEquals(tc, a->count, 1);
  568. CuAssertIntEquals(tc, a->ival[0], 0);
  569. CuAssertIntEquals(tc, b->count, 0);
  570. CuAssertIntEquals(tc, c->count, 0);
  571. CuAssertIntEquals(tc, d->count, 0);
  572. CuAssertIntEquals(tc, e->count, 0);
  573. CuAssertIntEquals(tc, f->count, 0);
  574. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  575. }
  576. void test_argint_basic_020(CuTest* tc) {
  577. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  578. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  579. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  580. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  581. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  582. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  583. struct arg_end* end = arg_end(20);
  584. void* argtable[] = {a, b, c, d, e, f, end};
  585. int nerrors;
  586. int i;
  587. char* argv[] = {"program", "0o10", NULL};
  588. int argc = sizeof(argv) / sizeof(char*) - 1;
  589. /* allow missing argument values for the f argument, and set defaults to -1 */
  590. f->hdr.flag |= ARG_HASOPTVALUE;
  591. for (i = 0; i < f->hdr.maxcount; i++)
  592. f->ival[i] = -1;
  593. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  594. nerrors = arg_parse(argc, argv, argtable);
  595. CuAssertIntEquals(tc, nerrors, 0);
  596. CuAssertIntEquals(tc, a->count, 1);
  597. CuAssertIntEquals(tc, a->ival[0], 010);
  598. CuAssertIntEquals(tc, b->count, 0);
  599. CuAssertIntEquals(tc, c->count, 0);
  600. CuAssertIntEquals(tc, d->count, 0);
  601. CuAssertIntEquals(tc, e->count, 0);
  602. CuAssertIntEquals(tc, f->count, 0);
  603. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  604. }
  605. void test_argint_basic_021(CuTest* tc) {
  606. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  607. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  608. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  609. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  610. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  611. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  612. struct arg_end* end = arg_end(20);
  613. void* argtable[] = {a, b, c, d, e, f, end};
  614. int nerrors;
  615. int i;
  616. char* argv[] = {"program", "0o67", "0O23", NULL};
  617. int argc = sizeof(argv) / sizeof(char*) - 1;
  618. /* allow missing argument values for the f argument, and set defaults to -1 */
  619. f->hdr.flag |= ARG_HASOPTVALUE;
  620. for (i = 0; i < f->hdr.maxcount; i++)
  621. f->ival[i] = -1;
  622. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  623. nerrors = arg_parse(argc, argv, argtable);
  624. CuAssertIntEquals(tc, nerrors, 0);
  625. CuAssertIntEquals(tc, a->count, 1);
  626. CuAssertIntEquals(tc, a->ival[0], 067);
  627. CuAssertIntEquals(tc, b->count, 1);
  628. CuAssertIntEquals(tc, b->ival[0], 023);
  629. CuAssertIntEquals(tc, c->count, 0);
  630. CuAssertIntEquals(tc, d->count, 0);
  631. CuAssertIntEquals(tc, e->count, 0);
  632. CuAssertIntEquals(tc, f->count, 0);
  633. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  634. }
  635. void test_argint_basic_022(CuTest* tc) {
  636. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  637. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  638. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  639. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  640. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  641. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  642. struct arg_end* end = arg_end(20);
  643. void* argtable[] = {a, b, c, d, e, f, end};
  644. int nerrors;
  645. int i;
  646. char* argv[] = {"program", "0o5", "0O0", "0x1", "-d", "-0o6", NULL};
  647. int argc = sizeof(argv) / sizeof(char*) - 1;
  648. /* allow missing argument values for the f argument, and set defaults to -1 */
  649. f->hdr.flag |= ARG_HASOPTVALUE;
  650. for (i = 0; i < f->hdr.maxcount; i++)
  651. f->ival[i] = -1;
  652. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  653. nerrors = arg_parse(argc, argv, argtable);
  654. CuAssertIntEquals(tc, nerrors, 0);
  655. CuAssertIntEquals(tc, a->count, 1);
  656. CuAssertIntEquals(tc, a->ival[0], 05);
  657. CuAssertIntEquals(tc, b->count, 1);
  658. CuAssertIntEquals(tc, b->ival[0], 0);
  659. CuAssertIntEquals(tc, c->count, 1);
  660. CuAssertIntEquals(tc, c->ival[0], 0x1);
  661. CuAssertIntEquals(tc, d->count, 1);
  662. CuAssertIntEquals(tc, d->ival[0], -06);
  663. CuAssertIntEquals(tc, e->count, 0);
  664. CuAssertIntEquals(tc, f->count, 0);
  665. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  666. }
  667. void test_argint_basic_023(CuTest* tc) {
  668. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  669. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  670. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  671. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  672. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  673. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  674. struct arg_end* end = arg_end(20);
  675. void* argtable[] = {a, b, c, d, e, f, end};
  676. int nerrors;
  677. int i;
  678. char* argv[] = {"program", "-d", "0o012", "-D0o0777", "--delta", "0o56", NULL};
  679. int argc = sizeof(argv) / sizeof(char*) - 1;
  680. /* allow missing argument values for the f argument, and set defaults to -1 */
  681. f->hdr.flag |= ARG_HASOPTVALUE;
  682. for (i = 0; i < f->hdr.maxcount; i++)
  683. f->ival[i] = -1;
  684. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  685. nerrors = arg_parse(argc, argv, argtable);
  686. CuAssertIntEquals(tc, nerrors, 1);
  687. CuAssertIntEquals(tc, a->count, 0);
  688. CuAssertIntEquals(tc, b->count, 0);
  689. CuAssertIntEquals(tc, c->count, 0);
  690. CuAssertIntEquals(tc, d->count, 3);
  691. CuAssertIntEquals(tc, d->ival[0], 012);
  692. CuAssertIntEquals(tc, d->ival[1], 0777);
  693. CuAssertIntEquals(tc, d->ival[2], 056);
  694. CuAssertIntEquals(tc, e->count, 0);
  695. CuAssertIntEquals(tc, f->count, 0);
  696. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  697. }
  698. void test_argint_basic_024(CuTest* tc) {
  699. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  700. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  701. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  702. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  703. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  704. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  705. struct arg_end* end = arg_end(20);
  706. void* argtable[] = {a, b, c, d, e, f, end};
  707. int nerrors;
  708. int i;
  709. char* argv[] = {"program", "0B0", NULL};
  710. int argc = sizeof(argv) / sizeof(char*) - 1;
  711. /* allow missing argument values for the f argument, and set defaults to -1 */
  712. f->hdr.flag |= ARG_HASOPTVALUE;
  713. for (i = 0; i < f->hdr.maxcount; i++)
  714. f->ival[i] = -1;
  715. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  716. nerrors = arg_parse(argc, argv, argtable);
  717. CuAssertIntEquals(tc, nerrors, 0);
  718. CuAssertIntEquals(tc, a->count, 1);
  719. CuAssertIntEquals(tc, a->ival[0], 0);
  720. CuAssertIntEquals(tc, b->count, 0);
  721. CuAssertIntEquals(tc, c->count, 0);
  722. CuAssertIntEquals(tc, d->count, 0);
  723. CuAssertIntEquals(tc, e->count, 0);
  724. CuAssertIntEquals(tc, f->count, 0);
  725. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  726. }
  727. void test_argint_basic_025(CuTest* tc) {
  728. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  729. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  730. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  731. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  732. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  733. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  734. struct arg_end* end = arg_end(20);
  735. void* argtable[] = {a, b, c, d, e, f, end};
  736. int nerrors;
  737. int i;
  738. char* argv[] = {"program", "0B0", NULL};
  739. int argc = sizeof(argv) / sizeof(char*) - 1;
  740. /* allow missing argument values for the f argument, and set defaults to -1 */
  741. f->hdr.flag |= ARG_HASOPTVALUE;
  742. for (i = 0; i < f->hdr.maxcount; i++)
  743. f->ival[i] = -1;
  744. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  745. nerrors = arg_parse(argc, argv, argtable);
  746. CuAssertIntEquals(tc, nerrors, 0);
  747. CuAssertIntEquals(tc, a->count, 1);
  748. CuAssertIntEquals(tc, a->ival[0], 0);
  749. CuAssertIntEquals(tc, b->count, 0);
  750. CuAssertIntEquals(tc, c->count, 0);
  751. CuAssertIntEquals(tc, d->count, 0);
  752. CuAssertIntEquals(tc, e->count, 0);
  753. CuAssertIntEquals(tc, f->count, 0);
  754. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  755. }
  756. void test_argint_basic_026(CuTest* tc) {
  757. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  758. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  759. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  760. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  761. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  762. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  763. struct arg_end* end = arg_end(20);
  764. void* argtable[] = {a, b, c, d, e, f, end};
  765. int nerrors;
  766. int i;
  767. char* argv[] = {"program", "0b10", NULL};
  768. int argc = sizeof(argv) / sizeof(char*) - 1;
  769. /* allow missing argument values for the f argument, and set defaults to -1 */
  770. f->hdr.flag |= ARG_HASOPTVALUE;
  771. for (i = 0; i < f->hdr.maxcount; i++)
  772. f->ival[i] = -1;
  773. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  774. nerrors = arg_parse(argc, argv, argtable);
  775. CuAssertIntEquals(tc, nerrors, 0);
  776. CuAssertIntEquals(tc, a->count, 1);
  777. CuAssertIntEquals(tc, a->ival[0], 2);
  778. CuAssertIntEquals(tc, b->count, 0);
  779. CuAssertIntEquals(tc, c->count, 0);
  780. CuAssertIntEquals(tc, d->count, 0);
  781. CuAssertIntEquals(tc, e->count, 0);
  782. CuAssertIntEquals(tc, f->count, 0);
  783. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  784. }
  785. void test_argint_basic_027(CuTest* tc) {
  786. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  787. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  788. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  789. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  790. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  791. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  792. struct arg_end* end = arg_end(20);
  793. void* argtable[] = {a, b, c, d, e, f, end};
  794. int nerrors;
  795. int i;
  796. char* argv[] = {"program", "0B10110", "0b111001", NULL};
  797. int argc = sizeof(argv) / sizeof(char*) - 1;
  798. /* allow missing argument values for the f argument, and set defaults to -1 */
  799. f->hdr.flag |= ARG_HASOPTVALUE;
  800. for (i = 0; i < f->hdr.maxcount; i++)
  801. f->ival[i] = -1;
  802. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  803. nerrors = arg_parse(argc, argv, argtable);
  804. CuAssertIntEquals(tc, nerrors, 0);
  805. CuAssertIntEquals(tc, a->count, 1);
  806. CuAssertIntEquals(tc, a->ival[0], 22);
  807. CuAssertIntEquals(tc, b->count, 1);
  808. CuAssertIntEquals(tc, b->ival[0], 57);
  809. CuAssertIntEquals(tc, c->count, 0);
  810. CuAssertIntEquals(tc, d->count, 0);
  811. CuAssertIntEquals(tc, e->count, 0);
  812. CuAssertIntEquals(tc, f->count, 0);
  813. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  814. }
  815. void test_argint_basic_028(CuTest* tc) {
  816. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  817. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  818. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  819. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  820. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  821. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  822. struct arg_end* end = arg_end(20);
  823. void* argtable[] = {a, b, c, d, e, f, end};
  824. int nerrors;
  825. int i;
  826. char* argv[] = {"program", "0B10110", "0b111001", NULL};
  827. int argc = sizeof(argv) / sizeof(char*) - 1;
  828. /* allow missing argument values for the f argument, and set defaults to -1 */
  829. f->hdr.flag |= ARG_HASOPTVALUE;
  830. for (i = 0; i < f->hdr.maxcount; i++)
  831. f->ival[i] = -1;
  832. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  833. nerrors = arg_parse(argc, argv, argtable);
  834. CuAssertIntEquals(tc, nerrors, 0);
  835. CuAssertIntEquals(tc, a->count, 1);
  836. CuAssertIntEquals(tc, a->ival[0], 22);
  837. CuAssertIntEquals(tc, b->count, 1);
  838. CuAssertIntEquals(tc, b->ival[0], 57);
  839. CuAssertIntEquals(tc, c->count, 0);
  840. CuAssertIntEquals(tc, d->count, 0);
  841. CuAssertIntEquals(tc, e->count, 0);
  842. CuAssertIntEquals(tc, f->count, 0);
  843. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  844. }
  845. void test_argint_basic_029(CuTest* tc) {
  846. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  847. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  848. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  849. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  850. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  851. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  852. struct arg_end* end = arg_end(20);
  853. void* argtable[] = {a, b, c, d, e, f, end};
  854. int nerrors;
  855. int i;
  856. char* argv[] = {"program", "0b101001", "0b101", "0b00101010101", "-d", "0B110000011", NULL};
  857. int argc = sizeof(argv) / sizeof(char*) - 1;
  858. /* allow missing argument values for the f argument, and set defaults to -1 */
  859. f->hdr.flag |= ARG_HASOPTVALUE;
  860. for (i = 0; i < f->hdr.maxcount; i++)
  861. f->ival[i] = -1;
  862. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  863. nerrors = arg_parse(argc, argv, argtable);
  864. CuAssertIntEquals(tc, nerrors, 0);
  865. CuAssertIntEquals(tc, a->count, 1);
  866. CuAssertIntEquals(tc, a->ival[0], 41);
  867. CuAssertIntEquals(tc, b->count, 1);
  868. CuAssertIntEquals(tc, b->ival[0], 5);
  869. CuAssertIntEquals(tc, c->count, 1);
  870. CuAssertIntEquals(tc, c->ival[0], 341);
  871. CuAssertIntEquals(tc, d->count, 1);
  872. CuAssertIntEquals(tc, d->ival[0], 387);
  873. CuAssertIntEquals(tc, e->count, 0);
  874. CuAssertIntEquals(tc, f->count, 0);
  875. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  876. }
  877. void test_argint_basic_030(CuTest* tc) {
  878. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  879. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  880. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  881. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  882. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  883. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  884. struct arg_end* end = arg_end(20);
  885. void* argtable[] = {a, b, c, d, e, f, end};
  886. int nerrors;
  887. int i;
  888. char* argv[] = {"program", "-d", "0b101", "-D0B11", "--delta", "0b11011", NULL};
  889. int argc = sizeof(argv) / sizeof(char*) - 1;
  890. /* allow missing argument values for the f argument, and set defaults to -1 */
  891. f->hdr.flag |= ARG_HASOPTVALUE;
  892. for (i = 0; i < f->hdr.maxcount; i++)
  893. f->ival[i] = -1;
  894. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  895. nerrors = arg_parse(argc, argv, argtable);
  896. CuAssertIntEquals(tc, nerrors, 1);
  897. CuAssertIntEquals(tc, a->count, 0);
  898. CuAssertIntEquals(tc, b->count, 0);
  899. CuAssertIntEquals(tc, c->count, 0);
  900. CuAssertIntEquals(tc, d->count, 3);
  901. CuAssertIntEquals(tc, d->ival[0], 5);
  902. CuAssertIntEquals(tc, d->ival[1], 3);
  903. CuAssertIntEquals(tc, d->ival[2], 27);
  904. CuAssertIntEquals(tc, e->count, 0);
  905. CuAssertIntEquals(tc, f->count, 0);
  906. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  907. }
  908. void test_argint_basic_031(CuTest* tc) {
  909. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  910. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  911. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  912. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  913. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  914. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  915. struct arg_end* end = arg_end(20);
  916. void* argtable[] = {a, b, c, d, e, f, end};
  917. int nerrors;
  918. int i;
  919. char* argv[] = {"program", "11", "0x11", "0o11", "-D0b11", "--eps", "-0o50", NULL};
  920. int argc = sizeof(argv) / sizeof(char*) - 1;
  921. /* allow missing argument values for the f argument, and set defaults to -1 */
  922. f->hdr.flag |= ARG_HASOPTVALUE;
  923. for (i = 0; i < f->hdr.maxcount; i++)
  924. f->ival[i] = -1;
  925. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  926. nerrors = arg_parse(argc, argv, argtable);
  927. CuAssertIntEquals(tc, nerrors, 0);
  928. CuAssertIntEquals(tc, a->count, 1);
  929. CuAssertIntEquals(tc, a->ival[0], 11);
  930. CuAssertIntEquals(tc, b->count, 1);
  931. CuAssertIntEquals(tc, b->ival[0], 0x11);
  932. CuAssertIntEquals(tc, c->count, 1);
  933. CuAssertIntEquals(tc, c->ival[0], 011);
  934. CuAssertIntEquals(tc, d->count, 1);
  935. CuAssertIntEquals(tc, d->ival[0], 3);
  936. CuAssertIntEquals(tc, e->count, 1);
  937. CuAssertIntEquals(tc, e->ival[0], -050);
  938. CuAssertIntEquals(tc, f->count, 0);
  939. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  940. }
  941. void test_argint_basic_032(CuTest* tc) {
  942. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  943. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  944. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  945. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  946. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  947. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  948. struct arg_end* end = arg_end(20);
  949. void* argtable[] = {a, b, c, d, e, f, end};
  950. int nerrors;
  951. int i;
  952. char* argv[] = {"program", "1KB", NULL};
  953. int argc = sizeof(argv) / sizeof(char*) - 1;
  954. /* allow missing argument values for the f argument, and set defaults to -1 */
  955. f->hdr.flag |= ARG_HASOPTVALUE;
  956. for (i = 0; i < f->hdr.maxcount; i++)
  957. f->ival[i] = -1;
  958. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  959. nerrors = arg_parse(argc, argv, argtable);
  960. CuAssertIntEquals(tc, nerrors, 0);
  961. CuAssertIntEquals(tc, a->count, 1);
  962. CuAssertIntEquals(tc, a->ival[0], 1024);
  963. CuAssertIntEquals(tc, b->count, 0);
  964. CuAssertIntEquals(tc, c->count, 0);
  965. CuAssertIntEquals(tc, d->count, 0);
  966. CuAssertIntEquals(tc, e->count, 0);
  967. CuAssertIntEquals(tc, f->count, 0);
  968. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  969. }
  970. void test_argint_basic_033(CuTest* tc) {
  971. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  972. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  973. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  974. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  975. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  976. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  977. struct arg_end* end = arg_end(20);
  978. void* argtable[] = {a, b, c, d, e, f, end};
  979. int nerrors;
  980. int i;
  981. char* argv[] = {"program", "1MB", NULL};
  982. int argc = sizeof(argv) / sizeof(char*) - 1;
  983. /* allow missing argument values for the f argument, and set defaults to -1 */
  984. f->hdr.flag |= ARG_HASOPTVALUE;
  985. for (i = 0; i < f->hdr.maxcount; i++)
  986. f->ival[i] = -1;
  987. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  988. nerrors = arg_parse(argc, argv, argtable);
  989. CuAssertIntEquals(tc, nerrors, 0);
  990. CuAssertIntEquals(tc, a->count, 1);
  991. CuAssertIntEquals(tc, a->ival[0], 1024 * 1024);
  992. CuAssertIntEquals(tc, b->count, 0);
  993. CuAssertIntEquals(tc, c->count, 0);
  994. CuAssertIntEquals(tc, d->count, 0);
  995. CuAssertIntEquals(tc, e->count, 0);
  996. CuAssertIntEquals(tc, f->count, 0);
  997. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  998. }
  999. void test_argint_basic_034(CuTest* tc) {
  1000. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1001. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1002. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1003. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1004. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1005. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1006. struct arg_end* end = arg_end(20);
  1007. void* argtable[] = {a, b, c, d, e, f, end};
  1008. int nerrors;
  1009. int i;
  1010. char* argv[] = {"program", "1GB", NULL};
  1011. int argc = sizeof(argv) / sizeof(char*) - 1;
  1012. /* allow missing argument values for the f argument, and set defaults to -1 */
  1013. f->hdr.flag |= ARG_HASOPTVALUE;
  1014. for (i = 0; i < f->hdr.maxcount; i++)
  1015. f->ival[i] = -1;
  1016. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1017. nerrors = arg_parse(argc, argv, argtable);
  1018. CuAssertIntEquals(tc, nerrors, 0);
  1019. CuAssertIntEquals(tc, a->count, 1);
  1020. CuAssertIntEquals(tc, a->ival[0], 1024 * 1024 * 1024);
  1021. CuAssertIntEquals(tc, b->count, 0);
  1022. CuAssertIntEquals(tc, c->count, 0);
  1023. CuAssertIntEquals(tc, d->count, 0);
  1024. CuAssertIntEquals(tc, e->count, 0);
  1025. CuAssertIntEquals(tc, f->count, 0);
  1026. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1027. }
  1028. void test_argint_basic_035(CuTest* tc) {
  1029. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1030. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1031. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1032. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1033. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1034. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1035. struct arg_end* end = arg_end(20);
  1036. void* argtable[] = {a, b, c, d, e, f, end};
  1037. int nerrors;
  1038. int i;
  1039. char* argv[] = {"program", "0x5KB", "0xAMB", "0x1GB", "-d", "-0x40A01400", NULL};
  1040. int argc = sizeof(argv) / sizeof(char*) - 1;
  1041. /* allow missing argument values for the f argument, and set defaults to -1 */
  1042. f->hdr.flag |= ARG_HASOPTVALUE;
  1043. for (i = 0; i < f->hdr.maxcount; i++)
  1044. f->ival[i] = -1;
  1045. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1046. nerrors = arg_parse(argc, argv, argtable);
  1047. CuAssertIntEquals(tc, nerrors, 0);
  1048. CuAssertIntEquals(tc, a->count, 1);
  1049. CuAssertIntEquals(tc, a->ival[0], 0x5 * 1024);
  1050. CuAssertIntEquals(tc, b->count, 1);
  1051. CuAssertIntEquals(tc, b->ival[0], 0xA * 1024 * 1024);
  1052. CuAssertIntEquals(tc, c->count, 1);
  1053. CuAssertIntEquals(tc, c->ival[0], 0x1 * 1024 * 1024 * 1024);
  1054. CuAssertIntEquals(tc, d->count, 1);
  1055. CuAssertIntEquals(tc, d->ival[0], -0x40A01400);
  1056. CuAssertIntEquals(tc, e->count, 0);
  1057. CuAssertIntEquals(tc, f->count, 0);
  1058. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1059. }
  1060. void test_argint_basic_036(CuTest* tc) {
  1061. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1062. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1063. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1064. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1065. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1066. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1067. struct arg_end* end = arg_end(20);
  1068. void* argtable[] = {a, b, c, d, e, f, end};
  1069. int nerrors;
  1070. int i;
  1071. char* argv[] = {"program", NULL};
  1072. int argc = sizeof(argv) / sizeof(char*) - 1;
  1073. /* allow missing argument values for the f argument, and set defaults to -1 */
  1074. f->hdr.flag |= ARG_HASOPTVALUE;
  1075. for (i = 0; i < f->hdr.maxcount; i++)
  1076. f->ival[i] = -1;
  1077. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1078. nerrors = arg_parse(argc, argv, argtable);
  1079. CuAssertIntEquals(tc, nerrors, 1);
  1080. CuAssertIntEquals(tc, a->count, 0);
  1081. CuAssertIntEquals(tc, b->count, 0);
  1082. CuAssertIntEquals(tc, c->count, 0);
  1083. CuAssertIntEquals(tc, d->count, 0);
  1084. CuAssertIntEquals(tc, e->count, 0);
  1085. CuAssertIntEquals(tc, f->count, 0);
  1086. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1087. }
  1088. void test_argint_basic_037(CuTest* tc) {
  1089. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1090. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1091. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1092. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1093. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1094. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1095. struct arg_end* end = arg_end(20);
  1096. void* argtable[] = {a, b, c, d, e, f, end};
  1097. int nerrors;
  1098. int i;
  1099. char* argv[] = {"program", "1", "2", "3", "4", NULL};
  1100. int argc = sizeof(argv) / sizeof(char*) - 1;
  1101. /* allow missing argument values for the f argument, and set defaults to -1 */
  1102. f->hdr.flag |= ARG_HASOPTVALUE;
  1103. for (i = 0; i < f->hdr.maxcount; i++)
  1104. f->ival[i] = -1;
  1105. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1106. nerrors = arg_parse(argc, argv, argtable);
  1107. CuAssertIntEquals(tc, nerrors, 1);
  1108. CuAssertIntEquals(tc, a->count, 1);
  1109. CuAssertIntEquals(tc, a->ival[0], 1);
  1110. CuAssertIntEquals(tc, b->count, 1);
  1111. CuAssertIntEquals(tc, b->ival[0], 2);
  1112. CuAssertIntEquals(tc, c->count, 1);
  1113. CuAssertIntEquals(tc, c->ival[0], 3);
  1114. CuAssertIntEquals(tc, d->count, 0);
  1115. CuAssertIntEquals(tc, e->count, 0);
  1116. CuAssertIntEquals(tc, f->count, 0);
  1117. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1118. }
  1119. void test_argint_basic_038(CuTest* tc) {
  1120. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1121. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1122. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1123. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1124. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1125. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1126. struct arg_end* end = arg_end(20);
  1127. void* argtable[] = {a, b, c, d, e, f, end};
  1128. int nerrors;
  1129. int i;
  1130. char* argv[] = {"program", "1", "2", "3", "-d1", "-d2", "-d3", "-d4", NULL};
  1131. int argc = sizeof(argv) / sizeof(char*) - 1;
  1132. /* allow missing argument values for the f argument, and set defaults to -1 */
  1133. f->hdr.flag |= ARG_HASOPTVALUE;
  1134. for (i = 0; i < f->hdr.maxcount; i++)
  1135. f->ival[i] = -1;
  1136. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1137. nerrors = arg_parse(argc, argv, argtable);
  1138. CuAssertIntEquals(tc, nerrors, 1);
  1139. CuAssertIntEquals(tc, a->count, 1);
  1140. CuAssertIntEquals(tc, a->ival[0], 1);
  1141. CuAssertIntEquals(tc, b->count, 1);
  1142. CuAssertIntEquals(tc, b->ival[0], 2);
  1143. CuAssertIntEquals(tc, c->count, 1);
  1144. CuAssertIntEquals(tc, c->ival[0], 3);
  1145. CuAssertIntEquals(tc, d->count, 3);
  1146. CuAssertIntEquals(tc, d->ival[0], 1);
  1147. CuAssertIntEquals(tc, d->ival[1], 2);
  1148. CuAssertIntEquals(tc, d->ival[2], 3);
  1149. CuAssertIntEquals(tc, e->count, 0);
  1150. CuAssertIntEquals(tc, f->count, 0);
  1151. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1152. }
  1153. void test_argint_basic_039(CuTest* tc) {
  1154. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1155. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1156. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1157. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1158. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1159. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1160. struct arg_end* end = arg_end(20);
  1161. void* argtable[] = {a, b, c, d, e, f, end};
  1162. int nerrors;
  1163. int i;
  1164. char* argv[] = {"program", "1", "2", "3", "-d1", "-d2", "-d3", "-d", NULL};
  1165. int argc = sizeof(argv) / sizeof(char*) - 1;
  1166. /* allow missing argument values for the f argument, and set defaults to -1 */
  1167. f->hdr.flag |= ARG_HASOPTVALUE;
  1168. for (i = 0; i < f->hdr.maxcount; i++)
  1169. f->ival[i] = -1;
  1170. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1171. nerrors = arg_parse(argc, argv, argtable);
  1172. CuAssertIntEquals(tc, nerrors, 1);
  1173. CuAssertIntEquals(tc, a->count, 1);
  1174. CuAssertIntEquals(tc, a->ival[0], 1);
  1175. CuAssertIntEquals(tc, b->count, 1);
  1176. CuAssertIntEquals(tc, b->ival[0], 2);
  1177. CuAssertIntEquals(tc, c->count, 1);
  1178. CuAssertIntEquals(tc, c->ival[0], 3);
  1179. CuAssertIntEquals(tc, d->count, 3);
  1180. CuAssertIntEquals(tc, d->ival[0], 1);
  1181. CuAssertIntEquals(tc, d->ival[1], 2);
  1182. CuAssertIntEquals(tc, d->ival[2], 3);
  1183. CuAssertIntEquals(tc, e->count, 0);
  1184. CuAssertIntEquals(tc, f->count, 0);
  1185. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1186. }
  1187. void test_argint_basic_040(CuTest* tc) {
  1188. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1189. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1190. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1191. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1192. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1193. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1194. struct arg_end* end = arg_end(20);
  1195. void* argtable[] = {a, b, c, d, e, f, end};
  1196. int nerrors;
  1197. int i;
  1198. char* argv[] = {"program", "1", "2", "3", "-d1", "-d2", "-d", NULL};
  1199. int argc = sizeof(argv) / sizeof(char*) - 1;
  1200. /* allow missing argument values for the f argument, and set defaults to -1 */
  1201. f->hdr.flag |= ARG_HASOPTVALUE;
  1202. for (i = 0; i < f->hdr.maxcount; i++)
  1203. f->ival[i] = -1;
  1204. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1205. nerrors = arg_parse(argc, argv, argtable);
  1206. CuAssertIntEquals(tc, nerrors, 1);
  1207. CuAssertIntEquals(tc, a->count, 1);
  1208. CuAssertIntEquals(tc, a->ival[0], 1);
  1209. CuAssertIntEquals(tc, b->count, 1);
  1210. CuAssertIntEquals(tc, b->ival[0], 2);
  1211. CuAssertIntEquals(tc, c->count, 1);
  1212. CuAssertIntEquals(tc, c->ival[0], 3);
  1213. CuAssertIntEquals(tc, d->count, 2);
  1214. CuAssertIntEquals(tc, d->ival[0], 1);
  1215. CuAssertIntEquals(tc, d->ival[1], 2);
  1216. CuAssertIntEquals(tc, e->count, 0);
  1217. CuAssertIntEquals(tc, f->count, 0);
  1218. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1219. }
  1220. void test_argint_basic_041(CuTest* tc) {
  1221. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1222. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1223. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1224. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1225. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1226. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1227. struct arg_end* end = arg_end(20);
  1228. void* argtable[] = {a, b, c, d, e, f, end};
  1229. int nerrors;
  1230. int i;
  1231. char* argv[] = {"program", "1", "2", "3", "-d1", "-d", NULL};
  1232. int argc = sizeof(argv) / sizeof(char*) - 1;
  1233. /* allow missing argument values for the f argument, and set defaults to -1 */
  1234. f->hdr.flag |= ARG_HASOPTVALUE;
  1235. for (i = 0; i < f->hdr.maxcount; i++)
  1236. f->ival[i] = -1;
  1237. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1238. nerrors = arg_parse(argc, argv, argtable);
  1239. CuAssertIntEquals(tc, nerrors, 1);
  1240. CuAssertIntEquals(tc, a->count, 1);
  1241. CuAssertIntEquals(tc, a->ival[0], 1);
  1242. CuAssertIntEquals(tc, b->count, 1);
  1243. CuAssertIntEquals(tc, b->ival[0], 2);
  1244. CuAssertIntEquals(tc, c->count, 1);
  1245. CuAssertIntEquals(tc, c->ival[0], 3);
  1246. CuAssertIntEquals(tc, d->count, 1);
  1247. CuAssertIntEquals(tc, d->ival[0], 1);
  1248. CuAssertIntEquals(tc, e->count, 0);
  1249. CuAssertIntEquals(tc, f->count, 0);
  1250. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1251. }
  1252. void test_argint_basic_042(CuTest* tc) {
  1253. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1254. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1255. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1256. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1257. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1258. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1259. struct arg_end* end = arg_end(20);
  1260. void* argtable[] = {a, b, c, d, e, f, end};
  1261. int nerrors;
  1262. int i;
  1263. char* argv[] = {"program", "1", "2", "3", "-d", NULL};
  1264. int argc = sizeof(argv) / sizeof(char*) - 1;
  1265. /* allow missing argument values for the f argument, and set defaults to -1 */
  1266. f->hdr.flag |= ARG_HASOPTVALUE;
  1267. for (i = 0; i < f->hdr.maxcount; i++)
  1268. f->ival[i] = -1;
  1269. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1270. nerrors = arg_parse(argc, argv, argtable);
  1271. CuAssertIntEquals(tc, nerrors, 1);
  1272. CuAssertIntEquals(tc, a->count, 1);
  1273. CuAssertIntEquals(tc, a->ival[0], 1);
  1274. CuAssertIntEquals(tc, b->count, 1);
  1275. CuAssertIntEquals(tc, b->ival[0], 2);
  1276. CuAssertIntEquals(tc, c->count, 1);
  1277. CuAssertIntEquals(tc, c->ival[0], 3);
  1278. CuAssertIntEquals(tc, d->count, 0);
  1279. CuAssertIntEquals(tc, e->count, 0);
  1280. CuAssertIntEquals(tc, f->count, 0);
  1281. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1282. }
  1283. void test_argint_basic_043(CuTest* tc) {
  1284. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1285. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1286. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1287. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1288. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1289. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1290. struct arg_end* end = arg_end(20);
  1291. void* argtable[] = {a, b, c, d, e, f, end};
  1292. int nerrors;
  1293. int i;
  1294. char* argv[] = {"program", "1", "2", "3", "--eps", NULL};
  1295. int argc = sizeof(argv) / sizeof(char*) - 1;
  1296. /* allow missing argument values for the f argument, and set defaults to -1 */
  1297. f->hdr.flag |= ARG_HASOPTVALUE;
  1298. for (i = 0; i < f->hdr.maxcount; i++)
  1299. f->ival[i] = -1;
  1300. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1301. nerrors = arg_parse(argc, argv, argtable);
  1302. CuAssertIntEquals(tc, nerrors, 1);
  1303. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1304. }
  1305. void test_argint_basic_044(CuTest* tc) {
  1306. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1307. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1308. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1309. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1310. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1311. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1312. struct arg_end* end = arg_end(20);
  1313. void* argtable[] = {a, b, c, d, e, f, end};
  1314. int nerrors;
  1315. int i;
  1316. char* argv[] = {"program", "1", "2", "3", "--eps", "3", "--eqn", "6", NULL};
  1317. int argc = sizeof(argv) / sizeof(char*) - 1;
  1318. /* allow missing argument values for the f argument, and set defaults to -1 */
  1319. f->hdr.flag |= ARG_HASOPTVALUE;
  1320. for (i = 0; i < f->hdr.maxcount; i++)
  1321. f->ival[i] = -1;
  1322. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1323. nerrors = arg_parse(argc, argv, argtable);
  1324. CuAssertIntEquals(tc, nerrors, 1);
  1325. CuAssertIntEquals(tc, a->count, 1);
  1326. CuAssertIntEquals(tc, a->ival[0], 1);
  1327. CuAssertIntEquals(tc, b->count, 1);
  1328. CuAssertIntEquals(tc, b->ival[0], 2);
  1329. CuAssertIntEquals(tc, c->count, 1);
  1330. CuAssertIntEquals(tc, c->ival[0], 3);
  1331. CuAssertIntEquals(tc, d->count, 0);
  1332. CuAssertIntEquals(tc, e->count, 1);
  1333. CuAssertIntEquals(tc, e->ival[0], 3);
  1334. CuAssertIntEquals(tc, f->count, 0);
  1335. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1336. }
  1337. void test_argint_basic_045(CuTest* tc) {
  1338. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1339. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1340. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1341. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1342. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1343. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1344. struct arg_end* end = arg_end(20);
  1345. void* argtable[] = {a, b, c, d, e, f, end};
  1346. int nerrors;
  1347. int i;
  1348. char* argv[] = {"program", "hello", NULL};
  1349. int argc = sizeof(argv) / sizeof(char*) - 1;
  1350. /* allow missing argument values for the f argument, and set defaults to -1 */
  1351. f->hdr.flag |= ARG_HASOPTVALUE;
  1352. for (i = 0; i < f->hdr.maxcount; i++)
  1353. f->ival[i] = -1;
  1354. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1355. nerrors = arg_parse(argc, argv, argtable);
  1356. CuAssertIntEquals(tc, nerrors, 1);
  1357. CuAssertIntEquals(tc, a->count, 0);
  1358. CuAssertIntEquals(tc, b->count, 0);
  1359. CuAssertIntEquals(tc, c->count, 0);
  1360. CuAssertIntEquals(tc, d->count, 0);
  1361. CuAssertIntEquals(tc, e->count, 0);
  1362. CuAssertIntEquals(tc, f->count, 0);
  1363. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1364. }
  1365. void test_argint_basic_046(CuTest* tc) {
  1366. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1367. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1368. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1369. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1370. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1371. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1372. struct arg_end* end = arg_end(20);
  1373. void* argtable[] = {a, b, c, d, e, f, end};
  1374. int nerrors;
  1375. int i;
  1376. char* argv[] = {"program", "1.234", NULL};
  1377. int argc = sizeof(argv) / sizeof(char*) - 1;
  1378. /* allow missing argument values for the f argument, and set defaults to -1 */
  1379. f->hdr.flag |= ARG_HASOPTVALUE;
  1380. for (i = 0; i < f->hdr.maxcount; i++)
  1381. f->ival[i] = -1;
  1382. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1383. nerrors = arg_parse(argc, argv, argtable);
  1384. CuAssertIntEquals(tc, nerrors, 1);
  1385. CuAssertIntEquals(tc, a->count, 0);
  1386. CuAssertIntEquals(tc, b->count, 0);
  1387. CuAssertIntEquals(tc, c->count, 0);
  1388. CuAssertIntEquals(tc, d->count, 0);
  1389. CuAssertIntEquals(tc, e->count, 0);
  1390. CuAssertIntEquals(tc, f->count, 0);
  1391. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1392. }
  1393. void test_argint_basic_047(CuTest* tc) {
  1394. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1395. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1396. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1397. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1398. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1399. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1400. struct arg_end* end = arg_end(20);
  1401. void* argtable[] = {a, b, c, d, e, f, end};
  1402. int nerrors;
  1403. int i;
  1404. char* argv[] = {"program", "4", "hello", NULL};
  1405. int argc = sizeof(argv) / sizeof(char*) - 1;
  1406. /* allow missing argument values for the f argument, and set defaults to -1 */
  1407. f->hdr.flag |= ARG_HASOPTVALUE;
  1408. for (i = 0; i < f->hdr.maxcount; i++)
  1409. f->ival[i] = -1;
  1410. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1411. nerrors = arg_parse(argc, argv, argtable);
  1412. CuAssertIntEquals(tc, nerrors, 1);
  1413. CuAssertIntEquals(tc, a->count, 1);
  1414. CuAssertIntEquals(tc, a->ival[0], 4);
  1415. CuAssertIntEquals(tc, b->count, 0);
  1416. CuAssertIntEquals(tc, c->count, 0);
  1417. CuAssertIntEquals(tc, d->count, 0);
  1418. CuAssertIntEquals(tc, e->count, 0);
  1419. CuAssertIntEquals(tc, f->count, 0);
  1420. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1421. }
  1422. void test_argint_basic_048(CuTest* tc) {
  1423. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1424. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1425. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1426. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1427. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1428. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1429. struct arg_end* end = arg_end(20);
  1430. void* argtable[] = {a, b, c, d, e, f, end};
  1431. int nerrors;
  1432. int i;
  1433. char* argv[] = {"program", "5", "1.234", NULL};
  1434. int argc = sizeof(argv) / sizeof(char*) - 1;
  1435. /* allow missing argument values for the f argument, and set defaults to -1 */
  1436. f->hdr.flag |= ARG_HASOPTVALUE;
  1437. for (i = 0; i < f->hdr.maxcount; i++)
  1438. f->ival[i] = -1;
  1439. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1440. nerrors = arg_parse(argc, argv, argtable);
  1441. CuAssertIntEquals(tc, nerrors, 1);
  1442. CuAssertIntEquals(tc, a->count, 1);
  1443. CuAssertIntEquals(tc, a->ival[0], 5);
  1444. CuAssertIntEquals(tc, b->count, 0);
  1445. CuAssertIntEquals(tc, c->count, 0);
  1446. CuAssertIntEquals(tc, d->count, 0);
  1447. CuAssertIntEquals(tc, e->count, 0);
  1448. CuAssertIntEquals(tc, f->count, 0);
  1449. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1450. }
  1451. void test_argint_basic_049(CuTest* tc) {
  1452. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1453. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1454. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1455. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1456. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1457. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1458. struct arg_end* end = arg_end(20);
  1459. void* argtable[] = {a, b, c, d, e, f, end};
  1460. int nerrors;
  1461. int i;
  1462. char* argv[] = {"program", "-f", "2", "--filler=", NULL};
  1463. int argc = sizeof(argv) / sizeof(char*) - 1;
  1464. /* allow missing argument values for the f argument, and set defaults to -1 */
  1465. f->hdr.flag |= ARG_HASOPTVALUE;
  1466. for (i = 0; i < f->hdr.maxcount; i++)
  1467. f->ival[i] = -1;
  1468. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1469. nerrors = arg_parse(argc, argv, argtable);
  1470. CuAssertIntEquals(tc, nerrors, 2);
  1471. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1472. }
  1473. void test_argint_basic_050(CuTest* tc) {
  1474. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1475. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1476. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1477. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1478. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1479. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1480. struct arg_end* end = arg_end(20);
  1481. void* argtable[] = {a, b, c, d, e, f, end};
  1482. int nerrors;
  1483. int i;
  1484. char* argv[] = {"program", "0x0g", NULL};
  1485. int argc = sizeof(argv) / sizeof(char*) - 1;
  1486. /* allow missing argument values for the f argument, and set defaults to -1 */
  1487. f->hdr.flag |= ARG_HASOPTVALUE;
  1488. for (i = 0; i < f->hdr.maxcount; i++)
  1489. f->ival[i] = -1;
  1490. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1491. nerrors = arg_parse(argc, argv, argtable);
  1492. CuAssertIntEquals(tc, nerrors, 1);
  1493. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1494. }
  1495. void test_argint_basic_051(CuTest* tc) {
  1496. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1497. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1498. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1499. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1500. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1501. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1502. struct arg_end* end = arg_end(20);
  1503. void* argtable[] = {a, b, c, d, e, f, end};
  1504. int nerrors;
  1505. int i;
  1506. char* argv[] = {"program", "0o08", NULL};
  1507. int argc = sizeof(argv) / sizeof(char*) - 1;
  1508. /* allow missing argument values for the f argument, and set defaults to -1 */
  1509. f->hdr.flag |= ARG_HASOPTVALUE;
  1510. for (i = 0; i < f->hdr.maxcount; i++)
  1511. f->ival[i] = -1;
  1512. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1513. nerrors = arg_parse(argc, argv, argtable);
  1514. CuAssertIntEquals(tc, nerrors, 1);
  1515. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1516. }
  1517. void test_argint_basic_052(CuTest* tc) {
  1518. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1519. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1520. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1521. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1522. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1523. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1524. struct arg_end* end = arg_end(20);
  1525. void* argtable[] = {a, b, c, d, e, f, end};
  1526. int nerrors;
  1527. int i;
  1528. char* argv[] = {"program", "0b02", NULL};
  1529. int argc = sizeof(argv) / sizeof(char*) - 1;
  1530. /* allow missing argument values for the f argument, and set defaults to -1 */
  1531. f->hdr.flag |= ARG_HASOPTVALUE;
  1532. for (i = 0; i < f->hdr.maxcount; i++)
  1533. f->ival[i] = -1;
  1534. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1535. nerrors = arg_parse(argc, argv, argtable);
  1536. CuAssertIntEquals(tc, nerrors, 1);
  1537. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1538. }
  1539. void test_argint_basic_053(CuTest* tc) {
  1540. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1541. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1542. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1543. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1544. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1545. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1546. struct arg_end* end = arg_end(20);
  1547. void* argtable[] = {a, b, c, d, e, f, end};
  1548. int nerrors;
  1549. int i;
  1550. char* argv[] = {"program", "1000GB", NULL};
  1551. int argc = sizeof(argv) / sizeof(char*) - 1;
  1552. /* allow missing argument values for the f argument, and set defaults to -1 */
  1553. f->hdr.flag |= ARG_HASOPTVALUE;
  1554. for (i = 0; i < f->hdr.maxcount; i++)
  1555. f->ival[i] = -1;
  1556. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1557. nerrors = arg_parse(argc, argv, argtable);
  1558. CuAssertIntEquals(tc, nerrors, 1);
  1559. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1560. }
  1561. void test_argint_basic_054(CuTest* tc) {
  1562. struct arg_int* a = arg_int1(NULL, NULL, "a", "a is <int>");
  1563. struct arg_int* b = arg_int0(NULL, NULL, "b", "b is <int>");
  1564. struct arg_int* c = arg_int0(NULL, NULL, "c", "c is <int>");
  1565. struct arg_int* d = arg_intn("dD", "delta", "<int>", 0, 3, "d can occur 0..3 times");
  1566. struct arg_int* e = arg_int0(NULL, "eps,eqn", "<int>", "eps is optional");
  1567. struct arg_int* f = arg_intn("fF", "filler", "<int>", 0, 3, "f can occur 0..3 times");
  1568. struct arg_end* end = arg_end(20);
  1569. void* argtable[] = {a, b, c, d, e, f, end};
  1570. int nerrors;
  1571. int i;
  1572. char* argv[] = {"program", "1GBH", NULL};
  1573. int argc = sizeof(argv) / sizeof(char*) - 1;
  1574. /* allow missing argument values for the f argument, and set defaults to -1 */
  1575. f->hdr.flag |= ARG_HASOPTVALUE;
  1576. for (i = 0; i < f->hdr.maxcount; i++)
  1577. f->ival[i] = -1;
  1578. CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
  1579. nerrors = arg_parse(argc, argv, argtable);
  1580. CuAssertIntEquals(tc, nerrors, 1);
  1581. arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
  1582. }
  1583. CuSuite* get_argint_testsuite() {
  1584. CuSuite* suite = CuSuiteNew();
  1585. SUITE_ADD_TEST(suite, test_argint_basic_001);
  1586. SUITE_ADD_TEST(suite, test_argint_basic_002);
  1587. SUITE_ADD_TEST(suite, test_argint_basic_003);
  1588. SUITE_ADD_TEST(suite, test_argint_basic_004);
  1589. SUITE_ADD_TEST(suite, test_argint_basic_005);
  1590. SUITE_ADD_TEST(suite, test_argint_basic_006);
  1591. SUITE_ADD_TEST(suite, test_argint_basic_007);
  1592. SUITE_ADD_TEST(suite, test_argint_basic_008);
  1593. SUITE_ADD_TEST(suite, test_argint_basic_009);
  1594. SUITE_ADD_TEST(suite, test_argint_basic_010);
  1595. SUITE_ADD_TEST(suite, test_argint_basic_011);
  1596. SUITE_ADD_TEST(suite, test_argint_basic_012);
  1597. SUITE_ADD_TEST(suite, test_argint_basic_013);
  1598. SUITE_ADD_TEST(suite, test_argint_basic_014);
  1599. SUITE_ADD_TEST(suite, test_argint_basic_015);
  1600. SUITE_ADD_TEST(suite, test_argint_basic_016);
  1601. SUITE_ADD_TEST(suite, test_argint_basic_017);
  1602. SUITE_ADD_TEST(suite, test_argint_basic_018);
  1603. SUITE_ADD_TEST(suite, test_argint_basic_019);
  1604. SUITE_ADD_TEST(suite, test_argint_basic_020);
  1605. SUITE_ADD_TEST(suite, test_argint_basic_021);
  1606. SUITE_ADD_TEST(suite, test_argint_basic_022);
  1607. SUITE_ADD_TEST(suite, test_argint_basic_023);
  1608. SUITE_ADD_TEST(suite, test_argint_basic_024);
  1609. SUITE_ADD_TEST(suite, test_argint_basic_025);
  1610. SUITE_ADD_TEST(suite, test_argint_basic_026);
  1611. SUITE_ADD_TEST(suite, test_argint_basic_027);
  1612. SUITE_ADD_TEST(suite, test_argint_basic_028);
  1613. SUITE_ADD_TEST(suite, test_argint_basic_029);
  1614. SUITE_ADD_TEST(suite, test_argint_basic_030);
  1615. SUITE_ADD_TEST(suite, test_argint_basic_031);
  1616. SUITE_ADD_TEST(suite, test_argint_basic_032);
  1617. SUITE_ADD_TEST(suite, test_argint_basic_033);
  1618. SUITE_ADD_TEST(suite, test_argint_basic_034);
  1619. SUITE_ADD_TEST(suite, test_argint_basic_035);
  1620. SUITE_ADD_TEST(suite, test_argint_basic_036);
  1621. SUITE_ADD_TEST(suite, test_argint_basic_037);
  1622. SUITE_ADD_TEST(suite, test_argint_basic_038);
  1623. SUITE_ADD_TEST(suite, test_argint_basic_039);
  1624. SUITE_ADD_TEST(suite, test_argint_basic_040);
  1625. SUITE_ADD_TEST(suite, test_argint_basic_041);
  1626. SUITE_ADD_TEST(suite, test_argint_basic_042);
  1627. SUITE_ADD_TEST(suite, test_argint_basic_043);
  1628. SUITE_ADD_TEST(suite, test_argint_basic_044);
  1629. SUITE_ADD_TEST(suite, test_argint_basic_045);
  1630. SUITE_ADD_TEST(suite, test_argint_basic_046);
  1631. SUITE_ADD_TEST(suite, test_argint_basic_047);
  1632. SUITE_ADD_TEST(suite, test_argint_basic_048);
  1633. SUITE_ADD_TEST(suite, test_argint_basic_049);
  1634. SUITE_ADD_TEST(suite, test_argint_basic_050);
  1635. SUITE_ADD_TEST(suite, test_argint_basic_051);
  1636. SUITE_ADD_TEST(suite, test_argint_basic_052);
  1637. SUITE_ADD_TEST(suite, test_argint_basic_053);
  1638. SUITE_ADD_TEST(suite, test_argint_basic_054);
  1639. return suite;
  1640. }
  1641. #if defined(_MSC_VER)
  1642. #pragma warning(pop)
  1643. #endif