diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest-death-test_test.cc | 18 | ||||
-rw-r--r-- | test/gtest-filepath_test.cc | 103 | ||||
-rw-r--r-- | test/gtest_break_on_failure_unittest_.cc | 20 |
3 files changed, 123 insertions, 18 deletions
diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc index 4dc85b41..1c7fa474 100644 --- a/test/gtest-death-test_test.cc +++ b/test/gtest-death-test_test.cc @@ -657,24 +657,6 @@ static void TestExitMacros() { EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42), ""); -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW - // MinGW (as of MinGW 5.1.6 and MSYS 1.0.11) does not tag crashed - // processes with non-zero exit code and does not honor calls to - // SetErrorMode(SEM_NOGPFAULTERRORBOX) that are supposed to suppress - // error pop-ups. - EXPECT_EXIT({ - testing::GTEST_FLAG(catch_exceptions) = false; - *static_cast<int*>(NULL) = 1; - }, testing::ExitedWithCode(0xC0000005), "") << "foo"; - - EXPECT_NONFATAL_FAILURE({ // NOLINT - EXPECT_EXIT({ - testing::GTEST_FLAG(catch_exceptions) = false; - *static_cast<int*>(NULL) = 1; - }, testing::ExitedWithCode(0), "") << "This failure is expected."; - }, "This failure is expected."); -#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW - #if GTEST_OS_WINDOWS // Of all signals effects on the process exit code, only those of SIGABRT // are documented on Windows. diff --git a/test/gtest-filepath_test.cc b/test/gtest-filepath_test.cc index 5bc4daf2..5706c8e1 100644 --- a/test/gtest-filepath_test.cc +++ b/test/gtest-filepath_test.cc @@ -151,6 +151,36 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) { .RemoveDirectoryName().c_str()); } +#if GTEST_HAS_ALT_PATH_SEP_ + +// Test RemoveDirectory* functions with "/". + +// RemoveDirectoryName "/afile" -> "afile" +TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) { + EXPECT_STREQ("afile", + FilePath("/afile").RemoveDirectoryName().c_str()); +} + +// RemoveDirectoryName "adir/" -> "" +TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) { + EXPECT_STREQ("", + FilePath("adir/").RemoveDirectoryName().c_str()); +} + +// RemoveDirectoryName "adir/afile" -> "afile" +TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) { + EXPECT_STREQ("afile", + FilePath("adir/afile").RemoveDirectoryName().c_str()); +} + +// RemoveDirectoryName "adir/subdir/afile" -> "afile" +TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) { + EXPECT_STREQ("afile", + FilePath("adir/subdir/afile") + .RemoveDirectoryName().c_str()); +} + +#endif // RemoveFileName "" -> "./" TEST(RemoveFileNameTest, EmptyName) { @@ -190,6 +220,37 @@ TEST(RemoveFileNameTest, GivesRootDir) { FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().c_str()); } +#if GTEST_HAS_ALT_PATH_SEP_ + +// Test RemoveFile* functions with "/". + +// RemoveFileName "adir/" -> "adir/" +TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) { + EXPECT_STREQ("adir" GTEST_PATH_SEP_, + FilePath("adir/").RemoveFileName().c_str()); +} + +// RemoveFileName "adir/afile" -> "adir/" +TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) { + EXPECT_STREQ("adir" GTEST_PATH_SEP_, + FilePath("adir/afile") + .RemoveFileName().c_str()); +} + +// RemoveFileName "adir/subdir/afile" -> "adir/subdir/" +TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) { + EXPECT_STREQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_, + FilePath("adir/subdir/afile") + .RemoveFileName().c_str()); +} + +// RemoveFileName "/afile" -> "\" +TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) { + EXPECT_STREQ(GTEST_PATH_SEP_, + FilePath("/afile").RemoveFileName().c_str()); +} + +#endif TEST(MakeFileNameTest, GenerateWhenNumberIsZero) { FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), @@ -295,6 +356,11 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) { EXPECT_STREQ( "foo", FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().c_str()); +#if GTEST_HAS_ALT_PATH_SEP_ + EXPECT_STREQ( + "foo", + FilePath("foo/").RemoveTrailingPathSeparator().c_str()); +#endif } // RemoveTrailingPathSeparator "foo/bar/" -> "foo/bar/" @@ -397,6 +463,20 @@ TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) { FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).c_str()); } +#if GTEST_HAS_ALT_PATH_SEP_ + +// "foo\" =="foo/\" == "foo\\/" +TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) { + EXPECT_STREQ("foo" GTEST_PATH_SEP_, + FilePath("foo/").c_str()); + EXPECT_STREQ("foo" GTEST_PATH_SEP_, + FilePath("foo" GTEST_PATH_SEP_ "/").c_str()); + EXPECT_STREQ("foo" GTEST_PATH_SEP_, + FilePath("foo//" GTEST_PATH_SEP_).c_str()); +} + +#endif + TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) { FilePath default_path; FilePath non_default_path("path"); @@ -566,6 +646,9 @@ TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) { TEST(FilePathTest, IsDirectory) { EXPECT_FALSE(FilePath("cola").IsDirectory()); EXPECT_TRUE(FilePath("koala" GTEST_PATH_SEP_).IsDirectory()); +#if GTEST_HAS_ALT_PATH_SEP_ + EXPECT_TRUE(FilePath("koala/").IsDirectory()); +#endif } TEST(FilePathTest, IsAbsolutePath) { @@ -575,12 +658,32 @@ TEST(FilePathTest, IsAbsolutePath) { EXPECT_TRUE(FilePath("c:\\" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative").IsAbsolutePath()); EXPECT_FALSE(FilePath("c:foo" GTEST_PATH_SEP_ "bar").IsAbsolutePath()); + EXPECT_TRUE(FilePath("c:/" GTEST_PATH_SEP_ "is_not" + GTEST_PATH_SEP_ "relative").IsAbsolutePath()); #else EXPECT_TRUE(FilePath(GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative") .IsAbsolutePath()); #endif // GTEST_OS_WINDOWS } +TEST(FilePathTest, IsRootDirectory) { +#if GTEST_OS_WINDOWS + EXPECT_TRUE(FilePath("a:\\").IsRootDirectory()); + EXPECT_TRUE(FilePath("Z:/").IsRootDirectory()); + EXPECT_TRUE(FilePath("e://").IsRootDirectory()); + EXPECT_FALSE(FilePath("").IsRootDirectory()); + EXPECT_FALSE(FilePath("b:").IsRootDirectory()); + EXPECT_FALSE(FilePath("b:a").IsRootDirectory()); + EXPECT_FALSE(FilePath("8:/").IsRootDirectory()); + EXPECT_FALSE(FilePath("c|/").IsRootDirectory()); +#else + EXPECT_TRUE(FilePath("/").IsRootDirectory()); + EXPECT_FALSE(FilePath("").IsRootDirectory()); + EXPECT_FALSE(FilePath("\\").IsRootDirectory()); + EXPECT_FALSE(FilePath("/x").IsRootDirectory()); +#endif +} + } // namespace } // namespace internal } // namespace testing diff --git a/test/gtest_break_on_failure_unittest_.cc b/test/gtest_break_on_failure_unittest_.cc index 10a1203b..d28d1d3d 100644 --- a/test/gtest_break_on_failure_unittest_.cc +++ b/test/gtest_break_on_failure_unittest_.cc @@ -43,6 +43,7 @@ #if GTEST_OS_WINDOWS #include <windows.h> +#include <stdlib.h> #endif namespace { @@ -52,6 +53,14 @@ TEST(Foo, Bar) { EXPECT_EQ(2, 3); } +#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE +// On Windows Mobile global exception handlers are not supported. +LONG WINAPI ExitWithExceptionCode( + struct _EXCEPTION_POINTERS* exception_pointers) { + exit(exception_pointers->ExceptionRecord->ExceptionCode); +} +#endif + } // namespace int main(int argc, char **argv) { @@ -59,7 +68,18 @@ int main(int argc, char **argv) { // Suppresses display of the Windows error dialog upon encountering // a general protection fault (segment violation). SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); + +#if !GTEST_OS_WINDOWS_MOBILE + // The default unhandled exception filter does not always exit + // with the exception code as exit code - for example it exits with + // 0 for EXCEPTION_ACCESS_VIOLATION and 1 for EXCEPTION_BREAKPOINT + // if the application is compiled in debug mode. Thus we use our own + // filter which always exits with the exception code for unhandled + // exceptions. + SetUnhandledExceptionFilter(ExitWithExceptionCode); +#endif #endif + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); |