Commit 3d704217 authored by vladlosev's avatar vladlosev
Browse files

Value-parameterized tests and many bugfixes

parent b6a296d0
......@@ -277,6 +277,9 @@ void AssertHelper::operator=(const Message& message) const {
); // NOLINT
}
// Mutex for linked pointers.
Mutex g_linked_ptr_mutex(Mutex::NO_CONSTRUCTOR_NEEDED_FOR_STATIC_MUTEX);
// Application pathname gotten in InitGoogleTest.
String g_executable_path;
......@@ -830,7 +833,7 @@ static void StreamWideCharsToMessage(const wchar_t* wstr, size_t len,
// several other places).
for (size_t i = 0; i != len; ) { // NOLINT
if (wstr[i] != L'\0') {
*msg << WideStringToUtf8(wstr + i, len - i);
*msg << WideStringToUtf8(wstr + i, static_cast<int>(len - i));
while (i != len && wstr[i] != L'\0')
i++;
} else {
......@@ -1453,7 +1456,7 @@ inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,
// will be encoded as individual Unicode characters from Basic Normal Plane.
String WideStringToUtf8(const wchar_t* str, int num_chars) {
if (num_chars == -1)
num_chars = wcslen(str);
num_chars = static_cast<int>(wcslen(str));
StrStream stream;
for (int i = 0; i < num_chars; ++i) {
......@@ -2080,6 +2083,25 @@ TestInfo* MakeAndRegisterTestInfo(
return test_info;
}
#ifdef GTEST_HAS_PARAM_TEST
void ReportInvalidTestCaseType(const char* test_case_name,
const char* file, int line) {
Message errors;
errors
<< "Attempted redefinition of test case " << test_case_name << ".\n"
<< "All tests in the same test case must use the same test fixture\n"
<< "class. However, in test case " << test_case_name << ", you tried\n"
<< "to define a test using a fixture class different from the one\n"
<< "used earlier. This can happen if the two fixture classes are\n"
<< "from different namespaces and have the same name. You should\n"
<< "probably rename one of the classes to put the tests into different\n"
<< "test cases.";
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
errors.GetString().c_str());
}
#endif // GTEST_HAS_PARAM_TEST
} // namespace internal
// Returns the test case name.
......@@ -2156,6 +2178,18 @@ TestInfo * TestCase::GetTestInfo(const char* test_name) {
namespace internal {
// This method expands all parameterized tests registered with macros TEST_P
// and INSTANTIATE_TEST_CASE_P into regular tests and registers those.
// This will be done just once during the program runtime.
void UnitTestImpl::RegisterParameterizedTests() {
#ifdef GTEST_HAS_PARAM_TEST
if (!parameterized_tests_registered_) {
parameterized_test_registry_.RegisterTests();
parameterized_tests_registered_ = true;
}
#endif
}
// Creates the test object, runs it, records its result, and then
// deletes it.
void TestInfoImpl::Run() {
......@@ -3269,6 +3303,16 @@ const TestInfo* UnitTest::current_test_info() const {
return impl_->current_test_info();
}
#ifdef GTEST_HAS_PARAM_TEST
// Returns ParameterizedTestCaseRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
// L < mutex_
internal::ParameterizedTestCaseRegistry&
UnitTest::parameterized_test_registry() {
return impl_->parameterized_test_registry();
}
#endif // GTEST_HAS_PARAM_TEST
// Creates an empty UnitTest.
UnitTest::UnitTest() {
impl_ = new internal::UnitTestImpl(this);
......@@ -3314,6 +3358,10 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
per_thread_test_part_result_reporter_(
&default_per_thread_test_part_result_reporter_),
test_cases_(),
#ifdef GTEST_HAS_PARAM_TEST
parameterized_test_registry_(),
parameterized_tests_registered_(false),
#endif // GTEST_HAS_PARAM_TEST
last_death_test_case_(NULL),
current_test_case_(NULL),
current_test_info_(NULL),
......@@ -3415,6 +3463,10 @@ static void TearDownEnvironment(Environment* env) { env->TearDown(); }
// considered to be failed, but the rest of the tests will still be
// run. (We disable exceptions on Linux and Mac OS X, so the issue
// doesn't apply there.)
// When parameterized tests are enabled, it explands and registers
// parameterized tests first in RegisterParameterizedTests().
// All other functions called from RunAllTests() may safely assume that
// parameterized tests are ready to be counted and run.
int UnitTestImpl::RunAllTests() {
// Makes sure InitGoogleTest() was called.
if (!GTestIsInitialized()) {
......@@ -3424,6 +3476,8 @@ int UnitTestImpl::RunAllTests() {
return 1;
}
RegisterParameterizedTests();
// Lists all the tests and exits if the --gtest_list_tests
// flag was specified.
if (GTEST_FLAG(list_tests)) {
......@@ -3639,7 +3693,7 @@ internal::TestResult* UnitTestImpl::current_test_result() {
}
// TestInfoImpl constructor. The new instance assumes ownership of the test
// factory opbject.
// factory object.
TestInfoImpl::TestInfoImpl(TestInfo* parent,
const char* test_case_name,
const char* name,
......@@ -3663,10 +3717,6 @@ TestInfoImpl::~TestInfoImpl() {
delete factory_;
}
} // namespace internal
namespace internal {
// Parses a string as a command line flag. The string should have
// the format "--flag=value". When def_optional is true, the "=value"
// part can be omitted.
......@@ -3814,6 +3864,27 @@ void InitGoogleTestImpl(int* argc, CharType** argv) {
}
}
// Returns the current OS stack trace as a String.
//
// The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter
// specifies the number of top frames to be skipped, which doesn't
// count against the number of frames to be included.
//
// For example, if Foo() calls Bar(), which in turn calls
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count) {
// We pass skip_count + 1 to skip this wrapper function in addition
// to what the user really wants to skip.
return unit_test->impl()->CurrentOsStackTraceExceptTop(skip_count + 1);
}
// Returns the number of failed test parts in the given test result object.
int GetFailedPartCount(const TestResult* result) {
return result->failed_part_count();
}
} // namespace internal
// Initializes Google Test. This must be called before calling
......
......@@ -83,12 +83,6 @@ int _rmdir(const char* path) {
return ret;
}
#elif defined(GTEST_LINUX_GOOGLE3_MODE)
// Creates a temporary directory and returns its path.
const char* MakeTempDir() {
static char dir_name[] = "gtest-filepath_test_tmpXXXXXX";
return mkdtemp(dir_name);
}
#endif // _WIN32_WCE
#ifndef _WIN32_WCE
......
// Copyright 2003, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Authors: Dan Egnor (egnor@google.com)
// Ported to Windows: Vadim Berman (vadimb@google.com)
#include <gtest/internal/gtest-linked_ptr.h>
#include <stdlib.h>
#include <gtest/gtest.h>
namespace {
using testing::Message;
using testing::internal::linked_ptr;
int num;
Message* history = NULL;
// Class which tracks allocation/deallocation
class A {
public:
A(): mynum(num++) { *history << "A" << mynum << " ctor\n"; }
virtual ~A() { *history << "A" << mynum << " dtor\n"; }
virtual void Use() { *history << "A" << mynum << " use\n"; }
protected:
int mynum;
};
// Subclass
class B : public A {
public:
B() { *history << "B" << mynum << " ctor\n"; }
~B() { *history << "B" << mynum << " dtor\n"; }
virtual void Use() { *history << "B" << mynum << " use\n"; }
};
class LinkedPtrTest : public testing::Test {
public:
LinkedPtrTest() {
num = 0;
history = new Message;
}
virtual ~LinkedPtrTest() {
delete history;
history = NULL;
}
};
TEST_F(LinkedPtrTest, GeneralTest) {
{
linked_ptr<A> a0, a1, a2;
a0 = a0;
a1 = a2;
ASSERT_EQ(a0.get(), static_cast<A*>(NULL));
ASSERT_EQ(a1.get(), static_cast<A*>(NULL));
ASSERT_EQ(a2.get(), static_cast<A*>(NULL));
ASSERT_TRUE(a0 == NULL);
ASSERT_TRUE(a1 == NULL);
ASSERT_TRUE(a2 == NULL);
{
linked_ptr<A> a3(new A);
a0 = a3;
ASSERT_TRUE(a0 == a3);
ASSERT_TRUE(a0 != NULL);
ASSERT_TRUE(a0.get() == a3);
ASSERT_TRUE(a0 == a3.get());
linked_ptr<A> a4(a0);
a1 = a4;
linked_ptr<A> a5(new A);
ASSERT_TRUE(a5.get() != a3);
ASSERT_TRUE(a5 != a3.get());
a2 = a5;
linked_ptr<B> b0(new B);
linked_ptr<A> a6(b0);
ASSERT_TRUE(b0 == a6);
ASSERT_TRUE(a6 == b0);
ASSERT_TRUE(b0 != NULL);
a5 = b0;
a5 = b0;
a3->Use();
a4->Use();
a5->Use();
a6->Use();
b0->Use();
(*b0).Use();
b0.get()->Use();
}
a0->Use();
a1->Use();
a2->Use();
a1 = a2;
a2.reset(new A);
a0.reset();
linked_ptr<A> a7;
}
ASSERT_STREQ(
"A0 ctor\n"
"A1 ctor\n"
"A2 ctor\n"
"B2 ctor\n"
"A0 use\n"
"A0 use\n"
"B2 use\n"
"B2 use\n"
"B2 use\n"
"B2 use\n"
"B2 use\n"
"B2 dtor\n"
"A2 dtor\n"
"A0 use\n"
"A0 use\n"
"A1 use\n"
"A3 ctor\n"
"A0 dtor\n"
"A3 dtor\n"
"A1 dtor\n",
history->GetString().c_str()
);
}
} // Unnamed namespace
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: vladl@google.com (Vlad Losev)
//
// Tests for Google Test itself. This verifies that the basic constructs of
// Google Test work.
#include <gtest/gtest.h>
#include "test/gtest-param-test_test.h"
#ifdef GTEST_HAS_PARAM_TEST
using ::testing::Values;
using ::testing::internal::ParamGenerator;
// Tests that generators defined in a different translation unit
// are functional. The test using extern_gen is defined
// in gtest-param-test_test.cc.
ParamGenerator<int> extern_gen = Values(33);
// Tests that a parameterized test case can be defined in one translation unit
// and instantiated in another. The test is defined in gtest-param-test_test.cc
// and ExternalInstantiationTest fixture class is defined in
// gtest-param-test_test.h.
INSTANTIATE_TEST_CASE_P(MultiplesOf33,
ExternalInstantiationTest,
Values(33, 66));
// Tests that a parameterized test case can be instantiated
// in multiple translation units. Another instantiation is defined
// in gtest-param-test_test.cc and InstantiationInMultipleTranslaionUnitsTest
// fixture is defined in gtest-param-test_test.h
INSTANTIATE_TEST_CASE_P(Sequence2,
InstantiationInMultipleTranslaionUnitsTest,
Values(42*3, 42*4, 42*5));
#endif // GTEST_HAS_PARAM_TEST
This diff is collapsed.
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Authors: vladl@google.com (Vlad Losev)
//
// The Google C++ Testing Framework (Google Test)
//
// This header file provides classes and functions used internally
// for testing Google Test itself.
#ifndef GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
#define GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
#include <gtest/gtest.h>
#ifdef GTEST_HAS_PARAM_TEST
// Test fixture for testing definition and instantiation of a test
// in separate translation units.
class ExternalInstantiationTest : public ::testing::TestWithParam<int> {};
// Test fixture for testing instantiation of a test in multiple
// translation units.
class InstantiationInMultipleTranslaionUnitsTest
: public ::testing::TestWithParam<int> {};
#endif // GTEST_HAS_PARAM_TEST
#endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: vladl@google.com (Vlad Losev)
//
// This file tests the internal cross-platform support utilities.
#include <gtest/internal/gtest-port.h>
#include <gtest/gtest.h>
#include <gtest/gtest-spi.h>
TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
if (false)
GTEST_CHECK_(false) << "This should never be executed; "
"It's a compilation test only.";
if (true)
GTEST_CHECK_(true);
else
; // NOLINT
if (false)
; // NOLINT
else
GTEST_CHECK_(true) << "";
}
TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
switch (0) {
case 1:
break;
default:
GTEST_CHECK_(true);
}
switch(0)
case 0:
GTEST_CHECK_(true) << "Check failed in switch case";
}
#ifdef GTEST_HAS_DEATH_TEST
TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) {
const bool a_false_condition = false;
EXPECT_DEATH(GTEST_CHECK_(a_false_condition) << "Extra info",
#ifdef _MSC_VER
"gtest-port_test\\.cc\\([0-9]+\\):"
#else
"gtest-port_test\\.cc:[0-9]+"
#endif // _MSC_VER
".*a_false_condition.*Extra info.*");
}
TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) {
EXPECT_EXIT({
GTEST_CHECK_(true) << "Extra info";
::std::cerr << "Success\n";
exit(0); },
::testing::ExitedWithCode(0), "Success");
}
#endif // GTEST_HAS_DEATH_TEST
#ifdef GTEST_USES_POSIX_RE
using ::testing::internal::RE;
template <typename Str>
class RETest : public ::testing::Test {};
// Defines StringTypes as the list of all string types that class RE
// supports.
typedef testing::Types<
#if GTEST_HAS_STD_STRING
::std::string,
#endif // GTEST_HAS_STD_STRING
#if GTEST_HAS_GLOBAL_STRING
::string,
#endif // GTEST_HAS_GLOBAL_STRING
const char*> StringTypes;
TYPED_TEST_CASE(RETest, StringTypes);
// Tests RE's implicit constructors.
TYPED_TEST(RETest, ImplicitConstructorWorks) {
const RE empty = TypeParam("");
EXPECT_STREQ("", empty.pattern());
const RE simple = TypeParam("hello");
EXPECT_STREQ("hello", simple.pattern());
const RE normal = TypeParam(".*(\\w+)");
EXPECT_STREQ(".*(\\w+)", normal.pattern());
}
// Tests that RE's constructors reject invalid regular expressions.
TYPED_TEST(RETest, RejectsInvalidRegex) {
EXPECT_NONFATAL_FAILURE({
const RE invalid = TypeParam("?");
}, "\"?\" is not a valid POSIX Extended regular expression.");
}
// Tests RE::FullMatch().
TYPED_TEST(RETest, FullMatchWorks) {
const RE empty = TypeParam("");
EXPECT_TRUE(RE::FullMatch(TypeParam(""), empty));
EXPECT_FALSE(RE::FullMatch(TypeParam("a"), empty));
const RE re = TypeParam("a.*z");
EXPECT_TRUE(RE::FullMatch(TypeParam("az"), re));
EXPECT_TRUE(RE::FullMatch(TypeParam("axyz"), re));
EXPECT_FALSE(RE::FullMatch(TypeParam("baz"), re));
EXPECT_FALSE(RE::FullMatch(TypeParam("azy"), re));
}
// Tests RE::PartialMatch().
TYPED_TEST(RETest, PartialMatchWorks) {
const RE empty = TypeParam("");
EXPECT_TRUE(RE::PartialMatch(TypeParam(""), empty));
EXPECT_TRUE(RE::PartialMatch(TypeParam("a"), empty));
const RE re = TypeParam("a.*z");
EXPECT_TRUE(RE::PartialMatch(TypeParam("az"), re));
EXPECT_TRUE(RE::PartialMatch(TypeParam("axyz"), re));
EXPECT_TRUE(RE::PartialMatch(TypeParam("baz"), re));
EXPECT_TRUE(RE::PartialMatch(TypeParam("azy"), re));
EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re));
}
#endif // GTEST_USES_POSIX_RE
......@@ -348,3 +348,15 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, NumericTest, NumericTypes);
} // namespace library2
#endif // GTEST_HAS_TYPED_TEST_P
#if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
// Google Test doesn't support type-parameterized tests on some platforms
// and compilers, such as MSVC 7.1. If we use conditional compilation to
// compile out all code referring to the gtest_main library, MSVC linker
// will not link that library at all and consequently complain about
// missing entry point defined in that library (fatal error LNK1561:
// entry point must be defined). This dummy test keeps gtest_main linked in.
TEST(DummyTest, TypedTestsAreNotSupportedOnThisPlatform) {}
#endif // #if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
This diff is collapsed.
......@@ -58,19 +58,19 @@ TEST_F(FooTest, Xyz) {
// Test case BarTest.
TEST(BarTest, Test1) {
TEST(BarTest, TestOne) {
}
TEST(BarTest, Test2) {
TEST(BarTest, TestTwo) {
}
TEST(BarTest, Test3) {
TEST(BarTest, TestThree) {
}
// Test case BazTest.
TEST(BazTest, Test1) {
TEST(BazTest, TestOne) {
FAIL() << "Expected failure.";
}
......@@ -80,6 +80,20 @@ TEST(BazTest, TestA) {
TEST(BazTest, TestB) {
}
#ifdef GTEST_HAS_PARAM_TEST
class ParamTest : public testing::TestWithParam<int> {
};
TEST_P(ParamTest, TestX) {
}
TEST_P(ParamTest, TestY) {
}
INSTANTIATE_TEST_CASE_P(SeqP, ParamTest, testing::Values(1, 2));
INSTANTIATE_TEST_CASE_P(SeqQ, ParamTest, testing::Values(5, 6));
#endif // GTEST_HAS_PARAM_TEST
} // namespace
......
......@@ -121,6 +121,24 @@ TEST(BarDeathTest, ThreadSafeAndFast) {
#endif // GTEST_HAS_DEATH_TEST
}
#ifdef GTEST_HAS_PARAM_TEST
int g_param_test_count = 0;
const int kNumberOfParamTests = 10;
class MyParamTest : public testing::TestWithParam<int> {};
TEST_P(MyParamTest, ShouldPass) {
// TODO(vladl@google.com): Make parameter value checking robust
// WRT order of tests.
GTEST_CHECK_INT_EQ_(g_param_test_count % kNumberOfParamTests, GetParam());
g_param_test_count++;
}
INSTANTIATE_TEST_CASE_P(MyParamSequence,
MyParamTest,
testing::Range(0, kNumberOfParamTests));
#endif // GTEST_HAS_PARAM_TEST
// Resets the count for each test.
void ResetCounts() {
g_environment_set_up_count = 0;
......@@ -128,6 +146,9 @@ void ResetCounts() {
g_should_fail_count = 0;
g_should_pass_count = 0;
g_death_test_count = 0;
#ifdef GTEST_HAS_PARAM_TEST
g_param_test_count = 0;
#endif // GTEST_HAS_PARAM_TEST
}
// Checks that the count for each test is expected.
......@@ -137,6 +158,9 @@ void CheckCounts(int expected) {
GTEST_CHECK_INT_EQ_(expected, g_should_fail_count);
GTEST_CHECK_INT_EQ_(expected, g_should_pass_count);
GTEST_CHECK_INT_EQ_(expected, g_death_test_count);
#ifdef GTEST_HAS_PARAM_TEST
GTEST_CHECK_INT_EQ_(expected * kNumberOfParamTests, g_param_test_count);
#endif // GTEST_HAS_PARAM_TEST
}
// Tests the behavior of Google Test when --gtest_repeat is not specified.
......@@ -179,6 +203,9 @@ void TestRepeatWithFilterForSuccessfulTests(int repeat) {
GTEST_CHECK_INT_EQ_(0, g_should_fail_count);
GTEST_CHECK_INT_EQ_(repeat, g_should_pass_count);
GTEST_CHECK_INT_EQ_(repeat, g_death_test_count);
#ifdef GTEST_HAS_PARAM_TEST
GTEST_CHECK_INT_EQ_(repeat * kNumberOfParamTests, g_param_test_count);
#endif // GTEST_HAS_PARAM_TEST
}
// Tests using --gtest_repeat when --gtest_filter specifies a set of
......@@ -194,6 +221,9 @@ void TestRepeatWithFilterForFailedTests(int repeat) {
GTEST_CHECK_INT_EQ_(repeat, g_should_fail_count);
GTEST_CHECK_INT_EQ_(0, g_should_pass_count);
GTEST_CHECK_INT_EQ_(0, g_death_test_count);
#ifdef GTEST_HAS_PARAM_TEST
GTEST_CHECK_INT_EQ_(0, g_param_test_count);
#endif // GTEST_HAS_PARAM_TEST
}
} // namespace
......
......@@ -109,6 +109,8 @@ using testing::internal::AppendUserMessage;
using testing::internal::CodePointToUtf8;
using testing::internal::EqFailure;
using testing::internal::FloatingPoint;
using testing::internal::GetCurrentOsStackTraceExceptTop;
using testing::internal::GetFailedPartCount;
using testing::internal::GTestFlagSaver;
using testing::internal::Int32;
using testing::internal::List;
......@@ -899,6 +901,13 @@ TEST_F(TestResultTest, failed_part_count) {
ASSERT_EQ(1u, r2->failed_part_count());
}
// Tests testing::internal::GetFailedPartCount().
TEST_F(TestResultTest, GetFailedPartCount) {
ASSERT_EQ(0u, GetFailedPartCount(r0));
ASSERT_EQ(0u, GetFailedPartCount(r1));
ASSERT_EQ(1u, GetFailedPartCount(r2));
}
// Tests TestResult::total_part_count()
TEST_F(TestResultTest, total_part_count) {
ASSERT_EQ(0u, r0->total_part_count());
......@@ -4914,6 +4923,14 @@ TEST(ThreadLocalTest, Init) {
EXPECT_EQ(&i, t2.get());
}
TEST(GetCurrentOsStackTraceExceptTopTest, ReturnsTheStackTrace) {
testing::UnitTest* const unit_test = testing::UnitTest::GetInstance();
// We don't have a stack walker in Google Test yet.
EXPECT_STREQ("", GetCurrentOsStackTraceExceptTop(unit_test, 0).c_str());
EXPECT_STREQ("", GetCurrentOsStackTraceExceptTop(unit_test, 1).c_str());
}
#ifndef GTEST_OS_SYMBIAN
// We will want to integrate running the unittests to a different
// main application on Symbian.
......
......@@ -5,4 +5,4 @@
// is set in the "Based On:" dropdown in the "Target" info dialog.
PRODUCT_NAME = $(TARGET_NAME)
HEADER_SEARCH_PATHS = "../"
\ No newline at end of file
HEADER_SEARCH_PATHS = ../ ../include
......@@ -5,3 +5,4 @@
// is set in the "Based On:" dropdown in the "Target" info dialog.
PRODUCT_NAME = $(TARGET_NAME)
HEADER_SEARCH_PATHS = ../include
......@@ -12,6 +12,8 @@ test_executables=("$BUILT_PRODUCTS_DIR/sample1_unittest"
"$BUILT_PRODUCTS_DIR/sample4_unittest"
"$BUILT_PRODUCTS_DIR/sample5_unittest"
"$BUILT_PRODUCTS_DIR/sample6_unittest"
"$BUILT_PRODUCTS_DIR/sample7_unittest"
"$BUILT_PRODUCTS_DIR/sample8_unittest"
"$BUILT_PRODUCTS_DIR/gtest_unittest"
"$BUILT_PRODUCTS_DIR/gtest-death-test_test"
......@@ -28,6 +30,9 @@ test_executables=("$BUILT_PRODUCTS_DIR/sample1_unittest"
"$BUILT_PRODUCTS_DIR/gtest_stress_test"
"$BUILT_PRODUCTS_DIR/gtest_test_part_test"
"$BUILT_PRODUCTS_DIR/gtest-typed-test_test"
"$BUILT_PRODUCTS_DIR/gtest-param-test_test"
"$BUILT_PRODUCTS_DIR/gtest-linked_ptr_test"
"$BUILT_PRODUCTS_DIR/gtest-port_test"
"$BUILT_PRODUCTS_DIR/gtest_output_test.py"
"$BUILT_PRODUCTS_DIR/gtest_color_test.py"
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment