From 7946f66f65a309c4e04226483497159da06c159a Mon Sep 17 00:00:00 2001 From: Mikael Arguedas Date: Wed, 19 Sep 2018 19:42:36 -0700 Subject: [PATCH] add test for to_native_path --- test/test_filesystem.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_filesystem.cpp b/test/test_filesystem.cpp index c7a1ac15..593d6f51 100644 --- a/test/test_filesystem.cpp +++ b/test/test_filesystem.cpp @@ -59,6 +59,35 @@ TEST_F(TestFilesystemFixture, join_path) { EXPECT_STREQ(ref_str, path); } +TEST_F(TestFilesystemFixture, to_native_path) { + { + char * path = rcutils_to_native_path("/foo/bar/baz", g_allocator); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + g_allocator.deallocate(path, g_allocator.state); + }); +#ifdef _WIN32 + const char * ref_str = "\\foo\\bar\\baz"; +#else + const char * ref_str = "/foo/bar/baz"; +#endif // _WIN32 + ASSERT_FALSE(nullptr == path); + EXPECT_STREQ(ref_str, path); + } + { + char * path = rcutils_to_native_path("/foo//bar/baz", g_allocator); + OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT({ + g_allocator.deallocate(path, g_allocator.state); + }); +#ifdef _WIN32 + const char * ref_str = "\\foo\\\\bar\\baz"; +#else + const char * ref_str = "/foo//bar/baz"; +#endif // _WIN32 + ASSERT_FALSE(nullptr == path); + EXPECT_STREQ(ref_str, path); + } +} + TEST_F(TestFilesystemFixture, exists) { { char * path = rcutils_join_path(this->test_path, "dummy_readable_file.txt", g_allocator);