Home | History | Annotate | Download | only in test
      1 // Copyright 2005, 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: wan (at) google.com (Zhanyong Wan)
     31 
     32 // Unit test for Google Test test filters.
     33 //
     34 // A user can specify which test(s) in a Google Test program to run via
     35 // either the GTEST_FILTER environment variable or the --gtest_filter
     36 // flag.  This is used for testing such functionality.
     37 //
     38 // The program will be invoked from a Python unit test.  Don't run it
     39 // directly.
     40 
     41 #include <gtest/gtest.h>
     42 
     43 
     44 namespace {
     45 
     46 // Test case FooTest.
     47 
     48 class FooTest : public testing::Test {
     49 };
     50 
     51 TEST_F(FooTest, Abc) {
     52 }
     53 
     54 TEST_F(FooTest, Xyz) {
     55   FAIL() << "Expected failure.";
     56 }
     57 
     58 
     59 // Test case BarTest.
     60 
     61 TEST(BarTest, TestOne) {
     62 }
     63 
     64 TEST(BarTest, TestTwo) {
     65 }
     66 
     67 TEST(BarTest, TestThree) {
     68 }
     69 
     70 TEST(BarTest, DISABLED_TestFour) {
     71   FAIL() << "Expected failure.";
     72 }
     73 
     74 TEST(BarTest, DISABLED_TestFive) {
     75   FAIL() << "Expected failure.";
     76 }
     77 
     78 // Test case BazTest.
     79 
     80 TEST(BazTest, TestOne) {
     81   FAIL() << "Expected failure.";
     82 }
     83 
     84 TEST(BazTest, TestA) {
     85 }
     86 
     87 TEST(BazTest, TestB) {
     88 }
     89 
     90 TEST(BazTest, DISABLED_TestC) {
     91   FAIL() << "Expected failure.";
     92 }
     93 
     94 // Test case HasDeathTest
     95 
     96 TEST(HasDeathTest, Test1) {
     97 #if GTEST_HAS_DEATH_TEST
     98   EXPECT_DEATH({exit(1);},
     99     ".*");
    100 #endif  // GTEST_HAS_DEATH_TEST
    101 }
    102 
    103 // We need at least two death tests to make sure that the all death tests
    104 // aren't on the first shard.
    105 TEST(HasDeathTest, Test2) {
    106 #if GTEST_HAS_DEATH_TEST
    107   EXPECT_DEATH({exit(1);},
    108     ".*");
    109 #endif  // GTEST_HAS_DEATH_TEST
    110 }
    111 
    112 
    113 // Test case FoobarTest
    114 
    115 TEST(DISABLED_FoobarTest, Test1) {
    116   FAIL() << "Expected failure.";
    117 }
    118 
    119 TEST(DISABLED_FoobarTest, DISABLED_Test2) {
    120   FAIL() << "Expected failure.";
    121 }
    122 
    123 // Test case FoobarbazTest
    124 
    125 TEST(DISABLED_FoobarbazTest, TestA) {
    126   FAIL() << "Expected failure.";
    127 }
    128 
    129 #if GTEST_HAS_PARAM_TEST
    130 class ParamTest : public testing::TestWithParam<int> {
    131 };
    132 
    133 TEST_P(ParamTest, TestX) {
    134 }
    135 
    136 TEST_P(ParamTest, TestY) {
    137 }
    138 
    139 INSTANTIATE_TEST_CASE_P(SeqP, ParamTest, testing::Values(1, 2));
    140 INSTANTIATE_TEST_CASE_P(SeqQ, ParamTest, testing::Values(5, 6));
    141 #endif  // GTEST_HAS_PARAM_TEST
    142 
    143 }  // namespace
    144 
    145 
    146 int main(int argc, char **argv) {
    147   testing::InitGoogleTest(&argc, argv);
    148 
    149   return RUN_ALL_TESTS();
    150 }
    151