Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
wjwwood committed May 22, 2018
1 parent 1f9f4d1 commit a12ea09
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 41 deletions.
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ endif()
set(rcutils_sources
src/allocator.c
src/cmdline_parser.c
src/concat.c
src/error_handling.c
src/filesystem.c
src/find.c
Expand Down Expand Up @@ -207,13 +206,6 @@ if(BUILD_TESTING)
target_link_libraries(test_find ${PROJECT_NAME})
endif()

rcutils_custom_add_gtest(test_concat
test/test_concat.cpp
)
if(TARGET test_concat)
target_link_libraries(test_concat ${PROJECT_NAME})
endif()

rcutils_custom_add_gtest(test_string_array
test/test_string_array.cpp
)
Expand Down
68 changes: 35 additions & 33 deletions test/test_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

static char cwd[1024];

static rcutils_allocator_t g_allocator = rcutils_get_default_allocator();

TEST(test_filesystem, join_path) {
char * path = rcutils_join_path("foo", "bar");
char * path = rcutils_join_path("foo", "bar", g_allocator);
#ifdef _WIN32
const char * ref_str = "foo\\bar";
#else
Expand All @@ -33,47 +35,47 @@ TEST(test_filesystem, join_path) {
TEST(test_filesystem, exists) {
EXPECT_FALSE(rcutils_get_cwd(NULL, 1024));
EXPECT_TRUE(rcutils_get_cwd(cwd, 1024));
char * path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_readable_file.txt");
char * path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_readable_file.txt", g_allocator);
EXPECT_TRUE(rcutils_exists(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_folder");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_folder", g_allocator);
EXPECT_TRUE(rcutils_exists(path));
}

TEST(test_filesystem, is_directory) {
EXPECT_TRUE(rcutils_get_cwd(cwd, 1024));
char * path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_readable_file.txt");
char * path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_readable_file.txt", g_allocator);
EXPECT_FALSE(rcutils_is_directory(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_folder");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_folder", g_allocator);
EXPECT_TRUE(rcutils_is_directory(path));
}

TEST(test_filesystem, is_file) {
EXPECT_TRUE(rcutils_get_cwd(cwd, 1024));
char * path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_readable_file.txt");
char * path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_readable_file.txt", g_allocator);
EXPECT_TRUE(rcutils_is_file(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_folder");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_folder", g_allocator);
EXPECT_FALSE(rcutils_is_file(path));
}

TEST(test_filesystem, is_readable) {
EXPECT_TRUE(rcutils_get_cwd(cwd, 1024));
char * path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_readable_file.txt");
char * path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_readable_file.txt", g_allocator);
EXPECT_TRUE(rcutils_is_readable(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_folder");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_folder", g_allocator);
EXPECT_TRUE(rcutils_is_readable(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_readable_writable_file.txt");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_readable_writable_file.txt", g_allocator);
EXPECT_TRUE(rcutils_is_readable(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_nonexisting_file.txt");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_nonexisting_file.txt", g_allocator);
EXPECT_FALSE(rcutils_is_readable(path));
}

Expand All @@ -82,28 +84,28 @@ TEST(test_filesystem, is_writable) {
// path = std::string(cwd) + delimiter + std::string("test") + delimiter + std::string(
// "dummy_readable_file.txt");
// EXPECT_FALSE(rcutils_is_writable(path.c_str()));
char * path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_folder");
char * path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_folder", g_allocator);
EXPECT_TRUE(rcutils_is_writable(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_readable_writable_file.txt");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_readable_writable_file.txt", g_allocator);
EXPECT_TRUE(rcutils_is_writable(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_nonexisting_file.txt");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_nonexisting_file.txt", g_allocator);
EXPECT_FALSE(rcutils_is_writable(path));
}

TEST(test_filesystem, is_readable_and_writable) {
EXPECT_TRUE(rcutils_get_cwd(cwd, 1024));
// path = std::string(cwd) + std::string("/test/dummy_readable_file.txt");
// EXPECT_FALSE(rcutils_is_readable_and_writable(path.c_str()));
char * path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_folder");
char * path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_folder", g_allocator);
EXPECT_TRUE(rcutils_is_readable_and_writable(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_readable_writable_file.txt");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_readable_writable_file.txt", g_allocator);
EXPECT_TRUE(rcutils_is_readable_and_writable(path));
path = rcutils_join_path(cwd, "test");
path = rcutils_join_path(path, "dummy_nonexisting_file.txt");
path = rcutils_join_path(cwd, "test", g_allocator);
path = rcutils_join_path(path, "dummy_nonexisting_file.txt", g_allocator);
EXPECT_FALSE(rcutils_is_readable_and_writable(path));
}

0 comments on commit a12ea09

Please sign in to comment.