]>
git.saurik.com Git - apple/libc.git/blob - tests/darwin_bsd.c
1 #include <darwintest.h>
3 #if !defined(DARWIN_API_AVAILABLE_20190830)
4 #define DARWIN_API_AVAILABLE_20190830
7 #include "../libdarwin/bsd.c"
9 static struct test_case
{
14 {"-x -a b=3 y=42", "-a", ""},
15 {"-x -a b=3 y=42", "b", "3"},
16 {"-x -a b=2 ba=3 y=42", "b", "2"},
17 {"-x -a ba=3 b=2 y=42", "b", "2"},
18 {"-x -a b=2 ba=3 y=42", "ba", "3"},
19 {"-x -a ba=3 b=2 y=42", "ba", "3"},
20 {"-x -ab -aa y=42", "-a", NULL
},
21 {"-x b=96 y=42", "bx", NULL
},
22 {"-x ab=96 y=42", "a", NULL
},
25 T_DECL(parse_boot_arg_value
, "Parsing boot args")
27 for (int i
= 0; i
< (int)(sizeof(test_cases
)/sizeof(test_cases
[0])); i
++) {
28 struct test_case
*test_case
= &test_cases
[i
];
29 T_LOG("\"%s\": Looking for \"%s\", expecting \"%s\"",
30 test_case
->args
, test_case
->argname
, test_case
->argvalue
);
32 char *argbuff
= strdup(test_case
->args
);
34 char result
[256] = "NOT_FOUND";
35 bool found
= _parse_boot_arg_value(argbuff
, test_case
->argname
,
36 result
,sizeof(result
));
38 if (test_case
->argvalue
) {
39 T_EXPECT_EQ(found
, true, "Should find argument");
40 T_EXPECT_EQ_STR(result
, test_case
->argvalue
, "Should find correct result");
42 T_EXPECT_EQ(found
, false, "Should not find argument");
49 T_DECL(os_parse_boot_arg
, "Getting boot args")
52 T_EXPECT_EQ(os_parse_boot_arg_int("notarealthing", &value
), false, NULL
);
55 T_EXPECT_EQ(os_parse_boot_arg_int("debug", &value
), true, NULL
);
56 T_EXPECT_GT(value
, 0LL, "non-zero debug= value");
60 T_EXPECT_EQ(os_parse_boot_arg_string("notarealthing", buf
, sizeof(buf
)), false, NULL
);
63 T_EXPECT_EQ(os_parse_boot_arg_string("debug", buf
, sizeof(buf
)), true, NULL
);
64 T_EXPECT_GT(strlen(buf
), 0UL, "non-empty debug= value");