Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "gtest/gtest.h"
00042
00043 #if GTEST_OS_WINDOWS_MOBILE
00044 # include <windows.h>
00045 #elif GTEST_OS_WINDOWS
00046 # include <direct.h>
00047 #endif // GTEST_OS_WINDOWS_MOBILE
00048
00049
00050
00051
00052
00053
00054 #define GTEST_IMPLEMENTATION_ 1
00055 #include "src/gtest-internal-inl.h"
00056 #undef GTEST_IMPLEMENTATION_
00057
00058 namespace testing {
00059 namespace internal {
00060 namespace {
00061
00062
00063 FilePath GetAbsolutePathOf(const FilePath& relative_path) {
00064 return FilePath::ConcatPaths(FilePath::GetCurrentDir(), relative_path);
00065 }
00066
00067
00068
00069 TEST(XmlOutputTest, GetOutputFormatDefault) {
00070 GTEST_FLAG(output) = "";
00071 EXPECT_STREQ("", UnitTestOptions::GetOutputFormat().c_str());
00072 }
00073
00074 TEST(XmlOutputTest, GetOutputFormat) {
00075 GTEST_FLAG(output) = "xml:filename";
00076 EXPECT_STREQ("xml", UnitTestOptions::GetOutputFormat().c_str());
00077 }
00078
00079 TEST(XmlOutputTest, GetOutputFileDefault) {
00080 GTEST_FLAG(output) = "";
00081 EXPECT_EQ(GetAbsolutePathOf(FilePath("test_detail.xml")).string(),
00082 UnitTestOptions::GetAbsolutePathToOutputFile());
00083 }
00084
00085 TEST(XmlOutputTest, GetOutputFileSingleFile) {
00086 GTEST_FLAG(output) = "xml:filename.abc";
00087 EXPECT_EQ(GetAbsolutePathOf(FilePath("filename.abc")).string(),
00088 UnitTestOptions::GetAbsolutePathToOutputFile());
00089 }
00090
00091 TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
00092 GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
00093 const std::string expected_output_file =
00094 GetAbsolutePathOf(
00095 FilePath(std::string("path") + GTEST_PATH_SEP_ +
00096 GetCurrentExecutableName().string() + ".xml")).string();
00097 const std::string& output_file =
00098 UnitTestOptions::GetAbsolutePathToOutputFile();
00099 #if GTEST_OS_WINDOWS
00100 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
00101 #else
00102 EXPECT_EQ(expected_output_file, output_file.c_str());
00103 #endif
00104 }
00105
00106 TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
00107 const std::string exe_str = GetCurrentExecutableName().string();
00108 #if GTEST_OS_WINDOWS
00109 const bool success =
00110 _strcmpi("gtest-options_test", exe_str.c_str()) == 0 ||
00111 _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
00112 _strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
00113 _strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
00114 #else
00115
00116
00117 const bool success =
00118 exe_str == "gtest-options_test" ||
00119 exe_str == "gtest_all_test" ||
00120 exe_str == "lt-gtest_all_test" ||
00121 exe_str == "gtest_dll_test";
00122 #endif // GTEST_OS_WINDOWS
00123 if (!success)
00124 FAIL() << "GetCurrentExecutableName() returns " << exe_str;
00125 }
00126
00127 class XmlOutputChangeDirTest : public Test {
00128 protected:
00129 virtual void SetUp() {
00130 original_working_dir_ = FilePath::GetCurrentDir();
00131 posix::ChDir("..");
00132
00133 EXPECT_NE(original_working_dir_.string(),
00134 FilePath::GetCurrentDir().string());
00135 }
00136
00137 virtual void TearDown() {
00138 posix::ChDir(original_working_dir_.string().c_str());
00139 }
00140
00141 FilePath original_working_dir_;
00142 };
00143
00144 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) {
00145 GTEST_FLAG(output) = "";
00146 EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_,
00147 FilePath("test_detail.xml")).string(),
00148 UnitTestOptions::GetAbsolutePathToOutputFile());
00149 }
00150
00151 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) {
00152 GTEST_FLAG(output) = "xml";
00153 EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_,
00154 FilePath("test_detail.xml")).string(),
00155 UnitTestOptions::GetAbsolutePathToOutputFile());
00156 }
00157
00158 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
00159 GTEST_FLAG(output) = "xml:filename.abc";
00160 EXPECT_EQ(FilePath::ConcatPaths(original_working_dir_,
00161 FilePath("filename.abc")).string(),
00162 UnitTestOptions::GetAbsolutePathToOutputFile());
00163 }
00164
00165 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
00166 GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
00167 const std::string expected_output_file =
00168 FilePath::ConcatPaths(
00169 original_working_dir_,
00170 FilePath(std::string("path") + GTEST_PATH_SEP_ +
00171 GetCurrentExecutableName().string() + ".xml")).string();
00172 const std::string& output_file =
00173 UnitTestOptions::GetAbsolutePathToOutputFile();
00174 #if GTEST_OS_WINDOWS
00175 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
00176 #else
00177 EXPECT_EQ(expected_output_file, output_file.c_str());
00178 #endif
00179 }
00180
00181 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
00182 #if GTEST_OS_WINDOWS
00183 GTEST_FLAG(output) = "xml:c:\\tmp\\filename.abc";
00184 EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(),
00185 UnitTestOptions::GetAbsolutePathToOutputFile());
00186 #else
00187 GTEST_FLAG(output) ="xml:/tmp/filename.abc";
00188 EXPECT_EQ(FilePath("/tmp/filename.abc").string(),
00189 UnitTestOptions::GetAbsolutePathToOutputFile());
00190 #endif
00191 }
00192
00193 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
00194 #if GTEST_OS_WINDOWS
00195 const std::string path = "c:\\tmp\\";
00196 #else
00197 const std::string path = "/tmp/";
00198 #endif
00199
00200 GTEST_FLAG(output) = "xml:" + path;
00201 const std::string expected_output_file =
00202 path + GetCurrentExecutableName().string() + ".xml";
00203 const std::string& output_file =
00204 UnitTestOptions::GetAbsolutePathToOutputFile();
00205
00206 #if GTEST_OS_WINDOWS
00207 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
00208 #else
00209 EXPECT_EQ(expected_output_file, output_file.c_str());
00210 #endif
00211 }
00212
00213 }
00214 }
00215 }