gtest-options_test.cc
Go to the documentation of this file.
00001 // Copyright 2008, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Authors: keith.ray@gmail.com (Keith Ray)
00031 //
00032 // Google Test UnitTestOptions tests
00033 //
00034 // This file tests classes and functions used internally by
00035 // Google Test.  They are subject to change without notice.
00036 //
00037 // This file is #included from gtest.cc, to avoid changing build or
00038 // make-files on Windows and other platforms. Do not #include this file
00039 // anywhere else!
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 // Indicates that this translation unit is part of Google Test's
00050 // implementation.  It must come before gtest-internal-inl.h is
00051 // included, or there will be a compiler error.  This trick is to
00052 // prevent a user from accidentally including gtest-internal-inl.h in
00053 // his code.
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 // Turns the given relative path into an absolute path.
00063 FilePath GetAbsolutePathOf(const FilePath& relative_path) {
00064   return FilePath::ConcatPaths(FilePath::GetCurrentDir(), relative_path);
00065 }
00066 
00067 // Testing UnitTestOptions::GetOutputFormat/GetOutputFile.
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   // TODO(wan@google.com): remove the hard-coded "lt-" prefix when
00116   //   Chandler Carruth's libtool replacement is ready.
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     // This will make the test fail if run from the root directory.
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 }  // namespace
00214 }  // namespace internal
00215 }  // namespace testing


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:03