cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
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 <string>
40
41#include "gtest/gtest.h"
42
43#ifdef GTEST_OS_WINDOWS_MOBILE
44#include <windows.h>
45#elif defined(GTEST_OS_WINDOWS)
46#include <direct.h>
47#elif defined(GTEST_OS_OS2)
48// For strcasecmp on OS/2
49#include <strings.h>
50#endif // GTEST_OS_WINDOWS_MOBILE
51
53
54namespace testing {
55namespace internal {
56namespace {
57
58// Turns the given relative path into an absolute path.
59FilePath GetAbsolutePathOf(const FilePath& relative_path) {
60 return FilePath::ConcatPaths(FilePath::GetCurrentDir(), relative_path);
61}
62
63// Testing UnitTestOptions::GetOutputFormat/GetOutputFile.
64
65TEST(XmlOutputTest, GetOutputFormatDefault) {
66 GTEST_FLAG_SET(output, "");
68}
69
70TEST(XmlOutputTest, GetOutputFormat) {
71 GTEST_FLAG_SET(output, "xml:filename");
73}
74
75TEST(XmlOutputTest, GetOutputFileDefault) {
76 GTEST_FLAG_SET(output, "");
77 EXPECT_EQ(GetAbsolutePathOf(FilePath("test_detail.xml")).string(),
79}
80
81TEST(XmlOutputTest, GetOutputFileSingleFile) {
82 GTEST_FLAG_SET(output, "xml:filename.abc");
83 EXPECT_EQ(GetAbsolutePathOf(FilePath("filename.abc")).string(),
85}
86
87TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
88 GTEST_FLAG_SET(output, "xml:path" GTEST_PATH_SEP_);
89 const std::string expected_output_file =
90 GetAbsolutePathOf(FilePath(std::string("path") + GTEST_PATH_SEP_ +
91 GetCurrentExecutableName().string() + ".xml"))
92 .string();
93 const std::string& output_file =
95#ifdef GTEST_OS_WINDOWS
96 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
97#else
98 EXPECT_EQ(expected_output_file, output_file.c_str());
99#endif
100}
101
102TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
103 const std::string exe_str = GetCurrentExecutableName().string();
104#ifdef GTEST_OS_WINDOWS
105 const bool success =
106 _strcmpi("googletest-options-test", exe_str.c_str()) == 0 ||
107 _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
108 _strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
109 _strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
110#elif defined(GTEST_OS_OS2)
111 const bool success =
112 strcasecmp("googletest-options-test", exe_str.c_str()) == 0 ||
113 strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 ||
114 strcasecmp("gtest_all_test", exe_str.c_str()) == 0 ||
115 strcasecmp("gtest_dll_test", exe_str.c_str()) == 0;
116#elif defined(GTEST_OS_FUCHSIA)
117 const bool success = exe_str == "app";
118#else
119 const bool success =
120 exe_str == "googletest-options-test" || exe_str == "gtest_all_test" ||
121 exe_str == "lt-gtest_all_test" || exe_str == "gtest_dll_test";
122#endif // GTEST_OS_WINDOWS
123 if (!success) FAIL() << "GetCurrentExecutableName() returns " << exe_str;
124}
125
126#ifndef GTEST_OS_FUCHSIA
127
128class XmlOutputChangeDirTest : public Test {
129 protected:
130 void SetUp() override {
131 original_working_dir_ = FilePath::GetCurrentDir();
132 posix::ChDir("..");
133 // This will make the test fail if run from the root directory.
135 FilePath::GetCurrentDir().string());
136 }
137
138 void TearDown() override {
139 posix::ChDir(original_working_dir_.string().c_str());
140 }
141
143};
144
145TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) {
147 EXPECT_EQ(
148 FilePath::ConcatPaths(original_working_dir_, FilePath("test_detail.xml"))
149 .string(),
151}
152
153TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) {
154 GTEST_FLAG_SET(output, "xml");
155 EXPECT_EQ(
156 FilePath::ConcatPaths(original_working_dir_, FilePath("test_detail.xml"))
157 .string(),
159}
160
161TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
162 GTEST_FLAG_SET(output, "xml:filename.abc");
163 EXPECT_EQ(
164 FilePath::ConcatPaths(original_working_dir_, FilePath("filename.abc"))
165 .string(),
167}
168
169TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
170 GTEST_FLAG_SET(output, "xml:path" GTEST_PATH_SEP_);
171 const std::string expected_output_file =
172 FilePath::ConcatPaths(
174 FilePath(std::string("path") + GTEST_PATH_SEP_ +
175 GetCurrentExecutableName().string() + ".xml"))
176 .string();
177 const std::string& output_file =
179#ifdef GTEST_OS_WINDOWS
180 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
181#else
182 EXPECT_EQ(expected_output_file, output_file.c_str());
183#endif
184}
185
186TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
187#ifdef GTEST_OS_WINDOWS
188 GTEST_FLAG_SET(output, "xml:c:\\tmp\\filename.abc");
189 EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(),
191#else
192 GTEST_FLAG_SET(output, "xml:/tmp/filename.abc");
193 EXPECT_EQ(FilePath("/tmp/filename.abc").string(),
195#endif
196}
197
198TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
199#ifdef GTEST_OS_WINDOWS
200 const std::string path = "c:\\tmp\\";
201#else
202 const std::string path = "/tmp/";
203#endif
204
205 GTEST_FLAG_SET(output, "xml:" + path);
206 const std::string expected_output_file =
207 path + GetCurrentExecutableName().string() + ".xml";
208 const std::string& output_file =
210
211#ifdef GTEST_OS_WINDOWS
212 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
213#else
214 EXPECT_EQ(expected_output_file, output_file.c_str());
215#endif
216}
217
218#endif // !GTEST_OS_FUCHSIA
219
220} // namespace
221} // namespace internal
222} // namespace testing
static std::string GetAbsolutePathToOutputFile()
static std::string GetOutputFormat()
Definition gtest.cc:654
FilePath original_working_dir_
Definition googletest-options-test.cc:142
#define GTEST_FLAG_SET(name, value)
Definition gtest-port.h:2294
#define GTEST_PATH_SEP_
Definition gtest-port.h:1918
#define TEST_F(test_fixture, test_name)
Definition gtest.h:2208
#define FAIL()
Definition gtest.h:1754
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1868
#define EXPECT_NE(val1, val2)
Definition gtest.h:1870
#define EXPECT_STRCASEEQ(s1, s2)
Definition gtest.h:1941
#define TEST(test_suite_name, test_name)
Definition gtest.h:2176
#define EXPECT_STREQ(s1, s2)
Definition gtest.h:1937
output
Definition gmock_output_test.py:182
int ChDir(const char *dir)
Definition gtest-port.h:2087
Definition gmock-actions.h:151