diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-03-13 13:01:50 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-03-13 13:01:50 +0100 |
commit | 3b9e2f480dade36224770f2c95c30ec5abca3386 (patch) | |
tree | 01efffa860ebf12ca077f0a52f3f7da3dfddd6f1 | |
parent | f76d23601543eee605be848f8607bf0ba52c2e5f (diff) | |
download | weechat-3b9e2f480dade36224770f2c95c30ec5abca3386.zip |
tests: reorder tests on core directory functions
-rw-r--r-- | tests/unit/core/test-core-dir.cpp | 188 |
1 files changed, 110 insertions, 78 deletions
diff --git a/tests/unit/core/test-core-dir.cpp b/tests/unit/core/test-core-dir.cpp index 12930d54d..0193e9c97 100644 --- a/tests/unit/core/test-core-dir.cpp +++ b/tests/unit/core/test-core-dir.cpp @@ -61,6 +61,7 @@ TEST(CoreDir, Mkdir) /* * Tests functions: + * dir_unlink_cb * dir_rmtree */ @@ -71,95 +72,40 @@ TEST(CoreDir, Rmtree) /* * Tests functions: - * dir_exec_on_files + * dir_set_home_path */ -TEST(CoreDir, ExecOnFiles) +TEST(CoreDir, SetHomePath) { /* TODO: write tests */ } /* * Tests functions: - * dir_search_full_lib_name + * dir_create_home_temp_dir */ -TEST(CoreDir, SearchFullLibName) +TEST(CoreDir, CreateHomeTempDir) { /* TODO: write tests */ } /* * Tests functions: - * dir_file_get_content - * dir_file_copy + * dir_find_xdg_dirs */ -TEST(CoreDir, FileGetContentCopy) +TEST(CoreDir, FindXdgDirs) { - char *path1, *path2, *content, *content_read1, *content_read2; - const char *content_small = "line 1\nline 2\nend"; - int length, i; - FILE *f; - - /* file not found */ - LONGS_EQUAL(0, dir_file_copy (NULL, NULL)); - LONGS_EQUAL(0, dir_file_copy ("", "")); - LONGS_EQUAL(0, dir_file_copy ("/tmp/does/not/exist.xyz", "/tmp/test.txt")); - - path1 = string_eval_path_home ("${weechat_data_dir}/test_file.txt", - NULL, NULL, NULL); - path2 = string_eval_path_home ("${weechat_data_dir}/test_file2.txt", - NULL, NULL, NULL); - - /* small file */ - length = strlen (content_small); - f = fopen (path1, "wb"); - CHECK(f); - LONGS_EQUAL(length, fwrite (content_small, 1, length, f)); - fclose (f); - LONGS_EQUAL(1, dir_file_copy (path1, path2)); - content_read1 = dir_file_get_content (path1); - content_read2 = dir_file_get_content (path2); - STRCMP_EQUAL(content_small, content_read1); - MEMCMP_EQUAL(content_read1, content_read2, length); - free (content_read1); - free (content_read2); - unlink (path1); - unlink (path2); - - /* bigger file: 26 lines of 5000 bytes */ - length = 26 * 5001; - content = (char *)malloc (length + 1); - CHECK(content); - for (i = 0; i < 26; i++) - { - memset (content + (i * 5001), 'a' + i, 5000); - content[(i * 5001) + 5000] = '\n'; - } - content[26 * 5001] = '\0'; - f = fopen (path1, "wb"); - CHECK(f); - LONGS_EQUAL(length, fwrite (content, 1, length, f)); - fclose (f); - LONGS_EQUAL(1, dir_file_copy (path1, path2)); - content_read1 = dir_file_get_content (path1); - content_read2 = dir_file_get_content (path2); - STRCMP_EQUAL(content, content_read1); - MEMCMP_EQUAL(content_read1, content_read2, length); - free (content_read1); - free (content_read2); - unlink (path1); - unlink (path2); - free (content); + /* TODO: write tests */ } /* * Tests functions: - * dir_set_home_path + * dir_find_home_dirs */ -TEST(CoreDir, SetHomePath) +TEST(CoreDir, FindHomeDirs) { /* TODO: write tests */ } @@ -202,70 +148,156 @@ TEST(CoreDir, RemoveTrailingSeparators) /* * Tests functions: - * dir_create_home_temp_dir + * dir_create_home_dir */ -TEST(CoreDir, CreateHomeTempDir) +TEST(CoreDir, CreateHomeDir) { /* TODO: write tests */ } /* * Tests functions: - * dir_find_xdg_dirs + * dir_create_home_dirs */ -TEST(CoreDir, FindXdgDirs) +TEST(CoreDir, CreateHomeDirs) { /* TODO: write tests */ } /* * Tests functions: - * dir_find_home_dirs + * dir_remove_home_dirs */ -TEST(CoreDir, FindHomeDirs) +TEST(CoreDir, RemoveHomeDirs) { /* TODO: write tests */ } /* * Tests functions: - * dir_create_home_dir + * dir_get_string_home_dirs */ -TEST(CoreDir, CreateHomeDir) +TEST(CoreDir, GetStringHomeDirs) { /* TODO: write tests */ } /* * Tests functions: - * dir_create_home_dirs + * dir_exec_on_files */ -TEST(CoreDir, CreateHomeDirs) +TEST(CoreDir, ExecOnFiles) { /* TODO: write tests */ } /* * Tests functions: - * dir_remove_home_dirs + * dir_search_full_lib_name_ext + * dir_search_full_lib_name */ -TEST(CoreDir, RemoveHomeDirs) +TEST(CoreDir, SearchFullLibName) { /* TODO: write tests */ } /* * Tests functions: - * dir_get_string_home_dirs + * dir_file_get_content + * dir_file_copy */ -TEST(CoreDir, GetStringHomeDirs) +TEST(CoreDir, FileGetContentCopy) +{ + char *path1, *path2, *content, *content_read1, *content_read2; + const char *content_small = "line 1\nline 2\nend"; + int length, i; + FILE *f; + + /* file not found */ + LONGS_EQUAL(0, dir_file_copy (NULL, NULL)); + LONGS_EQUAL(0, dir_file_copy ("", "")); + LONGS_EQUAL(0, dir_file_copy ("/tmp/does/not/exist.xyz", "/tmp/test.txt")); + + path1 = string_eval_path_home ("${weechat_data_dir}/test_file.txt", + NULL, NULL, NULL); + path2 = string_eval_path_home ("${weechat_data_dir}/test_file2.txt", + NULL, NULL, NULL); + + /* small file */ + length = strlen (content_small); + f = fopen (path1, "wb"); + CHECK(f); + LONGS_EQUAL(length, fwrite (content_small, 1, length, f)); + fclose (f); + LONGS_EQUAL(1, dir_file_copy (path1, path2)); + content_read1 = dir_file_get_content (path1); + content_read2 = dir_file_get_content (path2); + STRCMP_EQUAL(content_small, content_read1); + MEMCMP_EQUAL(content_read1, content_read2, length); + free (content_read1); + free (content_read2); + unlink (path1); + unlink (path2); + + /* bigger file: 26 lines of 5000 bytes */ + length = 26 * 5001; + content = (char *)malloc (length + 1); + CHECK(content); + for (i = 0; i < 26; i++) + { + memset (content + (i * 5001), 'a' + i, 5000); + content[(i * 5001) + 5000] = '\n'; + } + content[26 * 5001] = '\0'; + f = fopen (path1, "wb"); + CHECK(f); + LONGS_EQUAL(length, fwrite (content, 1, length, f)); + fclose (f); + LONGS_EQUAL(1, dir_file_copy (path1, path2)); + content_read1 = dir_file_get_content (path1); + content_read2 = dir_file_get_content (path2); + STRCMP_EQUAL(content, content_read1); + MEMCMP_EQUAL(content_read1, content_read2, length); + free (content_read1); + free (content_read2); + unlink (path1); + unlink (path2); + free (content); +} + +/* + * Tests functions: + * dir_file_compress_gzip + */ + +TEST(CoreDir, FileCompressGzip) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * dir_file_compress_zstd + */ + +TEST(CoreDir, FileCompressZstd) +{ + /* TODO: write tests */ +} + +/* + * Tests functions: + * dir_file_compress + */ + +TEST(CoreDir, FileCompress) { /* TODO: write tests */ } |