summaryrefslogtreecommitdiff
path: root/unittest/mysys
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2019-09-29 20:30:28 +0200
committerSergei Golubchik <serg@mariadb.org>2019-10-14 10:29:30 +0200
commit3ea51b518bf8c2ec55e125794a14fb152079839c (patch)
tree8676278e58713ccd8db9d2737710681a1ef06df6 /unittest/mysys
parenteb3431d5299d8ec531a3f54b0638d30efa391d55 (diff)
downloadmariadb-git-3ea51b518bf8c2ec55e125794a14fb152079839c.tar.gz
cleanup: my_getopt, get_one_option isn't optional
it turns out that practically every single user of handle_options() used the get_one_option callback. Simplify the code, make it mandatory, adjust unit tests.
Diffstat (limited to 'unittest/mysys')
-rw-r--r--unittest/mysys/my_getopt-t.c47
1 files changed, 21 insertions, 26 deletions
diff --git a/unittest/mysys/my_getopt-t.c b/unittest/mysys/my_getopt-t.c
index 3e16d79424e..181b5a6ec12 100644
--- a/unittest/mysys/my_getopt-t.c
+++ b/unittest/mysys/my_getopt-t.c
@@ -60,6 +60,13 @@ static struct my_option mopts_options[]=
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
+my_bool dummy_get_one_option(int optid __attribute__((unused)),
+ const struct my_option *opt __attribute__((unused)),
+ char *argument __attribute__((unused)))
+{
+ return FALSE;
+}
+
void run(const char *arg, ...)
{
va_list ap;
@@ -74,7 +81,7 @@ void run(const char *arg, ...)
va_end(ap);
arg_c= (int)(arg_v - arg_s);
arg_v= arg_s;
- res= handle_options(&arg_c, &arg_v, mopts_options, 0);
+ res= handle_options(&arg_c, &arg_v, mopts_options, &dummy_get_one_option);
}
int mopts1_argc= 4;
@@ -84,7 +91,7 @@ void test_mopts1()
int rc;
char **av= (char **)mopts1_argv;
- rc= handle_options(&mopts1_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts1_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts1 call");
ok( (mopts_num == 122), "%s", "test_mopts1 num");
ok( (strncmp(mopts_str, "str", 4) == 0), "%s", "test_mopts1 str");
@@ -98,7 +105,7 @@ void test_mopts2()
int rc;
char **av= (char **)mopts2_argv;
- rc= handle_options(&mopts2_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts2_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts2 call");
ok( (mopts_num == 124), "%s", "test_mopts2 num");
ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts2 str");
@@ -112,7 +119,7 @@ void test_mopts3()
int rc;
char **av= (char **)mopts3_argv;
- rc= handle_options(&mopts3_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts3_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts3 call");
ok( (mopts_num == 1000000L), "%s", "test_mopts3 num");
ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts3 str");
@@ -126,7 +133,7 @@ void test_mopts4()
int rc;
char **av= (char **)mopts4_argv;
- rc= handle_options(&mopts4_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts4_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts4 call");
ok( (mopts_num == 1000000L), "%s", "test_mopts4 num");
ok( (strncmp(mopts_str, "aa", 3) == 0), "%s", "test_mopts4 str");
@@ -140,7 +147,7 @@ void test_mopts5()
int rc;
char **av= (char **)mopts5_argv;
- rc= handle_options(&mopts5_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts5_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts5 call");
ok( (mopts_num == 1000000L), "%s", "test_mopts5 num");
ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts5 str");
@@ -154,7 +161,7 @@ void test_mopts6()
int rc;
char **av= (char **)mopts6_argv;
- rc= handle_options(&mopts6_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts6_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts6 call");
ok( (mopts_num == 1000000L), "%s", "test_mopts6 num");
ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts6 str");
@@ -168,7 +175,7 @@ void test_mopts7()
int rc;
char **av= (char **)mopts7_argv;
- rc= handle_options(&mopts7_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts7_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts7 call");
ok( (mopts_num == 1000000L), "%s", "test_mopts7 num");
ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts7 str");
@@ -182,7 +189,7 @@ void test_mopts8()
int rc;
char **av= (char **)mopts8_argv;
- rc= handle_options(&mopts8_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts8_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_mopts8 call");
ok( (mopts_num == 1000000L), "%s", "test_mopts7 num");
ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts7 str");
@@ -196,7 +203,7 @@ void test_mopts9()
int rc;
char **av= (char **)mopts9_argv;
- rc= handle_options(&mopts9_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts9_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc != 0), "%s", "test_mopts9 call");
}
@@ -207,7 +214,7 @@ void test_mopts10()
int rc;
char **av= (char **)mopts10_argv;
- rc= handle_options(&mopts10_argc, &av, mopts_options, NULL);
+ rc= handle_options(&mopts10_argc, &av, mopts_options, &dummy_get_one_option);
ok( (rc != 0), "%s", "test_mopts10 call");
}
@@ -238,17 +245,6 @@ my_bool auto_get_one_option(int optid __attribute__((unused)),
return FALSE;
}
-int auto1_argc= 3;
-const char *auto1_argv[]= {"auto1", "--anum=123", "--autoset-anum"};
-void test_auto1()
-{
- int rc;
- char **av= (char **)auto1_argv;
-
- rc= handle_options(&auto1_argc, &av, auto_options, NULL);
- ok( (rc == EXIT_ARGUMENT_INVALID), "%s", "test_auto1 call");
-}
-
int auto2_argc= 3;
const char *auto2_argv[]= {"auto2", "--num=123", "--autoset-num"};
void test_auto2()
@@ -330,7 +326,7 @@ void test_max1()
int rc;
char **av= (char **)max1_argv;
- rc= handle_options(&max1_argc, &av, max_options, NULL);
+ rc= handle_options(&max1_argc, &av, max_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_max1 call");
ok( (mopts_num == 200), "%s", "test_max1 num");
ok( (max_num == 1000001L), "%s", "test_max1 max_num");
@@ -342,7 +338,7 @@ void test_max2()
int rc;
char **av= (char **)max2_argv;
- rc= handle_options(&max2_argc, &av, max_options, NULL);
+ rc= handle_options(&max2_argc, &av, max_options, &dummy_get_one_option);
ok( (rc == 0), "%s", "test_max2 call");
ok( (mopts_num == 200), "%s", "test_max2 num");
ok( (max_num == 100), "%s", "test_max2 max_num");
@@ -351,7 +347,7 @@ void test_max2()
int main(int argc __attribute__((unused)), char **argv)
{
MY_INIT(argv[0]);
- plan(4*8 + 1*4 + 3*4 + 3*2 + 3);
+ plan(4*8 + 1*4 + 3*4 + 3*2 + 2);
/* gcc 4.1.2 doesn't want it in the initializer, we have to do it run-time */
mopts_options[0].def_value= (intptr)"ddd";
@@ -367,7 +363,6 @@ int main(int argc __attribute__((unused)), char **argv)
test_mopts9();
test_mopts10();
- test_auto1();
test_auto2();
test_auto3();