diff options
author | Alexandru Fazakas <alex.fazakas97@gmail.com> | 2018-05-15 15:56:14 +0300 |
---|---|---|
committer | Carlos Soriano <csoriano1618@gmail.com> | 2018-05-18 14:47:36 +0000 |
commit | bfc3aebe049ce395d58465a40e08e46f449cdf3a (patch) | |
tree | abda8939479d355cafcf98131a47c99849b7504f /test | |
parent | f3be754974e2de2acfd3fdbccab0809e9f8fc760 (diff) | |
download | nautilus-bfc3aebe049ce395d58465a40e08e46f449cdf3a.tar.gz |
test: Add dir_has_files unit test
In this patch we added an unit test with 3 simple tests for the
dir_has_files.
https://gitlab.gnome.org/GNOME/nautilus/issues/224
Diffstat (limited to 'test')
-rw-r--r-- | test/automated/displayless/meson.build | 3 | ||||
-rw-r--r-- | test/automated/displayless/test-file-operations-dir-has-files.c | 84 |
2 files changed, 87 insertions, 0 deletions
diff --git a/test/automated/displayless/meson.build b/test/automated/displayless/meson.build index 0c3a3e13d..08b06de10 100644 --- a/test/automated/displayless/meson.build +++ b/test/automated/displayless/meson.build @@ -7,6 +7,9 @@ tests = [ ]], ['test-file-utilities', [ 'test-file-utilities.c' + ]], + ['test-file-operations-dir-has-files', [ + 'test-file-operations-dir-has-files.c' ]] ] diff --git a/test/automated/displayless/test-file-operations-dir-has-files.c b/test/automated/displayless/test-file-operations-dir-has-files.c new file mode 100644 index 000000000..75c21e2c4 --- /dev/null +++ b/test/automated/displayless/test-file-operations-dir-has-files.c @@ -0,0 +1,84 @@ +#include <glib.h> +#include <glib/gprintf.h> +#include "src/nautilus-directory.h" +#include "src/nautilus-file-utilities.h" +#include "src/nautilus-search-directory.h" +#include "src/nautilus-directory.h" +#include "src/nautilus-file-operations.c" +#include <unistd.h> +#include "eel/eel-string.h" + +#define ROOT_DIR "file:///tmp" + +/* Tests the function for a simple file */ +static void +test_simple_file (void) +{ + g_autoptr (GFile) root = NULL; + g_autoptr (GFile) file = NULL; + + root = g_file_new_for_path (g_get_tmp_dir ()); + file = g_file_get_child (root, "simple_file"); + g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL); + g_assert_false (dir_has_files (file)); +} + +/* Tests the function for an empty directory */ +static void +test_empty_directory (void) +{ + g_autoptr (GFile) root = NULL; + g_autoptr (GFile) child = NULL; + + root = g_file_new_for_path (g_get_tmp_dir ()); + child = g_file_get_child (root, "empty_dir"); + + g_assert_true (child != NULL); + + g_file_make_directory (child, NULL, NULL); + + g_assert_false (dir_has_files (child)); +} + +/* Tests the function for a directory containing one directory */ +static void +test_directory_one_file (void) +{ + g_autoptr (GFile) root = NULL; + g_autoptr (GFile) parent_dir = NULL; + g_autoptr (GFile) child_file = NULL; + + root = g_file_new_for_path (g_get_tmp_dir ()); + parent_dir = g_file_get_child (root, "parent_dir"); + g_assert_true (parent_dir != NULL); + g_file_make_directory (parent_dir, NULL, NULL); + + child_file = g_file_get_child (parent_dir, "child_file"); + g_assert_true (child_file != NULL); + g_file_make_directory (child_file, NULL, NULL); + + g_assert_true (dir_has_files (parent_dir)); +} + +static void +setup_test_suite (void) +{ + g_test_add_func ("/dir-has-files-simple-file/1.0", + test_simple_file); + g_test_add_func ("/dir-has-files-empty-dir/1.0", + test_empty_directory); + g_test_add_func ("/dir-has-files-directroy-one-file/1.0", + test_directory_one_file); +} + +int +main (int argc, char *argv[]) +{ + g_test_init (&argc, &argv, NULL); + g_test_set_nonfatal_assertions (); + nautilus_ensure_extension_points(); + + setup_test_suite (); + + return g_test_run (); +} |