blob: 7335405c2a3824f0b21b736af3d01b0868447183 [file] [log] [blame]
shiqiane35fdd92008-12-10 05:08:54 +00001// Copyright 2008, 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: vladl@google.com (Vlad Losev)
31
32// Google Mock - a framework for writing C++ mock classes.
33//
34// This file tests the internal cross-platform support utilities.
35
36#include <gmock/internal/gmock-port.h>
37#include <gtest/gtest.h>
38
39TEST(GmockCheckSyntaxTest, BehavesLikeASingleStatement) {
40 if (false)
41 GMOCK_CHECK_(false) << "This should never be executed; "
42 "It's a compilation test only.";
43
44 if (true)
45 GMOCK_CHECK_(true);
46 else
47 ;
48
49 if (false)
50 ;
51 else
52 GMOCK_CHECK_(true) << "";
53}
54
55TEST(GmockCheckSyntaxTest, WorksWithSwitch) {
56 switch (0) {
57 case 1:
58 break;
59 default:
60 GMOCK_CHECK_(true);
61 }
62
63 switch(0)
64 case 0:
65 GMOCK_CHECK_(true) << "Check failed in switch case";
66}
67
shiqiane35fdd92008-12-10 05:08:54 +000068TEST(GmockCheckDeathTest, DiesWithCorrectOutputOnFailure) {
69 const bool a_false_condition = false;
zhanyong.wan93ad3552009-03-06 01:21:45 +000070 // MSVC and gcc use different formats to print source file locations.
71 // Google Mock's failure messages use the same format as used by the
72 // compiler, in order for the IDE to recognize them. Therefore we look
73 // for different patterns here depending on the compiler.
74 const char regex[] =
shiqiane35fdd92008-12-10 05:08:54 +000075#ifdef _MSC_VER
zhanyong.wan93ad3552009-03-06 01:21:45 +000076 "gmock-port_test\\.cc\\(\\d+\\):"
shiqiane35fdd92008-12-10 05:08:54 +000077#else
zhanyong.wan93ad3552009-03-06 01:21:45 +000078 "gmock-port_test\\.cc:[0-9]+"
shiqiane35fdd92008-12-10 05:08:54 +000079#endif // _MSC_VER
zhanyong.wan93ad3552009-03-06 01:21:45 +000080 ".*a_false_condition.*Extra info";
81
zhanyong.wan04d6ed82009-09-11 07:01:08 +000082 EXPECT_DEATH_IF_SUPPORTED(GMOCK_CHECK_(a_false_condition) << "Extra info",
83 regex);
shiqiane35fdd92008-12-10 05:08:54 +000084}
85
zhanyong.wan04d6ed82009-09-11 07:01:08 +000086#if GTEST_HAS_DEATH_TEST
87
shiqiane35fdd92008-12-10 05:08:54 +000088TEST(GmockCheckDeathTest, LivesSilentlyOnSuccess) {
89 EXPECT_EXIT({
90 GMOCK_CHECK_(true) << "Extra info";
91 ::std::cerr << "Success\n";
92 exit(0); },
93 ::testing::ExitedWithCode(0), "Success");
94}
95
96#endif // GTEST_HAS_DEATH_TEST