123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- /*******************************************************************************
- * This file is part of the argtable3 library.
- *
- * Copyright (C) 2013-2019 Tom G. Huang
- * <tomghuang@gmail.com>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of STEWART HEITMANN nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ******************************************************************************/
- #include <string.h>
- #include "CuTest.h"
- #include "argtable3.h"
- #if defined(_MSC_VER)
- #pragma warning(push)
- #pragma warning(disable : 4204)
- #endif
- void test_argstr_basic_001(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "--hello=string1", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 2);
- CuAssertTrue(tc, a->count == 1);
- CuAssertStrEquals(tc, a->sval[0], "string1");
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 0);
- CuAssertTrue(tc, d->count == 0);
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_002(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-cstring1", "-Dstring2", "-dstring3", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- if (nerrors > 0)
- arg_print_errors(stdout, end, argv[0]);
- CuAssertTrue(tc, nerrors == 0);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string1");
- CuAssertTrue(tc, d->count == 2);
- CuAssertStrEquals(tc, d->sval[0], "string2");
- CuAssertStrEquals(tc, d->sval[1], "string3");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_003(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Cstring1", "--delta=string2", "--delta=string3", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- if (nerrors > 0)
- arg_print_errors(stdout, end, argv[0]);
- CuAssertTrue(tc, nerrors == 0);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string1");
- CuAssertTrue(tc, d->count == 2);
- CuAssertStrEquals(tc, d->sval[0], "string2");
- CuAssertStrEquals(tc, d->sval[1], "string3");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_004(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "--delta=string1", "-cstring2", "-Dstring3", "-bstring4", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- if (nerrors > 0)
- arg_print_errors(stdout, end, argv[0]);
- CuAssertTrue(tc, nerrors == 0);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 1);
- CuAssertStrEquals(tc, b->sval[0], "string4");
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string2");
- CuAssertTrue(tc, d->count == 2);
- CuAssertStrEquals(tc, d->sval[0], "string1");
- CuAssertStrEquals(tc, d->sval[1], "string3");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_005(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Dstring1", "-Bstring2", "--delta=string3", "-Cstring4", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- if (nerrors > 0)
- arg_print_errors(stdout, end, argv[0]);
- CuAssertTrue(tc, nerrors == 0);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 1);
- CuAssertStrEquals(tc, b->sval[0], "string2");
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string4");
- CuAssertTrue(tc, d->count == 2);
- CuAssertStrEquals(tc, d->sval[0], "string1");
- CuAssertStrEquals(tc, d->sval[1], "string3");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_006(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Dstring1", "-Bstring2", "--delta=string3", "-Cstring4", "--hello=string5", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- if (nerrors > 0)
- arg_print_errors(stdout, end, argv[0]);
- CuAssertTrue(tc, nerrors == 0);
- CuAssertTrue(tc, a->count == 1);
- CuAssertStrEquals(tc, a->sval[0], "string5");
- CuAssertTrue(tc, b->count == 1);
- CuAssertStrEquals(tc, b->sval[0], "string2");
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string4");
- CuAssertTrue(tc, d->count == 2);
- CuAssertStrEquals(tc, d->sval[0], "string1");
- CuAssertStrEquals(tc, d->sval[1], "string3");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_007(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Dstring1", "-Bstring2", "--delta=string3", "-Cstring4", "--world=string5", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- if (nerrors > 0)
- arg_print_errors(stdout, end, argv[0]);
- CuAssertTrue(tc, nerrors == 0);
- CuAssertTrue(tc, a->count == 1);
- CuAssertStrEquals(tc, a->sval[0], "string5");
- CuAssertTrue(tc, b->count == 1);
- CuAssertStrEquals(tc, b->sval[0], "string2");
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string4");
- CuAssertTrue(tc, d->count == 2);
- CuAssertStrEquals(tc, d->sval[0], "string1");
- CuAssertStrEquals(tc, d->sval[1], "string3");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_008(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-cstring1", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string1");
- CuAssertTrue(tc, d->count == 0);
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_009(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Dstring1", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 2);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 0);
- CuAssertTrue(tc, d->count == 1);
- CuAssertStrEquals(tc, d->sval[0], "string1");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_010(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Cstring1", "-Dstring2", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "string1");
- CuAssertTrue(tc, d->count == 1);
- CuAssertStrEquals(tc, d->sval[0], "string2");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_011(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Dstring1", "-dstring2", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 0);
- CuAssertTrue(tc, d->count == 2);
- CuAssertStrEquals(tc, d->sval[0], "string1");
- CuAssertStrEquals(tc, d->sval[1], "string2");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_012(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-cs1", "-ds2", "-ds3", "-ds4", "-ds5", "-ds6", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "s1");
- CuAssertTrue(tc, d->count == 4);
- CuAssertStrEquals(tc, d->sval[0], "s2");
- CuAssertStrEquals(tc, d->sval[1], "s3");
- CuAssertStrEquals(tc, d->sval[2], "s4");
- CuAssertStrEquals(tc, d->sval[3], "s5");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_013(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-cs1", "-cs2", "-ds3", "-ds4", "-ds5", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "s1");
- CuAssertTrue(tc, d->count == 3);
- CuAssertStrEquals(tc, d->sval[0], "s3");
- CuAssertStrEquals(tc, d->sval[1], "s4");
- CuAssertStrEquals(tc, d->sval[2], "s5");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_014(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Cs1", "-ds2", "-Ds3", "--delta=s4", "-bs5", "-Bs6", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 0);
- CuAssertTrue(tc, b->count == 1);
- CuAssertStrEquals(tc, b->sval[0], "s5");
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "s1");
- CuAssertTrue(tc, d->count == 3);
- CuAssertStrEquals(tc, d->sval[0], "s2");
- CuAssertStrEquals(tc, d->sval[1], "s3");
- CuAssertStrEquals(tc, d->sval[2], "s4");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_015(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Cs1", "-ds2", "-Ds3", "--delta=s4", "--hello=s5", "--world=s6", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 1);
- CuAssertStrEquals(tc, a->sval[0], "s5");
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "s1");
- CuAssertTrue(tc, d->count == 3);
- CuAssertStrEquals(tc, d->sval[0], "s2");
- CuAssertStrEquals(tc, d->sval[1], "s3");
- CuAssertStrEquals(tc, d->sval[2], "s4");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- void test_argstr_basic_016(CuTest* tc) {
- struct arg_str* a = arg_str0(NULL, "hello,world", "STRVAL", "either --hello or --world or none");
- struct arg_str* b = arg_str0("bB", NULL, "STRVAL", "either -b or -B or none");
- struct arg_str* c = arg_str1("cC", NULL, "STRVAL", "either -c or -C");
- struct arg_str* d = arg_strn("dD", "delta", "STRVAL", 2, 4, "-d|-D|--delta 2..4 occurences");
- struct arg_end* end = arg_end(20);
- void* argtable[] = {a, b, c, d, end};
- int nerrors;
- char* argv[] = {"program", "-Cs1", "-ds2", "-Ds3", "--delta=s4", "--hello=s5", "X", NULL};
- int argc = sizeof(argv) / sizeof(char*) - 1;
- CuAssertTrue(tc, arg_nullcheck(argtable) == 0);
- nerrors = arg_parse(argc, argv, argtable);
- CuAssertTrue(tc, nerrors == 1);
- CuAssertTrue(tc, a->count == 1);
- CuAssertStrEquals(tc, a->sval[0], "s5");
- CuAssertTrue(tc, b->count == 0);
- CuAssertTrue(tc, c->count == 1);
- CuAssertStrEquals(tc, c->sval[0], "s1");
- CuAssertTrue(tc, d->count == 3);
- CuAssertStrEquals(tc, d->sval[0], "s2");
- CuAssertStrEquals(tc, d->sval[1], "s3");
- CuAssertStrEquals(tc, d->sval[2], "s4");
- arg_freetable(argtable, sizeof(argtable) / sizeof(argtable[0]));
- }
- CuSuite* get_argstr_testsuite() {
- CuSuite* suite = CuSuiteNew();
- SUITE_ADD_TEST(suite, test_argstr_basic_001);
- SUITE_ADD_TEST(suite, test_argstr_basic_002);
- SUITE_ADD_TEST(suite, test_argstr_basic_003);
- SUITE_ADD_TEST(suite, test_argstr_basic_004);
- SUITE_ADD_TEST(suite, test_argstr_basic_005);
- SUITE_ADD_TEST(suite, test_argstr_basic_006);
- SUITE_ADD_TEST(suite, test_argstr_basic_007);
- SUITE_ADD_TEST(suite, test_argstr_basic_008);
- SUITE_ADD_TEST(suite, test_argstr_basic_009);
- SUITE_ADD_TEST(suite, test_argstr_basic_010);
- SUITE_ADD_TEST(suite, test_argstr_basic_011);
- SUITE_ADD_TEST(suite, test_argstr_basic_012);
- SUITE_ADD_TEST(suite, test_argstr_basic_013);
- SUITE_ADD_TEST(suite, test_argstr_basic_014);
- SUITE_ADD_TEST(suite, test_argstr_basic_015);
- SUITE_ADD_TEST(suite, test_argstr_basic_016);
- return suite;
- }
- #if defined(_MSC_VER)
- #pragma warning(pop)
- #endif
|