diff --git a/README.md b/README.md index 4da9557..a7b2158 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ Apple's command-line build tools are usually installed as part of setting up Homebrew. HTTPDirFS will be installed in ``/usr/local``. ## Running Tests + GoogleTest is the utilized unit test framework. Google recommends you live at head, so it is also recommended that you compile and install the latest from [source](https://github.com/google/googletest.git), since what you install from @@ -107,9 +108,11 @@ a repository may be outdated. Below are the package names if installing from a repository ### Ubuntu and Debian + libgtest-dev ### FreeBSD and macOS + googletest Build and run tests diff --git a/test/test_utilities.cpp b/test/test_utilities.cpp index 6f848d5..5806f8a 100644 --- a/test/test_utilities.cpp +++ b/test/test_utilities.cpp @@ -7,57 +7,53 @@ extern "C" { #include namespace { -#define TEST_FILE_NAME_LEN 6 - const char *test_file_name = "id_rsa"; - -#define TEST_FOLDER_NAME_LEN 6 - const char test_folder_name[] = "/abcdefg"; - - const char *path_root = "/"; - const char *path_sample1 = "/www"; - const char *path_sample2 = "/www/folder1/"; - const char *path_sample3 = "/www/folder1/folder2"; + const char test_file_name[] = "id_rsa"; TEST(PathAppendTest, PathLengthLessThanMaxPathLen) { + const char *path_root = "/"; + const char *path_sample1 = "/www"; + const char *path_sample2 = "/www/folder1/"; + const char *path_sample3 = "/www/folder1/folder2"; char *path = path_append(path_root, test_file_name); ASSERT_STREQ("/id_rsa", path); - free(path); + FREE(path); path = path_append(path_sample1, test_file_name); ASSERT_STREQ("/www/id_rsa", path); - free(path); + FREE(path); path = path_append(path_sample2, test_file_name); ASSERT_STREQ("/www/folder1/id_rsa", path); - free(path); + FREE(path); path = path_append(path_sample3, test_file_name); ASSERT_STREQ("/www/folder1/folder2/id_rsa", path); - free(path); + FREE(path); } TEST(PathAppendTest, PathLengthGreaterThanMaxPathLen) { -#define PATH_LEN_4098 4098 - - char very_long_path[PATH_LEN_4098] = { 0 }; + const char test_folder_name[] = "/abcdefg"; + const int path_len_4098 = 4098; + const int test_folder_name_len = strlen(test_folder_name); + char very_long_path[path_len_4098] = { 0 }; char *p = very_long_path; /* - * MAX_PATH_LEN is a perfect multiple of the length of test_folder_name, + * MAX_PATH_LEN is an integer multiple of test_folder_name_len, * so it would fit perfectly in the 4096 bytes of very_long_path. */ - for (int i = 0; i < PATH_LEN_4098; i += TEST_FOLDER_NAME_LEN) { - memcpy(p, test_folder_name, TEST_FOLDER_NAME_LEN); - p += TEST_FOLDER_NAME_LEN; + for (int i = 0; i < path_len_4098; i += test_folder_name_len) { + memcpy(p, test_folder_name, test_folder_name_len); + p += test_folder_name_len; } char *path = path_append(very_long_path, test_file_name); ASSERT_NE(nullptr, path); - ASSERT_EQ(path[MAX_PATH_LEN - 1], 'c'); + ASSERT_EQ(path[MAX_PATH_LEN - 1], 'g'); ASSERT_EQ(path[MAX_PATH_LEN + 0], '/'); ASSERT_EQ(path[MAX_PATH_LEN + 1], 'i'); ASSERT_EQ(path[MAX_PATH_LEN + 6], 'a'); - free(path); + FREE(path); } } // namespace