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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/testing/gtest/test/gtest-options_test.cc	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,212 @@
     1.4 +// Copyright 2008, Google Inc.
     1.5 +// All rights reserved.
     1.6 +//
     1.7 +// Redistribution and use in source and binary forms, with or without
     1.8 +// modification, are permitted provided that the following conditions are
     1.9 +// met:
    1.10 +//
    1.11 +//     * Redistributions of source code must retain the above copyright
    1.12 +// notice, this list of conditions and the following disclaimer.
    1.13 +//     * Redistributions in binary form must reproduce the above
    1.14 +// copyright notice, this list of conditions and the following disclaimer
    1.15 +// in the documentation and/or other materials provided with the
    1.16 +// distribution.
    1.17 +//     * Neither the name of Google Inc. nor the names of its
    1.18 +// contributors may be used to endorse or promote products derived from
    1.19 +// this software without specific prior written permission.
    1.20 +//
    1.21 +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.22 +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.23 +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.24 +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.25 +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.26 +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.27 +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.28 +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.29 +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.30 +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.31 +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.32 +//
    1.33 +// Authors: keith.ray@gmail.com (Keith Ray)
    1.34 +//
    1.35 +// Google Test UnitTestOptions tests
    1.36 +//
    1.37 +// This file tests classes and functions used internally by
    1.38 +// Google Test.  They are subject to change without notice.
    1.39 +//
    1.40 +// This file is #included from gtest.cc, to avoid changing build or
    1.41 +// make-files on Windows and other platforms. Do not #include this file
    1.42 +// anywhere else!
    1.43 +
    1.44 +#include "gtest/gtest.h"
    1.45 +
    1.46 +#if GTEST_OS_WINDOWS_MOBILE
    1.47 +# include <windows.h>
    1.48 +#elif GTEST_OS_WINDOWS
    1.49 +# include <direct.h>
    1.50 +#endif  // GTEST_OS_WINDOWS_MOBILE
    1.51 +
    1.52 +// Indicates that this translation unit is part of Google Test's
    1.53 +// implementation.  It must come before gtest-internal-inl.h is
    1.54 +// included, or there will be a compiler error.  This trick is to
    1.55 +// prevent a user from accidentally including gtest-internal-inl.h in
    1.56 +// his code.
    1.57 +#define GTEST_IMPLEMENTATION_ 1
    1.58 +#include "src/gtest-internal-inl.h"
    1.59 +#undef GTEST_IMPLEMENTATION_
    1.60 +
    1.61 +namespace testing {
    1.62 +namespace internal {
    1.63 +namespace {
    1.64 +
    1.65 +// Turns the given relative path into an absolute path.
    1.66 +FilePath GetAbsolutePathOf(const FilePath& relative_path) {
    1.67 +  return FilePath::ConcatPaths(FilePath::GetCurrentDir(), relative_path);
    1.68 +}
    1.69 +
    1.70 +// Testing UnitTestOptions::GetOutputFormat/GetOutputFile.
    1.71 +
    1.72 +TEST(XmlOutputTest, GetOutputFormatDefault) {
    1.73 +  GTEST_FLAG(output) = "";
    1.74 +  EXPECT_STREQ("", UnitTestOptions::GetOutputFormat().c_str());
    1.75 +}
    1.76 +
    1.77 +TEST(XmlOutputTest, GetOutputFormat) {
    1.78 +  GTEST_FLAG(output) = "xml:filename";
    1.79 +  EXPECT_STREQ("xml", UnitTestOptions::GetOutputFormat().c_str());
    1.80 +}
    1.81 +
    1.82 +TEST(XmlOutputTest, GetOutputFileDefault) {
    1.83 +  GTEST_FLAG(output) = "";
    1.84 +  EXPECT_STREQ(GetAbsolutePathOf(FilePath("test_detail.xml")).c_str(),
    1.85 +               UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
    1.86 +}
    1.87 +
    1.88 +TEST(XmlOutputTest, GetOutputFileSingleFile) {
    1.89 +  GTEST_FLAG(output) = "xml:filename.abc";
    1.90 +  EXPECT_STREQ(GetAbsolutePathOf(FilePath("filename.abc")).c_str(),
    1.91 +               UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
    1.92 +}
    1.93 +
    1.94 +TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
    1.95 +  GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
    1.96 +  const std::string expected_output_file =
    1.97 +      GetAbsolutePathOf(
    1.98 +          FilePath(std::string("path") + GTEST_PATH_SEP_ +
    1.99 +                   GetCurrentExecutableName().c_str() + ".xml")).c_str();
   1.100 +  const String& output_file = UnitTestOptions::GetAbsolutePathToOutputFile();
   1.101 +#if GTEST_OS_WINDOWS
   1.102 +  EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
   1.103 +#else
   1.104 +  EXPECT_EQ(expected_output_file, output_file.c_str());
   1.105 +#endif
   1.106 +}
   1.107 +
   1.108 +TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
   1.109 +  const std::string exe_str = GetCurrentExecutableName().c_str();
   1.110 +#if GTEST_OS_WINDOWS
   1.111 +  const bool success =
   1.112 +      _strcmpi("gtest-options_test", exe_str.c_str()) == 0 ||
   1.113 +      _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
   1.114 +      _strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
   1.115 +      _strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
   1.116 +#else
   1.117 +  // TODO(wan@google.com): remove the hard-coded "lt-" prefix when
   1.118 +  //   Chandler Carruth's libtool replacement is ready.
   1.119 +  const bool success =
   1.120 +      exe_str == "gtest-options_test" ||
   1.121 +      exe_str == "gtest_all_test" ||
   1.122 +      exe_str == "lt-gtest_all_test" ||
   1.123 +      exe_str == "gtest_dll_test";
   1.124 +#endif  // GTEST_OS_WINDOWS
   1.125 +  if (!success)
   1.126 +    FAIL() << "GetCurrentExecutableName() returns " << exe_str;
   1.127 +}
   1.128 +
   1.129 +class XmlOutputChangeDirTest : public Test {
   1.130 + protected:
   1.131 +  virtual void SetUp() {
   1.132 +    original_working_dir_ = FilePath::GetCurrentDir();
   1.133 +    posix::ChDir("..");
   1.134 +    // This will make the test fail if run from the root directory.
   1.135 +    EXPECT_STRNE(original_working_dir_.c_str(),
   1.136 +                 FilePath::GetCurrentDir().c_str());
   1.137 +  }
   1.138 +
   1.139 +  virtual void TearDown() {
   1.140 +    posix::ChDir(original_working_dir_.c_str());
   1.141 +  }
   1.142 +
   1.143 +  FilePath original_working_dir_;
   1.144 +};
   1.145 +
   1.146 +TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefault) {
   1.147 +  GTEST_FLAG(output) = "";
   1.148 +  EXPECT_STREQ(FilePath::ConcatPaths(original_working_dir_,
   1.149 +                                     FilePath("test_detail.xml")).c_str(),
   1.150 +               UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
   1.151 +}
   1.152 +
   1.153 +TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithDefaultXML) {
   1.154 +  GTEST_FLAG(output) = "xml";
   1.155 +  EXPECT_STREQ(FilePath::ConcatPaths(original_working_dir_,
   1.156 +                                     FilePath("test_detail.xml")).c_str(),
   1.157 +               UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
   1.158 +}
   1.159 +
   1.160 +TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
   1.161 +  GTEST_FLAG(output) = "xml:filename.abc";
   1.162 +  EXPECT_STREQ(FilePath::ConcatPaths(original_working_dir_,
   1.163 +                                     FilePath("filename.abc")).c_str(),
   1.164 +               UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
   1.165 +}
   1.166 +
   1.167 +TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
   1.168 +  GTEST_FLAG(output) = "xml:path" GTEST_PATH_SEP_;
   1.169 +  const std::string expected_output_file =
   1.170 +      FilePath::ConcatPaths(
   1.171 +          original_working_dir_,
   1.172 +          FilePath(std::string("path") + GTEST_PATH_SEP_ +
   1.173 +                   GetCurrentExecutableName().c_str() + ".xml")).c_str();
   1.174 +  const String& output_file = UnitTestOptions::GetAbsolutePathToOutputFile();
   1.175 +#if GTEST_OS_WINDOWS
   1.176 +  EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
   1.177 +#else
   1.178 +  EXPECT_EQ(expected_output_file, output_file.c_str());
   1.179 +#endif
   1.180 +}
   1.181 +
   1.182 +TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
   1.183 +#if GTEST_OS_WINDOWS
   1.184 +  GTEST_FLAG(output) = "xml:c:\\tmp\\filename.abc";
   1.185 +  EXPECT_STREQ(FilePath("c:\\tmp\\filename.abc").c_str(),
   1.186 +               UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
   1.187 +#else
   1.188 +  GTEST_FLAG(output) ="xml:/tmp/filename.abc";
   1.189 +  EXPECT_STREQ(FilePath("/tmp/filename.abc").c_str(),
   1.190 +               UnitTestOptions::GetAbsolutePathToOutputFile().c_str());
   1.191 +#endif
   1.192 +}
   1.193 +
   1.194 +TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
   1.195 +#if GTEST_OS_WINDOWS
   1.196 +  const std::string path = "c:\\tmp\\";
   1.197 +#else
   1.198 +  const std::string path = "/tmp/";
   1.199 +#endif
   1.200 +
   1.201 +  GTEST_FLAG(output) = "xml:" + path;
   1.202 +  const std::string expected_output_file =
   1.203 +      path + GetCurrentExecutableName().c_str() + ".xml";
   1.204 +  const String& output_file = UnitTestOptions::GetAbsolutePathToOutputFile();
   1.205 +
   1.206 +#if GTEST_OS_WINDOWS
   1.207 +  EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
   1.208 +#else
   1.209 +  EXPECT_EQ(expected_output_file, output_file.c_str());
   1.210 +#endif
   1.211 +}
   1.212 +
   1.213 +}  // namespace
   1.214 +}  // namespace internal
   1.215 +}  // namespace testing

mercurial