shiqian | e35fdd9 | 2008-12-10 05:08:54 +0000 | [diff] [blame^] | 1 | // 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 | |
| 39 | TEST(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 | |
| 55 | TEST(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 | |
| 68 | #ifdef GTEST_HAS_DEATH_TEST |
| 69 | |
| 70 | TEST(GmockCheckDeathTest, DiesWithCorrectOutputOnFailure) { |
| 71 | const bool a_false_condition = false; |
| 72 | EXPECT_DEATH(GMOCK_CHECK_(a_false_condition) << "Extra info", |
| 73 | // MSVC and gcc use different formats to print source |
| 74 | // file locations. Google Mock's failure messages use |
| 75 | // the same format as used by the compiler, in order |
| 76 | // for the IDE to recognize them. Therefore we look |
| 77 | // for different patterns here depending on the |
| 78 | // compiler. |
| 79 | #ifdef _MSC_VER |
| 80 | "gmock-port_test\\.cc\\([0-9]+\\):" |
| 81 | #else |
| 82 | "gmock-port_test\\.cc:[0-9]+" |
| 83 | #endif // _MSC_VER |
| 84 | ".*a_false_condition.*Extra info"); |
| 85 | } |
| 86 | |
| 87 | TEST(GmockCheckDeathTest, LivesSilentlyOnSuccess) { |
| 88 | EXPECT_EXIT({ |
| 89 | GMOCK_CHECK_(true) << "Extra info"; |
| 90 | ::std::cerr << "Success\n"; |
| 91 | exit(0); }, |
| 92 | ::testing::ExitedWithCode(0), "Success"); |
| 93 | } |
| 94 | |
| 95 | #endif // GTEST_HAS_DEATH_TEST |