bloaty/third_party/googletest/googletest/test/googletest-options-test.cc
Go to the documentation of this file.
1 // Copyright 2008, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Google Test UnitTestOptions tests
31 //
32 // This file tests classes and functions used internally by
33 // Google Test. They are subject to change without notice.
34 //
35 // This file is #included from gtest.cc, to avoid changing build or
36 // make-files on Windows and other platforms. Do not #include this file
37 // anywhere else!
38 
39 #include "gtest/gtest.h"
40 
41 #if GTEST_OS_WINDOWS_MOBILE
42 # include <windows.h>
43 #elif GTEST_OS_WINDOWS
44 # include <direct.h>
45 #endif // GTEST_OS_WINDOWS_MOBILE
46 
47 #include "src/gtest-internal-inl.h"
48 
49 namespace testing {
50 namespace internal {
51 namespace {
52 
53 // Turns the given relative path into an absolute path.
54 FilePath GetAbsolutePathOf(const FilePath& relative_path) {
55  return FilePath::ConcatPaths(FilePath::GetCurrentDir(), relative_path);
56 }
57 
58 // Testing UnitTestOptions::GetOutputFormat/GetOutputFile.
59 
60 TEST(XmlOutputTest, GetOutputFormatDefault) {
61  GTEST_FLAG(output) = "";
63 }
64 
65 TEST(XmlOutputTest, GetOutputFormat) {
66  GTEST_FLAG(output) = "xml:filename";
68 }
69 
70 TEST(XmlOutputTest, GetOutputFileDefault) {
71  GTEST_FLAG(output) = "";
72  EXPECT_EQ(GetAbsolutePathOf(FilePath("test_detail.xml")).string(),
74 }
75 
76 TEST(XmlOutputTest, GetOutputFileSingleFile) {
77  GTEST_FLAG(output) = "xml:filename.abc";
78  EXPECT_EQ(GetAbsolutePathOf(FilePath("filename.abc")).string(),
80 }
81 
82 TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
83  GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
84  const std::string expected_output_file =
85  GetAbsolutePathOf(
87  GetCurrentExecutableName().string() + ".xml")).string();
88  const std::string& output_file =
90 #if GTEST_OS_WINDOWS
91  EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
92 #else
93  EXPECT_EQ(expected_output_file, output_file.c_str());
94 #endif
95 }
96 
97 TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
98  const std::string exe_str = GetCurrentExecutableName().string();
99 #if GTEST_OS_WINDOWS
100  const bool success =
101  _strcmpi("googletest-options-test", exe_str.c_str()) == 0 ||
102  _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
103  _strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
104  _strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
105 #elif GTEST_OS_OS2
106  const bool success =
107  strcasecmp("googletest-options-test", exe_str.c_str()) == 0 ||
108  strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 ||
109  strcasecmp("gtest_all_test", exe_str.c_str()) == 0 ||
110  strcasecmp("gtest_dll_test", exe_str.c_str()) == 0;
111 #elif GTEST_OS_FUCHSIA
112  const bool success = exe_str == "app";
113 #else
114  const bool success =
115  exe_str == "googletest-options-test" ||
116  exe_str == "gtest_all_test" ||
117  exe_str == "lt-gtest_all_test" ||
118  exe_str == "gtest_dll_test";
119 #endif // GTEST_OS_WINDOWS
120  if (!success)
121  FAIL() << "GetCurrentExecutableName() returns " << exe_str;
122 }
123 
124 #if !GTEST_OS_FUCHSIA
125 
126 class XmlOutputChangeDirTest : public Test {
127  protected:
128  void SetUp() override {
130  posix::ChDir("..");
131  // This will make the test fail if run from the root directory.
134  }
135 
136  void TearDown() override {
137  posix::ChDir(original_working_dir_.string().c_str());
138  }
139 
141 };
142 
143 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) {
144  GTEST_FLAG(output) = "";
146  FilePath("test_detail.xml")).string(),
148 }
149 
150 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) {
151  GTEST_FLAG(output) = "xml";
153  FilePath("test_detail.xml")).string(),
155 }
156 
157 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
158  GTEST_FLAG(output) = "xml:filename.abc";
160  FilePath("filename.abc")).string(),
162 }
163 
164 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
165  GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
166  const std::string expected_output_file =
170  GetCurrentExecutableName().string() + ".xml")).string();
171  const std::string& output_file =
173 #if GTEST_OS_WINDOWS
174  EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
175 #else
176  EXPECT_EQ(expected_output_file, output_file.c_str());
177 #endif
178 }
179 
180 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
181 #if GTEST_OS_WINDOWS
182  GTEST_FLAG(output) = "xml:c:\\tmp\\filename.abc";
183  EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(),
185 #else
186  GTEST_FLAG(output) ="xml:/tmp/filename.abc";
187  EXPECT_EQ(FilePath("/tmp/filename.abc").string(),
189 #endif
190 }
191 
192 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
193 #if GTEST_OS_WINDOWS
194  const std::string path = "c:\\tmp\\";
195 #else
196  const std::string path = "/tmp/";
197 #endif
198 
199  GTEST_FLAG(output) = "xml:" + path;
200  const std::string expected_output_file =
201  path + GetCurrentExecutableName().string() + ".xml";
202  const std::string& output_file =
204 
205 #if GTEST_OS_WINDOWS
206  EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
207 #else
208  EXPECT_EQ(expected_output_file, output_file.c_str());
209 #endif
210 }
211 
212 #endif // !GTEST_OS_FUCHSIA
213 
214 } // namespace
215 } // namespace internal
216 } // namespace testing
testing::internal::FilePath::string
const std::string & string() const
Definition: cares/cares/test/gmock-1.8.0/gtest/gtest.h:4342
testing
Definition: aws_request_signer_test.cc:25
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
testing::internal::FilePath::GetCurrentDir
static FilePath GetCurrentDir()
Definition: bloaty/third_party/googletest/googletest/src/gtest-filepath.cc:94
testing::internal::FilePath::ConcatPaths
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
Definition: bloaty/third_party/googletest/googletest/src/gtest-filepath.cc:195
testing::internal::posix::ChDir
int ChDir(const char *dir)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2031
check_documentation.path
path
Definition: check_documentation.py:57
original_working_dir_
FilePath original_working_dir_
Definition: bloaty/third_party/googletest/googletest/test/googletest-options-test.cc:140
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
GTEST_PATH_SEP_
#define GTEST_PATH_SEP_
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:1905
testing::internal::UnitTestOptions::GetAbsolutePathToOutputFile
static std::string GetAbsolutePathToOutputFile()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:455
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
EXPECT_NE
#define EXPECT_NE(val1, val2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2028
testing::internal::UnitTestOptions::GetOutputFormat
static std::string GetOutputFormat()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:444
FAIL
@ FAIL
Definition: call_creds.cc:42
testing::internal::TEST_F
TEST_F(ListenerTest, DoesFoo)
Definition: bloaty/third_party/googletest/googletest/test/googletest-listener-test.cc:226
testing::internal::GetCurrentExecutableName
FilePath GetCurrentExecutableName()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:429
EXPECT_STREQ
#define EXPECT_STREQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2095
GTEST_FLAG
#define GTEST_FLAG(name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2169
EXPECT_STRCASEEQ
#define EXPECT_STRCASEEQ(s1, s2)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2099
testing::internal::TEST
TEST(IsXDigitTest, WorksForNarrowAscii)
Definition: bloaty/third_party/googletest/googletest/test/googletest-port-test.cc:54
internal
Definition: benchmark/test/output_test_helper.cc:20
google::protobuf::compiler::objectivec::FilePath
string FilePath(const FileDescriptor *file)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc:404
Test
Definition: hpack_parser_test.cc:43
strcasecmp
#define strcasecmp(p1, p2)
Definition: ares_private.h:114


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:41