"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googletest/test/gtest_repeat_test.cc" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gtest_repeat_test.cc  (googletest-release-1.11.0):gtest_repeat_test.cc  (googletest-release-1.12.0)
skipping to change at line 33 skipping to change at line 33
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Tests the --gtest_repeat=number flag. // Tests the --gtest_repeat=number flag.
#include <stdlib.h> #include <stdlib.h>
#include <iostream> #include <iostream>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
namespace testing {
GTEST_DECLARE_string_(death_test_style);
GTEST_DECLARE_string_(filter);
GTEST_DECLARE_int32_(repeat);
} // namespace testing
using testing::GTEST_FLAG(death_test_style);
using testing::GTEST_FLAG(filter);
using testing::GTEST_FLAG(repeat);
namespace { namespace {
// We need this when we are testing Google Test itself and therefore // We need this when we are testing Google Test itself and therefore
// cannot use Google Test assertions. // cannot use Google Test assertions.
#define GTEST_CHECK_INT_EQ_(expected, actual) \ #define GTEST_CHECK_INT_EQ_(expected, actual) \
do {\ do { \
const int expected_val = (expected);\ const int expected_val = (expected); \
const int actual_val = (actual);\ const int actual_val = (actual); \
if (::testing::internal::IsTrue(expected_val != actual_val)) {\ if (::testing::internal::IsTrue(expected_val != actual_val)) { \
::std::cout << "Value of: " #actual "\n"\ ::std::cout << "Value of: " #actual "\n" \
<< " Actual: " << actual_val << "\n"\ << " Actual: " << actual_val << "\n" \
<< "Expected: " #expected "\n"\ << "Expected: " #expected "\n" \
<< "Which is: " << expected_val << "\n";\ << "Which is: " << expected_val << "\n"; \
::testing::internal::posix::Abort();\ ::testing::internal::posix::Abort(); \
}\ } \
} while (::testing::internal::AlwaysFalse()) } while (::testing::internal::AlwaysFalse())
// Used for verifying that global environment set-up and tear-down are // Used for verifying that global environment set-up and tear-down are
// inside the --gtest_repeat loop. // inside the --gtest_repeat loop.
int g_environment_set_up_count = 0; int g_environment_set_up_count = 0;
int g_environment_tear_down_count = 0; int g_environment_tear_down_count = 0;
class MyEnvironment : public testing::Environment { class MyEnvironment : public testing::Environment {
public: public:
skipping to change at line 92 skipping to change at line 82
TEST(FooTest, ShouldFail) { TEST(FooTest, ShouldFail) {
g_should_fail_count++; g_should_fail_count++;
EXPECT_EQ(0, 1) << "Expected failure."; EXPECT_EQ(0, 1) << "Expected failure.";
} }
// A test that should pass. // A test that should pass.
int g_should_pass_count = 0; int g_should_pass_count = 0;
TEST(FooTest, ShouldPass) { TEST(FooTest, ShouldPass) { g_should_pass_count++; }
g_should_pass_count++;
}
// A test that contains a thread-safe death test and a fast death // A test that contains a thread-safe death test and a fast death
// test. It should pass. // test. It should pass.
int g_death_test_count = 0; int g_death_test_count = 0;
TEST(BarDeathTest, ThreadSafeAndFast) { TEST(BarDeathTest, ThreadSafeAndFast) {
g_death_test_count++; g_death_test_count++;
GTEST_FLAG(death_test_style) = "threadsafe"; GTEST_FLAG_SET(death_test_style, "threadsafe");
EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), ""); EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), "");
GTEST_FLAG(death_test_style) = "fast"; GTEST_FLAG_SET(death_test_style, "fast");
EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), ""); EXPECT_DEATH_IF_SUPPORTED(::testing::internal::posix::Abort(), "");
} }
int g_param_test_count = 0; int g_param_test_count = 0;
const int kNumberOfParamTests = 10; const int kNumberOfParamTests = 10;
class MyParamTest : public testing::TestWithParam<int> {}; class MyParamTest : public testing::TestWithParam<int> {};
TEST_P(MyParamTest, ShouldPass) { TEST_P(MyParamTest, ShouldPass) {
GTEST_CHECK_INT_EQ_(g_param_test_count % kNumberOfParamTests, GetParam()); GTEST_CHECK_INT_EQ_(g_param_test_count % kNumberOfParamTests, GetParam());
g_param_test_count++; g_param_test_count++;
} }
INSTANTIATE_TEST_SUITE_P(MyParamSequence, INSTANTIATE_TEST_SUITE_P(MyParamSequence, MyParamTest,
MyParamTest,
testing::Range(0, kNumberOfParamTests)); testing::Range(0, kNumberOfParamTests));
// Resets the count for each test. // Resets the count for each test.
void ResetCounts() { void ResetCounts() {
g_environment_set_up_count = 0; g_environment_set_up_count = 0;
g_environment_tear_down_count = 0; g_environment_tear_down_count = 0;
g_should_fail_count = 0; g_should_fail_count = 0;
g_should_pass_count = 0; g_should_pass_count = 0;
g_death_test_count = 0; g_death_test_count = 0;
g_param_test_count = 0; g_param_test_count = 0;
skipping to change at line 154 skipping to change at line 141
// Tests the behavior of Google Test when --gtest_repeat is not specified. // Tests the behavior of Google Test when --gtest_repeat is not specified.
void TestRepeatUnspecified() { void TestRepeatUnspecified() {
ResetCounts(); ResetCounts();
GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS()); GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS());
CheckCounts(1); CheckCounts(1);
} }
// Tests the behavior of Google Test when --gtest_repeat has the given value. // Tests the behavior of Google Test when --gtest_repeat has the given value.
void TestRepeat(int repeat) { void TestRepeat(int repeat) {
GTEST_FLAG(repeat) = repeat; GTEST_FLAG_SET(repeat, repeat);
GTEST_FLAG_SET(recreate_environments_when_repeating, true);
ResetCounts(); ResetCounts();
GTEST_CHECK_INT_EQ_(repeat > 0 ? 1 : 0, RUN_ALL_TESTS()); GTEST_CHECK_INT_EQ_(repeat > 0 ? 1 : 0, RUN_ALL_TESTS());
CheckCounts(repeat); CheckCounts(repeat);
} }
// Tests using --gtest_repeat when --gtest_filter specifies an empty // Tests using --gtest_repeat when --gtest_filter specifies an empty
// set of tests. // set of tests.
void TestRepeatWithEmptyFilter(int repeat) { void TestRepeatWithEmptyFilter(int repeat) {
GTEST_FLAG(repeat) = repeat; GTEST_FLAG_SET(repeat, repeat);
GTEST_FLAG(filter) = "None"; GTEST_FLAG_SET(recreate_environments_when_repeating, true);
GTEST_FLAG_SET(filter, "None");
ResetCounts(); ResetCounts();
GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS()); GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS());
CheckCounts(0); CheckCounts(0);
} }
// Tests using --gtest_repeat when --gtest_filter specifies a set of // Tests using --gtest_repeat when --gtest_filter specifies a set of
// successful tests. // successful tests.
void TestRepeatWithFilterForSuccessfulTests(int repeat) { void TestRepeatWithFilterForSuccessfulTests(int repeat) {
GTEST_FLAG(repeat) = repeat; GTEST_FLAG_SET(repeat, repeat);
GTEST_FLAG(filter) = "*-*ShouldFail"; GTEST_FLAG_SET(recreate_environments_when_repeating, true);
GTEST_FLAG_SET(filter, "*-*ShouldFail");
ResetCounts(); ResetCounts();
GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS()); GTEST_CHECK_INT_EQ_(0, RUN_ALL_TESTS());
GTEST_CHECK_INT_EQ_(repeat, g_environment_set_up_count); GTEST_CHECK_INT_EQ_(repeat, g_environment_set_up_count);
GTEST_CHECK_INT_EQ_(repeat, g_environment_tear_down_count); GTEST_CHECK_INT_EQ_(repeat, g_environment_tear_down_count);
GTEST_CHECK_INT_EQ_(0, g_should_fail_count); GTEST_CHECK_INT_EQ_(0, g_should_fail_count);
GTEST_CHECK_INT_EQ_(repeat, g_should_pass_count); GTEST_CHECK_INT_EQ_(repeat, g_should_pass_count);
GTEST_CHECK_INT_EQ_(repeat, g_death_test_count); GTEST_CHECK_INT_EQ_(repeat, g_death_test_count);
GTEST_CHECK_INT_EQ_(repeat * kNumberOfParamTests, g_param_test_count); GTEST_CHECK_INT_EQ_(repeat * kNumberOfParamTests, g_param_test_count);
} }
// Tests using --gtest_repeat when --gtest_filter specifies a set of // Tests using --gtest_repeat when --gtest_filter specifies a set of
// failed tests. // failed tests.
void TestRepeatWithFilterForFailedTests(int repeat) { void TestRepeatWithFilterForFailedTests(int repeat) {
GTEST_FLAG(repeat) = repeat; GTEST_FLAG_SET(repeat, repeat);
GTEST_FLAG(filter) = "*ShouldFail"; GTEST_FLAG_SET(recreate_environments_when_repeating, true);
GTEST_FLAG_SET(filter, "*ShouldFail");
ResetCounts(); ResetCounts();
GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS()); GTEST_CHECK_INT_EQ_(1, RUN_ALL_TESTS());
GTEST_CHECK_INT_EQ_(repeat, g_environment_set_up_count); GTEST_CHECK_INT_EQ_(repeat, g_environment_set_up_count);
GTEST_CHECK_INT_EQ_(repeat, g_environment_tear_down_count); GTEST_CHECK_INT_EQ_(repeat, g_environment_tear_down_count);
GTEST_CHECK_INT_EQ_(repeat, g_should_fail_count); GTEST_CHECK_INT_EQ_(repeat, g_should_fail_count);
GTEST_CHECK_INT_EQ_(0, g_should_pass_count); GTEST_CHECK_INT_EQ_(0, g_should_pass_count);
GTEST_CHECK_INT_EQ_(0, g_death_test_count); GTEST_CHECK_INT_EQ_(0, g_death_test_count);
GTEST_CHECK_INT_EQ_(0, g_param_test_count); GTEST_CHECK_INT_EQ_(0, g_param_test_count);
} }
 End of changes. 12 change blocks. 
37 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)