]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add tests for config_parse_match_{strv,ifnames}()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 27 Jun 2019 13:03:02 +0000 (22:03 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 30 Jun 2019 16:24:42 +0000 (01:24 +0900)
src/network/test-networkd-conf.c

index 4b599c430bd73ccb6193f729486026bfef060d16..07ca127654ff8ac36f3b399f278e52e821885694 100644 (file)
@@ -215,6 +215,27 @@ static void test_config_parse_address(void) {
         test_config_parse_address_one("::1/-1", AF_INET6, 0, NULL, 0);
 }
 
+static void test_config_parse_match_ifnames(void) {
+        _cleanup_strv_free_ char **names = NULL;
+
+        assert_se(config_parse_match_ifnames("network", "filename", 1, "section", 1, "Name", 0, "!hoge hogehoge foo", &names, NULL) == 0);
+        assert_se(config_parse_match_ifnames("network", "filename", 1, "section", 1, "Name", 0, "!baz", &names, NULL) == 0);
+        assert_se(config_parse_match_ifnames("network", "filename", 1, "section", 1, "Name", 0, "aaa bbb ccc", &names, NULL) == 0);
+
+        strv_equal(names, STRV_MAKE("!hoge", "!hogehoge", "!foo", "!baz", "aaa", "bbb", "ccc"));
+}
+
+static void test_config_parse_match_strv(void) {
+        _cleanup_strv_free_ char **names = NULL;
+
+        assert_se(config_parse_match_strv("network", "filename", 1, "section", 1, "Name", 0, "!hoge hogehoge foo", &names, NULL) == 0);
+        assert_se(config_parse_match_strv("network", "filename", 1, "section", 1, "Name", 0, "!baz", &names, NULL) == 0);
+        assert_se(config_parse_match_strv("network", "filename", 1, "section", 1, "Name", 0,
+                                          "KEY=val \"KEY2=val with space\" \"KEY3=val with \\\"quotation\\\"\"", &names, NULL) == 0);
+
+        strv_equal(names, STRV_MAKE("!hoge", "!hogehoge", "!foo", "!baz", "KEY=val", "KEY2=val with space", "KEY3=val with \"quotation\""));
+}
+
 int main(int argc, char **argv) {
         log_parse_environment();
         log_open();
@@ -223,6 +244,8 @@ int main(int argc, char **argv) {
         test_config_parse_duid_rawdata();
         test_config_parse_hwaddr();
         test_config_parse_address();
+        test_config_parse_match_ifnames();
+        test_config_parse_match_strv();
 
         return 0;
 }