11be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Copyright 2008, Google Inc.
21be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// All rights reserved.
31be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
41be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Redistribution and use in source and binary forms, with or without
51be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// modification, are permitted provided that the following conditions are
61be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// met:
71be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
81be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     * Redistributions of source code must retain the above copyright
91be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// notice, this list of conditions and the following disclaimer.
101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     * Redistributions in binary form must reproduce the above
111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// copyright notice, this list of conditions and the following disclaimer
121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in the documentation and/or other materials provided with the
131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// distribution.
141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//     * Neither the name of Google Inc. nor the names of its
151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// contributors may be used to endorse or promote products derived from
161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// this software without specific prior written permission.
171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania//
301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Author: wan@google.com (Zhanyong Wan)
311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests the --gtest_repeat=number flag.
331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#include <stdlib.h>
351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#include <iostream>
3641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest.h"
371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Indicates that this translation unit is part of Google Test's
391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// implementation.  It must come before gtest-internal-inl.h is
401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// included, or there will be a compiler error.  This trick is to
411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// prevent a user from accidentally including gtest-internal-inl.h in
421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// his code.
431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define GTEST_IMPLEMENTATION_ 1
441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#include "src/gtest-internal-inl.h"
451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#undef GTEST_IMPLEMENTATION_
461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace testing {
481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
491be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_string_(death_test_style);
501be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_string_(filter);
511be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaGTEST_DECLARE_int32_(repeat);
521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}  // namespace testing
541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing testing::GTEST_FLAG(death_test_style);
561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing testing::GTEST_FLAG(filter);
571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing testing::GTEST_FLAG(repeat);
581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace {
601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// We need this when we are testing Google Test itself and therefore
621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// cannot use Google Test assertions.
631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define GTEST_CHECK_INT_EQ_(expected, actual) \
641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  do {\
651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const int expected_val = (expected);\
661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    const int actual_val = (actual);\
6741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot    if (::testing::internal::IsTrue(expected_val != actual_val)) {\
681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania      ::std::cout << "Value of: " #actual "\n"\
691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                  << "  Actual: " << actual_val << "\n"\
701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                  << "Expected: " #expected "\n"\
711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                  << "Which is: " << expected_val << "\n";\
7241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot      ::testing::internal::posix::Abort();\
731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania    }\
74fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes  } while (::testing::internal::AlwaysFalse())
751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Used for verifying that global environment set-up and tear-down are
781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// inside the gtest_repeat loop.
791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint g_environment_set_up_count = 0;
811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint g_environment_tear_down_count = 0;
821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass MyEnvironment : public testing::Environment {
841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania public:
851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  MyEnvironment() {}
861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual void SetUp() { g_environment_set_up_count++; }
871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  virtual void TearDown() { g_environment_tear_down_count++; }
881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania};
891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A test that should fail.
911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint g_should_fail_count = 0;
931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
941be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(FooTest, ShouldFail) {
951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_should_fail_count++;
961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  EXPECT_EQ(0, 1) << "Expected failure.";
971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A test that should pass.
1001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint g_should_pass_count = 0;
1021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1031be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(FooTest, ShouldPass) {
1041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_should_pass_count++;
1051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A test that contains a thread-safe death test and a fast death
1081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// test.  It should pass.
1091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint g_death_test_count = 0;
1111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1121be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(BarDeathTest, ThreadSafeAndFast) {
1131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_death_test_count++;
1141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(death_test_style) = "threadsafe";
11641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), "");
1171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(death_test_style) = "fast";
11941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot  EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), "");
1201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST
1231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint g_param_test_count = 0;
1241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaconst int kNumberOfParamTests = 10;
1261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaclass MyParamTest : public testing::TestWithParam<int> {};
1281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1291be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST_P(MyParamTest, ShouldPass) {
1301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // TODO(vladl@google.com): Make parameter value checking robust
1311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  //                         WRT order of tests.
1321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(g_param_test_count % kNumberOfParamTests, GetParam());
1331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_param_test_count++;
1341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1351be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaINSTANTIATE_TEST_CASE_P(MyParamSequence,
1361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                        MyParamTest,
1371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania                        testing::Range(0, kNumberOfParamTests));
1381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_PARAM_TEST
1391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Resets the count for each test.
1411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid ResetCounts() {
1421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_environment_set_up_count = 0;
1431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_environment_tear_down_count = 0;
1441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_should_fail_count = 0;
1451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_should_pass_count = 0;
1461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_death_test_count = 0;
1471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST
1481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  g_param_test_count = 0;
1491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_PARAM_TEST
1501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Checks that the count for each test is expected.
1531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid CheckCounts(int expected) {
1541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(expected, g_environment_set_up_count);
1551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(expected, g_environment_tear_down_count);
1561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(expected, g_should_fail_count);
1571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(expected, g_should_pass_count);
1581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(expected, g_death_test_count);
1591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST
1601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(expected * kNumberOfParamTests, g_param_test_count);
1611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_PARAM_TEST
1621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests the behavior of Google Test when --gtest_repeat is not specified.
1651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid TestRepeatUnspecified() {
1661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ResetCounts();
1671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS());
1681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  CheckCounts(1);
1691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests the behavior of Google Test when --gtest_repeat has the given value.
1721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid TestRepeat(int repeat) {
1731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(repeat) = repeat;
1741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ResetCounts();
1761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat > 0 ? 1 : 0, RUN_ALL_TESTS());
1771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  CheckCounts(repeat);
1781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests using --gtest_repeat when --gtest_filter specifies an empty
1811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// set of tests.
1821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid TestRepeatWithEmptyFilter(int repeat) {
1831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(repeat) = repeat;
1841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(filter) = "None";
1851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ResetCounts();
1871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS());
1881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  CheckCounts(0);
1891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
1901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests using --gtest_repeat when --gtest_filter specifies a set of
1921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// successful tests.
1931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid TestRepeatWithFilterForSuccessfulTests(int repeat) {
1941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(repeat) = repeat;
1951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(filter) = "*-*ShouldFail";
1961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
1971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ResetCounts();
1981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS());
1991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat, g_environment_set_up_count);
2001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat, g_environment_tear_down_count);
2011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(0, g_should_fail_count);
2021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat, g_should_pass_count);
2031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat, g_death_test_count);
2041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST
2051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat * kNumberOfParamTests, g_param_test_count);
2061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_PARAM_TEST
2071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
2081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Tests using --gtest_repeat when --gtest_filter specifies a set of
2101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// failed tests.
2111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid TestRepeatWithFilterForFailedTests(int repeat) {
2121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(repeat) = repeat;
2131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_FLAG(filter) = "*ShouldFail";
2141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  ResetCounts();
2161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS());
2171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat, g_environment_set_up_count);
2181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat, g_environment_tear_down_count);
2191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(repeat, g_should_fail_count);
2201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(0, g_should_pass_count);
2211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(0, g_death_test_count);
2221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_PARAM_TEST
2231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  GTEST_CHECK_INT_EQ_(0, g_param_test_count);
2241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif  // GTEST_HAS_PARAM_TEST
2251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
2261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}  // namespace
2281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint main(int argc, char **argv) {
2301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  testing::InitGoogleTest(&argc, argv);
2311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  testing::AddGlobalTestEnvironment(new MyEnvironment);
2321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeatUnspecified();
2341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeat(0);
2351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeat(1);
2361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeat(5);
2371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeatWithEmptyFilter(2);
2391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeatWithEmptyFilter(3);
2401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeatWithFilterForSuccessfulTests(3);
2421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  TestRepeatWithFilterForFailedTests(4);
2441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // It would be nice to verify that the tests indeed loop forever
2461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // when GTEST_FLAG(repeat) is negative, but this test will be quite
2471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // complicated to write.  Since this flag is for interactive
2481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // debugging only and doesn't affect the normal test result, such a
2491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  // test would be an overkill.
2501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania
2511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  printf("PASS\n");
2521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania  return 0;
2531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania}
254