2008-12-10 06:08:54 +01:00
|
|
|
// Copyright 2007, 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.
|
2018-08-14 20:04:07 +02:00
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
|
|
|
|
// Google Mock - a framework for writing C++ mock classes.
|
|
|
|
//
|
|
|
|
// This file tests the internal utilities.
|
|
|
|
|
2010-09-14 07:38:21 +02:00
|
|
|
#include "gmock/internal/gmock-internal-utils.h"
|
2019-08-23 17:57:56 +02:00
|
|
|
|
2009-05-14 22:55:30 +02:00
|
|
|
#include <stdlib.h>
|
2019-08-23 17:57:56 +02:00
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
#include <map>
|
2015-09-08 08:46:25 +02:00
|
|
|
#include <memory>
|
2008-12-10 06:08:54 +01:00
|
|
|
#include <sstream>
|
2019-08-23 17:57:56 +02:00
|
|
|
#include <string>
|
2008-12-10 06:08:54 +01:00
|
|
|
#include <vector>
|
2019-08-23 17:57:56 +02:00
|
|
|
|
2010-09-14 07:38:21 +02:00
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gmock/internal/gmock-port.h"
|
|
|
|
#include "gtest/gtest-spi.h"
|
2019-08-23 17:57:56 +02:00
|
|
|
#include "gtest/gtest.h"
|
2018-03-22 20:35:37 +01:00
|
|
|
|
|
|
|
// Indicates that this translation unit is part of Google Test's
|
|
|
|
// implementation. It must come before gtest-internal-inl.h is
|
|
|
|
// included, or there will be a compiler error. This trick is to
|
|
|
|
// prevent a user from accidentally including gtest-internal-inl.h in
|
|
|
|
// their code.
|
|
|
|
#define GTEST_IMPLEMENTATION_ 1
|
2015-07-28 02:12:51 +02:00
|
|
|
#include "src/gtest-internal-inl.h"
|
2018-03-22 20:35:37 +01:00
|
|
|
#undef GTEST_IMPLEMENTATION_
|
2015-07-28 02:12:51 +02:00
|
|
|
|
2009-05-14 22:55:30 +02:00
|
|
|
#if GTEST_OS_CYGWIN
|
2011-02-24 08:29:13 +01:00
|
|
|
# include <sys/types.h> // For ssize_t. NOLINT
|
2009-05-14 22:55:30 +02:00
|
|
|
#endif
|
|
|
|
|
2009-08-14 06:50:02 +02:00
|
|
|
namespace proto2 {
|
|
|
|
class Message;
|
|
|
|
} // namespace proto2
|
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
namespace testing {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-03-22 20:35:37 +01:00
|
|
|
TEST(JoinAsTupleTest, JoinsEmptyTuple) {
|
|
|
|
EXPECT_EQ("", JoinAsTuple(Strings()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(JoinAsTupleTest, JoinsOneTuple) {
|
|
|
|
const char* fields[] = {"1"};
|
|
|
|
EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(JoinAsTupleTest, JoinsTwoTuple) {
|
|
|
|
const char* fields[] = {"1", "a"};
|
|
|
|
EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(JoinAsTupleTest, JoinsTenTuple) {
|
|
|
|
const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
|
|
|
|
EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)",
|
|
|
|
JoinAsTuple(Strings(fields, fields + 10)));
|
|
|
|
}
|
|
|
|
|
2009-02-12 02:34:27 +01:00
|
|
|
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
|
|
|
|
EXPECT_EQ("", ConvertIdentifierNameToWords(""));
|
|
|
|
EXPECT_EQ("", ConvertIdentifierNameToWords("_"));
|
|
|
|
EXPECT_EQ("", ConvertIdentifierNameToWords("__"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsDigits) {
|
|
|
|
EXPECT_EQ("1", ConvertIdentifierNameToWords("_1"));
|
|
|
|
EXPECT_EQ("2", ConvertIdentifierNameToWords("2_"));
|
|
|
|
EXPECT_EQ("34", ConvertIdentifierNameToWords("_34_"));
|
|
|
|
EXPECT_EQ("34 56", ConvertIdentifierNameToWords("_34_56"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsCamelCaseWords) {
|
|
|
|
EXPECT_EQ("a big word", ConvertIdentifierNameToWords("ABigWord"));
|
|
|
|
EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("FooBar"));
|
|
|
|
EXPECT_EQ("foo", ConvertIdentifierNameToWords("Foo_"));
|
|
|
|
EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_Foo_Bar_"));
|
|
|
|
EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_Foo__And_Bar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContains_SeparatedWords) {
|
|
|
|
EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("foo_bar"));
|
|
|
|
EXPECT_EQ("foo", ConvertIdentifierNameToWords("_foo_"));
|
|
|
|
EXPECT_EQ("foo bar", ConvertIdentifierNameToWords("_foo_bar_"));
|
|
|
|
EXPECT_EQ("foo and bar", ConvertIdentifierNameToWords("_foo__and_bar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
|
|
|
|
EXPECT_EQ("foo bar 123", ConvertIdentifierNameToWords("Foo_bar123"));
|
|
|
|
EXPECT_EQ("chapter 11 section 1",
|
|
|
|
ConvertIdentifierNameToWords("_Chapter11Section_1_"));
|
|
|
|
}
|
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
TEST(PointeeOfTest, WorksForSmartPointers) {
|
2019-09-12 16:36:44 +02:00
|
|
|
EXPECT_TRUE(
|
|
|
|
(std::is_same<int, PointeeOf<std::unique_ptr<int>>::type>::value));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
(std::is_same<std::string,
|
|
|
|
PointeeOf<std::shared_ptr<std::string>>::type>::value));
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PointeeOfTest, WorksForRawPointers) {
|
2019-09-12 16:36:44 +02:00
|
|
|
EXPECT_TRUE((std::is_same<int, PointeeOf<int*>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<const char, PointeeOf<const char*>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_void<PointeeOf<void*>::type>::value));
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GetRawPointerTest, WorksForSmartPointers) {
|
2015-07-28 01:51:16 +02:00
|
|
|
const char* const raw_p1 = new const char('a'); // NOLINT
|
|
|
|
const std::unique_ptr<const char> p1(raw_p1);
|
|
|
|
EXPECT_EQ(raw_p1, GetRawPointer(p1));
|
|
|
|
double* const raw_p2 = new double(2.5); // NOLINT
|
|
|
|
const std::shared_ptr<double> p2(raw_p2);
|
|
|
|
EXPECT_EQ(raw_p2, GetRawPointer(p2));
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GetRawPointerTest, WorksForRawPointers) {
|
2018-10-05 00:28:05 +02:00
|
|
|
int* p = nullptr;
|
|
|
|
EXPECT_TRUE(nullptr == GetRawPointer(p));
|
2008-12-10 06:08:54 +01:00
|
|
|
int n = 1;
|
|
|
|
EXPECT_EQ(&n, GetRawPointer(&n));
|
|
|
|
}
|
|
|
|
|
2010-05-10 19:14:29 +02:00
|
|
|
// Tests KindOf<T>.
|
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
class Base {};
|
|
|
|
class Derived : public Base {};
|
|
|
|
|
2009-05-14 22:55:30 +02:00
|
|
|
TEST(KindOfTest, Bool) {
|
|
|
|
EXPECT_EQ(kBool, GMOCK_KIND_OF_(bool)); // NOLINT
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(KindOfTest, Integer) {
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(char)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(signed char)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned char)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(short)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned short)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(int)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(Int64)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(UInt64)); // NOLINT
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
|
|
|
|
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
|
|
|
|
// ssize_t is not defined on Windows and possibly some other OSes.
|
|
|
|
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(KindOfTest, FloatingPoint) {
|
|
|
|
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(float)); // NOLINT
|
|
|
|
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(double)); // NOLINT
|
|
|
|
EXPECT_EQ(kFloatingPoint, GMOCK_KIND_OF_(long double)); // NOLINT
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(KindOfTest, Other) {
|
|
|
|
EXPECT_EQ(kOther, GMOCK_KIND_OF_(void*)); // NOLINT
|
|
|
|
EXPECT_EQ(kOther, GMOCK_KIND_OF_(char**)); // NOLINT
|
|
|
|
EXPECT_EQ(kOther, GMOCK_KIND_OF_(Base)); // NOLINT
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests LosslessArithmeticConvertible<T, U>.
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, BoolToBool) {
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<bool, bool>::value));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, BoolToInteger) {
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<bool, char>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<bool, int>::value));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
(LosslessArithmeticConvertible<bool, unsigned long>::value)); // NOLINT
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, BoolToFloatingPoint) {
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<bool, float>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<bool, double>::value));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, IntegerToBool) {
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<unsigned char, bool>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<int, bool>::value));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
|
|
|
|
// Unsigned => larger signed is fine.
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
|
|
|
|
|
|
|
|
// Unsigned => larger unsigned is fine.
|
|
|
|
EXPECT_TRUE(
|
|
|
|
(LosslessArithmeticConvertible<unsigned short, UInt64>::value)); // NOLINT
|
|
|
|
|
|
|
|
// Signed => unsigned is not fine.
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value)); // NOLINT
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<
|
|
|
|
signed char, unsigned int>::value)); // NOLINT
|
|
|
|
|
|
|
|
// Same size and same signedness: fine too.
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<
|
|
|
|
unsigned char, unsigned char>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<int, int>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<wchar_t, wchar_t>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<
|
|
|
|
unsigned long, unsigned long>::value)); // NOLINT
|
|
|
|
|
|
|
|
// Same size, different signedness: not fine.
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<
|
|
|
|
unsigned char, signed char>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value));
|
|
|
|
|
|
|
|
// Larger size => smaller size is not fine.
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value)); // NOLINT
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<Int64, unsigned int>::value));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
|
|
|
|
// Integers cannot be losslessly converted to floating-points, as
|
|
|
|
// the format of the latter is implementation-defined.
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<char, float>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<int, double>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<
|
|
|
|
short, long double>::value)); // NOLINT
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<float, bool>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<double, bool>::value));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value)); // NOLINT
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value));
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
|
|
|
|
// Smaller size => larger size is fine.
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<float, double>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<float, long double>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<double, long double>::value));
|
|
|
|
|
|
|
|
// Same size: fine.
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<float, float>::value));
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<double, double>::value));
|
|
|
|
|
|
|
|
// Larger size => smaller size is not fine.
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<double, float>::value));
|
2014-05-19 19:54:51 +02:00
|
|
|
GTEST_INTENTIONAL_CONST_COND_PUSH_()
|
2009-05-14 22:55:30 +02:00
|
|
|
if (sizeof(double) == sizeof(long double)) { // NOLINT
|
2014-05-19 19:54:51 +02:00
|
|
|
GTEST_INTENTIONAL_CONST_COND_POP_()
|
2009-05-14 22:55:30 +02:00
|
|
|
// In some implementations (e.g. MSVC), double and long double
|
|
|
|
// have the same size.
|
|
|
|
EXPECT_TRUE((LosslessArithmeticConvertible<long double, double>::value));
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE((LosslessArithmeticConvertible<long double, double>::value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
// Tests the TupleMatches() template function.
|
|
|
|
|
|
|
|
TEST(TupleMatchesTest, WorksForSize0) {
|
2018-10-09 20:50:26 +02:00
|
|
|
std::tuple<> matchers;
|
|
|
|
std::tuple<> values;
|
2008-12-10 06:08:54 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(TupleMatches(matchers, values));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TupleMatchesTest, WorksForSize1) {
|
2018-10-09 20:50:26 +02:00
|
|
|
std::tuple<Matcher<int> > matchers(Eq(1));
|
|
|
|
std::tuple<int> values1(1), values2(2);
|
2008-12-10 06:08:54 +01:00
|
|
|
|
|
|
|
EXPECT_TRUE(TupleMatches(matchers, values1));
|
|
|
|
EXPECT_FALSE(TupleMatches(matchers, values2));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TupleMatchesTest, WorksForSize2) {
|
2018-10-09 20:50:26 +02:00
|
|
|
std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
|
|
|
|
std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'),
|
2008-12-10 06:08:54 +01:00
|
|
|
values4(2, 'b');
|
|
|
|
|
|
|
|
EXPECT_TRUE(TupleMatches(matchers, values1));
|
|
|
|
EXPECT_FALSE(TupleMatches(matchers, values2));
|
|
|
|
EXPECT_FALSE(TupleMatches(matchers, values3));
|
|
|
|
EXPECT_FALSE(TupleMatches(matchers, values4));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TupleMatchesTest, WorksForSize5) {
|
2018-10-09 20:50:26 +02:00
|
|
|
std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
|
|
|
|
Matcher<long>, // NOLINT
|
|
|
|
Matcher<std::string> >
|
2008-12-10 06:08:54 +01:00
|
|
|
matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
|
2018-10-09 20:50:26 +02:00
|
|
|
std::tuple<int, char, bool, long, std::string> // NOLINT
|
2017-05-15 23:07:03 +02:00
|
|
|
values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
|
2008-12-10 06:08:54 +01:00
|
|
|
values3(2, 'a', true, 2L, "hi");
|
|
|
|
|
|
|
|
EXPECT_TRUE(TupleMatches(matchers, values1));
|
|
|
|
EXPECT_FALSE(TupleMatches(matchers, values2));
|
|
|
|
EXPECT_FALSE(TupleMatches(matchers, values3));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that Assert(true, ...) succeeds.
|
|
|
|
TEST(AssertTest, SucceedsOnTrue) {
|
|
|
|
Assert(true, __FILE__, __LINE__, "This should succeed.");
|
|
|
|
Assert(true, __FILE__, __LINE__); // This should succeed too.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that Assert(false, ...) generates a fatal failure.
|
|
|
|
TEST(AssertTest, FailsFatallyOnFalse) {
|
2009-09-11 09:01:08 +02:00
|
|
|
EXPECT_DEATH_IF_SUPPORTED({
|
2008-12-10 06:08:54 +01:00
|
|
|
Assert(false, __FILE__, __LINE__, "This should fail.");
|
|
|
|
}, "");
|
|
|
|
|
2009-09-11 09:01:08 +02:00
|
|
|
EXPECT_DEATH_IF_SUPPORTED({
|
2008-12-10 06:08:54 +01:00
|
|
|
Assert(false, __FILE__, __LINE__);
|
|
|
|
}, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that Expect(true, ...) succeeds.
|
|
|
|
TEST(ExpectTest, SucceedsOnTrue) {
|
|
|
|
Expect(true, __FILE__, __LINE__, "This should succeed.");
|
|
|
|
Expect(true, __FILE__, __LINE__); // This should succeed too.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that Expect(false, ...) generates a non-fatal failure.
|
|
|
|
TEST(ExpectTest, FailsNonfatallyOnFalse) {
|
|
|
|
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
|
|
|
Expect(false, __FILE__, __LINE__, "This should fail.");
|
|
|
|
}, "This should fail");
|
|
|
|
|
|
|
|
EXPECT_NONFATAL_FAILURE({ // NOLINT
|
|
|
|
Expect(false, __FILE__, __LINE__);
|
|
|
|
}, "Expectation failed");
|
|
|
|
}
|
|
|
|
|
2009-05-29 21:50:06 +02:00
|
|
|
// Tests LogIsVisible().
|
|
|
|
|
|
|
|
class LogIsVisibleTest : public ::testing::Test {
|
|
|
|
protected:
|
2018-12-03 17:30:02 +01:00
|
|
|
void SetUp() override { original_verbose_ = GMOCK_FLAG(verbose); }
|
2009-06-23 01:30:47 +02:00
|
|
|
|
2018-12-03 17:30:02 +01:00
|
|
|
void TearDown() override { GMOCK_FLAG(verbose) = original_verbose_; }
|
2009-05-29 21:50:06 +02:00
|
|
|
|
2017-05-15 23:07:03 +02:00
|
|
|
std::string original_verbose_;
|
2009-05-29 21:50:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
|
|
|
|
GMOCK_FLAG(verbose) = kInfoVerbosity;
|
2012-05-31 22:40:56 +02:00
|
|
|
EXPECT_TRUE(LogIsVisible(kInfo));
|
|
|
|
EXPECT_TRUE(LogIsVisible(kWarning));
|
2009-05-29 21:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
|
|
|
|
GMOCK_FLAG(verbose) = kErrorVerbosity;
|
2012-05-31 22:40:56 +02:00
|
|
|
EXPECT_FALSE(LogIsVisible(kInfo));
|
|
|
|
EXPECT_FALSE(LogIsVisible(kWarning));
|
2009-05-29 21:50:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
|
|
|
|
GMOCK_FLAG(verbose) = kWarningVerbosity;
|
2012-05-31 22:40:56 +02:00
|
|
|
EXPECT_FALSE(LogIsVisible(kInfo));
|
|
|
|
EXPECT_TRUE(LogIsVisible(kWarning));
|
2009-05-29 21:50:06 +02:00
|
|
|
}
|
|
|
|
|
2010-08-31 20:28:02 +02:00
|
|
|
#if GTEST_HAS_STREAM_REDIRECTION
|
2008-12-10 06:08:54 +01:00
|
|
|
|
|
|
|
// Tests the Log() function.
|
|
|
|
|
|
|
|
// Verifies that Log() behaves correctly for the given verbosity level
|
|
|
|
// and log severity.
|
2017-05-15 23:07:03 +02:00
|
|
|
void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity,
|
2008-12-10 06:08:54 +01:00
|
|
|
bool should_print) {
|
2017-05-15 23:07:03 +02:00
|
|
|
const std::string old_flag = GMOCK_FLAG(verbose);
|
2008-12-10 06:08:54 +01:00
|
|
|
GMOCK_FLAG(verbose) = verbosity;
|
2010-02-02 23:34:58 +01:00
|
|
|
CaptureStdout();
|
2008-12-10 06:08:54 +01:00
|
|
|
Log(severity, "Test log.\n", 0);
|
|
|
|
if (should_print) {
|
2010-02-02 23:34:58 +01:00
|
|
|
EXPECT_THAT(GetCapturedStdout().c_str(),
|
|
|
|
ContainsRegex(
|
2012-05-31 22:40:56 +02:00
|
|
|
severity == kWarning ?
|
2010-02-02 23:34:58 +01:00
|
|
|
"^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" :
|
|
|
|
"^\nTest log\\.\nStack trace:\n"));
|
2008-12-10 06:08:54 +01:00
|
|
|
} else {
|
2010-02-02 23:34:58 +01:00
|
|
|
EXPECT_STREQ("", GetCapturedStdout().c_str());
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
GMOCK_FLAG(verbose) = old_flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that when the stack_frames_to_skip parameter is negative,
|
|
|
|
// Log() doesn't include the stack trace in the output.
|
|
|
|
TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) {
|
2017-05-15 23:07:03 +02:00
|
|
|
const std::string saved_flag = GMOCK_FLAG(verbose);
|
2008-12-10 06:08:54 +01:00
|
|
|
GMOCK_FLAG(verbose) = kInfoVerbosity;
|
2010-02-02 23:34:58 +01:00
|
|
|
CaptureStdout();
|
2012-05-31 22:40:56 +02:00
|
|
|
Log(kInfo, "Test log.\n", -1);
|
2010-02-02 23:34:58 +01:00
|
|
|
EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
|
2010-05-05 21:47:46 +02:00
|
|
|
GMOCK_FLAG(verbose) = saved_flag;
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
2015-07-28 02:12:51 +02:00
|
|
|
struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
|
2018-12-03 17:30:02 +01:00
|
|
|
std::string CurrentStackTrace(int max_depth, int skip_count) override {
|
2015-07-28 02:12:51 +02:00
|
|
|
return (testing::Message() << max_depth << "::" << skip_count << "\n")
|
|
|
|
.GetString();
|
|
|
|
}
|
2018-12-03 17:30:02 +01:00
|
|
|
void UponLeavingGTest() override {}
|
2015-07-28 02:12:51 +02:00
|
|
|
};
|
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
// Tests that in opt mode, a positive stack_frames_to_skip argument is
|
|
|
|
// treated as 0.
|
|
|
|
TEST(LogTest, NoSkippingStackFrameInOptMode) {
|
2015-07-28 02:12:51 +02:00
|
|
|
MockStackTraceGetter* mock_os_stack_trace_getter = new MockStackTraceGetter;
|
|
|
|
GetUnitTestImpl()->set_os_stack_trace_getter(mock_os_stack_trace_getter);
|
|
|
|
|
2010-02-02 23:34:58 +01:00
|
|
|
CaptureStdout();
|
2012-05-31 22:40:56 +02:00
|
|
|
Log(kWarning, "Test log.\n", 100);
|
2017-05-15 23:07:03 +02:00
|
|
|
const std::string log = GetCapturedStdout();
|
2011-02-24 08:29:13 +01:00
|
|
|
|
2017-05-15 23:07:03 +02:00
|
|
|
std::string expected_trace =
|
2015-07-28 02:12:51 +02:00
|
|
|
(testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString();
|
2017-05-15 23:07:03 +02:00
|
|
|
std::string expected_message =
|
2015-07-28 02:12:51 +02:00
|
|
|
"\nGMOCK WARNING:\n"
|
|
|
|
"Test log.\n"
|
|
|
|
"Stack trace:\n" +
|
|
|
|
expected_trace;
|
|
|
|
EXPECT_THAT(log, HasSubstr(expected_message));
|
|
|
|
int skip_count = atoi(log.substr(expected_message.size()).c_str());
|
|
|
|
|
|
|
|
# if defined(NDEBUG)
|
2008-12-10 06:08:54 +01:00
|
|
|
// In opt mode, no stack frame should be skipped.
|
2015-07-28 02:12:51 +02:00
|
|
|
const int expected_skip_count = 0;
|
2011-02-24 08:29:13 +01:00
|
|
|
# else
|
2008-12-10 06:08:54 +01:00
|
|
|
// In dbg mode, the stack frames should be skipped.
|
2015-07-28 02:12:51 +02:00
|
|
|
const int expected_skip_count = 100;
|
2011-02-24 08:29:13 +01:00
|
|
|
# endif
|
2015-07-28 02:12:51 +02:00
|
|
|
|
|
|
|
// Note that each inner implementation layer will +1 the number to remove
|
|
|
|
// itself from the trace. This means that the value is a little higher than
|
|
|
|
// expected, but close enough.
|
|
|
|
EXPECT_THAT(skip_count,
|
|
|
|
AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10)));
|
|
|
|
|
|
|
|
// Restores the default OS stack trace getter.
|
2018-10-05 00:28:05 +02:00
|
|
|
GetUnitTestImpl()->set_os_stack_trace_getter(nullptr);
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that all logs are printed when the value of the
|
|
|
|
// --gmock_verbose flag is "info".
|
|
|
|
TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) {
|
2012-05-31 22:40:56 +02:00
|
|
|
TestLogWithSeverity(kInfoVerbosity, kInfo, true);
|
|
|
|
TestLogWithSeverity(kInfoVerbosity, kWarning, true);
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that only warnings are printed when the value of the
|
|
|
|
// --gmock_verbose flag is "warning".
|
|
|
|
TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsWarning) {
|
2012-05-31 22:40:56 +02:00
|
|
|
TestLogWithSeverity(kWarningVerbosity, kInfo, false);
|
|
|
|
TestLogWithSeverity(kWarningVerbosity, kWarning, true);
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that no logs are printed when the value of the
|
|
|
|
// --gmock_verbose flag is "error".
|
|
|
|
TEST(LogTest, NoLogsArePrintedWhenVerbosityIsError) {
|
2012-05-31 22:40:56 +02:00
|
|
|
TestLogWithSeverity(kErrorVerbosity, kInfo, false);
|
|
|
|
TestLogWithSeverity(kErrorVerbosity, kWarning, false);
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tests that only warnings are printed when the value of the
|
|
|
|
// --gmock_verbose flag is invalid.
|
|
|
|
TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
|
2012-05-31 22:40:56 +02:00
|
|
|
TestLogWithSeverity("invalid", kInfo, false);
|
|
|
|
TestLogWithSeverity("invalid", kWarning, true);
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that Log() behaves correctly for the given verbosity level
|
|
|
|
// and log severity.
|
2012-11-15 16:50:36 +01:00
|
|
|
std::string GrabOutput(void(*logger)(), const char* verbosity) {
|
2017-05-15 23:07:03 +02:00
|
|
|
const std::string saved_flag = GMOCK_FLAG(verbose);
|
2008-12-10 06:08:54 +01:00
|
|
|
GMOCK_FLAG(verbose) = verbosity;
|
2010-02-02 23:34:58 +01:00
|
|
|
CaptureStdout();
|
2008-12-10 06:08:54 +01:00
|
|
|
logger();
|
|
|
|
GMOCK_FLAG(verbose) = saved_flag;
|
2010-02-02 23:34:58 +01:00
|
|
|
return GetCapturedStdout();
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class DummyMock {
|
|
|
|
public:
|
|
|
|
MOCK_METHOD0(TestMethod, void());
|
|
|
|
MOCK_METHOD1(TestMethodArg, void(int dummy));
|
|
|
|
};
|
|
|
|
|
|
|
|
void ExpectCallLogger() {
|
|
|
|
DummyMock mock;
|
|
|
|
EXPECT_CALL(mock, TestMethod());
|
|
|
|
mock.TestMethod();
|
2019-03-04 15:38:02 +01:00
|
|
|
}
|
2008-12-10 06:08:54 +01:00
|
|
|
|
|
|
|
// Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info".
|
|
|
|
TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
|
2012-11-15 16:50:36 +01:00
|
|
|
EXPECT_THAT(std::string(GrabOutput(ExpectCallLogger, kInfoVerbosity)),
|
2008-12-10 06:08:54 +01:00
|
|
|
HasSubstr("EXPECT_CALL(mock, TestMethod())"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that EXPECT_CALL doesn't log
|
|
|
|
// if the --gmock_verbose flag is set to "warning".
|
|
|
|
TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) {
|
2010-02-02 23:34:58 +01:00
|
|
|
EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str());
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that EXPECT_CALL doesn't log
|
|
|
|
// if the --gmock_verbose flag is set to "error".
|
|
|
|
TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
|
2010-02-02 23:34:58 +01:00
|
|
|
EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str());
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnCallLogger() {
|
|
|
|
DummyMock mock;
|
|
|
|
ON_CALL(mock, TestMethod());
|
2019-03-04 15:38:02 +01:00
|
|
|
}
|
2008-12-10 06:08:54 +01:00
|
|
|
|
|
|
|
// Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info".
|
|
|
|
TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
|
2012-11-15 16:50:36 +01:00
|
|
|
EXPECT_THAT(std::string(GrabOutput(OnCallLogger, kInfoVerbosity)),
|
2008-12-10 06:08:54 +01:00
|
|
|
HasSubstr("ON_CALL(mock, TestMethod())"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that ON_CALL doesn't log
|
|
|
|
// if the --gmock_verbose flag is set to "warning".
|
|
|
|
TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) {
|
2010-02-02 23:34:58 +01:00
|
|
|
EXPECT_STREQ("", GrabOutput(OnCallLogger, kWarningVerbosity).c_str());
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that ON_CALL doesn't log if
|
|
|
|
// the --gmock_verbose flag is set to "error".
|
|
|
|
TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) {
|
2010-02-02 23:34:58 +01:00
|
|
|
EXPECT_STREQ("", GrabOutput(OnCallLogger, kErrorVerbosity).c_str());
|
2008-12-10 06:08:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnCallAnyArgumentLogger() {
|
|
|
|
DummyMock mock;
|
|
|
|
ON_CALL(mock, TestMethodArg(_));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that ON_CALL prints provided _ argument.
|
|
|
|
TEST(OnCallTest, LogsAnythingArgument) {
|
2012-11-15 16:50:36 +01:00
|
|
|
EXPECT_THAT(std::string(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity)),
|
2008-12-10 06:08:54 +01:00
|
|
|
HasSubstr("ON_CALL(mock, TestMethodArg(_)"));
|
|
|
|
}
|
|
|
|
|
2010-08-31 20:28:02 +02:00
|
|
|
#endif // GTEST_HAS_STREAM_REDIRECTION
|
2008-12-10 06:08:54 +01:00
|
|
|
|
2009-06-04 07:48:20 +02:00
|
|
|
// Tests StlContainerView.
|
|
|
|
|
|
|
|
TEST(StlContainerViewTest, WorksForStlContainer) {
|
|
|
|
StaticAssertTypeEq<std::vector<int>,
|
|
|
|
StlContainerView<std::vector<int> >::type>();
|
|
|
|
StaticAssertTypeEq<const std::vector<double>&,
|
|
|
|
StlContainerView<std::vector<double> >::const_reference>();
|
|
|
|
|
|
|
|
typedef std::vector<char> Chars;
|
|
|
|
Chars v1;
|
|
|
|
const Chars& v2(StlContainerView<Chars>::ConstReference(v1));
|
|
|
|
EXPECT_EQ(&v1, &v2);
|
|
|
|
|
|
|
|
v1.push_back('a');
|
|
|
|
Chars v3 = StlContainerView<Chars>::Copy(v1);
|
|
|
|
EXPECT_THAT(v3, Eq(v3));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StlContainerViewTest, WorksForStaticNativeArray) {
|
|
|
|
StaticAssertTypeEq<NativeArray<int>,
|
|
|
|
StlContainerView<int[3]>::type>();
|
|
|
|
StaticAssertTypeEq<NativeArray<double>,
|
|
|
|
StlContainerView<const double[4]>::type>();
|
|
|
|
StaticAssertTypeEq<NativeArray<char[3]>,
|
|
|
|
StlContainerView<const char[2][3]>::type>();
|
|
|
|
|
|
|
|
StaticAssertTypeEq<const NativeArray<int>,
|
|
|
|
StlContainerView<int[2]>::const_reference>();
|
|
|
|
|
|
|
|
int a1[3] = { 0, 1, 2 };
|
|
|
|
NativeArray<int> a2 = StlContainerView<int[3]>::ConstReference(a1);
|
2009-12-23 01:13:23 +01:00
|
|
|
EXPECT_EQ(3U, a2.size());
|
2009-06-04 07:48:20 +02:00
|
|
|
EXPECT_EQ(a1, a2.begin());
|
|
|
|
|
|
|
|
const NativeArray<int> a3 = StlContainerView<int[3]>::Copy(a1);
|
2009-12-23 01:13:23 +01:00
|
|
|
ASSERT_EQ(3U, a3.size());
|
2009-06-04 07:48:20 +02:00
|
|
|
EXPECT_EQ(0, a3.begin()[0]);
|
|
|
|
EXPECT_EQ(1, a3.begin()[1]);
|
|
|
|
EXPECT_EQ(2, a3.begin()[2]);
|
|
|
|
|
|
|
|
// Makes sure a1 and a3 aren't aliases.
|
|
|
|
a1[0] = 3;
|
|
|
|
EXPECT_EQ(0, a3.begin()[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
|
|
|
|
StaticAssertTypeEq<NativeArray<int>,
|
2018-10-09 20:50:26 +02:00
|
|
|
StlContainerView<std::tuple<const int*, size_t> >::type>();
|
|
|
|
StaticAssertTypeEq<
|
|
|
|
NativeArray<double>,
|
2018-10-29 16:09:33 +01:00
|
|
|
StlContainerView<std::tuple<std::shared_ptr<double>, int> >::type>();
|
2009-06-04 07:48:20 +02:00
|
|
|
|
2018-10-09 20:50:26 +02:00
|
|
|
StaticAssertTypeEq<
|
|
|
|
const NativeArray<int>,
|
|
|
|
StlContainerView<std::tuple<const int*, int> >::const_reference>();
|
2009-06-04 07:48:20 +02:00
|
|
|
|
|
|
|
int a1[3] = { 0, 1, 2 };
|
2009-06-18 00:11:04 +02:00
|
|
|
const int* const p1 = a1;
|
2018-10-09 20:50:26 +02:00
|
|
|
NativeArray<int> a2 =
|
|
|
|
StlContainerView<std::tuple<const int*, int> >::ConstReference(
|
|
|
|
std::make_tuple(p1, 3));
|
2009-12-23 01:13:23 +01:00
|
|
|
EXPECT_EQ(3U, a2.size());
|
2009-06-04 07:48:20 +02:00
|
|
|
EXPECT_EQ(a1, a2.begin());
|
|
|
|
|
2018-10-09 20:50:26 +02:00
|
|
|
const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
|
|
|
|
std::make_tuple(static_cast<int*>(a1), 3));
|
2009-12-23 01:13:23 +01:00
|
|
|
ASSERT_EQ(3U, a3.size());
|
2009-06-04 07:48:20 +02:00
|
|
|
EXPECT_EQ(0, a3.begin()[0]);
|
|
|
|
EXPECT_EQ(1, a3.begin()[1]);
|
|
|
|
EXPECT_EQ(2, a3.begin()[2]);
|
|
|
|
|
|
|
|
// Makes sure a1 and a3 aren't aliases.
|
|
|
|
a1[0] = 3;
|
|
|
|
EXPECT_EQ(0, a3.begin()[0]);
|
|
|
|
}
|
|
|
|
|
2019-01-07 23:06:16 +01:00
|
|
|
// Tests the Function template struct.
|
|
|
|
|
|
|
|
TEST(FunctionTest, Nullary) {
|
|
|
|
typedef Function<int()> F; // NOLINT
|
|
|
|
EXPECT_EQ(0u, F::ArgumentCount);
|
2019-09-12 16:36:44 +02:00
|
|
|
EXPECT_TRUE((std::is_same<int, F::Result>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentTuple>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<std::tuple<>, F::ArgumentMatcherTuple>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<void(), F::MakeResultVoid>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<IgnoredValue(), F::MakeResultIgnoredValue>::value));
|
2019-01-07 23:06:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionTest, Unary) {
|
|
|
|
typedef Function<int(bool)> F; // NOLINT
|
|
|
|
EXPECT_EQ(1u, F::ArgumentCount);
|
2019-09-12 16:36:44 +02:00
|
|
|
EXPECT_TRUE((std::is_same<int, F::Result>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<std::tuple<bool>, F::ArgumentTuple>::value));
|
|
|
|
EXPECT_TRUE((
|
|
|
|
std::is_same<std::tuple<Matcher<bool>>, F::ArgumentMatcherTuple>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<void(bool), F::MakeResultVoid>::value)); // NOLINT
|
|
|
|
EXPECT_TRUE((std::is_same<IgnoredValue(bool), // NOLINT
|
|
|
|
F::MakeResultIgnoredValue>::value));
|
2019-01-07 23:06:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionTest, Binary) {
|
|
|
|
typedef Function<int(bool, const long&)> F; // NOLINT
|
|
|
|
EXPECT_EQ(2u, F::ArgumentCount);
|
2019-09-12 16:36:44 +02:00
|
|
|
EXPECT_TRUE((std::is_same<int, F::Result>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<const long&, F::Arg<1>::type>::value)); // NOLINT
|
|
|
|
EXPECT_TRUE((std::is_same<std::tuple<bool, const long&>, // NOLINT
|
|
|
|
F::ArgumentTuple>::value));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
(std::is_same<std::tuple<Matcher<bool>, Matcher<const long&>>, // NOLINT
|
|
|
|
F::ArgumentMatcherTuple>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<void(bool, const long&), // NOLINT
|
|
|
|
F::MakeResultVoid>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<IgnoredValue(bool, const long&), // NOLINT
|
|
|
|
F::MakeResultIgnoredValue>::value));
|
2019-01-07 23:06:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FunctionTest, LongArgumentList) {
|
|
|
|
typedef Function<char(bool, int, char*, int&, const long&)> F; // NOLINT
|
|
|
|
EXPECT_EQ(5u, F::ArgumentCount);
|
2019-09-12 16:36:44 +02:00
|
|
|
EXPECT_TRUE((std::is_same<char, F::Result>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<bool, F::Arg<0>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<int, F::Arg<1>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<char*, F::Arg<2>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<int&, F::Arg<3>::type>::value));
|
|
|
|
EXPECT_TRUE((std::is_same<const long&, F::Arg<4>::type>::value)); // NOLINT
|
|
|
|
EXPECT_TRUE(
|
|
|
|
(std::is_same<std::tuple<bool, int, char*, int&, const long&>, // NOLINT
|
|
|
|
F::ArgumentTuple>::value));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
(std::is_same<
|
|
|
|
std::tuple<Matcher<bool>, Matcher<int>, Matcher<char*>, Matcher<int&>,
|
|
|
|
Matcher<const long&>>, // NOLINT
|
|
|
|
F::ArgumentMatcherTuple>::value));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
(std::is_same<void(bool, int, char*, int&, const long&), // NOLINT
|
|
|
|
F::MakeResultVoid>::value));
|
|
|
|
EXPECT_TRUE((
|
|
|
|
std::is_same<IgnoredValue(bool, int, char*, int&, const long&), // NOLINT
|
|
|
|
F::MakeResultIgnoredValue>::value));
|
2019-01-07 23:06:16 +01:00
|
|
|
}
|
|
|
|
|
2008-12-10 06:08:54 +01:00
|
|
|
} // namespace
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace testing
|