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

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

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 // Author: mheule@google.com (Markus Heule)
michael@0 31 //
michael@0 32
michael@0 33 #include "gtest/gtest-test-part.h"
michael@0 34
michael@0 35 #include "gtest/gtest.h"
michael@0 36
michael@0 37 using testing::Message;
michael@0 38 using testing::Test;
michael@0 39 using testing::TestPartResult;
michael@0 40 using testing::TestPartResultArray;
michael@0 41
michael@0 42 namespace {
michael@0 43
michael@0 44 // Tests the TestPartResult class.
michael@0 45
michael@0 46 // The test fixture for testing TestPartResult.
michael@0 47 class TestPartResultTest : public Test {
michael@0 48 protected:
michael@0 49 TestPartResultTest()
michael@0 50 : r1_(TestPartResult::kSuccess, "foo/bar.cc", 10, "Success!"),
michael@0 51 r2_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure!"),
michael@0 52 r3_(TestPartResult::kFatalFailure, NULL, -1, "Failure!") {}
michael@0 53
michael@0 54 TestPartResult r1_, r2_, r3_;
michael@0 55 };
michael@0 56
michael@0 57
michael@0 58 TEST_F(TestPartResultTest, ConstructorWorks) {
michael@0 59 Message message;
michael@0 60 message << "something is terribly wrong";
michael@0 61 message << static_cast<const char*>(testing::internal::kStackTraceMarker);
michael@0 62 message << "some unimportant stack trace";
michael@0 63
michael@0 64 const TestPartResult result(TestPartResult::kNonFatalFailure,
michael@0 65 "some_file.cc",
michael@0 66 42,
michael@0 67 message.GetString().c_str());
michael@0 68
michael@0 69 EXPECT_EQ(TestPartResult::kNonFatalFailure, result.type());
michael@0 70 EXPECT_STREQ("some_file.cc", result.file_name());
michael@0 71 EXPECT_EQ(42, result.line_number());
michael@0 72 EXPECT_STREQ(message.GetString().c_str(), result.message());
michael@0 73 EXPECT_STREQ("something is terribly wrong", result.summary());
michael@0 74 }
michael@0 75
michael@0 76 TEST_F(TestPartResultTest, ResultAccessorsWork) {
michael@0 77 const TestPartResult success(TestPartResult::kSuccess,
michael@0 78 "file.cc",
michael@0 79 42,
michael@0 80 "message");
michael@0 81 EXPECT_TRUE(success.passed());
michael@0 82 EXPECT_FALSE(success.failed());
michael@0 83 EXPECT_FALSE(success.nonfatally_failed());
michael@0 84 EXPECT_FALSE(success.fatally_failed());
michael@0 85
michael@0 86 const TestPartResult nonfatal_failure(TestPartResult::kNonFatalFailure,
michael@0 87 "file.cc",
michael@0 88 42,
michael@0 89 "message");
michael@0 90 EXPECT_FALSE(nonfatal_failure.passed());
michael@0 91 EXPECT_TRUE(nonfatal_failure.failed());
michael@0 92 EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
michael@0 93 EXPECT_FALSE(nonfatal_failure.fatally_failed());
michael@0 94
michael@0 95 const TestPartResult fatal_failure(TestPartResult::kFatalFailure,
michael@0 96 "file.cc",
michael@0 97 42,
michael@0 98 "message");
michael@0 99 EXPECT_FALSE(fatal_failure.passed());
michael@0 100 EXPECT_TRUE(fatal_failure.failed());
michael@0 101 EXPECT_FALSE(fatal_failure.nonfatally_failed());
michael@0 102 EXPECT_TRUE(fatal_failure.fatally_failed());
michael@0 103 }
michael@0 104
michael@0 105 // Tests TestPartResult::type().
michael@0 106 TEST_F(TestPartResultTest, type) {
michael@0 107 EXPECT_EQ(TestPartResult::kSuccess, r1_.type());
michael@0 108 EXPECT_EQ(TestPartResult::kNonFatalFailure, r2_.type());
michael@0 109 EXPECT_EQ(TestPartResult::kFatalFailure, r3_.type());
michael@0 110 }
michael@0 111
michael@0 112 // Tests TestPartResult::file_name().
michael@0 113 TEST_F(TestPartResultTest, file_name) {
michael@0 114 EXPECT_STREQ("foo/bar.cc", r1_.file_name());
michael@0 115 EXPECT_STREQ(NULL, r3_.file_name());
michael@0 116 }
michael@0 117
michael@0 118 // Tests TestPartResult::line_number().
michael@0 119 TEST_F(TestPartResultTest, line_number) {
michael@0 120 EXPECT_EQ(10, r1_.line_number());
michael@0 121 EXPECT_EQ(-1, r2_.line_number());
michael@0 122 }
michael@0 123
michael@0 124 // Tests TestPartResult::message().
michael@0 125 TEST_F(TestPartResultTest, message) {
michael@0 126 EXPECT_STREQ("Success!", r1_.message());
michael@0 127 }
michael@0 128
michael@0 129 // Tests TestPartResult::passed().
michael@0 130 TEST_F(TestPartResultTest, Passed) {
michael@0 131 EXPECT_TRUE(r1_.passed());
michael@0 132 EXPECT_FALSE(r2_.passed());
michael@0 133 EXPECT_FALSE(r3_.passed());
michael@0 134 }
michael@0 135
michael@0 136 // Tests TestPartResult::failed().
michael@0 137 TEST_F(TestPartResultTest, Failed) {
michael@0 138 EXPECT_FALSE(r1_.failed());
michael@0 139 EXPECT_TRUE(r2_.failed());
michael@0 140 EXPECT_TRUE(r3_.failed());
michael@0 141 }
michael@0 142
michael@0 143 // Tests TestPartResult::fatally_failed().
michael@0 144 TEST_F(TestPartResultTest, FatallyFailed) {
michael@0 145 EXPECT_FALSE(r1_.fatally_failed());
michael@0 146 EXPECT_FALSE(r2_.fatally_failed());
michael@0 147 EXPECT_TRUE(r3_.fatally_failed());
michael@0 148 }
michael@0 149
michael@0 150 // Tests TestPartResult::nonfatally_failed().
michael@0 151 TEST_F(TestPartResultTest, NonfatallyFailed) {
michael@0 152 EXPECT_FALSE(r1_.nonfatally_failed());
michael@0 153 EXPECT_TRUE(r2_.nonfatally_failed());
michael@0 154 EXPECT_FALSE(r3_.nonfatally_failed());
michael@0 155 }
michael@0 156
michael@0 157 // Tests the TestPartResultArray class.
michael@0 158
michael@0 159 class TestPartResultArrayTest : public Test {
michael@0 160 protected:
michael@0 161 TestPartResultArrayTest()
michael@0 162 : r1_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure 1"),
michael@0 163 r2_(TestPartResult::kFatalFailure, "foo/bar.cc", -1, "Failure 2") {}
michael@0 164
michael@0 165 const TestPartResult r1_, r2_;
michael@0 166 };
michael@0 167
michael@0 168 // Tests that TestPartResultArray initially has size 0.
michael@0 169 TEST_F(TestPartResultArrayTest, InitialSizeIsZero) {
michael@0 170 TestPartResultArray results;
michael@0 171 EXPECT_EQ(0, results.size());
michael@0 172 }
michael@0 173
michael@0 174 // Tests that TestPartResultArray contains the given TestPartResult
michael@0 175 // after one Append() operation.
michael@0 176 TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) {
michael@0 177 TestPartResultArray results;
michael@0 178 results.Append(r1_);
michael@0 179 EXPECT_EQ(1, results.size());
michael@0 180 EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
michael@0 181 }
michael@0 182
michael@0 183 // Tests that TestPartResultArray contains the given TestPartResults
michael@0 184 // after two Append() operations.
michael@0 185 TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) {
michael@0 186 TestPartResultArray results;
michael@0 187 results.Append(r1_);
michael@0 188 results.Append(r2_);
michael@0 189 EXPECT_EQ(2, results.size());
michael@0 190 EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
michael@0 191 EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message());
michael@0 192 }
michael@0 193
michael@0 194 typedef TestPartResultArrayTest TestPartResultArrayDeathTest;
michael@0 195
michael@0 196 // Tests that the program dies when GetTestPartResult() is called with
michael@0 197 // an invalid index.
michael@0 198 TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
michael@0 199 TestPartResultArray results;
michael@0 200 results.Append(r1_);
michael@0 201
michael@0 202 EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(-1), "");
michael@0 203 EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(1), "");
michael@0 204 }
michael@0 205
michael@0 206 // TODO(mheule@google.com): Add a test for the class HasNewFatalFailureHelper.
michael@0 207
michael@0 208 } // namespace

mercurial