media/webrtc/trunk/testing/gtest/test/gtest-options_test.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright 2008, Google Inc.
michael@0 2 // All rights reserved.
michael@0 3 //
michael@0 4 // Redistribution and use in source and binary forms, with or without
michael@0 5 // modification, are permitted provided that the following conditions are
michael@0 6 // met:
michael@0 7 //
michael@0 8 // * Redistributions of source code must retain the above copyright
michael@0 9 // notice, this list of conditions and the following disclaimer.
michael@0 10 // * Redistributions in binary form must reproduce the above
michael@0 11 // copyright notice, this list of conditions and the following disclaimer
michael@0 12 // in the documentation and/or other materials provided with the
michael@0 13 // distribution.
michael@0 14 // * Neither the name of Google Inc. nor the names of its
michael@0 15 // contributors may be used to endorse or promote products derived from
michael@0 16 // this software without specific prior written permission.
michael@0 17 //
michael@0 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
michael@0 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
michael@0 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
michael@0 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
michael@0 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
michael@0 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 29 //
michael@0 30 // Authors: keith.ray@gmail.com (Keith Ray)
michael@0 31 //
michael@0 32 // Google Test UnitTestOptions tests
michael@0 33 //
michael@0 34 // This file tests classes and functions used internally by
michael@0 35 // Google Test. They are subject to change without notice.
michael@0 36 //
michael@0 37 // This file is #included from gtest.cc, to avoid changing build or
michael@0 38 // make-files on Windows and other platforms. Do not #include this file
michael@0 39 // anywhere else!
michael@0 40
michael@0 41 #include "gtest/gtest.h"
michael@0 42
michael@0 43 #if GTEST_OS_WINDOWS_MOBILE
michael@0 44 # include <windows.h>
michael@0 45 #elif GTEST_OS_WINDOWS
michael@0 46 # include <direct.h>
michael@0 47 #endif // GTEST_OS_WINDOWS_MOBILE
michael@0 48
michael@0 49 // Indicates that this translation unit is part of Google Test's
michael@0 50 // implementation. It must come before gtest-internal-inl.h is
michael@0 51 // included, or there will be a compiler error. This trick is to
michael@0 52 // prevent a user from accidentally including gtest-internal-inl.h in
michael@0 53 // his code.
michael@0 54 #define GTEST_IMPLEMENTATION_ 1
michael@0 55 #include "src/gtest-internal-inl.h"
michael@0 56 #undef GTEST_IMPLEMENTATION_
michael@0 57
michael@0 58 namespace testing {
michael@0 59 namespace internal {
michael@0 60 namespace {
michael@0 61
michael@0 62 // Turns the given relative path into an absolute path.
michael@0 63 FilePath GetAbsolutePathOf(const FilePath& relative_path) {
michael@0 64 return FilePath::ConcatPaths(FilePath::GetCurrentDir(), relative_path);
michael@0 65 }
michael@0 66
michael@0 67 // Testing UnitTestOptions::GetOutputFormat/GetOutputFile.
michael@0 68
michael@0 69 TEST(XmlOutputTest, GetOutputFormatDefault) {
michael@0 70 GTEST_FLAG(output) = "";
michael@0 71 EXPECT_STREQ("", UnitTestOptions::GetOutputFormat().c_str());
michael@0 72 }
michael@0 73
michael@0 74 TEST(XmlOutputTest, GetOutputFormat) {
michael@0 75 GTEST_FLAG(output) = "xml:filename";
michael@0 76 EXPECT_STREQ("xml", UnitTestOptions::GetOutputFormat().c_str());
michael@0 77 }
michael@0 78
michael@0 79 TEST(XmlOutputTest, GetOutputFileDefault) {
michael@0 80 GTEST_FLAG(output) = "";
michael@0 81 EXPECT_STREQ(GetAbsolutePathOf(FilePath("test_detail.xml")).c_str(),
michael@0 82 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
michael@0 83 }
michael@0 84
michael@0 85 TEST(XmlOutputTest, GetOutputFileSingleFile) {
michael@0 86 GTEST_FLAG(output) = "xml:filename.abc";
michael@0 87 EXPECT_STREQ(GetAbsolutePathOf(FilePath("filename.abc")).c_str(),
michael@0 88 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
michael@0 89 }
michael@0 90
michael@0 91 TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
michael@0 92 GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
michael@0 93 const std::string expected_output_file =
michael@0 94 GetAbsolutePathOf(
michael@0 95 FilePath(std::string("path") + GTEST_PATH_SEP_ +
michael@0 96 GetCurrentExecutableName().c_str() + ".xml")).c_str();
michael@0 97 const String& output_file = UnitTestOptions::GetAbsolutePathToOutputFile();
michael@0 98 #if GTEST_OS_WINDOWS
michael@0 99 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
michael@0 100 #else
michael@0 101 EXPECT_EQ(expected_output_file, output_file.c_str());
michael@0 102 #endif
michael@0 103 }
michael@0 104
michael@0 105 TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
michael@0 106 const std::string exe_str = GetCurrentExecutableName().c_str();
michael@0 107 #if GTEST_OS_WINDOWS
michael@0 108 const bool success =
michael@0 109 _strcmpi("gtest-options_test", exe_str.c_str()) == 0 ||
michael@0 110 _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
michael@0 111 _strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
michael@0 112 _strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
michael@0 113 #else
michael@0 114 // TODO(wan@google.com): remove the hard-coded "lt-" prefix when
michael@0 115 // Chandler Carruth's libtool replacement is ready.
michael@0 116 const bool success =
michael@0 117 exe_str == "gtest-options_test" ||
michael@0 118 exe_str == "gtest_all_test" ||
michael@0 119 exe_str == "lt-gtest_all_test" ||
michael@0 120 exe_str == "gtest_dll_test";
michael@0 121 #endif // GTEST_OS_WINDOWS
michael@0 122 if (!success)
michael@0 123 FAIL() << "GetCurrentExecutableName() returns " << exe_str;
michael@0 124 }
michael@0 125
michael@0 126 class XmlOutputChangeDirTest : public Test {
michael@0 127 protected:
michael@0 128 virtual void SetUp() {
michael@0 129 original_working_dir_ = FilePath::GetCurrentDir();
michael@0 130 posix::ChDir("..");
michael@0 131 // This will make the test fail if run from the root directory.
michael@0 132 EXPECT_STRNE(original_working_dir_.c_str(),
michael@0 133 FilePath::GetCurrentDir().c_str());
michael@0 134 }
michael@0 135
michael@0 136 virtual void TearDown() {
michael@0 137 posix::ChDir(original_working_dir_.c_str());
michael@0 138 }
michael@0 139
michael@0 140 FilePath original_working_dir_;
michael@0 141 };
michael@0 142
michael@0 143 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) {
michael@0 144 GTEST_FLAG(output) = "";
michael@0 145 EXPECT_STREQ(FilePath::ConcatPaths(original_working_dir_,
michael@0 146 FilePath("test_detail.xml")).c_str(),
michael@0 147 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
michael@0 148 }
michael@0 149
michael@0 150 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) {
michael@0 151 GTEST_FLAG(output) = "xml";
michael@0 152 EXPECT_STREQ(FilePath::ConcatPaths(original_working_dir_,
michael@0 153 FilePath("test_detail.xml")).c_str(),
michael@0 154 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
michael@0 155 }
michael@0 156
michael@0 157 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
michael@0 158 GTEST_FLAG(output) = "xml:filename.abc";
michael@0 159 EXPECT_STREQ(FilePath::ConcatPaths(original_working_dir_,
michael@0 160 FilePath("filename.abc")).c_str(),
michael@0 161 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
michael@0 162 }
michael@0 163
michael@0 164 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
michael@0 165 GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
michael@0 166 const std::string expected_output_file =
michael@0 167 FilePath::ConcatPaths(
michael@0 168 original_working_dir_,
michael@0 169 FilePath(std::string("path") + GTEST_PATH_SEP_ +
michael@0 170 GetCurrentExecutableName().c_str() + ".xml")).c_str();
michael@0 171 const String& output_file = UnitTestOptions::GetAbsolutePathToOutputFile();
michael@0 172 #if GTEST_OS_WINDOWS
michael@0 173 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
michael@0 174 #else
michael@0 175 EXPECT_EQ(expected_output_file, output_file.c_str());
michael@0 176 #endif
michael@0 177 }
michael@0 178
michael@0 179 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
michael@0 180 #if GTEST_OS_WINDOWS
michael@0 181 GTEST_FLAG(output) = "xml:c:\\tmp\\filename.abc";
michael@0 182 EXPECT_STREQ(FilePath("c:\\tmp\\filename.abc").c_str(),
michael@0 183 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
michael@0 184 #else
michael@0 185 GTEST_FLAG(output) ="xml:/tmp/filename.abc";
michael@0 186 EXPECT_STREQ(FilePath("/tmp/filename.abc").c_str(),
michael@0 187 UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
michael@0 188 #endif
michael@0 189 }
michael@0 190
michael@0 191 TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
michael@0 192 #if GTEST_OS_WINDOWS
michael@0 193 const std::string path = "c:\\tmp\\";
michael@0 194 #else
michael@0 195 const std::string path = "/tmp/";
michael@0 196 #endif
michael@0 197
michael@0 198 GTEST_FLAG(output) = "xml:" + path;
michael@0 199 const std::string expected_output_file =
michael@0 200 path + GetCurrentExecutableName().c_str() + ".xml";
michael@0 201 const String& output_file = UnitTestOptions::GetAbsolutePathToOutputFile();
michael@0 202
michael@0 203 #if GTEST_OS_WINDOWS
michael@0 204 EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
michael@0 205 #else
michael@0 206 EXPECT_EQ(expected_output_file, output_file.c_str());
michael@0 207 #endif
michael@0 208 }
michael@0 209
michael@0 210 } // namespace
michael@0 211 } // namespace internal
michael@0 212 } // namespace testing

mercurial