>From 89b91d5c4e05cd5c595b02fe646c5b362706506e Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sun, 11 May 2014 16:18:28 +0200 Subject: [PATCH 3/3] IFP: Add a unit test for ifp_reply_objpath --- src/tests/cmocka/test_ifp.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/tests/cmocka/test_ifp.c b/src/tests/cmocka/test_ifp.c index 5dfa04b069635f42d27ac911977f28be8db37499..c8e9a230e06bb0a24d3d29c2dec84b08ce7c3851 100644 --- a/src/tests/cmocka/test_ifp.c +++ b/src/tests/cmocka/test_ifp.c @@ -399,6 +399,32 @@ void ifp_test_req_teardown(void **state) assert_true(leak_check_teardown()); } +void test_reply_path(void **state) +{ + struct ifp_test_req_ctx *test_ctx = talloc_get_type_abort(*state, + struct ifp_test_req_ctx); + char *path; + + /* Doesn't need escaping */ + path = ifp_reply_objpath(test_ctx->ireq, PATH_BASE, "domname", NULL); + assert_non_null(path); + assert_string_equal(path, PATH_BASE"/domname"); + talloc_free(path); +} + +void test_reply_path_escape(void **state) +{ + struct ifp_test_req_ctx *test_ctx = talloc_get_type_abort(*state, + struct ifp_test_req_ctx); + char *path; + + /* A dot needs escaping */ + path = ifp_reply_objpath(test_ctx->ireq, PATH_BASE, "redhat.com", NULL); + assert_non_null(path); + assert_string_equal(path, PATH_BASE"/redhat_2ecom"); + talloc_free(path); +} + int main(int argc, const char *argv[]) { poptContext pc; @@ -418,6 +444,10 @@ int main(int argc, const char *argv[]) unit_test(test_attr_allowed), unit_test(test_path_escape), unit_test(test_path_unescape), + unit_test_setup_teardown(test_reply_path, + ifp_test_req_setup, ifp_test_req_teardown), + unit_test_setup_teardown(test_reply_path_escape, + ifp_test_req_setup, ifp_test_req_teardown), }; /* Set debug level to invalid value so we can deside if -d 0 was used. */ -- 1.9.0