1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/testing/gtest/test/gtest-test-part_test.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,208 @@ 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 +// Author: mheule@google.com (Markus Heule) 1.34 +// 1.35 + 1.36 +#include "gtest/gtest-test-part.h" 1.37 + 1.38 +#include "gtest/gtest.h" 1.39 + 1.40 +using testing::Message; 1.41 +using testing::Test; 1.42 +using testing::TestPartResult; 1.43 +using testing::TestPartResultArray; 1.44 + 1.45 +namespace { 1.46 + 1.47 +// Tests the TestPartResult class. 1.48 + 1.49 +// The test fixture for testing TestPartResult. 1.50 +class TestPartResultTest : public Test { 1.51 + protected: 1.52 + TestPartResultTest() 1.53 + : r1_(TestPartResult::kSuccess, "foo/bar.cc", 10, "Success!"), 1.54 + r2_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure!"), 1.55 + r3_(TestPartResult::kFatalFailure, NULL, -1, "Failure!") {} 1.56 + 1.57 + TestPartResult r1_, r2_, r3_; 1.58 +}; 1.59 + 1.60 + 1.61 +TEST_F(TestPartResultTest, ConstructorWorks) { 1.62 + Message message; 1.63 + message << "something is terribly wrong"; 1.64 + message << static_cast<const char*>(testing::internal::kStackTraceMarker); 1.65 + message << "some unimportant stack trace"; 1.66 + 1.67 + const TestPartResult result(TestPartResult::kNonFatalFailure, 1.68 + "some_file.cc", 1.69 + 42, 1.70 + message.GetString().c_str()); 1.71 + 1.72 + EXPECT_EQ(TestPartResult::kNonFatalFailure, result.type()); 1.73 + EXPECT_STREQ("some_file.cc", result.file_name()); 1.74 + EXPECT_EQ(42, result.line_number()); 1.75 + EXPECT_STREQ(message.GetString().c_str(), result.message()); 1.76 + EXPECT_STREQ("something is terribly wrong", result.summary()); 1.77 +} 1.78 + 1.79 +TEST_F(TestPartResultTest, ResultAccessorsWork) { 1.80 + const TestPartResult success(TestPartResult::kSuccess, 1.81 + "file.cc", 1.82 + 42, 1.83 + "message"); 1.84 + EXPECT_TRUE(success.passed()); 1.85 + EXPECT_FALSE(success.failed()); 1.86 + EXPECT_FALSE(success.nonfatally_failed()); 1.87 + EXPECT_FALSE(success.fatally_failed()); 1.88 + 1.89 + const TestPartResult nonfatal_failure(TestPartResult::kNonFatalFailure, 1.90 + "file.cc", 1.91 + 42, 1.92 + "message"); 1.93 + EXPECT_FALSE(nonfatal_failure.passed()); 1.94 + EXPECT_TRUE(nonfatal_failure.failed()); 1.95 + EXPECT_TRUE(nonfatal_failure.nonfatally_failed()); 1.96 + EXPECT_FALSE(nonfatal_failure.fatally_failed()); 1.97 + 1.98 + const TestPartResult fatal_failure(TestPartResult::kFatalFailure, 1.99 + "file.cc", 1.100 + 42, 1.101 + "message"); 1.102 + EXPECT_FALSE(fatal_failure.passed()); 1.103 + EXPECT_TRUE(fatal_failure.failed()); 1.104 + EXPECT_FALSE(fatal_failure.nonfatally_failed()); 1.105 + EXPECT_TRUE(fatal_failure.fatally_failed()); 1.106 +} 1.107 + 1.108 +// Tests TestPartResult::type(). 1.109 +TEST_F(TestPartResultTest, type) { 1.110 + EXPECT_EQ(TestPartResult::kSuccess, r1_.type()); 1.111 + EXPECT_EQ(TestPartResult::kNonFatalFailure, r2_.type()); 1.112 + EXPECT_EQ(TestPartResult::kFatalFailure, r3_.type()); 1.113 +} 1.114 + 1.115 +// Tests TestPartResult::file_name(). 1.116 +TEST_F(TestPartResultTest, file_name) { 1.117 + EXPECT_STREQ("foo/bar.cc", r1_.file_name()); 1.118 + EXPECT_STREQ(NULL, r3_.file_name()); 1.119 +} 1.120 + 1.121 +// Tests TestPartResult::line_number(). 1.122 +TEST_F(TestPartResultTest, line_number) { 1.123 + EXPECT_EQ(10, r1_.line_number()); 1.124 + EXPECT_EQ(-1, r2_.line_number()); 1.125 +} 1.126 + 1.127 +// Tests TestPartResult::message(). 1.128 +TEST_F(TestPartResultTest, message) { 1.129 + EXPECT_STREQ("Success!", r1_.message()); 1.130 +} 1.131 + 1.132 +// Tests TestPartResult::passed(). 1.133 +TEST_F(TestPartResultTest, Passed) { 1.134 + EXPECT_TRUE(r1_.passed()); 1.135 + EXPECT_FALSE(r2_.passed()); 1.136 + EXPECT_FALSE(r3_.passed()); 1.137 +} 1.138 + 1.139 +// Tests TestPartResult::failed(). 1.140 +TEST_F(TestPartResultTest, Failed) { 1.141 + EXPECT_FALSE(r1_.failed()); 1.142 + EXPECT_TRUE(r2_.failed()); 1.143 + EXPECT_TRUE(r3_.failed()); 1.144 +} 1.145 + 1.146 +// Tests TestPartResult::fatally_failed(). 1.147 +TEST_F(TestPartResultTest, FatallyFailed) { 1.148 + EXPECT_FALSE(r1_.fatally_failed()); 1.149 + EXPECT_FALSE(r2_.fatally_failed()); 1.150 + EXPECT_TRUE(r3_.fatally_failed()); 1.151 +} 1.152 + 1.153 +// Tests TestPartResult::nonfatally_failed(). 1.154 +TEST_F(TestPartResultTest, NonfatallyFailed) { 1.155 + EXPECT_FALSE(r1_.nonfatally_failed()); 1.156 + EXPECT_TRUE(r2_.nonfatally_failed()); 1.157 + EXPECT_FALSE(r3_.nonfatally_failed()); 1.158 +} 1.159 + 1.160 +// Tests the TestPartResultArray class. 1.161 + 1.162 +class TestPartResultArrayTest : public Test { 1.163 + protected: 1.164 + TestPartResultArrayTest() 1.165 + : r1_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure 1"), 1.166 + r2_(TestPartResult::kFatalFailure, "foo/bar.cc", -1, "Failure 2") {} 1.167 + 1.168 + const TestPartResult r1_, r2_; 1.169 +}; 1.170 + 1.171 +// Tests that TestPartResultArray initially has size 0. 1.172 +TEST_F(TestPartResultArrayTest, InitialSizeIsZero) { 1.173 + TestPartResultArray results; 1.174 + EXPECT_EQ(0, results.size()); 1.175 +} 1.176 + 1.177 +// Tests that TestPartResultArray contains the given TestPartResult 1.178 +// after one Append() operation. 1.179 +TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) { 1.180 + TestPartResultArray results; 1.181 + results.Append(r1_); 1.182 + EXPECT_EQ(1, results.size()); 1.183 + EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message()); 1.184 +} 1.185 + 1.186 +// Tests that TestPartResultArray contains the given TestPartResults 1.187 +// after two Append() operations. 1.188 +TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) { 1.189 + TestPartResultArray results; 1.190 + results.Append(r1_); 1.191 + results.Append(r2_); 1.192 + EXPECT_EQ(2, results.size()); 1.193 + EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message()); 1.194 + EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message()); 1.195 +} 1.196 + 1.197 +typedef TestPartResultArrayTest TestPartResultArrayDeathTest; 1.198 + 1.199 +// Tests that the program dies when GetTestPartResult() is called with 1.200 +// an invalid index. 1.201 +TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) { 1.202 + TestPartResultArray results; 1.203 + results.Append(r1_); 1.204 + 1.205 + EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(-1), ""); 1.206 + EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(1), ""); 1.207 +} 1.208 + 1.209 +// TODO(mheule@google.com): Add a test for the class HasNewFatalFailureHelper. 1.210 + 1.211 +} // namespace