Googletest export

Change ValuesArray to require much less template instantiation depth.

PiperOrigin-RevId: 218170842
This commit is contained in:
Abseil Team
2018-10-22 11:21:18 -04:00
committed by Gennadiy Civil
parent 32dbcac06e
commit 82987067d8
3 changed files with 193 additions and 37 deletions

View File

@@ -7450,6 +7450,84 @@ TEST(NativeArrayTest, WorksForTwoDimensionalArray) {
EXPECT_EQ(a, na.begin());
}
// IndexSequence
TEST(IndexSequence, MakeIndexSequence) {
using testing::internal::IndexSequence;
using testing::internal::MakeIndexSequence;
EXPECT_TRUE(
(std::is_same<IndexSequence<>, MakeIndexSequence<0>::type>::value));
EXPECT_TRUE(
(std::is_same<IndexSequence<0>, MakeIndexSequence<1>::type>::value));
EXPECT_TRUE(
(std::is_same<IndexSequence<0, 1>, MakeIndexSequence<2>::type>::value));
EXPECT_TRUE((
std::is_same<IndexSequence<0, 1, 2>, MakeIndexSequence<3>::type>::value));
EXPECT_TRUE(
(std::is_base_of<IndexSequence<0, 1, 2>, MakeIndexSequence<3>>::value));
}
// ElemFromList
TEST(ElemFromList, Basic) {
using testing::internal::ElemFromList;
using Idx = testing::internal::MakeIndexSequence<3>::type;
EXPECT_TRUE((
std::is_same<int, ElemFromList<0, Idx, int, double, char>::type>::value));
EXPECT_TRUE(
(std::is_same<double,
ElemFromList<1, Idx, int, double, char>::type>::value));
EXPECT_TRUE(
(std::is_same<char,
ElemFromList<2, Idx, int, double, char>::type>::value));
EXPECT_TRUE(
(std::is_same<
char, ElemFromList<7, testing::internal::MakeIndexSequence<12>::type,
int, int, int, int, int, int, int, char, int, int,
int, int>::type>::value));
}
// FlatTuple
TEST(FlatTuple, Basic) {
using testing::internal::FlatTuple;
FlatTuple<int, double, const char*> tuple = {};
EXPECT_EQ(0, tuple.Get<0>());
EXPECT_EQ(0.0, tuple.Get<1>());
EXPECT_EQ(nullptr, tuple.Get<2>());
tuple = FlatTuple<int, double, const char*>(7, 3.2, "Foo");
EXPECT_EQ(7, tuple.Get<0>());
EXPECT_EQ(3.2, tuple.Get<1>());
EXPECT_EQ(std::string("Foo"), tuple.Get<2>());
tuple.Get<1>() = 5.1;
EXPECT_EQ(5.1, tuple.Get<1>());
}
TEST(FlatTuple, ManyTypes) {
using testing::internal::FlatTuple;
// Instantiate FlatTuple with 257 ints.
// Tests show that we can do it with thousands of elements, but very long
// compile times makes it unusuitable for this test.
#define GTEST_FLAT_TUPLE_INT8 int, int, int, int, int, int, int, int,
#define GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT8 GTEST_FLAT_TUPLE_INT8
#define GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT16 GTEST_FLAT_TUPLE_INT16
#define GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT32 GTEST_FLAT_TUPLE_INT32
#define GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT64 GTEST_FLAT_TUPLE_INT64
#define GTEST_FLAT_TUPLE_INT256 GTEST_FLAT_TUPLE_INT128 GTEST_FLAT_TUPLE_INT128
// Let's make sure that we can have a very long list of types without blowing
// up the template instantiation depth.
FlatTuple<GTEST_FLAT_TUPLE_INT256 int> tuple;
tuple.Get<0>() = 7;
tuple.Get<99>() = 17;
tuple.Get<256>() = 1000;
EXPECT_EQ(7, tuple.Get<0>());
EXPECT_EQ(17, tuple.Get<99>());
EXPECT_EQ(1000, tuple.Get<256>());
}
// Tests SkipPrefix().
TEST(SkipPrefixTest, SkipsWhenPrefixMatches) {