diff --git a/tests/pressure-vessel/utils.c b/tests/pressure-vessel/utils.c index ded857df2020f22dd0df6ac78819bd325edd0f05..d900b89643b799d51e435957434848dca84b0296 100644 --- a/tests/pressure-vessel/utils.c +++ b/tests/pressure-vessel/utils.c @@ -81,29 +81,6 @@ test_arbitrary_key (Fixture *f, g_assert_cmpstr (k, ==, "world"); } -static void -test_avoid_gvfs (Fixture *f, - gconstpointer context) -{ - /* This doesn't actually call _srt_setenv_disable_gio_modules(), - * because that's documented - * to have to happen as early as possible in main(). Instead, we do that - * in main() as documented, and in this function we just assert that - * we did. */ - GVfs *vfs = g_vfs_get_default (); - GVfs *local = g_vfs_get_local (); - - g_test_message ("Default VFS: %s at %p", G_OBJECT_TYPE_NAME (vfs), vfs); - g_test_message ("Local VFS: %s at %p", G_OBJECT_TYPE_NAME (local), local); - /* We compare by string equality to have a better message if this - * assertion fails. We can't assert that the pointers are the same, - * because GLib currently uses two instances of the same class. */ - g_assert_cmpstr (G_OBJECT_TYPE_NAME (vfs), ==, - G_OBJECT_TYPE_NAME (local)); - g_assert_cmpuint (G_OBJECT_TYPE (vfs), ==, - G_OBJECT_TYPE (local)); -} - static void test_capture_output (Fixture *f, gconstpointer context) @@ -280,108 +257,6 @@ test_search_path_append (Fixture *f, g_assert_cmpstr (str->str, ==, "/bin:/usr/bin:/usr/bin"); } -typedef struct -{ - const char *name; - mode_t mode; -} File; - -typedef struct -{ - const char *name; - const char *target; -} Symlink; - -typedef struct -{ - const char *path; - GFileTest test; - gboolean expected_result; -} InSysrootTest; - -static void -test_file_in_sysroot (Fixture *f, - gconstpointer context) -{ - static const char * const prepare_dirs[] = - { - "dir1/dir2/dir3", - }; - - static const File prepare_files[] = - { - { "dir1/file1", 0600 }, - { "dir1/dir2/file2", 0600 }, - { "dir1/exec1", 0700 }, - }; - - static const Symlink prepare_symlinks[] = - { - { "dir1/dir2/symlink_to_dir3", "dir3" }, - { "dir1/dir2/symlink_to_file2", "file2" }, - { "dir1/dir2/sym_to_sym_to_file2", "symlink_to_file2" }, - { "dir1/abs_symlink_to_run", "/run" }, - }; - - static const InSysrootTest tests[] = - { - { "dir1", G_FILE_TEST_IS_DIR, TRUE }, - { "dir1", G_FILE_TEST_EXISTS, TRUE }, - { "/dir1", G_FILE_TEST_EXISTS, TRUE }, - { "dir1/dir2", G_FILE_TEST_IS_DIR, TRUE }, - /* These gets solved in sysroot, following symlinks too */ - { "dir1/dir2/symlink_to_dir3", G_FILE_TEST_IS_DIR, TRUE }, - { "dir1/dir2/sym_to_sym_to_file2", G_FILE_TEST_IS_REGULAR, TRUE }, - { "dir1/abs_symlink_to_run", G_FILE_TEST_IS_DIR, FALSE }, - { "dir1/missing", G_FILE_TEST_EXISTS, FALSE }, - { "dir1/file1", G_FILE_TEST_IS_REGULAR, TRUE }, - { "dir1/file1", (G_FILE_TEST_IS_DIR | G_FILE_TEST_IS_EXECUTABLE), FALSE }, - { "dir1/exec1", G_FILE_TEST_IS_REGULAR, TRUE }, - { "dir1/exec1", G_FILE_TEST_IS_EXECUTABLE, TRUE }, - }; - - g_autoptr(GError) error = NULL; - g_auto(GLnxTmpDir) tmpdir = { FALSE }; - gsize i; - - glnx_mkdtemp ("test-XXXXXX", 0700, &tmpdir, &error); - g_assert_no_error (error); - - for (i = 0; i < G_N_ELEMENTS (prepare_dirs); i++) - { - const char *it = prepare_dirs[i]; - - glnx_shutil_mkdir_p_at (tmpdir.fd, it, 0700, NULL, &error); - g_assert_no_error (error); - } - - for (i = 0; i < G_N_ELEMENTS (prepare_files); i++) - { - const File *it = &prepare_files[i]; - - glnx_autofd int fd = openat (tmpdir.fd, it->name, O_WRONLY|O_CREAT, it->mode); - if (fd == -1) - g_error ("openat %s: %s", it->name, g_strerror (errno)); - } - - for (i = 0; i < G_N_ELEMENTS (prepare_symlinks); i++) - { - const Symlink *it = &prepare_symlinks[i]; - - if (symlinkat (it->target, tmpdir.fd, it->name) != 0) - g_error ("symlinkat %s: %s", it->name, g_strerror (errno)); - } - - for (i = 0; i < G_N_ELEMENTS (tests); i++) - { - const InSysrootTest *it = &tests[i]; - - g_assert_cmpint (_srt_file_test_in_sysroot (tmpdir.path, -1, - it->path, it->test), - ==, it->expected_result); - } -} - int main (int argc, char **argv) @@ -391,15 +266,12 @@ main (int argc, g_test_init (&argc, &argv, NULL); g_test_add ("/arbitrary-key", Fixture, NULL, setup, test_arbitrary_key, teardown); - g_test_add ("/avoid-gvfs", Fixture, NULL, setup, test_avoid_gvfs, teardown); g_test_add ("/capture-output", Fixture, NULL, setup, test_capture_output, teardown); g_test_add ("/envp-cmp", Fixture, NULL, setup, test_envp_cmp, teardown); g_test_add ("/same-file", Fixture, NULL, setup, test_same_file, teardown); g_test_add ("/search-path-append", Fixture, NULL, setup, test_search_path_append, teardown); - g_test_add ("/test-file-in-sysroot", Fixture, NULL, - setup, test_file_in_sysroot, teardown); return g_test_run (); } diff --git a/tests/utils.c b/tests/utils.c index 2fc3c60c0ed215ad2a0ed16e3baba4746779c35d..25c70547c87fc504dd5ac07d1740d71f57b302e2 100644 --- a/tests/utils.c +++ b/tests/utils.c @@ -56,6 +56,131 @@ teardown (Fixture *f, G_GNUC_UNUSED const Config *config = context; } +static void +test_avoid_gvfs (Fixture *f, + gconstpointer context) +{ + /* This doesn't actually call _srt_setenv_disable_gio_modules(), + * because that's documented + * to have to happen as early as possible in main(). Instead, we do that + * in main() as documented, and in this function we just assert that + * we did. */ + GVfs *vfs = g_vfs_get_default (); + GVfs *local = g_vfs_get_local (); + + g_test_message ("Default VFS: %s at %p", G_OBJECT_TYPE_NAME (vfs), vfs); + g_test_message ("Local VFS: %s at %p", G_OBJECT_TYPE_NAME (local), local); + /* We compare by string equality to have a better message if this + * assertion fails. We can't assert that the pointers are the same, + * because GLib currently uses two instances of the same class. */ + g_assert_cmpstr (G_OBJECT_TYPE_NAME (vfs), ==, + G_OBJECT_TYPE_NAME (local)); + g_assert_cmpuint (G_OBJECT_TYPE (vfs), ==, + G_OBJECT_TYPE (local)); +} + +typedef struct +{ + const char *name; + mode_t mode; +} File; + +typedef struct +{ + const char *name; + const char *target; +} Symlink; + +typedef struct +{ + const char *path; + GFileTest test; + gboolean expected_result; +} InSysrootTest; + +static void +test_file_in_sysroot (Fixture *f, + gconstpointer context) +{ + static const char * const prepare_dirs[] = + { + "dir1/dir2/dir3", + }; + + static const File prepare_files[] = + { + { "dir1/file1", 0600 }, + { "dir1/dir2/file2", 0600 }, + { "dir1/exec1", 0700 }, + }; + + static const Symlink prepare_symlinks[] = + { + { "dir1/dir2/symlink_to_dir3", "dir3" }, + { "dir1/dir2/symlink_to_file2", "file2" }, + { "dir1/dir2/sym_to_sym_to_file2", "symlink_to_file2" }, + { "dir1/abs_symlink_to_run", "/run" }, + }; + + static const InSysrootTest tests[] = + { + { "dir1", G_FILE_TEST_IS_DIR, TRUE }, + { "dir1", G_FILE_TEST_EXISTS, TRUE }, + { "/dir1", G_FILE_TEST_EXISTS, TRUE }, + { "dir1/dir2", G_FILE_TEST_IS_DIR, TRUE }, + /* These gets solved in sysroot, following symlinks too */ + { "dir1/dir2/symlink_to_dir3", G_FILE_TEST_IS_DIR, TRUE }, + { "dir1/dir2/sym_to_sym_to_file2", G_FILE_TEST_IS_REGULAR, TRUE }, + { "dir1/abs_symlink_to_run", G_FILE_TEST_IS_DIR, FALSE }, + { "dir1/missing", G_FILE_TEST_EXISTS, FALSE }, + { "dir1/file1", G_FILE_TEST_IS_REGULAR, TRUE }, + { "dir1/file1", (G_FILE_TEST_IS_DIR | G_FILE_TEST_IS_EXECUTABLE), FALSE }, + { "dir1/exec1", G_FILE_TEST_IS_REGULAR, TRUE }, + { "dir1/exec1", G_FILE_TEST_IS_EXECUTABLE, TRUE }, + }; + + g_autoptr(GError) error = NULL; + g_auto(GLnxTmpDir) tmpdir = { FALSE }; + gsize i; + + glnx_mkdtemp ("test-XXXXXX", 0700, &tmpdir, &error); + g_assert_no_error (error); + + for (i = 0; i < G_N_ELEMENTS (prepare_dirs); i++) + { + const char *it = prepare_dirs[i]; + + glnx_shutil_mkdir_p_at (tmpdir.fd, it, 0700, NULL, &error); + g_assert_no_error (error); + } + + for (i = 0; i < G_N_ELEMENTS (prepare_files); i++) + { + const File *it = &prepare_files[i]; + + glnx_autofd int fd = openat (tmpdir.fd, it->name, O_WRONLY|O_CREAT, it->mode); + if (fd == -1) + g_error ("openat %s: %s", it->name, g_strerror (errno)); + } + + for (i = 0; i < G_N_ELEMENTS (prepare_symlinks); i++) + { + const Symlink *it = &prepare_symlinks[i]; + + if (symlinkat (it->target, tmpdir.fd, it->name) != 0) + g_error ("symlinkat %s: %s", it->name, g_strerror (errno)); + } + + for (i = 0; i < G_N_ELEMENTS (tests); i++) + { + const InSysrootTest *it = &tests[i]; + + g_assert_cmpint (_srt_file_test_in_sysroot (tmpdir.path, -1, + it->path, it->test), + ==, it->expected_result); + } +} + /* * Test _srt_filter_gameoverlayrenderer function. */ @@ -95,7 +220,12 @@ int main (int argc, char **argv) { + _srt_setenv_disable_gio_modules (); + g_test_init (&argc, &argv, NULL); + g_test_add ("/utils/avoid-gvfs", Fixture, NULL, setup, test_avoid_gvfs, teardown); + g_test_add ("/utils/test-file-in-sysroot", Fixture, NULL, + setup, test_file_in_sysroot, teardown); g_test_add ("/utils/filter_gameoverlayrenderer", Fixture, NULL, setup, filter_gameoverlayrenderer, teardown);