]>
git.saurik.com Git - apple/libc.git/blob - tests/darwin_bsd.c
1 #include <darwintest.h>
3 #include "../libdarwin/bsd.c"
5 static struct test_case
{
10 {"-x -a b=3 y=42", "-a", ""},
11 {"-x -a b=3 y=42", "b", "3"},
12 {"-x -a b=2 ba=3 y=42", "b", "2"},
13 {"-x -a ba=3 b=2 y=42", "b", "2"},
14 {"-x -a b=2 ba=3 y=42", "ba", "3"},
15 {"-x -a ba=3 b=2 y=42", "ba", "3"},
16 {"-x -ab -aa y=42", "-a", NULL
},
17 {"-x b=96 y=42", "bx", NULL
},
18 {"-x ab=96 y=42", "a", NULL
},
21 T_DECL(parse_boot_arg_value
, "Parsing boot args")
23 for (int i
= 0; i
< (int)(sizeof(test_cases
)/sizeof(test_cases
[0])); i
++) {
24 struct test_case
*test_case
= &test_cases
[i
];
25 T_LOG("\"%s\": Looking for \"%s\", expecting \"%s\"",
26 test_case
->args
, test_case
->argname
, test_case
->argvalue
);
28 char *argbuff
= strdup(test_case
->args
);
30 char result
[256] = "NOT_FOUND";
31 bool found
= _parse_boot_arg_value(argbuff
, test_case
->argname
,
32 result
,sizeof(result
));
34 if (test_case
->argvalue
) {
35 T_EXPECT_EQ(found
, true, "Should find argument");
36 T_EXPECT_EQ_STR(result
, test_case
->argvalue
, "Should find correct result");
38 T_EXPECT_EQ(found
, false, "Should not find argument");
45 T_DECL(os_parse_boot_arg
, "Getting boot args")
48 T_EXPECT_EQ(os_parse_boot_arg_int("notarealthing", &value
), false, NULL
);
51 T_EXPECT_EQ(os_parse_boot_arg_int("debug", &value
), true, NULL
);
52 T_EXPECT_GT(value
, 0LL, "non-zero debug= value");
56 T_EXPECT_EQ(os_parse_boot_arg_string("notarealthing", buf
, sizeof(buf
)), false, NULL
);
59 T_EXPECT_EQ(os_parse_boot_arg_string("debug", buf
, sizeof(buf
)), true, NULL
);
60 T_EXPECT_GT(strlen(buf
), 0UL, "non-empty debug= value");