~ubuntu-branches/ubuntu/precise/protobuf/precise

« back to all changes in this revision

Viewing changes to gtest/test/gtest-test-part_test.cc

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2009-11-16 10:41:33 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091116104133-ykhy3deg5l4975tw
Tags: 2.1.0-1ubuntu1
* Merge from Debian testing.
* Remaining Ubuntu changes:
  - Disable the death tests on IA64, now as a quilt patch.
  - Don't use python2.4, also as a quilt patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2008 Google Inc. All Rights Reserved.
 
2
// Author: mheule@google.com (Markus Heule)
 
3
 
 
4
#include <gtest/gtest-test-part.h>
 
5
 
 
6
#include <gtest/gtest.h>
 
7
 
 
8
using testing::Test;
 
9
using testing::TestPartResult;
 
10
using testing::TestPartResultArray;
 
11
 
 
12
using testing::TPRT_FATAL_FAILURE;
 
13
using testing::TPRT_NONFATAL_FAILURE;
 
14
using testing::TPRT_SUCCESS;
 
15
 
 
16
namespace {
 
17
 
 
18
// Tests the TestPartResult class.
 
19
 
 
20
// The test fixture for testing TestPartResult.
 
21
class TestPartResultTest : public Test {
 
22
 protected:
 
23
  TestPartResultTest()
 
24
      : r1_(TPRT_SUCCESS, "foo/bar.cc", 10, "Success!"),
 
25
        r2_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure!"),
 
26
        r3_(TPRT_FATAL_FAILURE, NULL, -1, "Failure!") {}
 
27
 
 
28
  TestPartResult r1_, r2_, r3_;
 
29
};
 
30
 
 
31
// Tests TestPartResult::type().
 
32
TEST_F(TestPartResultTest, type) {
 
33
  EXPECT_EQ(TPRT_SUCCESS, r1_.type());
 
34
  EXPECT_EQ(TPRT_NONFATAL_FAILURE, r2_.type());
 
35
  EXPECT_EQ(TPRT_FATAL_FAILURE, r3_.type());
 
36
}
 
37
 
 
38
// Tests TestPartResult::file_name().
 
39
TEST_F(TestPartResultTest, file_name) {
 
40
  EXPECT_STREQ("foo/bar.cc", r1_.file_name());
 
41
  EXPECT_STREQ(NULL, r3_.file_name());
 
42
}
 
43
 
 
44
// Tests TestPartResult::line_number().
 
45
TEST_F(TestPartResultTest, line_number) {
 
46
  EXPECT_EQ(10, r1_.line_number());
 
47
  EXPECT_EQ(-1, r2_.line_number());
 
48
}
 
49
 
 
50
// Tests TestPartResult::message().
 
51
TEST_F(TestPartResultTest, message) {
 
52
  EXPECT_STREQ("Success!", r1_.message());
 
53
}
 
54
 
 
55
// Tests TestPartResult::passed().
 
56
TEST_F(TestPartResultTest, Passed) {
 
57
  EXPECT_TRUE(r1_.passed());
 
58
  EXPECT_FALSE(r2_.passed());
 
59
  EXPECT_FALSE(r3_.passed());
 
60
}
 
61
 
 
62
// Tests TestPartResult::failed().
 
63
TEST_F(TestPartResultTest, Failed) {
 
64
  EXPECT_FALSE(r1_.failed());
 
65
  EXPECT_TRUE(r2_.failed());
 
66
  EXPECT_TRUE(r3_.failed());
 
67
}
 
68
 
 
69
// Tests TestPartResult::fatally_failed().
 
70
TEST_F(TestPartResultTest, FatallyFailed) {
 
71
  EXPECT_FALSE(r1_.fatally_failed());
 
72
  EXPECT_FALSE(r2_.fatally_failed());
 
73
  EXPECT_TRUE(r3_.fatally_failed());
 
74
}
 
75
 
 
76
// Tests TestPartResult::nonfatally_failed().
 
77
TEST_F(TestPartResultTest, NonfatallyFailed) {
 
78
  EXPECT_FALSE(r1_.nonfatally_failed());
 
79
  EXPECT_TRUE(r2_.nonfatally_failed());
 
80
  EXPECT_FALSE(r3_.nonfatally_failed());
 
81
}
 
82
 
 
83
// Tests the TestPartResultArray class.
 
84
 
 
85
class TestPartResultArrayTest : public Test {
 
86
 protected:
 
87
  TestPartResultArrayTest()
 
88
      : r1_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure 1"),
 
89
        r2_(TPRT_FATAL_FAILURE, "foo/bar.cc", -1, "Failure 2") {}
 
90
 
 
91
  const TestPartResult r1_, r2_;
 
92
};
 
93
 
 
94
// Tests that TestPartResultArray initially has size 0.
 
95
TEST_F(TestPartResultArrayTest, InitialSizeIsZero) {
 
96
  TestPartResultArray results;
 
97
  EXPECT_EQ(0, results.size());
 
98
}
 
99
 
 
100
// Tests that TestPartResultArray contains the given TestPartResult
 
101
// after one Append() operation.
 
102
TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) {
 
103
  TestPartResultArray results;
 
104
  results.Append(r1_);
 
105
  EXPECT_EQ(1, results.size());
 
106
  EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
 
107
}
 
108
 
 
109
// Tests that TestPartResultArray contains the given TestPartResults
 
110
// after two Append() operations.
 
111
TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) {
 
112
  TestPartResultArray results;
 
113
  results.Append(r1_);
 
114
  results.Append(r2_);
 
115
  EXPECT_EQ(2, results.size());
 
116
  EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
 
117
  EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message());
 
118
}
 
119
 
 
120
#if GTEST_HAS_DEATH_TEST
 
121
 
 
122
typedef TestPartResultArrayTest TestPartResultArrayDeathTest;
 
123
 
 
124
// Tests that the program dies when GetTestPartResult() is called with
 
125
// an invalid index.
 
126
TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
 
127
  TestPartResultArray results;
 
128
  results.Append(r1_);
 
129
 
 
130
  EXPECT_DEATH(results.GetTestPartResult(-1), "");
 
131
  EXPECT_DEATH(results.GetTestPartResult(1), "");
 
132
}
 
133
 
 
134
#endif  // GTEST_HAS_DEATH_TEST
 
135
 
 
136
// TODO(mheule@google.com): Add a test for the class HasNewFatalFailureHelper.
 
137
 
 
138
}  // namespace