blob: d7ce2c6f9b19d832c8aae83481ab025eca223bb3 [file] [log] [blame]
shiqiand2014562008-07-03 22:38:12 +00001// Copyright 2006, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30// Author: eefacm@gmail.com (Sean Mcafee)
31
32// Unit test for Google Test XML output.
33//
34// A user can specify XML output in a Google Test program to run via
35// either the GTEST_OUTPUT environment variable or the --gtest_output
36// flag. This is used for testing such functionality.
37//
38// This program will be invoked from a Python unit test. Don't run it
39// directly.
40
41#include <gtest/gtest.h>
42
43class SuccessfulTest : public testing::Test {
44};
45
46TEST_F(SuccessfulTest, Succeeds) {
47 SUCCEED() << "This is a success.";
48 ASSERT_EQ(1, 1);
49}
50
51class FailedTest : public testing::Test {
52};
53
54TEST_F(FailedTest, Fails) {
55 ASSERT_EQ(1, 2);
56}
57
58class DisabledTest : public testing::Test {
59};
60
61TEST_F(DisabledTest, DISABLED_test_not_run) {
62 FAIL() << "Unexpected failure: Disabled test should not be run";
63}
64
65TEST(MixedResultTest, Succeeds) {
66 EXPECT_EQ(1, 1);
67 ASSERT_EQ(1, 1);
68}
69
70TEST(MixedResultTest, Fails) {
71 EXPECT_EQ(1, 2);
72 ASSERT_EQ(2, 3);
73}
74
75TEST(MixedResultTest, DISABLED_test) {
76 FAIL() << "Unexpected failure: Disabled test should not be run";
77}
78
79class PropertyRecordingTest : public testing::Test {
80};
81
82TEST_F(PropertyRecordingTest, OneProperty) {
83 RecordProperty("key_1", "1");
84}
85
86TEST_F(PropertyRecordingTest, IntValuedProperty) {
87 RecordProperty("key_int", 1);
88}
89
90TEST_F(PropertyRecordingTest, ThreeProperties) {
91 RecordProperty("key_1", "1");
92 RecordProperty("key_2", "2");
93 RecordProperty("key_3", "3");
94}
95
96TEST_F(PropertyRecordingTest, TwoValuesForOneKeyUsesLastValue) {
97 RecordProperty("key_1", "1");
98 RecordProperty("key_1", "2");
99}
100
101TEST(NoFixtureTest, RecordProperty) {
102 RecordProperty("key", "1");
103}
104
105void ExternalUtilityThatCallsRecordProperty(const char* key, int value) {
106 testing::Test::RecordProperty(key, value);
107}
108
109void ExternalUtilityThatCallsRecordProperty(const char* key,
110 const char* value) {
111 testing::Test::RecordProperty(key, value);
112}
113
114TEST(NoFixtureTest, ExternalUtilityThatCallsRecordIntValuedProperty) {
115 ExternalUtilityThatCallsRecordProperty("key_for_utility_int", 1);
116}
117
118TEST(NoFixtureTest, ExternalUtilityThatCallsRecordStringValuedProperty) {
119 ExternalUtilityThatCallsRecordProperty("key_for_utility_string", "1");
120}