00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "gtest/gtest-test-part.h"
00034
00035 #include "gtest/gtest.h"
00036
00037 using testing::Message;
00038 using testing::Test;
00039 using testing::TestPartResult;
00040 using testing::TestPartResultArray;
00041
00042 namespace {
00043
00044
00045
00046
00047 class TestPartResultTest : public Test {
00048 protected:
00049 TestPartResultTest()
00050 : r1_(TestPartResult::kSuccess, "foo/bar.cc", 10, "Success!"),
00051 r2_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure!"),
00052 r3_(TestPartResult::kFatalFailure, NULL, -1, "Failure!") {}
00053
00054 TestPartResult r1_, r2_, r3_;
00055 };
00056
00057
00058 TEST_F(TestPartResultTest, ConstructorWorks) {
00059 Message message;
00060 message << "something is terribly wrong";
00061 message << static_cast<const char*>(testing::internal::kStackTraceMarker);
00062 message << "some unimportant stack trace";
00063
00064 const TestPartResult result(TestPartResult::kNonFatalFailure,
00065 "some_file.cc",
00066 42,
00067 message.GetString().c_str());
00068
00069 EXPECT_EQ(TestPartResult::kNonFatalFailure, result.type());
00070 EXPECT_STREQ("some_file.cc", result.file_name());
00071 EXPECT_EQ(42, result.line_number());
00072 EXPECT_STREQ(message.GetString().c_str(), result.message());
00073 EXPECT_STREQ("something is terribly wrong", result.summary());
00074 }
00075
00076 TEST_F(TestPartResultTest, ResultAccessorsWork) {
00077 const TestPartResult success(TestPartResult::kSuccess,
00078 "file.cc",
00079 42,
00080 "message");
00081 EXPECT_TRUE(success.passed());
00082 EXPECT_FALSE(success.failed());
00083 EXPECT_FALSE(success.nonfatally_failed());
00084 EXPECT_FALSE(success.fatally_failed());
00085
00086 const TestPartResult nonfatal_failure(TestPartResult::kNonFatalFailure,
00087 "file.cc",
00088 42,
00089 "message");
00090 EXPECT_FALSE(nonfatal_failure.passed());
00091 EXPECT_TRUE(nonfatal_failure.failed());
00092 EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
00093 EXPECT_FALSE(nonfatal_failure.fatally_failed());
00094
00095 const TestPartResult fatal_failure(TestPartResult::kFatalFailure,
00096 "file.cc",
00097 42,
00098 "message");
00099 EXPECT_FALSE(fatal_failure.passed());
00100 EXPECT_TRUE(fatal_failure.failed());
00101 EXPECT_FALSE(fatal_failure.nonfatally_failed());
00102 EXPECT_TRUE(fatal_failure.fatally_failed());
00103 }
00104
00105
00106 TEST_F(TestPartResultTest, type) {
00107 EXPECT_EQ(TestPartResult::kSuccess, r1_.type());
00108 EXPECT_EQ(TestPartResult::kNonFatalFailure, r2_.type());
00109 EXPECT_EQ(TestPartResult::kFatalFailure, r3_.type());
00110 }
00111
00112
00113 TEST_F(TestPartResultTest, file_name) {
00114 EXPECT_STREQ("foo/bar.cc", r1_.file_name());
00115 EXPECT_STREQ(NULL, r3_.file_name());
00116 }
00117
00118
00119 TEST_F(TestPartResultTest, line_number) {
00120 EXPECT_EQ(10, r1_.line_number());
00121 EXPECT_EQ(-1, r2_.line_number());
00122 }
00123
00124
00125 TEST_F(TestPartResultTest, message) {
00126 EXPECT_STREQ("Success!", r1_.message());
00127 }
00128
00129
00130 TEST_F(TestPartResultTest, Passed) {
00131 EXPECT_TRUE(r1_.passed());
00132 EXPECT_FALSE(r2_.passed());
00133 EXPECT_FALSE(r3_.passed());
00134 }
00135
00136
00137 TEST_F(TestPartResultTest, Failed) {
00138 EXPECT_FALSE(r1_.failed());
00139 EXPECT_TRUE(r2_.failed());
00140 EXPECT_TRUE(r3_.failed());
00141 }
00142
00143
00144 TEST_F(TestPartResultTest, FatallyFailed) {
00145 EXPECT_FALSE(r1_.fatally_failed());
00146 EXPECT_FALSE(r2_.fatally_failed());
00147 EXPECT_TRUE(r3_.fatally_failed());
00148 }
00149
00150
00151 TEST_F(TestPartResultTest, NonfatallyFailed) {
00152 EXPECT_FALSE(r1_.nonfatally_failed());
00153 EXPECT_TRUE(r2_.nonfatally_failed());
00154 EXPECT_FALSE(r3_.nonfatally_failed());
00155 }
00156
00157
00158
00159 class TestPartResultArrayTest : public Test {
00160 protected:
00161 TestPartResultArrayTest()
00162 : r1_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure 1"),
00163 r2_(TestPartResult::kFatalFailure, "foo/bar.cc", -1, "Failure 2") {}
00164
00165 const TestPartResult r1_, r2_;
00166 };
00167
00168
00169 TEST_F(TestPartResultArrayTest, InitialSizeIsZero) {
00170 TestPartResultArray results;
00171 EXPECT_EQ(0, results.size());
00172 }
00173
00174
00175
00176 TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) {
00177 TestPartResultArray results;
00178 results.Append(r1_);
00179 EXPECT_EQ(1, results.size());
00180 EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
00181 }
00182
00183
00184
00185 TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) {
00186 TestPartResultArray results;
00187 results.Append(r1_);
00188 results.Append(r2_);
00189 EXPECT_EQ(2, results.size());
00190 EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
00191 EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message());
00192 }
00193
00194 typedef TestPartResultArrayTest TestPartResultArrayDeathTest;
00195
00196
00197
00198 TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
00199 TestPartResultArray results;
00200 results.Append(r1_);
00201
00202 EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(-1), "");
00203 EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(1), "");
00204 }
00205
00206
00207
00208 }