From ef5d7264f15f65aefc4ea332b4744d7f94596ecc Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 17 Feb 2017 18:12:54 +0000 Subject: [PATCH 3/9] config-parser test: Exercise the full config-parser Don't just exercise _dbus_get_standard_session_servicedirs(), but also its integration into the BusConfigParser. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825 Reviewed-by: Philip Withnall Signed-off-by: Simon McVittie --- bus/config-parser.c | 54 ++++++++++++++-------- test/Makefile.am | 1 + .../valid-config-files/standard-session-dirs.conf | 8 ++++ 3 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 test/data/valid-config-files/standard-session-dirs.conf diff --git a/bus/config-parser.c b/bus/config-parser.c index bb2712bb..5275f8f1 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -3394,10 +3394,14 @@ static const char *test_session_service_dir_matches[] = }; static dbus_bool_t -test_default_session_servicedirs (void) +test_default_session_servicedirs (const DBusString *test_base_dir) { - DBusList *dirs; + BusConfigParser *parser = NULL; + DBusError error = DBUS_ERROR_INIT; + DBusList **dirs; DBusList *link; + DBusString tmp; + DBusString full_path; DBusString progs; DBusString install_root_based; DBusString data_home_based; @@ -3415,13 +3419,28 @@ test_default_session_servicedirs (void) /* On each platform we don't actually use all of these, but it's easier to * handle the deallocation if we always allocate them, whether needed or * not */ - if (!_dbus_string_init (&progs) || + if (!_dbus_string_init (&full_path) || + !_dbus_string_init (&progs) || !_dbus_string_init (&install_root_based) || !_dbus_string_init (&data_home_based) || !_dbus_string_init (&data_dirs_based) || !_dbus_string_init (&data_dirs_based2)) _dbus_assert_not_reached ("OOM allocating strings"); + if (!_dbus_string_copy (test_base_dir, 0, + &full_path, 0)) + _dbus_assert_not_reached ("couldn't copy test_base_dir to full_path"); + + _dbus_string_init_const (&tmp, "valid-config-files"); + + if (!_dbus_concat_dir_and_file (&full_path, &tmp)) + _dbus_assert_not_reached ("couldn't allocate full path"); + + _dbus_string_init_const (&tmp, "standard-session-dirs.conf"); + + if (!_dbus_concat_dir_and_file (&full_path, &tmp)) + _dbus_assert_not_reached ("couldn't allocate full path"); + #ifdef DBUS_WIN if (!_dbus_string_append (&install_root_based, DBUS_DATADIR) || !_dbus_string_append (&install_root_based, "/dbus-1/services") || @@ -3479,22 +3498,22 @@ test_default_session_servicedirs (void) &data_dirs_based2); #endif - dirs = NULL; + parser = bus_config_load (&full_path, TRUE, NULL, &error); - if (!_dbus_get_standard_session_servicedirs (&dirs)) - _dbus_assert_not_reached ("couldn't get stardard dirs"); + if (parser == NULL) + _dbus_assert_not_reached (error.message); - /* make sure we read and parse the env variable correctly */ - i = 0; - while ((link = _dbus_list_pop_first_link (&dirs))) + dirs = bus_config_parser_get_service_dirs (parser); + + for (link = _dbus_list_get_first_link (dirs), i = 0; + link != NULL; + link = _dbus_list_get_next_link (dirs, link), i++) { printf (" test service dir: '%s'\n", (char *)link->data); printf (" current standard service dir: '%s'\n", test_session_service_dir_matches[i]); if (test_session_service_dir_matches[i] == NULL) { printf ("more directories parsed than in match set\n"); - dbus_free (link->data); - _dbus_list_free_link (link); goto out; } @@ -3504,15 +3523,8 @@ test_default_session_servicedirs (void) printf ("'%s' directory does not match '%s' in the match set\n", (char *)link->data, test_session_service_dir_matches[i]); - dbus_free (link->data); - _dbus_list_free_link (link); goto out; } - - ++i; - - dbus_free (link->data); - _dbus_list_free_link (link); } if (test_session_service_dir_matches[i] != NULL) @@ -3525,6 +3537,10 @@ test_default_session_servicedirs (void) ret = TRUE; out: + if (parser != NULL) + bus_config_parser_unref (parser); + + _dbus_string_free (&full_path); _dbus_string_free (&install_root_based); _dbus_string_free (&progs); _dbus_string_free (&data_home_based); @@ -3607,7 +3623,7 @@ bus_config_parser_test (const DBusString *test_data_dir) return TRUE; } - if (!test_default_session_servicedirs()) + if (!test_default_session_servicedirs (test_data_dir)) return FALSE; #ifdef DBUS_WIN diff --git a/test/Makefile.am b/test/Makefile.am index f6fd041d..616e6bc8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -489,6 +489,7 @@ static_data = \ data/valid-config-files/entities.conf \ data/valid-config-files/listen-unix-runtime.conf \ data/valid-config-files/many-rules.conf \ + data/valid-config-files/standard-session-dirs.conf \ data/valid-config-files-system/system.d/test.conf \ data/valid-messages/array-of-array-of-uint32.message \ data/valid-messages/dict-simple.message \ diff --git a/test/data/valid-config-files/standard-session-dirs.conf b/test/data/valid-config-files/standard-session-dirs.conf new file mode 100644 index 00000000..f62dc87f --- /dev/null +++ b/test/data/valid-config-files/standard-session-dirs.conf @@ -0,0 +1,8 @@ + + + + unix:path=/foo + session + + -- 2.11.0