Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
gtest-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//
31// Google Test UnitTestOptions tests
32//
33// This file tests classes and functions used internally by
34// Google Test. They are subject to change without notice.
35//
36// This file is #included from gtest.cc, to avoid changing build or
37// make-files on Windows and other platforms. Do not #include this file
38// anywhere else!
39
40#include "gtest/gtest.h"
41
42#if GTEST_OS_WINDOWS_MOBILE
43# include <windows.h>
44#elif GTEST_OS_WINDOWS
45# include <direct.h>
46#endif // GTEST_OS_WINDOWS_MOBILE
47
49
50namespace testing {
51namespace internal {
52namespace {
53
54// Turns the given relative path into an absolute path.
55FilePath GetAbsolutePathOf(const FilePath& relative_path) {
56 return FilePath::ConcatPaths(FilePath::GetCurrentDir(), relative_path);
57}
58
59// Testing UnitTestOptions::GetOutputFormat/GetOutputFile.
60
61TEST(XmlOutputTest, GetOutputFormatDefault) {
62 GTEST_FLAG(output) = "";
64}
65
66TEST(XmlOutputTest, GetOutputFormat) {
67 GTEST_FLAG(output) = "xml:filename";
69}
70
71TEST(XmlOutputTest, GetOutputFileDefault) {
72 GTEST_FLAG(output) = "";
73 EXPECT_EQ(GetAbsolutePathOf(FilePath("test_detail.xml")).string(),
75}
76
77TEST(XmlOutputTest, GetOutputFileSingleFile) {
78 GTEST_FLAG(output) = "xml:filename.abc";
79 EXPECT_EQ(GetAbsolutePathOf(FilePath("filename.abc")).string(),
81}
82
83TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
84 GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
85 const std::string expected_output_file =
86 GetAbsolutePathOf(
87 FilePath(std::string("path") + GTEST_PATH_SEP_ +
88 GetCurrentExecutableName().string() + ".xml")).string();
89 const std::string& output_file =
91#if GTEST_OS_WINDOWS
92 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
93#else
94 EXPECT_EQ(expected_output_file, output_file.c_str());
95#endif
96}
97
98TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
99 const std::string exe_str = GetCurrentExecutableName().string();
100#if GTEST_OS_WINDOWS
101 const bool success =
102 _strcmpi("gtest-options_test", exe_str.c_str()) == 0 ||
103 _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
104 _strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
105 _strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
106#elif GTEST_OS_FUCHSIA
107 const bool success = exe_str == "app";
108#else
109 // TODO(wan@google.com): remove the hard-coded "lt-" prefix when
110 // Chandler Carruth's libtool replacement is ready.
111 const bool success =
112 exe_str == "gtest-options_test" ||
113 exe_str == "gtest_all_test" ||
114 exe_str == "lt-gtest_all_test" ||
115 exe_str == "gtest_dll_test";
116#endif // GTEST_OS_WINDOWS
117 if (!success)
118 FAIL() << "GetCurrentExecutableName() returns " << exe_str;
119}
120
121#if !GTEST_OS_FUCHSIA
122
123class XmlOutputChangeDirTest : public Test {
124 protected:
125 virtual void SetUp() {
127 posix::ChDir("..");
128 // This will make the test fail if run from the root directory.
131 }
132
133 virtual void TearDown() {
134 posix::ChDir(original_working_dir_.string().c_str());
135 }
136
138};
139
140TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) {
141 GTEST_FLAG(output) = "";
143 FilePath("test_detail.xml")).string(),
145}
146
147TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) {
148 GTEST_FLAG(output) = "xml";
150 FilePath("test_detail.xml")).string(),
152}
153
154TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
155 GTEST_FLAG(output) = "xml:filename.abc";
157 FilePath("filename.abc")).string(),
159}
160
161TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
162 GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
163 const std::string expected_output_file =
166 FilePath(std::string("path") + GTEST_PATH_SEP_ +
167 GetCurrentExecutableName().string() + ".xml")).string();
168 const std::string& output_file =
170#if GTEST_OS_WINDOWS
171 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
172#else
173 EXPECT_EQ(expected_output_file, output_file.c_str());
174#endif
175}
176
177TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
178#if GTEST_OS_WINDOWS
179 GTEST_FLAG(output) = "xml:c:\\tmp\\filename.abc";
180 EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(),
182#else
183 GTEST_FLAG(output) ="xml:/tmp/filename.abc";
184 EXPECT_EQ(FilePath("/tmp/filename.abc").string(),
186#endif
187}
188
189TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
190#if GTEST_OS_WINDOWS
191 const std::string path = "c:\\tmp\\";
192#else
193 const std::string path = "/tmp/";
194#endif
195
196 GTEST_FLAG(output) = "xml:" + path;
197 const std::string expected_output_file =
198 path + GetCurrentExecutableName().string() + ".xml";
199 const std::string& output_file =
201
202#if GTEST_OS_WINDOWS
203 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
204#else
205 EXPECT_EQ(expected_output_file, output_file.c_str());
206#endif
207}
208
209#endif // !GTEST_OS_FUCHSIA
210
211} // namespace
212} // namespace internal
213} // namespace testing
const std::string & string() const
static FilePath GetCurrentDir()
static FilePath ConcatPaths(const FilePath &directory, const FilePath &relative_path)
static std::string GetAbsolutePathToOutputFile()
Definition gtest.cc:438
static std::string GetOutputFormat()
Definition gtest.cc:426
FilePath original_working_dir_
#define GTEST_FLAG(name)
#define GTEST_PATH_SEP_
#define TEST_F(test_fixture, test_name)
Definition gtest.h:2304
#define FAIL()
Definition gtest.h:1858
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954
#define EXPECT_NE(val1, val2)
Definition gtest.h:1958
#define EXPECT_STRCASEEQ(s1, s2)
Definition gtest.h:2031
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:2027
#define TEST(test_case_name, test_name)
Definition gtest.h:2275
int ChDir(const char *dir)
GTEST_API_ FilePath GetCurrentExecutableName()
Definition gtest.cc:411