Source release 17.1.0
This commit is contained in:
@@ -26,30 +26,33 @@
|
||||
// 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: wan@google.com (Zhanyong Wan)
|
||||
|
||||
|
||||
// Google Mock - a framework for writing C++ mock classes.
|
||||
//
|
||||
// This file tests the internal utilities.
|
||||
|
||||
#include "gmock/internal/gmock-internal-utils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gmock/internal/gmock-port.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// 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
|
||||
// his code.
|
||||
// their code.
|
||||
#define GTEST_IMPLEMENTATION_ 1
|
||||
#include "src/gtest-internal-inl.h"
|
||||
#undef GTEST_IMPLEMENTATION_
|
||||
@@ -58,8 +61,6 @@
|
||||
# include <sys/types.h> // For ssize_t. NOLINT
|
||||
#endif
|
||||
|
||||
class ProtocolMessage;
|
||||
|
||||
namespace proto2 {
|
||||
class Message;
|
||||
} // namespace proto2
|
||||
@@ -69,6 +70,26 @@ namespace internal {
|
||||
|
||||
namespace {
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {
|
||||
EXPECT_EQ("", ConvertIdentifierNameToWords(""));
|
||||
EXPECT_EQ("", ConvertIdentifierNameToWords("_"));
|
||||
@@ -103,45 +124,18 @@ TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameIsMixture) {
|
||||
ConvertIdentifierNameToWords("_Chapter11Section_1_"));
|
||||
}
|
||||
|
||||
TEST(PointeeOfTest, WorksForSmartPointers) {
|
||||
CompileAssertTypesEqual<const char,
|
||||
PointeeOf<internal::linked_ptr<const char> >::type>();
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
CompileAssertTypesEqual<int, PointeeOf<std::unique_ptr<int> >::type>();
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
#if GTEST_HAS_STD_SHARED_PTR_
|
||||
CompileAssertTypesEqual<std::string,
|
||||
PointeeOf<std::shared_ptr<std::string> >::type>();
|
||||
#endif // GTEST_HAS_STD_SHARED_PTR_
|
||||
}
|
||||
|
||||
TEST(PointeeOfTest, WorksForRawPointers) {
|
||||
CompileAssertTypesEqual<int, PointeeOf<int*>::type>();
|
||||
CompileAssertTypesEqual<const char, PointeeOf<const char*>::type>();
|
||||
CompileAssertTypesEqual<void, PointeeOf<void*>::type>();
|
||||
}
|
||||
|
||||
TEST(GetRawPointerTest, WorksForSmartPointers) {
|
||||
#if GTEST_HAS_STD_UNIQUE_PTR_
|
||||
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));
|
||||
#endif // GTEST_HAS_STD_UNIQUE_PTR_
|
||||
#if GTEST_HAS_STD_SHARED_PTR_
|
||||
double* const raw_p2 = new double(2.5); // NOLINT
|
||||
const std::shared_ptr<double> p2(raw_p2);
|
||||
EXPECT_EQ(raw_p2, GetRawPointer(p2));
|
||||
#endif // GTEST_HAS_STD_SHARED_PTR_
|
||||
|
||||
const char* const raw_p4 = new const char('a'); // NOLINT
|
||||
const internal::linked_ptr<const char> p4(raw_p4);
|
||||
EXPECT_EQ(raw_p4, GetRawPointer(p4));
|
||||
}
|
||||
|
||||
TEST(GetRawPointerTest, WorksForRawPointers) {
|
||||
int* p = NULL;
|
||||
// Don't use EXPECT_EQ as no NULL-testing magic on Symbian.
|
||||
EXPECT_TRUE(NULL == GetRawPointer(p));
|
||||
int* p = nullptr;
|
||||
EXPECT_TRUE(nullptr == GetRawPointer(p));
|
||||
int n = 1;
|
||||
EXPECT_EQ(&n, GetRawPointer(&n));
|
||||
}
|
||||
@@ -165,9 +159,9 @@ TEST(KindOfTest, Integer) {
|
||||
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_(long long)); // NOLINT
|
||||
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long 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.
|
||||
@@ -215,11 +209,12 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
|
||||
|
||||
// Unsigned => larger unsigned is fine.
|
||||
EXPECT_TRUE(
|
||||
(LosslessArithmeticConvertible<unsigned short, UInt64>::value)); // NOLINT
|
||||
EXPECT_TRUE((LosslessArithmeticConvertible<
|
||||
unsigned short, uint64_t>::value)); // NOLINT
|
||||
|
||||
// Signed => unsigned is not fine.
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value)); // NOLINT
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<
|
||||
short, uint64_t>::value)); // NOLINT
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<
|
||||
signed char, unsigned int>::value)); // NOLINT
|
||||
|
||||
@@ -235,12 +230,12 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<
|
||||
unsigned char, signed char>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<uint64_t, int64_t>::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));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<int64_t, unsigned int>::value));
|
||||
}
|
||||
|
||||
TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
|
||||
@@ -259,7 +254,7 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
|
||||
|
||||
TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value)); // NOLINT
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<double, int64_t>::value));
|
||||
EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value));
|
||||
}
|
||||
|
||||
@@ -289,26 +284,23 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToFloatingPoint) {
|
||||
// Tests the TupleMatches() template function.
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize0) {
|
||||
tuple<> matchers;
|
||||
tuple<> values;
|
||||
std::tuple<> matchers;
|
||||
std::tuple<> values;
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values));
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize1) {
|
||||
tuple<Matcher<int> > matchers(Eq(1));
|
||||
tuple<int> values1(1),
|
||||
values2(2);
|
||||
std::tuple<Matcher<int> > matchers(Eq(1));
|
||||
std::tuple<int> values1(1), values2(2);
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values1));
|
||||
EXPECT_FALSE(TupleMatches(matchers, values2));
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize2) {
|
||||
tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
|
||||
tuple<int, char> values1(1, 'a'),
|
||||
values2(1, 'b'),
|
||||
values3(2, 'a'),
|
||||
std::tuple<Matcher<int>, Matcher<char> > matchers(Eq(1), Eq('a'));
|
||||
std::tuple<int, char> values1(1, 'a'), values2(1, 'b'), values3(2, 'a'),
|
||||
values4(2, 'b');
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values1));
|
||||
@@ -318,12 +310,12 @@ TEST(TupleMatchesTest, WorksForSize2) {
|
||||
}
|
||||
|
||||
TEST(TupleMatchesTest, WorksForSize5) {
|
||||
tuple<Matcher<int>, Matcher<char>, Matcher<bool>, Matcher<long>, // NOLINT
|
||||
Matcher<string> >
|
||||
std::tuple<Matcher<int>, Matcher<char>, Matcher<bool>,
|
||||
Matcher<long>, // NOLINT
|
||||
Matcher<std::string> >
|
||||
matchers(Eq(1), Eq('a'), Eq(true), Eq(2L), Eq("hi"));
|
||||
tuple<int, char, bool, long, string> // NOLINT
|
||||
values1(1, 'a', true, 2L, "hi"),
|
||||
values2(1, 'a', true, 2L, "hello"),
|
||||
std::tuple<int, char, bool, long, std::string> // NOLINT
|
||||
values1(1, 'a', true, 2L, "hi"), values2(1, 'a', true, 2L, "hello"),
|
||||
values3(2, 'a', true, 2L, "hi");
|
||||
|
||||
EXPECT_TRUE(TupleMatches(matchers, values1));
|
||||
@@ -369,29 +361,27 @@ TEST(ExpectTest, FailsNonfatallyOnFalse) {
|
||||
|
||||
class LogIsVisibleTest : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
original_verbose_ = GMOCK_FLAG(verbose);
|
||||
}
|
||||
void SetUp() override { original_verbose_ = GMOCK_FLAG_GET(verbose); }
|
||||
|
||||
virtual void TearDown() { GMOCK_FLAG(verbose) = original_verbose_; }
|
||||
void TearDown() override { GMOCK_FLAG_SET(verbose, original_verbose_); }
|
||||
|
||||
string original_verbose_;
|
||||
std::string original_verbose_;
|
||||
};
|
||||
|
||||
TEST_F(LogIsVisibleTest, AlwaysReturnsTrueIfVerbosityIsInfo) {
|
||||
GMOCK_FLAG(verbose) = kInfoVerbosity;
|
||||
GMOCK_FLAG_SET(verbose, kInfoVerbosity);
|
||||
EXPECT_TRUE(LogIsVisible(kInfo));
|
||||
EXPECT_TRUE(LogIsVisible(kWarning));
|
||||
}
|
||||
|
||||
TEST_F(LogIsVisibleTest, AlwaysReturnsFalseIfVerbosityIsError) {
|
||||
GMOCK_FLAG(verbose) = kErrorVerbosity;
|
||||
GMOCK_FLAG_SET(verbose, kErrorVerbosity);
|
||||
EXPECT_FALSE(LogIsVisible(kInfo));
|
||||
EXPECT_FALSE(LogIsVisible(kWarning));
|
||||
}
|
||||
|
||||
TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
|
||||
GMOCK_FLAG(verbose) = kWarningVerbosity;
|
||||
GMOCK_FLAG_SET(verbose, kWarningVerbosity);
|
||||
EXPECT_FALSE(LogIsVisible(kInfo));
|
||||
EXPECT_TRUE(LogIsVisible(kWarning));
|
||||
}
|
||||
@@ -402,10 +392,10 @@ TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) {
|
||||
|
||||
// Verifies that Log() behaves correctly for the given verbosity level
|
||||
// and log severity.
|
||||
void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
|
||||
void TestLogWithSeverity(const std::string& verbosity, LogSeverity severity,
|
||||
bool should_print) {
|
||||
const string old_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = verbosity;
|
||||
const std::string old_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, verbosity);
|
||||
CaptureStdout();
|
||||
Log(severity, "Test log.\n", 0);
|
||||
if (should_print) {
|
||||
@@ -417,26 +407,26 @@ void TestLogWithSeverity(const string& verbosity, LogSeverity severity,
|
||||
} else {
|
||||
EXPECT_STREQ("", GetCapturedStdout().c_str());
|
||||
}
|
||||
GMOCK_FLAG(verbose) = old_flag;
|
||||
GMOCK_FLAG_SET(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) {
|
||||
const string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = kInfoVerbosity;
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, kInfoVerbosity);
|
||||
CaptureStdout();
|
||||
Log(kInfo, "Test log.\n", -1);
|
||||
EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str());
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
}
|
||||
|
||||
struct MockStackTraceGetter : testing::internal::OsStackTraceGetterInterface {
|
||||
virtual string CurrentStackTrace(int max_depth, int skip_count) {
|
||||
std::string CurrentStackTrace(int max_depth, int skip_count) override {
|
||||
return (testing::Message() << max_depth << "::" << skip_count << "\n")
|
||||
.GetString();
|
||||
}
|
||||
virtual void UponLeavingGTest() {}
|
||||
void UponLeavingGTest() override {}
|
||||
};
|
||||
|
||||
// Tests that in opt mode, a positive stack_frames_to_skip argument is
|
||||
@@ -447,11 +437,12 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
|
||||
|
||||
CaptureStdout();
|
||||
Log(kWarning, "Test log.\n", 100);
|
||||
const string log = GetCapturedStdout();
|
||||
const std::string log = GetCapturedStdout();
|
||||
|
||||
string expected_trace =
|
||||
(testing::Message() << GTEST_FLAG(stack_trace_depth) << "::").GetString();
|
||||
string expected_message =
|
||||
std::string expected_trace =
|
||||
(testing::Message() << GTEST_FLAG_GET(stack_trace_depth) << "::")
|
||||
.GetString();
|
||||
std::string expected_message =
|
||||
"\nGMOCK WARNING:\n"
|
||||
"Test log.\n"
|
||||
"Stack trace:\n" +
|
||||
@@ -474,7 +465,7 @@ TEST(LogTest, NoSkippingStackFrameInOptMode) {
|
||||
AllOf(Ge(expected_skip_count), Le(expected_skip_count + 10)));
|
||||
|
||||
// Restores the default OS stack trace getter.
|
||||
GetUnitTestImpl()->set_os_stack_trace_getter(NULL);
|
||||
GetUnitTestImpl()->set_os_stack_trace_getter(nullptr);
|
||||
}
|
||||
|
||||
// Tests that all logs are printed when the value of the
|
||||
@@ -505,53 +496,14 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) {
|
||||
TestLogWithSeverity("invalid", kWarning, true);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
TEST(TypeTraitsTest, true_type) {
|
||||
EXPECT_TRUE(true_type::value);
|
||||
}
|
||||
|
||||
TEST(TypeTraitsTest, false_type) {
|
||||
EXPECT_FALSE(false_type::value);
|
||||
}
|
||||
|
||||
TEST(TypeTraitsTest, is_reference) {
|
||||
EXPECT_FALSE(is_reference<int>::value);
|
||||
EXPECT_FALSE(is_reference<char*>::value);
|
||||
EXPECT_TRUE(is_reference<const int&>::value);
|
||||
}
|
||||
|
||||
TEST(TypeTraitsTest, is_pointer) {
|
||||
EXPECT_FALSE(is_pointer<int>::value);
|
||||
EXPECT_FALSE(is_pointer<char&>::value);
|
||||
EXPECT_TRUE(is_pointer<const int*>::value);
|
||||
}
|
||||
|
||||
TEST(TypeTraitsTest, type_equals) {
|
||||
EXPECT_FALSE((type_equals<int, const int>::value));
|
||||
EXPECT_FALSE((type_equals<int, int&>::value));
|
||||
EXPECT_FALSE((type_equals<int, double>::value));
|
||||
EXPECT_TRUE((type_equals<char, char>::value));
|
||||
}
|
||||
|
||||
TEST(TypeTraitsTest, remove_reference) {
|
||||
EXPECT_TRUE((type_equals<char, remove_reference<char&>::type>::value));
|
||||
EXPECT_TRUE((type_equals<const int,
|
||||
remove_reference<const int&>::type>::value));
|
||||
EXPECT_TRUE((type_equals<int, remove_reference<int>::type>::value));
|
||||
EXPECT_TRUE((type_equals<double*, remove_reference<double*>::type>::value));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STREAM_REDIRECTION
|
||||
|
||||
// Verifies that Log() behaves correctly for the given verbosity level
|
||||
// and log severity.
|
||||
std::string GrabOutput(void(*logger)(), const char* verbosity) {
|
||||
const string saved_flag = GMOCK_FLAG(verbose);
|
||||
GMOCK_FLAG(verbose) = verbosity;
|
||||
const std::string saved_flag = GMOCK_FLAG_GET(verbose);
|
||||
GMOCK_FLAG_SET(verbose, verbosity);
|
||||
CaptureStdout();
|
||||
logger();
|
||||
GMOCK_FLAG(verbose) = saved_flag;
|
||||
GMOCK_FLAG_SET(verbose, saved_flag);
|
||||
return GetCapturedStdout();
|
||||
}
|
||||
|
||||
@@ -565,7 +517,7 @@ void ExpectCallLogger() {
|
||||
DummyMock mock;
|
||||
EXPECT_CALL(mock, TestMethod());
|
||||
mock.TestMethod();
|
||||
};
|
||||
}
|
||||
|
||||
// Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info".
|
||||
TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) {
|
||||
@@ -588,7 +540,7 @@ TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) {
|
||||
void OnCallLogger() {
|
||||
DummyMock mock;
|
||||
ON_CALL(mock, TestMethod());
|
||||
};
|
||||
}
|
||||
|
||||
// Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info".
|
||||
TEST(OnCallTest, LogsWhenVerbosityIsInfo) {
|
||||
@@ -668,22 +620,25 @@ TEST(StlContainerViewTest, WorksForStaticNativeArray) {
|
||||
|
||||
TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
|
||||
StaticAssertTypeEq<NativeArray<int>,
|
||||
StlContainerView<tuple<const int*, size_t> >::type>();
|
||||
StaticAssertTypeEq<NativeArray<double>,
|
||||
StlContainerView<tuple<linked_ptr<double>, int> >::type>();
|
||||
StlContainerView<std::tuple<const int*, size_t> >::type>();
|
||||
StaticAssertTypeEq<
|
||||
NativeArray<double>,
|
||||
StlContainerView<std::tuple<std::shared_ptr<double>, int> >::type>();
|
||||
|
||||
StaticAssertTypeEq<const NativeArray<int>,
|
||||
StlContainerView<tuple<const int*, int> >::const_reference>();
|
||||
StaticAssertTypeEq<
|
||||
const NativeArray<int>,
|
||||
StlContainerView<std::tuple<const int*, int> >::const_reference>();
|
||||
|
||||
int a1[3] = { 0, 1, 2 };
|
||||
const int* const p1 = a1;
|
||||
NativeArray<int> a2 = StlContainerView<tuple<const int*, int> >::
|
||||
ConstReference(make_tuple(p1, 3));
|
||||
NativeArray<int> a2 =
|
||||
StlContainerView<std::tuple<const int*, int> >::ConstReference(
|
||||
std::make_tuple(p1, 3));
|
||||
EXPECT_EQ(3U, a2.size());
|
||||
EXPECT_EQ(a1, a2.begin());
|
||||
|
||||
const NativeArray<int> a3 = StlContainerView<tuple<int*, size_t> >::
|
||||
Copy(make_tuple(static_cast<int*>(a1), 3));
|
||||
const NativeArray<int> a3 = StlContainerView<std::tuple<int*, size_t> >::Copy(
|
||||
std::make_tuple(static_cast<int*>(a1), 3));
|
||||
ASSERT_EQ(3U, a3.size());
|
||||
EXPECT_EQ(0, a3.begin()[0]);
|
||||
EXPECT_EQ(1, a3.begin()[1]);
|
||||
@@ -694,6 +649,113 @@ TEST(StlContainerViewTest, WorksForDynamicNativeArray) {
|
||||
EXPECT_EQ(0, a3.begin()[0]);
|
||||
}
|
||||
|
||||
// Tests the Function template struct.
|
||||
|
||||
TEST(FunctionTest, Nullary) {
|
||||
typedef Function<int()> F; // NOLINT
|
||||
EXPECT_EQ(0u, F::ArgumentCount);
|
||||
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));
|
||||
}
|
||||
|
||||
TEST(FunctionTest, Unary) {
|
||||
typedef Function<int(bool)> F; // NOLINT
|
||||
EXPECT_EQ(1u, F::ArgumentCount);
|
||||
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));
|
||||
}
|
||||
|
||||
TEST(FunctionTest, Binary) {
|
||||
typedef Function<int(bool, const long&)> F; // NOLINT
|
||||
EXPECT_EQ(2u, F::ArgumentCount);
|
||||
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));
|
||||
}
|
||||
|
||||
TEST(FunctionTest, LongArgumentList) {
|
||||
typedef Function<char(bool, int, char*, int&, const long&)> F; // NOLINT
|
||||
EXPECT_EQ(5u, F::ArgumentCount);
|
||||
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));
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, InvalidString) {
|
||||
std::string unescaped;
|
||||
EXPECT_FALSE(Base64Unescape("(invalid)", &unescaped));
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, ShortString) {
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQh", &unescaped));
|
||||
EXPECT_EQ("Hello world!", unescaped);
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, ShortStringWithPadding) {
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQ=", &unescaped));
|
||||
EXPECT_EQ("Hello world", unescaped);
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, ShortStringWithoutPadding) {
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape("SGVsbG8gd29ybGQ", &unescaped));
|
||||
EXPECT_EQ("Hello world", unescaped);
|
||||
}
|
||||
|
||||
TEST(Base64Unescape, LongStringWithWhiteSpaces) {
|
||||
std::string escaped =
|
||||
R"(TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
|
||||
IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg
|
||||
dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu
|
||||
dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo
|
||||
ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=)";
|
||||
std::string expected =
|
||||
"Man is distinguished, not only by his reason, but by this singular "
|
||||
"passion from other animals, which is a lust of the mind, that by a "
|
||||
"perseverance of delight in the continued and indefatigable generation "
|
||||
"of knowledge, exceeds the short vehemence of any carnal pleasure.";
|
||||
std::string unescaped;
|
||||
EXPECT_TRUE(Base64Unescape(escaped, &unescaped));
|
||||
EXPECT_EQ(expected, unescaped);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace internal
|
||||
} // namespace testing
|
||||
|
||||
Reference in New Issue
Block a user