From 09fc73dde963132ded6595cdb724171c78436e52 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Wed, 1 Aug 2018 15:34:30 -0400 Subject: more test changes --- googletest/test/BUILD.bazel | 14 + googletest/test/googletest-filepath-test.cc | 652 +++++++++++++++++++++++ googletest/test/googletest-json-outfiles-test.py | 162 ++++++ googletest/test/googletest-linked-ptr-test.cc | 154 ++++++ googletest/test/gtest-filepath_test.cc | 652 ----------------------- googletest/test/gtest-linked_ptr_test.cc | 154 ------ googletest/test/gtest-listener_test.cc | 311 ----------- 7 files changed, 982 insertions(+), 1117 deletions(-) create mode 100644 googletest/test/googletest-filepath-test.cc create mode 100644 googletest/test/googletest-json-outfiles-test.py create mode 100644 googletest/test/googletest-linked-ptr-test.cc delete mode 100644 googletest/test/gtest-filepath_test.cc delete mode 100644 googletest/test/gtest-linked_ptr_test.cc delete mode 100644 googletest/test/gtest-listener_test.cc diff --git a/googletest/test/BUILD.bazel b/googletest/test/BUILD.bazel index 780b278..fdec685 100644 --- a/googletest/test/BUILD.bazel +++ b/googletest/test/BUILD.bazel @@ -448,3 +448,17 @@ py_test( data = [":gtest_testbridge_test_"], deps = [":gtest_test_utils"], ) + +py_test( + name = "googletest-json-outfiles-test", + size = "small", + srcs = [ + "googletest-json-outfiles-test.py", + "gtest_json_test_utils.py", + ], + data = [ + ":gtest_xml_outfile1_test_", + ":gtest_xml_outfile2_test_", + ], + deps = [":gtest_test_utils"], +) diff --git a/googletest/test/googletest-filepath-test.cc b/googletest/test/googletest-filepath-test.cc new file mode 100644 index 0000000..29cea3d --- /dev/null +++ b/googletest/test/googletest-filepath-test.cc @@ -0,0 +1,652 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// +// Google Test filepath utilities +// +// This file tests classes and functions used internally by +// Google Test. They are subject to change without notice. +// +// This file is #included from gtest-internal.h. +// Do not #include this file anywhere else! + +#include "gtest/internal/gtest-filepath.h" +#include "gtest/gtest.h" +#include "src/gtest-internal-inl.h" + +#if GTEST_OS_WINDOWS_MOBILE +# include // NOLINT +#elif GTEST_OS_WINDOWS +# include // NOLINT +#endif // GTEST_OS_WINDOWS_MOBILE + +namespace testing { +namespace internal { +namespace { + +#if GTEST_OS_WINDOWS_MOBILE +// TODO(wan@google.com): Move these to the POSIX adapter section in +// gtest-port.h. + +// Windows CE doesn't have the remove C function. +int remove(const char* path) { + LPCWSTR wpath = String::AnsiToUtf16(path); + int ret = DeleteFile(wpath) ? 0 : -1; + delete [] wpath; + return ret; +} +// Windows CE doesn't have the _rmdir C function. +int _rmdir(const char* path) { + FilePath filepath(path); + LPCWSTR wpath = String::AnsiToUtf16( + filepath.RemoveTrailingPathSeparator().c_str()); + int ret = RemoveDirectory(wpath) ? 0 : -1; + delete [] wpath; + return ret; +} + +#else + +TEST(GetCurrentDirTest, ReturnsCurrentDir) { + const FilePath original_dir = FilePath::GetCurrentDir(); + EXPECT_FALSE(original_dir.IsEmpty()); + + posix::ChDir(GTEST_PATH_SEP_); + const FilePath cwd = FilePath::GetCurrentDir(); + posix::ChDir(original_dir.c_str()); + +# if GTEST_OS_WINDOWS + + // Skips the ":". + const char* const cwd_without_drive = strchr(cwd.c_str(), ':'); + ASSERT_TRUE(cwd_without_drive != NULL); + EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1); + +# else + + EXPECT_EQ(GTEST_PATH_SEP_, cwd.string()); + +# endif +} + +#endif // GTEST_OS_WINDOWS_MOBILE + +TEST(IsEmptyTest, ReturnsTrueForEmptyPath) { + EXPECT_TRUE(FilePath("").IsEmpty()); +} + +TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) { + EXPECT_FALSE(FilePath("a").IsEmpty()); + EXPECT_FALSE(FilePath(".").IsEmpty()); + EXPECT_FALSE(FilePath("a/b").IsEmpty()); + EXPECT_FALSE(FilePath("a\\b\\").IsEmpty()); +} + +// RemoveDirectoryName "" -> "" +TEST(RemoveDirectoryNameTest, WhenEmptyName) { + EXPECT_EQ("", FilePath("").RemoveDirectoryName().string()); +} + +// RemoveDirectoryName "afile" -> "afile" +TEST(RemoveDirectoryNameTest, ButNoDirectory) { + EXPECT_EQ("afile", + FilePath("afile").RemoveDirectoryName().string()); +} + +// RemoveDirectoryName "/afile" -> "afile" +TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) { + EXPECT_EQ("afile", + FilePath(GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string()); +} + +// RemoveDirectoryName "adir/" -> "" +TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) { + EXPECT_EQ("", + FilePath("adir" GTEST_PATH_SEP_).RemoveDirectoryName().string()); +} + +// RemoveDirectoryName "adir/afile" -> "afile" +TEST(RemoveDirectoryNameTest, ShouldGiveFileName) { + EXPECT_EQ("afile", + FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string()); +} + +// RemoveDirectoryName "adir/subdir/afile" -> "afile" +TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) { + EXPECT_EQ("afile", + FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile") + .RemoveDirectoryName().string()); +} + +#if GTEST_HAS_ALT_PATH_SEP_ + +// Tests that RemoveDirectoryName() works with the alternate separator +// on Windows. + +// RemoveDirectoryName("/afile") -> "afile" +TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) { + EXPECT_EQ("afile", FilePath("/afile").RemoveDirectoryName().string()); +} + +// RemoveDirectoryName("adir/") -> "" +TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) { + EXPECT_EQ("", FilePath("adir/").RemoveDirectoryName().string()); +} + +// RemoveDirectoryName("adir/afile") -> "afile" +TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) { + EXPECT_EQ("afile", FilePath("adir/afile").RemoveDirectoryName().string()); +} + +// RemoveDirectoryName("adir/subdir/afile") -> "afile" +TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) { + EXPECT_EQ("afile", + FilePath("adir/subdir/afile").RemoveDirectoryName().string()); +} + +#endif + +// RemoveFileName "" -> "./" +TEST(RemoveFileNameTest, EmptyName) { +#if GTEST_OS_WINDOWS_MOBILE + // On Windows CE, we use the root as the current directory. + EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); +#else + EXPECT_EQ("." GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); +#endif +} + +// RemoveFileName "adir/" -> "adir/" +TEST(RemoveFileNameTest, ButNoFile) { + EXPECT_EQ("adir" GTEST_PATH_SEP_, + FilePath("adir" GTEST_PATH_SEP_).RemoveFileName().string()); +} + +// RemoveFileName "adir/afile" -> "adir/" +TEST(RemoveFileNameTest, GivesDirName) { + EXPECT_EQ("adir" GTEST_PATH_SEP_, + FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveFileName().string()); +} + +// RemoveFileName "adir/subdir/afile" -> "adir/subdir/" +TEST(RemoveFileNameTest, GivesDirAndSubDirName) { + EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_, + FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile") + .RemoveFileName().string()); +} + +// RemoveFileName "/afile" -> "/" +TEST(RemoveFileNameTest, GivesRootDir) { + EXPECT_EQ(GTEST_PATH_SEP_, + FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().string()); +} + +#if GTEST_HAS_ALT_PATH_SEP_ + +// Tests that RemoveFileName() works with the alternate separator on +// Windows. + +// RemoveFileName("adir/") -> "adir/" +TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) { + EXPECT_EQ("adir" GTEST_PATH_SEP_, + FilePath("adir/").RemoveFileName().string()); +} + +// RemoveFileName("adir/afile") -> "adir/" +TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) { + EXPECT_EQ("adir" GTEST_PATH_SEP_, + FilePath("adir/afile").RemoveFileName().string()); +} + +// RemoveFileName("adir/subdir/afile") -> "adir/subdir/" +TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) { + EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_, + FilePath("adir/subdir/afile").RemoveFileName().string()); +} + +// RemoveFileName("/afile") -> "\" +TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) { + EXPECT_EQ(GTEST_PATH_SEP_, FilePath("/afile").RemoveFileName().string()); +} + +#endif + +TEST(MakeFileNameTest, GenerateWhenNumberIsZero) { + FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), + 0, "xml"); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); +} + +TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) { + FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), + 12, "xml"); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string()); +} + +TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) { + FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_), + FilePath("bar"), 0, "xml"); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); +} + +TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) { + FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_), + FilePath("bar"), 12, "xml"); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string()); +} + +TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) { + FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"), + 0, "xml"); + EXPECT_EQ("bar.xml", actual.string()); +} + +TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) { + FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"), + 14, "xml"); + EXPECT_EQ("bar_14.xml", actual.string()); +} + +TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) { + FilePath actual = FilePath::ConcatPaths(FilePath("foo"), + FilePath("bar.xml")); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); +} + +TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) { + FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_), + FilePath("bar.xml")); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); +} + +TEST(ConcatPathsTest, Path1BeingEmpty) { + FilePath actual = FilePath::ConcatPaths(FilePath(""), + FilePath("bar.xml")); + EXPECT_EQ("bar.xml", actual.string()); +} + +TEST(ConcatPathsTest, Path2BeingEmpty) { + FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath("")); + EXPECT_EQ("foo" GTEST_PATH_SEP_, actual.string()); +} + +TEST(ConcatPathsTest, BothPathBeingEmpty) { + FilePath actual = FilePath::ConcatPaths(FilePath(""), + FilePath("")); + EXPECT_EQ("", actual.string()); +} + +TEST(ConcatPathsTest, Path1ContainsPathSep) { + FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_ "bar"), + FilePath("foobar.xml")); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "foobar.xml", + actual.string()); +} + +TEST(ConcatPathsTest, Path2ContainsPathSep) { + FilePath actual = FilePath::ConcatPaths( + FilePath("foo" GTEST_PATH_SEP_), + FilePath("bar" GTEST_PATH_SEP_ "bar.xml")); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "bar.xml", + actual.string()); +} + +TEST(ConcatPathsTest, Path2EndsWithPathSep) { + FilePath actual = FilePath::ConcatPaths(FilePath("foo"), + FilePath("bar" GTEST_PATH_SEP_)); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_, actual.string()); +} + +// RemoveTrailingPathSeparator "" -> "" +TEST(RemoveTrailingPathSeparatorTest, EmptyString) { + EXPECT_EQ("", FilePath("").RemoveTrailingPathSeparator().string()); +} + +// RemoveTrailingPathSeparator "foo" -> "foo" +TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) { + EXPECT_EQ("foo", FilePath("foo").RemoveTrailingPathSeparator().string()); +} + +// RemoveTrailingPathSeparator "foo/" -> "foo" +TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) { + EXPECT_EQ("foo", + FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().string()); +#if GTEST_HAS_ALT_PATH_SEP_ + EXPECT_EQ("foo", FilePath("foo/").RemoveTrailingPathSeparator().string()); +#endif +} + +// RemoveTrailingPathSeparator "foo/bar/" -> "foo/bar/" +TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) { + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", + FilePath("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_) + .RemoveTrailingPathSeparator().string()); +} + +// RemoveTrailingPathSeparator "foo/bar" -> "foo/bar" +TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) { + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", + FilePath("foo" GTEST_PATH_SEP_ "bar") + .RemoveTrailingPathSeparator().string()); +} + +TEST(DirectoryTest, RootDirectoryExists) { +#if GTEST_OS_WINDOWS // We are on Windows. + char current_drive[_MAX_PATH]; // NOLINT + current_drive[0] = static_cast(_getdrive() + 'A' - 1); + current_drive[1] = ':'; + current_drive[2] = '\\'; + current_drive[3] = '\0'; + EXPECT_TRUE(FilePath(current_drive).DirectoryExists()); +#else + EXPECT_TRUE(FilePath("/").DirectoryExists()); +#endif // GTEST_OS_WINDOWS +} + +#if GTEST_OS_WINDOWS +TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { + const int saved_drive_ = _getdrive(); + // Find a drive that doesn't exist. Start with 'Z' to avoid common ones. + for (char drive = 'Z'; drive >= 'A'; drive--) + if (_chdrive(drive - 'A' + 1) == -1) { + char non_drive[_MAX_PATH]; // NOLINT + non_drive[0] = drive; + non_drive[1] = ':'; + non_drive[2] = '\\'; + non_drive[3] = '\0'; + EXPECT_FALSE(FilePath(non_drive).DirectoryExists()); + break; + } + _chdrive(saved_drive_); +} +#endif // GTEST_OS_WINDOWS + +#if !GTEST_OS_WINDOWS_MOBILE +// Windows CE _does_ consider an empty directory to exist. +TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { + EXPECT_FALSE(FilePath("").DirectoryExists()); +} +#endif // !GTEST_OS_WINDOWS_MOBILE + +TEST(DirectoryTest, CurrentDirectoryExists) { +#if GTEST_OS_WINDOWS // We are on Windows. +# ifndef _WIN32_CE // Windows CE doesn't have a current directory. + + EXPECT_TRUE(FilePath(".").DirectoryExists()); + EXPECT_TRUE(FilePath(".\\").DirectoryExists()); + +# endif // _WIN32_CE +#else + EXPECT_TRUE(FilePath(".").DirectoryExists()); + EXPECT_TRUE(FilePath("./").DirectoryExists()); +#endif // GTEST_OS_WINDOWS +} + +// "foo/bar" == foo//bar" == "foo///bar" +TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) { + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", + FilePath("foo" GTEST_PATH_SEP_ "bar").string()); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", + FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); + EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", + FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ + GTEST_PATH_SEP_ "bar").string()); +} + +// "/bar" == //bar" == "///bar" +TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) { + EXPECT_EQ(GTEST_PATH_SEP_ "bar", + FilePath(GTEST_PATH_SEP_ "bar").string()); + EXPECT_EQ(GTEST_PATH_SEP_ "bar", + FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); + EXPECT_EQ(GTEST_PATH_SEP_ "bar", + FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); +} + +// "foo/" == foo//" == "foo///" +TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) { + EXPECT_EQ("foo" GTEST_PATH_SEP_, + FilePath("foo" GTEST_PATH_SEP_).string()); + EXPECT_EQ("foo" GTEST_PATH_SEP_, + FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).string()); + EXPECT_EQ("foo" GTEST_PATH_SEP_, + FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).string()); +} + +#if GTEST_HAS_ALT_PATH_SEP_ + +// Tests that separators at the end of the string are normalized +// regardless of their combination (e.g. "foo\" =="foo/\" == +// "foo\\/"). +TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) { + EXPECT_EQ("foo" GTEST_PATH_SEP_, + FilePath("foo/").string()); + EXPECT_EQ("foo" GTEST_PATH_SEP_, + FilePath("foo" GTEST_PATH_SEP_ "/").string()); + EXPECT_EQ("foo" GTEST_PATH_SEP_, + FilePath("foo//" GTEST_PATH_SEP_).string()); +} + +#endif + +TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) { + FilePath default_path; + FilePath non_default_path("path"); + non_default_path = default_path; + EXPECT_EQ("", non_default_path.string()); + EXPECT_EQ("", default_path.string()); // RHS var is unchanged. +} + +TEST(AssignmentOperatorTest, NonDefaultAssignedToDefault) { + FilePath non_default_path("path"); + FilePath default_path; + default_path = non_default_path; + EXPECT_EQ("path", default_path.string()); + EXPECT_EQ("path", non_default_path.string()); // RHS var is unchanged. +} + +TEST(AssignmentOperatorTest, ConstAssignedToNonConst) { + const FilePath const_default_path("const_path"); + FilePath non_default_path("path"); + non_default_path = const_default_path; + EXPECT_EQ("const_path", non_default_path.string()); +} + +class DirectoryCreationTest : public Test { + protected: + virtual void SetUp() { + testdata_path_.Set(FilePath( + TempDir() + GetCurrentExecutableName().string() + + "_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_)); + testdata_file_.Set(testdata_path_.RemoveTrailingPathSeparator()); + + unique_file0_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"), + 0, "txt")); + unique_file1_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"), + 1, "txt")); + + remove(testdata_file_.c_str()); + remove(unique_file0_.c_str()); + remove(unique_file1_.c_str()); + posix::RmDir(testdata_path_.c_str()); + } + + virtual void TearDown() { + remove(testdata_file_.c_str()); + remove(unique_file0_.c_str()); + remove(unique_file1_.c_str()); + posix::RmDir(testdata_path_.c_str()); + } + + void CreateTextFile(const char* filename) { + FILE* f = posix::FOpen(filename, "w"); + fprintf(f, "text\n"); + fclose(f); + } + + // Strings representing a directory and a file, with identical paths + // except for the trailing separator character that distinquishes + // a directory named 'test' from a file named 'test'. Example names: + FilePath testdata_path_; // "/tmp/directory_creation/test/" + FilePath testdata_file_; // "/tmp/directory_creation/test" + FilePath unique_file0_; // "/tmp/directory_creation/test/unique.txt" + FilePath unique_file1_; // "/tmp/directory_creation/test/unique_1.txt" +}; + +TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) { + EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string(); + EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); + EXPECT_TRUE(testdata_path_.DirectoryExists()); +} + +TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) { + EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string(); + EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); + // Call 'create' again... should still succeed. + EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); +} + +TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) { + FilePath file_path(FilePath::GenerateUniqueFileName(testdata_path_, + FilePath("unique"), "txt")); + EXPECT_EQ(unique_file0_.string(), file_path.string()); + EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file not there + + testdata_path_.CreateDirectoriesRecursively(); + EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file still not there + CreateTextFile(file_path.c_str()); + EXPECT_TRUE(file_path.FileOrDirectoryExists()); + + FilePath file_path2(FilePath::GenerateUniqueFileName(testdata_path_, + FilePath("unique"), "txt")); + EXPECT_EQ(unique_file1_.string(), file_path2.string()); + EXPECT_FALSE(file_path2.FileOrDirectoryExists()); // file not there + CreateTextFile(file_path2.c_str()); + EXPECT_TRUE(file_path2.FileOrDirectoryExists()); +} + +TEST_F(DirectoryCreationTest, CreateDirectoriesFail) { + // force a failure by putting a file where we will try to create a directory. + CreateTextFile(testdata_file_.c_str()); + EXPECT_TRUE(testdata_file_.FileOrDirectoryExists()); + EXPECT_FALSE(testdata_file_.DirectoryExists()); + EXPECT_FALSE(testdata_file_.CreateDirectoriesRecursively()); +} + +TEST(NoDirectoryCreationTest, CreateNoDirectoriesForDefaultXmlFile) { + const FilePath test_detail_xml("test_detail.xml"); + EXPECT_FALSE(test_detail_xml.CreateDirectoriesRecursively()); +} + +TEST(FilePathTest, DefaultConstructor) { + FilePath fp; + EXPECT_EQ("", fp.string()); +} + +TEST(FilePathTest, CharAndCopyConstructors) { + const FilePath fp("spicy"); + EXPECT_EQ("spicy", fp.string()); + + const FilePath fp_copy(fp); + EXPECT_EQ("spicy", fp_copy.string()); +} + +TEST(FilePathTest, StringConstructor) { + const FilePath fp(std::string("cider")); + EXPECT_EQ("cider", fp.string()); +} + +TEST(FilePathTest, Set) { + const FilePath apple("apple"); + FilePath mac("mac"); + mac.Set(apple); // Implement Set() since overloading operator= is forbidden. + EXPECT_EQ("apple", mac.string()); + EXPECT_EQ("apple", apple.string()); +} + +TEST(FilePathTest, ToString) { + const FilePath file("drink"); + EXPECT_EQ("drink", file.string()); +} + +TEST(FilePathTest, RemoveExtension) { + EXPECT_EQ("app", FilePath("app.cc").RemoveExtension("cc").string()); + EXPECT_EQ("app", FilePath("app.exe").RemoveExtension("exe").string()); + EXPECT_EQ("APP", FilePath("APP.EXE").RemoveExtension("exe").string()); +} + +TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) { + EXPECT_EQ("app", FilePath("app").RemoveExtension("exe").string()); +} + +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) { + EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath()); + EXPECT_FALSE(FilePath("").IsAbsolutePath()); +#if GTEST_OS_WINDOWS + 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_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/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py new file mode 100644 index 0000000..46010d8 --- /dev/null +++ b/googletest/test/googletest-json-outfiles-test.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# Copyright 2018, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Unit test for the gtest_json_output module.""" + +import json +import os +import gtest_json_test_utils +import gtest_test_utils + +GTEST_OUTPUT_SUBDIR = 'json_outfiles' +GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_' +GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_' + +EXPECTED_1 = { + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'timestamp': u'*', + u'name': u'AllTests', + u'testsuites': [{ + u'name': u'PropertyOne', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [{ + u'name': u'TestSomeProperties', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyOne', + u'SetUpProp': u'1', + u'TestSomeProperty': u'1', + u'TearDownProp': u'1', + }], + }], +} + +EXPECTED_2 = { + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'timestamp': u'*', + u'name': u'AllTests', + u'testsuites': [{ + u'name': u'PropertyTwo', + u'tests': 1, + u'failures': 0, + u'disabled': 0, + u'errors': 0, + u'time': u'*', + u'testsuite': [{ + u'name': u'TestSomeProperties', + u'status': u'RUN', + u'time': u'*', + u'classname': u'PropertyTwo', + u'SetUpProp': u'2', + u'TestSomeProperty': u'2', + u'TearDownProp': u'2', + }], + }], +} + + +class GTestJsonOutFilesTest(gtest_test_utils.TestCase): + """Unit test for Google Test's JSON output functionality.""" + + def setUp(self): + # We want the trailing '/' that the last "" provides in os.path.join, for + # telling Google Test to create an output directory instead of a single file + # for xml output. + self.output_dir_ = os.path.join(gtest_test_utils.GetTempDir(), + GTEST_OUTPUT_SUBDIR, '') + self.DeleteFilesAndDir() + + def tearDown(self): + self.DeleteFilesAndDir() + + def DeleteFilesAndDir(self): + try: + os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_1_TEST + '.json')) + except os.error: + pass + try: + os.remove(os.path.join(self.output_dir_, GTEST_OUTPUT_2_TEST + '.json')) + except os.error: + pass + try: + os.rmdir(self.output_dir_) + except os.error: + pass + + def testOutfile1(self): + self._TestOutFile(GTEST_OUTPUT_1_TEST, EXPECTED_1) + + def testOutfile2(self): + self._TestOutFile(GTEST_OUTPUT_2_TEST, EXPECTED_2) + + def _TestOutFile(self, test_name, expected): + gtest_prog_path = gtest_test_utils.GetTestExecutablePath(test_name) + command = [gtest_prog_path, '--gtest_output=json:%s' % self.output_dir_] + p = gtest_test_utils.Subprocess(command, + working_dir=gtest_test_utils.GetTempDir()) + self.assert_(p.exited) + self.assertEquals(0, p.exit_code) + + # TODO(wan@google.com): libtool causes the built test binary to be + # named lt-gtest_xml_outfiles_test_ instead of + # gtest_xml_outfiles_test_. To account for this possibility, we + # allow both names in the following code. We should remove this + # hack when Chandler Carruth's libtool replacement tool is ready. + output_file_name1 = test_name + '.json' + output_file1 = os.path.join(self.output_dir_, output_file_name1) + output_file_name2 = 'lt-' + output_file_name1 + output_file2 = os.path.join(self.output_dir_, output_file_name2) + self.assert_(os.path.isfile(output_file1) or os.path.isfile(output_file2), + output_file1) + + if os.path.isfile(output_file1): + with open(output_file1) as f: + actual = json.load(f) + else: + with open(output_file2) as f: + actual = json.load(f) + self.assertEqual(expected, gtest_json_test_utils.normalize(actual)) + + +if __name__ == '__main__': + os.environ['GTEST_STACK_TRACE_DEPTH'] = '0' + gtest_test_utils.Main() diff --git a/googletest/test/googletest-linked-ptr-test.cc b/googletest/test/googletest-linked-ptr-test.cc new file mode 100644 index 0000000..6fcf512 --- /dev/null +++ b/googletest/test/googletest-linked-ptr-test.cc @@ -0,0 +1,154 @@ +// Copyright 2003, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Authors: Dan Egnor (egnor@google.com) +// Ported to Windows: Vadim Berman (vadimb@google.com) + +#include "gtest/internal/gtest-linked_ptr.h" + +#include +#include "gtest/gtest.h" + +namespace { + +using testing::Message; +using testing::internal::linked_ptr; + +int num; +Message* history = NULL; + +// Class which tracks allocation/deallocation +class A { + public: + A(): mynum(num++) { *history << "A" << mynum << " ctor\n"; } + virtual ~A() { *history << "A" << mynum << " dtor\n"; } + virtual void Use() { *history << "A" << mynum << " use\n"; } + protected: + int mynum; +}; + +// Subclass +class B : public A { + public: + B() { *history << "B" << mynum << " ctor\n"; } + ~B() { *history << "B" << mynum << " dtor\n"; } + virtual void Use() { *history << "B" << mynum << " use\n"; } +}; + +class LinkedPtrTest : public testing::Test { + public: + LinkedPtrTest() { + num = 0; + history = new Message; + } + + virtual ~LinkedPtrTest() { + delete history; + history = NULL; + } +}; + +TEST_F(LinkedPtrTest, GeneralTest) { + { + linked_ptr a0, a1, a2; + // Use explicit function call notation here to suppress self-assign warning. + a0.operator=(a0); + a1 = a2; + ASSERT_EQ(a0.get(), static_cast(NULL)); + ASSERT_EQ(a1.get(), static_cast(NULL)); + ASSERT_EQ(a2.get(), static_cast(NULL)); + ASSERT_TRUE(a0 == NULL); + ASSERT_TRUE(a1 == NULL); + ASSERT_TRUE(a2 == NULL); + + { + linked_ptr a3(new A); + a0 = a3; + ASSERT_TRUE(a0 == a3); + ASSERT_TRUE(a0 != NULL); + ASSERT_TRUE(a0.get() == a3); + ASSERT_TRUE(a0 == a3.get()); + linked_ptr a4(a0); + a1 = a4; + linked_ptr a5(new A); + ASSERT_TRUE(a5.get() != a3); + ASSERT_TRUE(a5 != a3.get()); + a2 = a5; + linked_ptr b0(new B); + linked_ptr a6(b0); + ASSERT_TRUE(b0 == a6); + ASSERT_TRUE(a6 == b0); + ASSERT_TRUE(b0 != NULL); + a5 = b0; + a5 = b0; + a3->Use(); + a4->Use(); + a5->Use(); + a6->Use(); + b0->Use(); + (*b0).Use(); + b0.get()->Use(); + } + + a0->Use(); + a1->Use(); + a2->Use(); + + a1 = a2; + a2.reset(new A); + a0.reset(); + + linked_ptr a7; + } + + ASSERT_STREQ( + "A0 ctor\n" + "A1 ctor\n" + "A2 ctor\n" + "B2 ctor\n" + "A0 use\n" + "A0 use\n" + "B2 use\n" + "B2 use\n" + "B2 use\n" + "B2 use\n" + "B2 use\n" + "B2 dtor\n" + "A2 dtor\n" + "A0 use\n" + "A0 use\n" + "A1 use\n" + "A3 ctor\n" + "A0 dtor\n" + "A3 dtor\n" + "A1 dtor\n", + history->GetString().c_str()); +} + +} // Unnamed namespace diff --git a/googletest/test/gtest-filepath_test.cc b/googletest/test/gtest-filepath_test.cc deleted file mode 100644 index 29cea3d..0000000 --- a/googletest/test/gtest-filepath_test.cc +++ /dev/null @@ -1,652 +0,0 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// -// Google Test filepath utilities -// -// This file tests classes and functions used internally by -// Google Test. They are subject to change without notice. -// -// This file is #included from gtest-internal.h. -// Do not #include this file anywhere else! - -#include "gtest/internal/gtest-filepath.h" -#include "gtest/gtest.h" -#include "src/gtest-internal-inl.h" - -#if GTEST_OS_WINDOWS_MOBILE -# include // NOLINT -#elif GTEST_OS_WINDOWS -# include // NOLINT -#endif // GTEST_OS_WINDOWS_MOBILE - -namespace testing { -namespace internal { -namespace { - -#if GTEST_OS_WINDOWS_MOBILE -// TODO(wan@google.com): Move these to the POSIX adapter section in -// gtest-port.h. - -// Windows CE doesn't have the remove C function. -int remove(const char* path) { - LPCWSTR wpath = String::AnsiToUtf16(path); - int ret = DeleteFile(wpath) ? 0 : -1; - delete [] wpath; - return ret; -} -// Windows CE doesn't have the _rmdir C function. -int _rmdir(const char* path) { - FilePath filepath(path); - LPCWSTR wpath = String::AnsiToUtf16( - filepath.RemoveTrailingPathSeparator().c_str()); - int ret = RemoveDirectory(wpath) ? 0 : -1; - delete [] wpath; - return ret; -} - -#else - -TEST(GetCurrentDirTest, ReturnsCurrentDir) { - const FilePath original_dir = FilePath::GetCurrentDir(); - EXPECT_FALSE(original_dir.IsEmpty()); - - posix::ChDir(GTEST_PATH_SEP_); - const FilePath cwd = FilePath::GetCurrentDir(); - posix::ChDir(original_dir.c_str()); - -# if GTEST_OS_WINDOWS - - // Skips the ":". - const char* const cwd_without_drive = strchr(cwd.c_str(), ':'); - ASSERT_TRUE(cwd_without_drive != NULL); - EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1); - -# else - - EXPECT_EQ(GTEST_PATH_SEP_, cwd.string()); - -# endif -} - -#endif // GTEST_OS_WINDOWS_MOBILE - -TEST(IsEmptyTest, ReturnsTrueForEmptyPath) { - EXPECT_TRUE(FilePath("").IsEmpty()); -} - -TEST(IsEmptyTest, ReturnsFalseForNonEmptyPath) { - EXPECT_FALSE(FilePath("a").IsEmpty()); - EXPECT_FALSE(FilePath(".").IsEmpty()); - EXPECT_FALSE(FilePath("a/b").IsEmpty()); - EXPECT_FALSE(FilePath("a\\b\\").IsEmpty()); -} - -// RemoveDirectoryName "" -> "" -TEST(RemoveDirectoryNameTest, WhenEmptyName) { - EXPECT_EQ("", FilePath("").RemoveDirectoryName().string()); -} - -// RemoveDirectoryName "afile" -> "afile" -TEST(RemoveDirectoryNameTest, ButNoDirectory) { - EXPECT_EQ("afile", - FilePath("afile").RemoveDirectoryName().string()); -} - -// RemoveDirectoryName "/afile" -> "afile" -TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileName) { - EXPECT_EQ("afile", - FilePath(GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string()); -} - -// RemoveDirectoryName "adir/" -> "" -TEST(RemoveDirectoryNameTest, WhereThereIsNoFileName) { - EXPECT_EQ("", - FilePath("adir" GTEST_PATH_SEP_).RemoveDirectoryName().string()); -} - -// RemoveDirectoryName "adir/afile" -> "afile" -TEST(RemoveDirectoryNameTest, ShouldGiveFileName) { - EXPECT_EQ("afile", - FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveDirectoryName().string()); -} - -// RemoveDirectoryName "adir/subdir/afile" -> "afile" -TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileName) { - EXPECT_EQ("afile", - FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile") - .RemoveDirectoryName().string()); -} - -#if GTEST_HAS_ALT_PATH_SEP_ - -// Tests that RemoveDirectoryName() works with the alternate separator -// on Windows. - -// RemoveDirectoryName("/afile") -> "afile" -TEST(RemoveDirectoryNameTest, RootFileShouldGiveFileNameForAlternateSeparator) { - EXPECT_EQ("afile", FilePath("/afile").RemoveDirectoryName().string()); -} - -// RemoveDirectoryName("adir/") -> "" -TEST(RemoveDirectoryNameTest, WhereThereIsNoFileNameForAlternateSeparator) { - EXPECT_EQ("", FilePath("adir/").RemoveDirectoryName().string()); -} - -// RemoveDirectoryName("adir/afile") -> "afile" -TEST(RemoveDirectoryNameTest, ShouldGiveFileNameForAlternateSeparator) { - EXPECT_EQ("afile", FilePath("adir/afile").RemoveDirectoryName().string()); -} - -// RemoveDirectoryName("adir/subdir/afile") -> "afile" -TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) { - EXPECT_EQ("afile", - FilePath("adir/subdir/afile").RemoveDirectoryName().string()); -} - -#endif - -// RemoveFileName "" -> "./" -TEST(RemoveFileNameTest, EmptyName) { -#if GTEST_OS_WINDOWS_MOBILE - // On Windows CE, we use the root as the current directory. - EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); -#else - EXPECT_EQ("." GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); -#endif -} - -// RemoveFileName "adir/" -> "adir/" -TEST(RemoveFileNameTest, ButNoFile) { - EXPECT_EQ("adir" GTEST_PATH_SEP_, - FilePath("adir" GTEST_PATH_SEP_).RemoveFileName().string()); -} - -// RemoveFileName "adir/afile" -> "adir/" -TEST(RemoveFileNameTest, GivesDirName) { - EXPECT_EQ("adir" GTEST_PATH_SEP_, - FilePath("adir" GTEST_PATH_SEP_ "afile").RemoveFileName().string()); -} - -// RemoveFileName "adir/subdir/afile" -> "adir/subdir/" -TEST(RemoveFileNameTest, GivesDirAndSubDirName) { - EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_, - FilePath("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_ "afile") - .RemoveFileName().string()); -} - -// RemoveFileName "/afile" -> "/" -TEST(RemoveFileNameTest, GivesRootDir) { - EXPECT_EQ(GTEST_PATH_SEP_, - FilePath(GTEST_PATH_SEP_ "afile").RemoveFileName().string()); -} - -#if GTEST_HAS_ALT_PATH_SEP_ - -// Tests that RemoveFileName() works with the alternate separator on -// Windows. - -// RemoveFileName("adir/") -> "adir/" -TEST(RemoveFileNameTest, ButNoFileForAlternateSeparator) { - EXPECT_EQ("adir" GTEST_PATH_SEP_, - FilePath("adir/").RemoveFileName().string()); -} - -// RemoveFileName("adir/afile") -> "adir/" -TEST(RemoveFileNameTest, GivesDirNameForAlternateSeparator) { - EXPECT_EQ("adir" GTEST_PATH_SEP_, - FilePath("adir/afile").RemoveFileName().string()); -} - -// RemoveFileName("adir/subdir/afile") -> "adir/subdir/" -TEST(RemoveFileNameTest, GivesDirAndSubDirNameForAlternateSeparator) { - EXPECT_EQ("adir" GTEST_PATH_SEP_ "subdir" GTEST_PATH_SEP_, - FilePath("adir/subdir/afile").RemoveFileName().string()); -} - -// RemoveFileName("/afile") -> "\" -TEST(RemoveFileNameTest, GivesRootDirForAlternateSeparator) { - EXPECT_EQ(GTEST_PATH_SEP_, FilePath("/afile").RemoveFileName().string()); -} - -#endif - -TEST(MakeFileNameTest, GenerateWhenNumberIsZero) { - FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), - 0, "xml"); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); -} - -TEST(MakeFileNameTest, GenerateFileNameNumberGtZero) { - FilePath actual = FilePath::MakeFileName(FilePath("foo"), FilePath("bar"), - 12, "xml"); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string()); -} - -TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberIsZero) { - FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_), - FilePath("bar"), 0, "xml"); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); -} - -TEST(MakeFileNameTest, GenerateFileNameWithSlashNumberGtZero) { - FilePath actual = FilePath::MakeFileName(FilePath("foo" GTEST_PATH_SEP_), - FilePath("bar"), 12, "xml"); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar_12.xml", actual.string()); -} - -TEST(MakeFileNameTest, GenerateWhenNumberIsZeroAndDirIsEmpty) { - FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"), - 0, "xml"); - EXPECT_EQ("bar.xml", actual.string()); -} - -TEST(MakeFileNameTest, GenerateWhenNumberIsNotZeroAndDirIsEmpty) { - FilePath actual = FilePath::MakeFileName(FilePath(""), FilePath("bar"), - 14, "xml"); - EXPECT_EQ("bar_14.xml", actual.string()); -} - -TEST(ConcatPathsTest, WorksWhenDirDoesNotEndWithPathSep) { - FilePath actual = FilePath::ConcatPaths(FilePath("foo"), - FilePath("bar.xml")); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); -} - -TEST(ConcatPathsTest, WorksWhenPath1EndsWithPathSep) { - FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_), - FilePath("bar.xml")); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar.xml", actual.string()); -} - -TEST(ConcatPathsTest, Path1BeingEmpty) { - FilePath actual = FilePath::ConcatPaths(FilePath(""), - FilePath("bar.xml")); - EXPECT_EQ("bar.xml", actual.string()); -} - -TEST(ConcatPathsTest, Path2BeingEmpty) { - FilePath actual = FilePath::ConcatPaths(FilePath("foo"), FilePath("")); - EXPECT_EQ("foo" GTEST_PATH_SEP_, actual.string()); -} - -TEST(ConcatPathsTest, BothPathBeingEmpty) { - FilePath actual = FilePath::ConcatPaths(FilePath(""), - FilePath("")); - EXPECT_EQ("", actual.string()); -} - -TEST(ConcatPathsTest, Path1ContainsPathSep) { - FilePath actual = FilePath::ConcatPaths(FilePath("foo" GTEST_PATH_SEP_ "bar"), - FilePath("foobar.xml")); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "foobar.xml", - actual.string()); -} - -TEST(ConcatPathsTest, Path2ContainsPathSep) { - FilePath actual = FilePath::ConcatPaths( - FilePath("foo" GTEST_PATH_SEP_), - FilePath("bar" GTEST_PATH_SEP_ "bar.xml")); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_ "bar.xml", - actual.string()); -} - -TEST(ConcatPathsTest, Path2EndsWithPathSep) { - FilePath actual = FilePath::ConcatPaths(FilePath("foo"), - FilePath("bar" GTEST_PATH_SEP_)); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_, actual.string()); -} - -// RemoveTrailingPathSeparator "" -> "" -TEST(RemoveTrailingPathSeparatorTest, EmptyString) { - EXPECT_EQ("", FilePath("").RemoveTrailingPathSeparator().string()); -} - -// RemoveTrailingPathSeparator "foo" -> "foo" -TEST(RemoveTrailingPathSeparatorTest, FileNoSlashString) { - EXPECT_EQ("foo", FilePath("foo").RemoveTrailingPathSeparator().string()); -} - -// RemoveTrailingPathSeparator "foo/" -> "foo" -TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveTrailingSeparator) { - EXPECT_EQ("foo", - FilePath("foo" GTEST_PATH_SEP_).RemoveTrailingPathSeparator().string()); -#if GTEST_HAS_ALT_PATH_SEP_ - EXPECT_EQ("foo", FilePath("foo/").RemoveTrailingPathSeparator().string()); -#endif -} - -// RemoveTrailingPathSeparator "foo/bar/" -> "foo/bar/" -TEST(RemoveTrailingPathSeparatorTest, ShouldRemoveLastSeparator) { - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", - FilePath("foo" GTEST_PATH_SEP_ "bar" GTEST_PATH_SEP_) - .RemoveTrailingPathSeparator().string()); -} - -// RemoveTrailingPathSeparator "foo/bar" -> "foo/bar" -TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) { - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", - FilePath("foo" GTEST_PATH_SEP_ "bar") - .RemoveTrailingPathSeparator().string()); -} - -TEST(DirectoryTest, RootDirectoryExists) { -#if GTEST_OS_WINDOWS // We are on Windows. - char current_drive[_MAX_PATH]; // NOLINT - current_drive[0] = static_cast(_getdrive() + 'A' - 1); - current_drive[1] = ':'; - current_drive[2] = '\\'; - current_drive[3] = '\0'; - EXPECT_TRUE(FilePath(current_drive).DirectoryExists()); -#else - EXPECT_TRUE(FilePath("/").DirectoryExists()); -#endif // GTEST_OS_WINDOWS -} - -#if GTEST_OS_WINDOWS -TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { - const int saved_drive_ = _getdrive(); - // Find a drive that doesn't exist. Start with 'Z' to avoid common ones. - for (char drive = 'Z'; drive >= 'A'; drive--) - if (_chdrive(drive - 'A' + 1) == -1) { - char non_drive[_MAX_PATH]; // NOLINT - non_drive[0] = drive; - non_drive[1] = ':'; - non_drive[2] = '\\'; - non_drive[3] = '\0'; - EXPECT_FALSE(FilePath(non_drive).DirectoryExists()); - break; - } - _chdrive(saved_drive_); -} -#endif // GTEST_OS_WINDOWS - -#if !GTEST_OS_WINDOWS_MOBILE -// Windows CE _does_ consider an empty directory to exist. -TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { - EXPECT_FALSE(FilePath("").DirectoryExists()); -} -#endif // !GTEST_OS_WINDOWS_MOBILE - -TEST(DirectoryTest, CurrentDirectoryExists) { -#if GTEST_OS_WINDOWS // We are on Windows. -# ifndef _WIN32_CE // Windows CE doesn't have a current directory. - - EXPECT_TRUE(FilePath(".").DirectoryExists()); - EXPECT_TRUE(FilePath(".\\").DirectoryExists()); - -# endif // _WIN32_CE -#else - EXPECT_TRUE(FilePath(".").DirectoryExists()); - EXPECT_TRUE(FilePath("./").DirectoryExists()); -#endif // GTEST_OS_WINDOWS -} - -// "foo/bar" == foo//bar" == "foo///bar" -TEST(NormalizeTest, MultipleConsecutiveSepaparatorsInMidstring) { - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", - FilePath("foo" GTEST_PATH_SEP_ "bar").string()); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", - FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); - EXPECT_EQ("foo" GTEST_PATH_SEP_ "bar", - FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ - GTEST_PATH_SEP_ "bar").string()); -} - -// "/bar" == //bar" == "///bar" -TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringStart) { - EXPECT_EQ(GTEST_PATH_SEP_ "bar", - FilePath(GTEST_PATH_SEP_ "bar").string()); - EXPECT_EQ(GTEST_PATH_SEP_ "bar", - FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); - EXPECT_EQ(GTEST_PATH_SEP_ "bar", - FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); -} - -// "foo/" == foo//" == "foo///" -TEST(NormalizeTest, MultipleConsecutiveSepaparatorsAtStringEnd) { - EXPECT_EQ("foo" GTEST_PATH_SEP_, - FilePath("foo" GTEST_PATH_SEP_).string()); - EXPECT_EQ("foo" GTEST_PATH_SEP_, - FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_).string()); - EXPECT_EQ("foo" GTEST_PATH_SEP_, - FilePath("foo" GTEST_PATH_SEP_ GTEST_PATH_SEP_ GTEST_PATH_SEP_).string()); -} - -#if GTEST_HAS_ALT_PATH_SEP_ - -// Tests that separators at the end of the string are normalized -// regardless of their combination (e.g. "foo\" =="foo/\" == -// "foo\\/"). -TEST(NormalizeTest, MixAlternateSeparatorAtStringEnd) { - EXPECT_EQ("foo" GTEST_PATH_SEP_, - FilePath("foo/").string()); - EXPECT_EQ("foo" GTEST_PATH_SEP_, - FilePath("foo" GTEST_PATH_SEP_ "/").string()); - EXPECT_EQ("foo" GTEST_PATH_SEP_, - FilePath("foo//" GTEST_PATH_SEP_).string()); -} - -#endif - -TEST(AssignmentOperatorTest, DefaultAssignedToNonDefault) { - FilePath default_path; - FilePath non_default_path("path"); - non_default_path = default_path; - EXPECT_EQ("", non_default_path.string()); - EXPECT_EQ("", default_path.string()); // RHS var is unchanged. -} - -TEST(AssignmentOperatorTest, NonDefaultAssignedToDefault) { - FilePath non_default_path("path"); - FilePath default_path; - default_path = non_default_path; - EXPECT_EQ("path", default_path.string()); - EXPECT_EQ("path", non_default_path.string()); // RHS var is unchanged. -} - -TEST(AssignmentOperatorTest, ConstAssignedToNonConst) { - const FilePath const_default_path("const_path"); - FilePath non_default_path("path"); - non_default_path = const_default_path; - EXPECT_EQ("const_path", non_default_path.string()); -} - -class DirectoryCreationTest : public Test { - protected: - virtual void SetUp() { - testdata_path_.Set(FilePath( - TempDir() + GetCurrentExecutableName().string() + - "_directory_creation" GTEST_PATH_SEP_ "test" GTEST_PATH_SEP_)); - testdata_file_.Set(testdata_path_.RemoveTrailingPathSeparator()); - - unique_file0_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"), - 0, "txt")); - unique_file1_.Set(FilePath::MakeFileName(testdata_path_, FilePath("unique"), - 1, "txt")); - - remove(testdata_file_.c_str()); - remove(unique_file0_.c_str()); - remove(unique_file1_.c_str()); - posix::RmDir(testdata_path_.c_str()); - } - - virtual void TearDown() { - remove(testdata_file_.c_str()); - remove(unique_file0_.c_str()); - remove(unique_file1_.c_str()); - posix::RmDir(testdata_path_.c_str()); - } - - void CreateTextFile(const char* filename) { - FILE* f = posix::FOpen(filename, "w"); - fprintf(f, "text\n"); - fclose(f); - } - - // Strings representing a directory and a file, with identical paths - // except for the trailing separator character that distinquishes - // a directory named 'test' from a file named 'test'. Example names: - FilePath testdata_path_; // "/tmp/directory_creation/test/" - FilePath testdata_file_; // "/tmp/directory_creation/test" - FilePath unique_file0_; // "/tmp/directory_creation/test/unique.txt" - FilePath unique_file1_; // "/tmp/directory_creation/test/unique_1.txt" -}; - -TEST_F(DirectoryCreationTest, CreateDirectoriesRecursively) { - EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string(); - EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); - EXPECT_TRUE(testdata_path_.DirectoryExists()); -} - -TEST_F(DirectoryCreationTest, CreateDirectoriesForAlreadyExistingPath) { - EXPECT_FALSE(testdata_path_.DirectoryExists()) << testdata_path_.string(); - EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); - // Call 'create' again... should still succeed. - EXPECT_TRUE(testdata_path_.CreateDirectoriesRecursively()); -} - -TEST_F(DirectoryCreationTest, CreateDirectoriesAndUniqueFilename) { - FilePath file_path(FilePath::GenerateUniqueFileName(testdata_path_, - FilePath("unique"), "txt")); - EXPECT_EQ(unique_file0_.string(), file_path.string()); - EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file not there - - testdata_path_.CreateDirectoriesRecursively(); - EXPECT_FALSE(file_path.FileOrDirectoryExists()); // file still not there - CreateTextFile(file_path.c_str()); - EXPECT_TRUE(file_path.FileOrDirectoryExists()); - - FilePath file_path2(FilePath::GenerateUniqueFileName(testdata_path_, - FilePath("unique"), "txt")); - EXPECT_EQ(unique_file1_.string(), file_path2.string()); - EXPECT_FALSE(file_path2.FileOrDirectoryExists()); // file not there - CreateTextFile(file_path2.c_str()); - EXPECT_TRUE(file_path2.FileOrDirectoryExists()); -} - -TEST_F(DirectoryCreationTest, CreateDirectoriesFail) { - // force a failure by putting a file where we will try to create a directory. - CreateTextFile(testdata_file_.c_str()); - EXPECT_TRUE(testdata_file_.FileOrDirectoryExists()); - EXPECT_FALSE(testdata_file_.DirectoryExists()); - EXPECT_FALSE(testdata_file_.CreateDirectoriesRecursively()); -} - -TEST(NoDirectoryCreationTest, CreateNoDirectoriesForDefaultXmlFile) { - const FilePath test_detail_xml("test_detail.xml"); - EXPECT_FALSE(test_detail_xml.CreateDirectoriesRecursively()); -} - -TEST(FilePathTest, DefaultConstructor) { - FilePath fp; - EXPECT_EQ("", fp.string()); -} - -TEST(FilePathTest, CharAndCopyConstructors) { - const FilePath fp("spicy"); - EXPECT_EQ("spicy", fp.string()); - - const FilePath fp_copy(fp); - EXPECT_EQ("spicy", fp_copy.string()); -} - -TEST(FilePathTest, StringConstructor) { - const FilePath fp(std::string("cider")); - EXPECT_EQ("cider", fp.string()); -} - -TEST(FilePathTest, Set) { - const FilePath apple("apple"); - FilePath mac("mac"); - mac.Set(apple); // Implement Set() since overloading operator= is forbidden. - EXPECT_EQ("apple", mac.string()); - EXPECT_EQ("apple", apple.string()); -} - -TEST(FilePathTest, ToString) { - const FilePath file("drink"); - EXPECT_EQ("drink", file.string()); -} - -TEST(FilePathTest, RemoveExtension) { - EXPECT_EQ("app", FilePath("app.cc").RemoveExtension("cc").string()); - EXPECT_EQ("app", FilePath("app.exe").RemoveExtension("exe").string()); - EXPECT_EQ("APP", FilePath("APP.EXE").RemoveExtension("exe").string()); -} - -TEST(FilePathTest, RemoveExtensionWhenThereIsNoExtension) { - EXPECT_EQ("app", FilePath("app").RemoveExtension("exe").string()); -} - -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) { - EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath()); - EXPECT_FALSE(FilePath("").IsAbsolutePath()); -#if GTEST_OS_WINDOWS - 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_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/googletest/test/gtest-linked_ptr_test.cc b/googletest/test/gtest-linked_ptr_test.cc deleted file mode 100644 index 6fcf512..0000000 --- a/googletest/test/gtest-linked_ptr_test.cc +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2003, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Authors: Dan Egnor (egnor@google.com) -// Ported to Windows: Vadim Berman (vadimb@google.com) - -#include "gtest/internal/gtest-linked_ptr.h" - -#include -#include "gtest/gtest.h" - -namespace { - -using testing::Message; -using testing::internal::linked_ptr; - -int num; -Message* history = NULL; - -// Class which tracks allocation/deallocation -class A { - public: - A(): mynum(num++) { *history << "A" << mynum << " ctor\n"; } - virtual ~A() { *history << "A" << mynum << " dtor\n"; } - virtual void Use() { *history << "A" << mynum << " use\n"; } - protected: - int mynum; -}; - -// Subclass -class B : public A { - public: - B() { *history << "B" << mynum << " ctor\n"; } - ~B() { *history << "B" << mynum << " dtor\n"; } - virtual void Use() { *history << "B" << mynum << " use\n"; } -}; - -class LinkedPtrTest : public testing::Test { - public: - LinkedPtrTest() { - num = 0; - history = new Message; - } - - virtual ~LinkedPtrTest() { - delete history; - history = NULL; - } -}; - -TEST_F(LinkedPtrTest, GeneralTest) { - { - linked_ptr a0, a1, a2; - // Use explicit function call notation here to suppress self-assign warning. - a0.operator=(a0); - a1 = a2; - ASSERT_EQ(a0.get(), static_cast(NULL)); - ASSERT_EQ(a1.get(), static_cast(NULL)); - ASSERT_EQ(a2.get(), static_cast(NULL)); - ASSERT_TRUE(a0 == NULL); - ASSERT_TRUE(a1 == NULL); - ASSERT_TRUE(a2 == NULL); - - { - linked_ptr a3(new A); - a0 = a3; - ASSERT_TRUE(a0 == a3); - ASSERT_TRUE(a0 != NULL); - ASSERT_TRUE(a0.get() == a3); - ASSERT_TRUE(a0 == a3.get()); - linked_ptr a4(a0); - a1 = a4; - linked_ptr a5(new A); - ASSERT_TRUE(a5.get() != a3); - ASSERT_TRUE(a5 != a3.get()); - a2 = a5; - linked_ptr b0(new B); - linked_ptr a6(b0); - ASSERT_TRUE(b0 == a6); - ASSERT_TRUE(a6 == b0); - ASSERT_TRUE(b0 != NULL); - a5 = b0; - a5 = b0; - a3->Use(); - a4->Use(); - a5->Use(); - a6->Use(); - b0->Use(); - (*b0).Use(); - b0.get()->Use(); - } - - a0->Use(); - a1->Use(); - a2->Use(); - - a1 = a2; - a2.reset(new A); - a0.reset(); - - linked_ptr a7; - } - - ASSERT_STREQ( - "A0 ctor\n" - "A1 ctor\n" - "A2 ctor\n" - "B2 ctor\n" - "A0 use\n" - "A0 use\n" - "B2 use\n" - "B2 use\n" - "B2 use\n" - "B2 use\n" - "B2 use\n" - "B2 dtor\n" - "A2 dtor\n" - "A0 use\n" - "A0 use\n" - "A1 use\n" - "A3 ctor\n" - "A0 dtor\n" - "A3 dtor\n" - "A1 dtor\n", - history->GetString().c_str()); -} - -} // Unnamed namespace diff --git a/googletest/test/gtest-listener_test.cc b/googletest/test/gtest-listener_test.cc deleted file mode 100644 index 639529c..0000000 --- a/googletest/test/gtest-listener_test.cc +++ /dev/null @@ -1,311 +0,0 @@ -// Copyright 2009 Google Inc. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: vladl@google.com (Vlad Losev) -// -// The Google C++ Testing and Mocking Framework (Google Test) -// -// This file verifies Google Test event listeners receive events at the -// right times. - -#include "gtest/gtest.h" -#include - -using ::testing::AddGlobalTestEnvironment; -using ::testing::Environment; -using ::testing::InitGoogleTest; -using ::testing::Test; -using ::testing::TestCase; -using ::testing::TestEventListener; -using ::testing::TestInfo; -using ::testing::TestPartResult; -using ::testing::UnitTest; - -// Used by tests to register their events. -std::vector* g_events = NULL; - -namespace testing { -namespace internal { - -class EventRecordingListener : public TestEventListener { - public: - explicit EventRecordingListener(const char* name) : name_(name) {} - - protected: - virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) { - g_events->push_back(GetFullMethodName("OnTestProgramStart")); - } - - virtual void OnTestIterationStart(const UnitTest& /*unit_test*/, - int iteration) { - Message message; - message << GetFullMethodName("OnTestIterationStart") - << "(" << iteration << ")"; - g_events->push_back(message.GetString()); - } - - virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) { - g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpStart")); - } - - virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) { - g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd")); - } - - virtual void OnTestCaseStart(const TestCase& /*test_case*/) { - g_events->push_back(GetFullMethodName("OnTestCaseStart")); - } - - virtual void OnTestStart(const TestInfo& /*test_info*/) { - g_events->push_back(GetFullMethodName("OnTestStart")); - } - - virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) { - g_events->push_back(GetFullMethodName("OnTestPartResult")); - } - - virtual void OnTestEnd(const TestInfo& /*test_info*/) { - g_events->push_back(GetFullMethodName("OnTestEnd")); - } - - virtual void OnTestCaseEnd(const TestCase& /*test_case*/) { - g_events->push_back(GetFullMethodName("OnTestCaseEnd")); - } - - virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) { - g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart")); - } - - virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) { - g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownEnd")); - } - - virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/, - int iteration) { - Message message; - message << GetFullMethodName("OnTestIterationEnd") - << "(" << iteration << ")"; - g_events->push_back(message.GetString()); - } - - virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) { - g_events->push_back(GetFullMethodName("OnTestProgramEnd")); - } - - private: - std::string GetFullMethodName(const char* name) { - return name_ + "." + name; - } - - std::string name_; -}; - -class EnvironmentInvocationCatcher : public Environment { - protected: - virtual void SetUp() { - g_events->push_back("Environment::SetUp"); - } - - virtual void TearDown() { - g_events->push_back("Environment::TearDown"); - } -}; - -class ListenerTest : public Test { - protected: - static void SetUpTestCase() { - g_events->push_back("ListenerTest::SetUpTestCase"); - } - - static void TearDownTestCase() { - g_events->push_back("ListenerTest::TearDownTestCase"); - } - - virtual void SetUp() { - g_events->push_back("ListenerTest::SetUp"); - } - - virtual void TearDown() { - g_events->push_back("ListenerTest::TearDown"); - } -}; - -TEST_F(ListenerTest, DoesFoo) { - // Test execution order within a test case is not guaranteed so we are not - // recording the test name. - g_events->push_back("ListenerTest::* Test Body"); - SUCCEED(); // Triggers OnTestPartResult. -} - -TEST_F(ListenerTest, DoesBar) { - g_events->push_back("ListenerTest::* Test Body"); - SUCCEED(); // Triggers OnTestPartResult. -} - -} // namespace internal - -} // namespace testing - -using ::testing::internal::EnvironmentInvocationCatcher; -using ::testing::internal::EventRecordingListener; - -void VerifyResults(const std::vector& data, - const char* const* expected_data, - size_t expected_data_size) { - const size_t actual_size = data.size(); - // If the following assertion fails, a new entry will be appended to - // data. Hence we save data.size() first. - EXPECT_EQ(expected_data_size, actual_size); - - // Compares the common prefix. - const size_t shorter_size = expected_data_size <= actual_size ? - expected_data_size : actual_size; - size_t i = 0; - for (; i < shorter_size; ++i) { - ASSERT_STREQ(expected_data[i], data[i].c_str()) - << "at position " << i; - } - - // Prints extra elements in the actual data. - for (; i < actual_size; ++i) { - printf(" Actual event #%lu: %s\n", - static_cast(i), data[i].c_str()); - } -} - -int main(int argc, char **argv) { - std::vector events; - g_events = &events; - InitGoogleTest(&argc, argv); - - UnitTest::GetInstance()->listeners().Append( - new EventRecordingListener("1st")); - UnitTest::GetInstance()->listeners().Append( - new EventRecordingListener("2nd")); - - AddGlobalTestEnvironment(new EnvironmentInvocationCatcher); - - GTEST_CHECK_(events.size() == 0) - << "AddGlobalTestEnvironment should not generate any events itself."; - - ::testing::GTEST_FLAG(repeat) = 2; - int ret_val = RUN_ALL_TESTS(); - - const char* const expected_events[] = { - "1st.OnTestProgramStart", - "2nd.OnTestProgramStart", - "1st.OnTestIterationStart(0)", - "2nd.OnTestIterationStart(0)", - "1st.OnEnvironmentsSetUpStart", - "2nd.OnEnvironmentsSetUpStart", - "Environment::SetUp", - "2nd.OnEnvironmentsSetUpEnd", - "1st.OnEnvironmentsSetUpEnd", - "1st.OnTestCaseStart", - "2nd.OnTestCaseStart", - "ListenerTest::SetUpTestCase", - "1st.OnTestStart", - "2nd.OnTestStart", - "ListenerTest::SetUp", - "ListenerTest::* Test Body", - "1st.OnTestPartResult", - "2nd.OnTestPartResult", - "ListenerTest::TearDown", - "2nd.OnTestEnd", - "1st.OnTestEnd", - "1st.OnTestStart", - "2nd.OnTestStart", - "ListenerTest::SetUp", - "ListenerTest::* Test Body", - "1st.OnTestPartResult", - "2nd.OnTestPartResult", - "ListenerTest::TearDown", - "2nd.OnTestEnd", - "1st.OnTestEnd", - "ListenerTest::TearDownTestCase", - "2nd.OnTestCaseEnd", - "1st.OnTestCaseEnd", - "1st.OnEnvironmentsTearDownStart", - "2nd.OnEnvironmentsTearDownStart", - "Environment::TearDown", - "2nd.OnEnvironmentsTearDownEnd", - "1st.OnEnvironmentsTearDownEnd", - "2nd.OnTestIterationEnd(0)", - "1st.OnTestIterationEnd(0)", - "1st.OnTestIterationStart(1)", - "2nd.OnTestIterationStart(1)", - "1st.OnEnvironmentsSetUpStart", - "2nd.OnEnvironmentsSetUpStart", - "Environment::SetUp", - "2nd.OnEnvironmentsSetUpEnd", - "1st.OnEnvironmentsSetUpEnd", - "1st.OnTestCaseStart", - "2nd.OnTestCaseStart", - "ListenerTest::SetUpTestCase", - "1st.OnTestStart", - "2nd.OnTestStart", - "ListenerTest::SetUp", - "ListenerTest::* Test Body", - "1st.OnTestPartResult", - "2nd.OnTestPartResult", - "ListenerTest::TearDown", - "2nd.OnTestEnd", - "1st.OnTestEnd", - "1st.OnTestStart", - "2nd.OnTestStart", - "ListenerTest::SetUp", - "ListenerTest::* Test Body", - "1st.OnTestPartResult", - "2nd.OnTestPartResult", - "ListenerTest::TearDown", - "2nd.OnTestEnd", - "1st.OnTestEnd", - "ListenerTest::TearDownTestCase", - "2nd.OnTestCaseEnd", - "1st.OnTestCaseEnd", - "1st.OnEnvironmentsTearDownStart", - "2nd.OnEnvironmentsTearDownStart", - "Environment::TearDown", - "2nd.OnEnvironmentsTearDownEnd", - "1st.OnEnvironmentsTearDownEnd", - "2nd.OnTestIterationEnd(1)", - "1st.OnTestIterationEnd(1)", - "2nd.OnTestProgramEnd", - "1st.OnTestProgramEnd" - }; - VerifyResults(events, - expected_events, - sizeof(expected_events)/sizeof(expected_events[0])); - - // We need to check manually for ad hoc test failures that happen after - // RUN_ALL_TESTS finishes. - if (UnitTest::GetInstance()->Failed()) - ret_val = 1; - - return ret_val; -} -- cgit v0.12