3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina Jakub Hrozek <jhrozek@redhat.com>
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina Pavel Březina <pbrezina@redhat.com>
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina Copyright (C) 2014 Red Hat
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina This program is free software; you can redistribute it and/or modify
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina it under the terms of the GNU General Public License as published by
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina the Free Software Foundation; either version 3 of the License, or
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina (at your option) any later version.
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina This program is distributed in the hope that it will be useful,
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina GNU General Public License for more details.
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina You should have received a copy of the GNU General Public License
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březinavoid test_sbus_opath_strip_prefix(void **state)
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina const char *prefix = "/org/freedesktop/sssd/";
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina const char *path = "/org/freedesktop/sssd/infopipe";
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina strip = sbus_opath_strip_prefix(path, prefix);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina strip = sbus_opath_strip_prefix("/other/path", prefix);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březinavoid test_sbus_opath_escape_unescape(void **state)
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina escaped = sbus_opath_escape_part(mem_ctx, "noescape");
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina raw = sbus_opath_unescape_part(mem_ctx, escaped);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina escaped = sbus_opath_escape_part(mem_ctx, "redhat.com");
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina assert_string_equal(escaped, "redhat_2ecom"); /* dot is 0x2E in ASCII */
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina raw = sbus_opath_unescape_part(mem_ctx, escaped);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina escaped = sbus_opath_escape_part(mem_ctx, "path_with_underscore");
a02a5ed51178b2cbede0396d66aed716b8898096René Genz /* underscore is 0x5F in ASCII */
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina assert_string_equal(escaped, "path_5fwith_5funderscore");
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina raw = sbus_opath_unescape_part(mem_ctx, escaped);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina assert_string_equal(raw, "path_with_underscore");
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina /* empty string */
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina escaped = sbus_opath_escape_part(mem_ctx, "");
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina raw = sbus_opath_unescape_part(mem_ctx, escaped);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina /* negative tests */
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina escaped = sbus_opath_escape_part(mem_ctx, NULL);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina raw = sbus_opath_unescape_part(mem_ctx, "wrongpath_");
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina /* Doesn't need escaping */
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina path = sbus_opath_compose(NULL, BASE_PATH, "domname");
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina assert_string_equal(path, BASE_PATH "/domname");
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březinavoid test_sbus_opath_compose_escape(void **state)
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina /* A dot needs escaping */
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina path = sbus_opath_compose(NULL, BASE_PATH, "redhat.com", NULL);
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina assert_string_equal(path, BASE_PATH "/redhat_2ecom");
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinastatic void check_opath_components(char **input,
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinastatic void check_opath_components_and_length(char **input,
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinavoid test_sbus_opath_decompose_noprefix(void **state)
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina const char *expected[] = {"object", "path", "parts", NULL};
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina size_t expected_len = sizeof(expected) / sizeof(char *) - 1;
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina ret = sbus_opath_decompose(NULL, path, NULL, &components, &len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina check_opath_components_and_length(components, len, expected, expected_len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinavoid test_sbus_opath_decompose_prefix(void **state)
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina size_t expected_len = sizeof(expected) / sizeof(char *) - 1;
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina ret = sbus_opath_decompose(NULL, path, "/object/path", &components, &len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina check_opath_components_and_length(components, len, expected, expected_len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinavoid test_sbus_opath_decompose_prefix_slash(void **state)
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina size_t expected_len = sizeof(expected) / sizeof(char *) - 1;
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina ret = sbus_opath_decompose(NULL, path, "/object/path/", &components, &len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina check_opath_components_and_length(components, len, expected, expected_len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinavoid test_sbus_opath_decompose_wrong_prefix(void **state)
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina ret = sbus_opath_decompose(NULL, path, "/wrong/prefix", &components, &len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinavoid test_sbus_opath_decompose_escaped(void **state)
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina const char *expected[] = {"object", "redhat.com", NULL};
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina size_t expected_len = sizeof(expected) / sizeof(char *) - 1;
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina ret = sbus_opath_decompose(NULL, path, NULL, &components, &len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina check_opath_components_and_length(components, len, expected, expected_len);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinavoid test_sbus_opath_decompose_exact_correct(void **state)
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina const char *expected[] = {"object", "path", "parts", NULL};
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina ret = sbus_opath_decompose_exact(NULL, path, NULL, 3, &components);
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březinavoid test_sbus_opath_decompose_exact_wrong(void **state)
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina ret = sbus_opath_decompose_exact(NULL, path, NULL, 2, &components);
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březinavoid test_sbus_opath_get_object_name(void **state)
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(NULL, path, BASE_PATH);
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(NULL, path, BASE_PATH "/");
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(NULL, BASE_PATH, BASE_PATH);
ca6dd8e7ac91c7f8e3b4d55206d4f39791ab7149Pavel Březina name = sbus_opath_get_object_name(NULL, "invalid", BASE_PATH);
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_sbus_opath_strip_prefix),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_sbus_opath_escape_unescape),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_sbus_opath_compose_escape),
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina cmocka_unit_test(test_sbus_opath_decompose_noprefix),
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina cmocka_unit_test(test_sbus_opath_decompose_prefix),
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina cmocka_unit_test(test_sbus_opath_decompose_prefix_slash),
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina cmocka_unit_test(test_sbus_opath_decompose_wrong_prefix),
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina cmocka_unit_test(test_sbus_opath_decompose_escaped),
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina cmocka_unit_test(test_sbus_opath_decompose_exact_correct),
10a28f461c25d788ff4dcffefa881e7aa724a25dPavel Březina cmocka_unit_test(test_sbus_opath_decompose_exact_wrong),
4e5e846de22407f825fe3b4040d79606818a2419Jakub Hrozek cmocka_unit_test(test_sbus_opath_get_object_name)
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina pc = poptGetContext(argv[0], argc, argv, long_options, 0);
3a8f6b575f4019f21c9425a26f1b346c08a197aePavel Březina fprintf(stderr, "\nInvalid option %s: %s\n\n",