Merge branch 'master' into python3-tests
This commit is contained in:
@@ -49,7 +49,7 @@ config_setting(
|
||||
values = {"define": "absl=1"},
|
||||
)
|
||||
|
||||
#on windows exclude gtest-tuple.h and googletest-tuple-test.cc
|
||||
#on windows exclude gtest-tuple.h
|
||||
cc_test(
|
||||
name = "gtest_all_test",
|
||||
size = "small",
|
||||
@@ -62,7 +62,6 @@ cc_test(
|
||||
],
|
||||
exclude = [
|
||||
"gtest-unittest-api_test.cc",
|
||||
"googletest-tuple-test.cc",
|
||||
"googletest/src/gtest-all.cc",
|
||||
"gtest_all_test.cc",
|
||||
"gtest-death-test_ex_test.cc",
|
||||
@@ -89,9 +88,7 @@ cc_test(
|
||||
) + select({
|
||||
"//:windows": [],
|
||||
"//:windows_msvc": [],
|
||||
"//conditions:default": [
|
||||
"googletest-tuple-test.cc",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
copts = select({
|
||||
"//:windows": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
|
||||
|
||||
@@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
|
||||
const FilePath cwd = FilePath::GetCurrentDir();
|
||||
posix::ChDir(original_dir.c_str());
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_OS2
|
||||
|
||||
// Skips the ":".
|
||||
const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
|
||||
|
||||
@@ -102,6 +102,12 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
|
||||
_strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
|
||||
_strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
|
||||
_strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
|
||||
#elif GTEST_OS_OS2
|
||||
const bool success =
|
||||
strcasecmp("googletest-options-test", exe_str.c_str()) == 0 ||
|
||||
strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 ||
|
||||
strcasecmp("gtest_all_test", exe_str.c_str()) == 0 ||
|
||||
strcasecmp("gtest_dll_test", exe_str.c_str()) == 0;
|
||||
#elif GTEST_OS_FUCHSIA
|
||||
const bool success = exe_str == "app";
|
||||
#else
|
||||
|
||||
@@ -49,19 +49,13 @@ using ::std::sort;
|
||||
|
||||
using ::testing::AddGlobalTestEnvironment;
|
||||
using ::testing::Bool;
|
||||
using ::testing::Combine;
|
||||
using ::testing::Message;
|
||||
using ::testing::Range;
|
||||
using ::testing::TestWithParam;
|
||||
using ::testing::Values;
|
||||
using ::testing::ValuesIn;
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
using ::testing::Combine;
|
||||
using ::testing::get;
|
||||
using ::testing::make_tuple;
|
||||
using ::testing::tuple;
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
using ::testing::internal::ParamGenerator;
|
||||
using ::testing::internal::UnitTestOptions;
|
||||
|
||||
@@ -73,49 +67,9 @@ using ::testing::internal::UnitTestOptions;
|
||||
// EXPECT_THAT() and the matchers know how to print tuples.
|
||||
template <typename T>
|
||||
::std::string PrintValue(const T& value) {
|
||||
::std::stringstream stream;
|
||||
stream << value;
|
||||
return stream.str();
|
||||
return testing::PrintToString(value);
|
||||
}
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
|
||||
// These overloads allow printing tuples in our tests. We cannot
|
||||
// define an operator<< for tuples, as that definition needs to be in
|
||||
// the std namespace in order to be picked up by Google Test via
|
||||
// Argument-Dependent Lookup, yet defining anything in the std
|
||||
// namespace in non-STL code is undefined behavior.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
::std::string PrintValue(const tuple<T1, T2>& value) {
|
||||
::std::stringstream stream;
|
||||
stream << "(" << get<0>(value) << ", " << get<1>(value) << ")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3>
|
||||
::std::string PrintValue(const tuple<T1, T2, T3>& value) {
|
||||
::std::stringstream stream;
|
||||
stream << "(" << get<0>(value) << ", " << get<1>(value)
|
||||
<< ", "<< get<2>(value) << ")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
template <typename T1, typename T2, typename T3, typename T4, typename T5,
|
||||
typename T6, typename T7, typename T8, typename T9, typename T10>
|
||||
::std::string PrintValue(
|
||||
const tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& value) {
|
||||
::std::stringstream stream;
|
||||
stream << "(" << get<0>(value) << ", " << get<1>(value)
|
||||
<< ", "<< get<2>(value) << ", " << get<3>(value)
|
||||
<< ", "<< get<4>(value) << ", " << get<5>(value)
|
||||
<< ", "<< get<6>(value) << ", " << get<7>(value)
|
||||
<< ", "<< get<8>(value) << ", " << get<9>(value) << ")";
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
// Verifies that a sequence generated by the generator and accessed
|
||||
// via the iterator object matches the expected one using Google Test
|
||||
// assertions.
|
||||
@@ -450,31 +404,28 @@ TEST(BoolTest, BoolWorks) {
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
# if GTEST_HAS_COMBINE
|
||||
|
||||
// Tests that Combine() with two parameters generates the expected sequence.
|
||||
TEST(CombineTest, CombineWithTwoParameters) {
|
||||
const char* foo = "foo";
|
||||
const char* bar = "bar";
|
||||
const ParamGenerator<tuple<const char*, int> > gen =
|
||||
const ParamGenerator<std::tuple<const char*, int> > gen =
|
||||
Combine(Values(foo, bar), Values(3, 4));
|
||||
|
||||
tuple<const char*, int> expected_values[] = {
|
||||
make_tuple(foo, 3), make_tuple(foo, 4),
|
||||
make_tuple(bar, 3), make_tuple(bar, 4)};
|
||||
std::tuple<const char*, int> expected_values[] = {
|
||||
std::make_tuple(foo, 3), std::make_tuple(foo, 4), std::make_tuple(bar, 3),
|
||||
std::make_tuple(bar, 4)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
// Tests that Combine() with three parameters generates the expected sequence.
|
||||
TEST(CombineTest, CombineWithThreeParameters) {
|
||||
const ParamGenerator<tuple<int, int, int> > gen = Combine(Values(0, 1),
|
||||
Values(3, 4),
|
||||
Values(5, 6));
|
||||
tuple<int, int, int> expected_values[] = {
|
||||
make_tuple(0, 3, 5), make_tuple(0, 3, 6),
|
||||
make_tuple(0, 4, 5), make_tuple(0, 4, 6),
|
||||
make_tuple(1, 3, 5), make_tuple(1, 3, 6),
|
||||
make_tuple(1, 4, 5), make_tuple(1, 4, 6)};
|
||||
const ParamGenerator<std::tuple<int, int, int> > gen =
|
||||
Combine(Values(0, 1), Values(3, 4), Values(5, 6));
|
||||
std::tuple<int, int, int> expected_values[] = {
|
||||
std::make_tuple(0, 3, 5), std::make_tuple(0, 3, 6),
|
||||
std::make_tuple(0, 4, 5), std::make_tuple(0, 4, 6),
|
||||
std::make_tuple(1, 3, 5), std::make_tuple(1, 3, 6),
|
||||
std::make_tuple(1, 4, 5), std::make_tuple(1, 4, 6)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
@@ -482,10 +433,11 @@ TEST(CombineTest, CombineWithThreeParameters) {
|
||||
// sequence generates a sequence with the number of elements equal to the
|
||||
// number of elements in the sequence generated by the second parameter.
|
||||
TEST(CombineTest, CombineWithFirstParameterSingleValue) {
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Values(42),
|
||||
Values(0, 1));
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Values(42), Values(0, 1));
|
||||
|
||||
tuple<int, int> expected_values[] = {make_tuple(42, 0), make_tuple(42, 1)};
|
||||
std::tuple<int, int> expected_values[] = {std::make_tuple(42, 0),
|
||||
std::make_tuple(42, 1)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
@@ -493,26 +445,27 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) {
|
||||
// sequence generates a sequence with the number of elements equal to the
|
||||
// number of elements in the sequence generated by the first parameter.
|
||||
TEST(CombineTest, CombineWithSecondParameterSingleValue) {
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1),
|
||||
Values(42));
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Values(0, 1), Values(42));
|
||||
|
||||
tuple<int, int> expected_values[] = {make_tuple(0, 42), make_tuple(1, 42)};
|
||||
std::tuple<int, int> expected_values[] = {std::make_tuple(0, 42),
|
||||
std::make_tuple(1, 42)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
// Tests that when the first parameter produces an empty sequence,
|
||||
// Combine() produces an empty sequence, too.
|
||||
TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Range(0, 0),
|
||||
Values(0, 1));
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Range(0, 0), Values(0, 1));
|
||||
VerifyGeneratorIsEmpty(gen);
|
||||
}
|
||||
|
||||
// Tests that when the second parameter produces an empty sequence,
|
||||
// Combine() produces an empty sequence, too.
|
||||
TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
|
||||
const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1),
|
||||
Range(1, 1));
|
||||
const ParamGenerator<std::tuple<int, int> > gen =
|
||||
Combine(Values(0, 1), Range(1, 1));
|
||||
VerifyGeneratorIsEmpty(gen);
|
||||
}
|
||||
|
||||
@@ -521,17 +474,15 @@ TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
|
||||
TEST(CombineTest, CombineWithMaxNumberOfParameters) {
|
||||
const char* foo = "foo";
|
||||
const char* bar = "bar";
|
||||
const ParamGenerator<tuple<const char*, int, int, int, int, int, int, int,
|
||||
int, int> > gen = Combine(Values(foo, bar),
|
||||
Values(1), Values(2),
|
||||
Values(3), Values(4),
|
||||
Values(5), Values(6),
|
||||
Values(7), Values(8),
|
||||
Values(9));
|
||||
const ParamGenerator<
|
||||
std::tuple<const char*, int, int, int, int, int, int, int, int, int> >
|
||||
gen =
|
||||
Combine(Values(foo, bar), Values(1), Values(2), Values(3), Values(4),
|
||||
Values(5), Values(6), Values(7), Values(8), Values(9));
|
||||
|
||||
tuple<const char*, int, int, int, int, int, int, int, int, int>
|
||||
expected_values[] = {make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
|
||||
make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
|
||||
std::tuple<const char*, int, int, int, int, int, int, int, int, int>
|
||||
expected_values[] = {std::make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
|
||||
std::make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
|
||||
VerifyGenerator(gen, expected_values);
|
||||
}
|
||||
|
||||
@@ -551,12 +502,12 @@ class NonDefaultConstructAssignString {
|
||||
};
|
||||
|
||||
TEST(CombineTest, NonDefaultConstructAssign) {
|
||||
const ParamGenerator<tuple<int, NonDefaultConstructAssignString> > gen =
|
||||
const ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> > gen =
|
||||
Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"),
|
||||
NonDefaultConstructAssignString("B")));
|
||||
|
||||
ParamGenerator<tuple<int, NonDefaultConstructAssignString> >::iterator it =
|
||||
gen.begin();
|
||||
ParamGenerator<std::tuple<int, NonDefaultConstructAssignString> >::iterator
|
||||
it = gen.begin();
|
||||
|
||||
EXPECT_EQ(0, std::get<0>(*it));
|
||||
EXPECT_EQ("A", std::get<1>(*it).str());
|
||||
@@ -577,7 +528,6 @@ TEST(CombineTest, NonDefaultConstructAssign) {
|
||||
EXPECT_TRUE(it == gen.end());
|
||||
}
|
||||
|
||||
# endif // GTEST_HAS_COMBINE
|
||||
|
||||
// Tests that an generator produces correct sequence after being
|
||||
// assigned from another generator.
|
||||
@@ -1081,6 +1031,18 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RangeZeroToFive, ParameterizedDerivedTest, Range(0, 5));
|
||||
|
||||
// Tests param generator working with Enums
|
||||
enum MyEnums {
|
||||
ENUM1 = 1,
|
||||
ENUM2 = 3,
|
||||
ENUM3 = 8,
|
||||
};
|
||||
|
||||
class MyEnumTest : public testing::TestWithParam<MyEnums> {};
|
||||
|
||||
TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); }
|
||||
INSTANTIATE_TEST_CASE_P(MyEnumTests, MyEnumTest,
|
||||
::testing::Values(ENUM1, ENUM2, 0));
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Used in TestGenerationTest test case.
|
||||
|
||||
@@ -228,9 +228,7 @@ using ::testing::internal::Strings;
|
||||
using ::testing::internal::UniversalPrint;
|
||||
using ::testing::internal::UniversalPrinter;
|
||||
using ::testing::internal::UniversalTersePrint;
|
||||
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
|
||||
using ::testing::internal::UniversalTersePrintTupleFieldsToStrings;
|
||||
#endif
|
||||
|
||||
// Prints a value to a string using the universal value printer. This
|
||||
// is a helper for testing UniversalPrinter<T>::Print() for various types.
|
||||
@@ -991,67 +989,6 @@ TEST(PrintStlContainerTest, ConstIterator) {
|
||||
EXPECT_EQ("1-byte object <00>", Print(it));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
// Tests printing ::std::tr1::tuples.
|
||||
|
||||
// Tuples of various arities.
|
||||
TEST(PrintTr1TupleTest, VariousSizes) {
|
||||
::std::tr1::tuple<> t0;
|
||||
EXPECT_EQ("()", Print(t0));
|
||||
|
||||
::std::tr1::tuple<int> t1(5);
|
||||
EXPECT_EQ("(5)", Print(t1));
|
||||
|
||||
::std::tr1::tuple<char, bool> t2('a', true);
|
||||
EXPECT_EQ("('a' (97, 0x61), true)", Print(t2));
|
||||
|
||||
::std::tr1::tuple<bool, int, int> t3(false, 2, 3);
|
||||
EXPECT_EQ("(false, 2, 3)", Print(t3));
|
||||
|
||||
::std::tr1::tuple<bool, int, int, int> t4(false, 2, 3, 4);
|
||||
EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
|
||||
|
||||
::std::tr1::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
|
||||
|
||||
::std::tr1::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
|
||||
|
||||
::std::tr1::tuple<bool, int, int, int, bool, int, int> t7(
|
||||
false, 2, 3, 4, true, 6, 7);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
|
||||
|
||||
::std::tr1::tuple<bool, int, int, int, bool, int, int, bool> t8(
|
||||
false, 2, 3, 4, true, 6, 7, true);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
|
||||
|
||||
::std::tr1::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
|
||||
false, 2, 3, 4, true, 6, 7, true, 9);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
|
||||
|
||||
const char* const str = "8";
|
||||
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
|
||||
// an explicit type cast of NULL to be used.
|
||||
::std::tr1::tuple<bool, char, short, testing::internal::Int32, // NOLINT
|
||||
testing::internal::Int64, float, double, const char*, void*,
|
||||
std::string>
|
||||
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT
|
||||
ImplicitCast_<void*>(NULL), "10");
|
||||
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
|
||||
" pointing to \"8\", NULL, \"10\")",
|
||||
Print(t10));
|
||||
}
|
||||
|
||||
// Nested tuples.
|
||||
TEST(PrintTr1TupleTest, NestedTuple) {
|
||||
::std::tr1::tuple< ::std::tr1::tuple<int, bool>, char> nested(
|
||||
::std::tr1::make_tuple(5, true), 'a');
|
||||
EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
// Tests printing ::std::tuples.
|
||||
|
||||
// Tuples of various arities.
|
||||
@@ -1071,32 +1008,12 @@ TEST(PrintStdTupleTest, VariousSizes) {
|
||||
::std::tuple<bool, int, int, int> t4(false, 2, 3, 4);
|
||||
EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
|
||||
|
||||
::std::tuple<bool, int, int, int, bool> t5(false, 2, 3, 4, true);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true)", Print(t5));
|
||||
|
||||
::std::tuple<bool, int, int, int, bool, int> t6(false, 2, 3, 4, true, 6);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6)", Print(t6));
|
||||
|
||||
::std::tuple<bool, int, int, int, bool, int, int> t7(
|
||||
false, 2, 3, 4, true, 6, 7);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7)", Print(t7));
|
||||
|
||||
::std::tuple<bool, int, int, int, bool, int, int, bool> t8(
|
||||
false, 2, 3, 4, true, 6, 7, true);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true)", Print(t8));
|
||||
|
||||
::std::tuple<bool, int, int, int, bool, int, int, bool, int> t9(
|
||||
false, 2, 3, 4, true, 6, 7, true, 9);
|
||||
EXPECT_EQ("(false, 2, 3, 4, true, 6, 7, true, 9)", Print(t9));
|
||||
|
||||
const char* const str = "8";
|
||||
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
|
||||
// an explicit type cast of NULL to be used.
|
||||
::std::tuple<bool, char, short, testing::internal::Int32, // NOLINT
|
||||
testing::internal::Int64, float, double, const char*, void*,
|
||||
std::string>
|
||||
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT
|
||||
ImplicitCast_<void*>(NULL), "10");
|
||||
nullptr, "10");
|
||||
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
|
||||
" pointing to \"8\", NULL, \"10\")",
|
||||
Print(t10));
|
||||
@@ -1109,8 +1026,6 @@ TEST(PrintStdTupleTest, NestedTuple) {
|
||||
EXPECT_EQ("((5, true), 'a' (97, 0x61))", Print(nested));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
TEST(PrintNullptrT, Basic) {
|
||||
EXPECT_EQ("(nullptr)", Print(nullptr));
|
||||
}
|
||||
@@ -1662,42 +1577,6 @@ TEST(UniversalPrintTest, WorksForCharArray) {
|
||||
EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
|
||||
}
|
||||
|
||||
#if GTEST_HAS_TR1_TUPLE
|
||||
|
||||
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsEmptyTuple) {
|
||||
Strings result = UniversalTersePrintTupleFieldsToStrings(
|
||||
::std::tr1::make_tuple());
|
||||
EXPECT_EQ(0u, result.size());
|
||||
}
|
||||
|
||||
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsOneTuple) {
|
||||
Strings result = UniversalTersePrintTupleFieldsToStrings(
|
||||
::std::tr1::make_tuple(1));
|
||||
ASSERT_EQ(1u, result.size());
|
||||
EXPECT_EQ("1", result[0]);
|
||||
}
|
||||
|
||||
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTwoTuple) {
|
||||
Strings result = UniversalTersePrintTupleFieldsToStrings(
|
||||
::std::tr1::make_tuple(1, 'a'));
|
||||
ASSERT_EQ(2u, result.size());
|
||||
EXPECT_EQ("1", result[0]);
|
||||
EXPECT_EQ("'a' (97, 0x61)", result[1]);
|
||||
}
|
||||
|
||||
TEST(UniversalTersePrintTupleFieldsToStringsTestWithTr1, PrintsTersely) {
|
||||
const int n = 1;
|
||||
Strings result = UniversalTersePrintTupleFieldsToStrings(
|
||||
::std::tr1::tuple<const int&, const char*>(n, "a"));
|
||||
ASSERT_EQ(2u, result.size());
|
||||
EXPECT_EQ("1", result[0]);
|
||||
EXPECT_EQ("\"a\"", result[1]);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_TR1_TUPLE
|
||||
|
||||
#if GTEST_HAS_STD_TUPLE_
|
||||
|
||||
TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
|
||||
Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
|
||||
EXPECT_EQ(0u, result.size());
|
||||
@@ -1727,8 +1606,6 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
|
||||
EXPECT_EQ("\"a\"", result[1]);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_STD_TUPLE_
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
|
||||
TEST(PrintOptionalTest, Basic) {
|
||||
|
||||
@@ -1,319 +0,0 @@
|
||||
// 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.
|
||||
|
||||
|
||||
#include "gtest/internal/gtest-tuple.h"
|
||||
#include <utility>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using ::std::tr1::get;
|
||||
using ::std::tr1::make_tuple;
|
||||
using ::std::tr1::tuple;
|
||||
using ::std::tr1::tuple_element;
|
||||
using ::std::tr1::tuple_size;
|
||||
using ::testing::StaticAssertTypeEq;
|
||||
|
||||
// Tests that tuple_element<K, tuple<T0, T1, ..., TN> >::type returns TK.
|
||||
TEST(tuple_element_Test, ReturnsElementType) {
|
||||
StaticAssertTypeEq<int, tuple_element<0, tuple<int, char> >::type>();
|
||||
StaticAssertTypeEq<int&, tuple_element<1, tuple<double, int&> >::type>();
|
||||
StaticAssertTypeEq<bool, tuple_element<2, tuple<double, int, bool> >::type>();
|
||||
}
|
||||
|
||||
// Tests that tuple_size<T>::value gives the number of fields in tuple
|
||||
// type T.
|
||||
TEST(tuple_size_Test, ReturnsNumberOfFields) {
|
||||
EXPECT_EQ(0, +tuple_size<tuple<> >::value);
|
||||
EXPECT_EQ(1, +tuple_size<tuple<void*> >::value);
|
||||
EXPECT_EQ(1, +tuple_size<tuple<char> >::value);
|
||||
EXPECT_EQ(1, +(tuple_size<tuple<tuple<int, double> > >::value));
|
||||
EXPECT_EQ(2, +(tuple_size<tuple<int&, const char> >::value));
|
||||
EXPECT_EQ(3, +(tuple_size<tuple<char*, void, const bool&> >::value));
|
||||
}
|
||||
|
||||
// Tests comparing a tuple with itself.
|
||||
TEST(ComparisonTest, ComparesWithSelf) {
|
||||
const tuple<int, char, bool> a(5, 'a', false);
|
||||
|
||||
EXPECT_TRUE(a == a);
|
||||
EXPECT_FALSE(a != a);
|
||||
}
|
||||
|
||||
// Tests comparing two tuples with the same value.
|
||||
TEST(ComparisonTest, ComparesEqualTuples) {
|
||||
const tuple<int, bool> a(5, true), b(5, true);
|
||||
|
||||
EXPECT_TRUE(a == b);
|
||||
EXPECT_FALSE(a != b);
|
||||
}
|
||||
|
||||
// Tests comparing two different tuples that have no reference fields.
|
||||
TEST(ComparisonTest, ComparesUnequalTuplesWithoutReferenceFields) {
|
||||
typedef tuple<const int, char> FooTuple;
|
||||
|
||||
const FooTuple a(0, 'x');
|
||||
const FooTuple b(1, 'a');
|
||||
|
||||
EXPECT_TRUE(a != b);
|
||||
EXPECT_FALSE(a == b);
|
||||
|
||||
const FooTuple c(1, 'b');
|
||||
|
||||
EXPECT_TRUE(b != c);
|
||||
EXPECT_FALSE(b == c);
|
||||
}
|
||||
|
||||
// Tests comparing two different tuples that have reference fields.
|
||||
TEST(ComparisonTest, ComparesUnequalTuplesWithReferenceFields) {
|
||||
typedef tuple<int&, const char&> FooTuple;
|
||||
|
||||
int i = 5;
|
||||
const char ch = 'a';
|
||||
const FooTuple a(i, ch);
|
||||
|
||||
int j = 6;
|
||||
const FooTuple b(j, ch);
|
||||
|
||||
EXPECT_TRUE(a != b);
|
||||
EXPECT_FALSE(a == b);
|
||||
|
||||
j = 5;
|
||||
const char ch2 = 'b';
|
||||
const FooTuple c(j, ch2);
|
||||
|
||||
EXPECT_TRUE(b != c);
|
||||
EXPECT_FALSE(b == c);
|
||||
}
|
||||
|
||||
// Tests that a tuple field with a reference type is an alias of the
|
||||
// variable it's supposed to reference.
|
||||
TEST(ReferenceFieldTest, IsAliasOfReferencedVariable) {
|
||||
int n = 0;
|
||||
tuple<bool, int&> t(true, n);
|
||||
|
||||
n = 1;
|
||||
EXPECT_EQ(n, get<1>(t))
|
||||
<< "Changing a underlying variable should update the reference field.";
|
||||
|
||||
// Makes sure that the implementation doesn't do anything funny with
|
||||
// the & operator for the return type of get<>().
|
||||
EXPECT_EQ(&n, &(get<1>(t)))
|
||||
<< "The address of a reference field should equal the address of "
|
||||
<< "the underlying variable.";
|
||||
|
||||
get<1>(t) = 2;
|
||||
EXPECT_EQ(2, n)
|
||||
<< "Changing a reference field should update the underlying variable.";
|
||||
}
|
||||
|
||||
// Tests that tuple's default constructor default initializes each field.
|
||||
// This test needs to compile without generating warnings.
|
||||
TEST(TupleConstructorTest, DefaultConstructorDefaultInitializesEachField) {
|
||||
// The TR1 report requires that tuple's default constructor default
|
||||
// initializes each field, even if it's a primitive type. If the
|
||||
// implementation forgets to do this, this test will catch it by
|
||||
// generating warnings about using uninitialized variables (assuming
|
||||
// a decent compiler).
|
||||
|
||||
tuple<> empty;
|
||||
|
||||
tuple<int> a1, b1;
|
||||
b1 = a1;
|
||||
EXPECT_EQ(0, get<0>(b1));
|
||||
|
||||
tuple<int, double> a2, b2;
|
||||
b2 = a2;
|
||||
EXPECT_EQ(0, get<0>(b2));
|
||||
EXPECT_EQ(0.0, get<1>(b2));
|
||||
|
||||
tuple<double, char, bool*> a3, b3;
|
||||
b3 = a3;
|
||||
EXPECT_EQ(0.0, get<0>(b3));
|
||||
EXPECT_EQ('\0', get<1>(b3));
|
||||
EXPECT_TRUE(get<2>(b3) == nullptr);
|
||||
|
||||
tuple<int, int, int, int, int, int, int, int, int, int> a10, b10;
|
||||
b10 = a10;
|
||||
EXPECT_EQ(0, get<0>(b10));
|
||||
EXPECT_EQ(0, get<1>(b10));
|
||||
EXPECT_EQ(0, get<2>(b10));
|
||||
EXPECT_EQ(0, get<3>(b10));
|
||||
EXPECT_EQ(0, get<4>(b10));
|
||||
EXPECT_EQ(0, get<5>(b10));
|
||||
EXPECT_EQ(0, get<6>(b10));
|
||||
EXPECT_EQ(0, get<7>(b10));
|
||||
EXPECT_EQ(0, get<8>(b10));
|
||||
EXPECT_EQ(0, get<9>(b10));
|
||||
}
|
||||
|
||||
// Tests constructing a tuple from its fields.
|
||||
TEST(TupleConstructorTest, ConstructsFromFields) {
|
||||
int n = 1;
|
||||
// Reference field.
|
||||
tuple<int&> a(n);
|
||||
EXPECT_EQ(&n, &(get<0>(a)));
|
||||
|
||||
// Non-reference fields.
|
||||
tuple<int, char> b(5, 'a');
|
||||
EXPECT_EQ(5, get<0>(b));
|
||||
EXPECT_EQ('a', get<1>(b));
|
||||
|
||||
// Const reference field.
|
||||
const int m = 2;
|
||||
tuple<bool, const int&> c(true, m);
|
||||
EXPECT_TRUE(get<0>(c));
|
||||
EXPECT_EQ(&m, &(get<1>(c)));
|
||||
}
|
||||
|
||||
// Tests tuple's copy constructor.
|
||||
TEST(TupleConstructorTest, CopyConstructor) {
|
||||
tuple<double, bool> a(0.0, true);
|
||||
tuple<double, bool> b(a);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, get<0>(b));
|
||||
EXPECT_TRUE(get<1>(b));
|
||||
}
|
||||
|
||||
// Tests constructing a tuple from another tuple that has a compatible
|
||||
// but different type.
|
||||
TEST(TupleConstructorTest, ConstructsFromDifferentTupleType) {
|
||||
tuple<int, int, char> a(0, 1, 'a');
|
||||
tuple<double, long, int> b(a);
|
||||
|
||||
EXPECT_DOUBLE_EQ(0.0, get<0>(b));
|
||||
EXPECT_EQ(1, get<1>(b));
|
||||
EXPECT_EQ('a', get<2>(b));
|
||||
}
|
||||
|
||||
// Tests constructing a 2-tuple from an std::pair.
|
||||
TEST(TupleConstructorTest, ConstructsFromPair) {
|
||||
::std::pair<int, char> a(1, 'a');
|
||||
tuple<int, char> b(a);
|
||||
tuple<int, const char&> c(a);
|
||||
}
|
||||
|
||||
// Tests assigning a tuple to another tuple with the same type.
|
||||
TEST(TupleAssignmentTest, AssignsToSameTupleType) {
|
||||
const tuple<int, long> a(5, 7L);
|
||||
tuple<int, long> b;
|
||||
b = a;
|
||||
EXPECT_EQ(5, get<0>(b));
|
||||
EXPECT_EQ(7L, get<1>(b));
|
||||
}
|
||||
|
||||
// Tests assigning a tuple to another tuple with a different but
|
||||
// compatible type.
|
||||
TEST(TupleAssignmentTest, AssignsToDifferentTupleType) {
|
||||
const tuple<int, long, bool> a(1, 7L, true);
|
||||
tuple<long, int, bool> b;
|
||||
b = a;
|
||||
EXPECT_EQ(1L, get<0>(b));
|
||||
EXPECT_EQ(7, get<1>(b));
|
||||
EXPECT_TRUE(get<2>(b));
|
||||
}
|
||||
|
||||
// Tests assigning an std::pair to a 2-tuple.
|
||||
TEST(TupleAssignmentTest, AssignsFromPair) {
|
||||
const ::std::pair<int, bool> a(5, true);
|
||||
tuple<int, bool> b;
|
||||
b = a;
|
||||
EXPECT_EQ(5, get<0>(b));
|
||||
EXPECT_TRUE(get<1>(b));
|
||||
|
||||
tuple<long, bool> c;
|
||||
c = a;
|
||||
EXPECT_EQ(5L, get<0>(c));
|
||||
EXPECT_TRUE(get<1>(c));
|
||||
}
|
||||
|
||||
// A fixture for testing big tuples.
|
||||
class BigTupleTest : public testing::Test {
|
||||
protected:
|
||||
typedef tuple<int, int, int, int, int, int, int, int, int, int> BigTuple;
|
||||
|
||||
BigTupleTest() :
|
||||
a_(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
|
||||
b_(1, 0, 0, 0, 0, 0, 0, 0, 0, 3) {}
|
||||
|
||||
BigTuple a_, b_;
|
||||
};
|
||||
|
||||
// Tests constructing big tuples.
|
||||
TEST_F(BigTupleTest, Construction) {
|
||||
BigTuple a;
|
||||
BigTuple b(b_);
|
||||
}
|
||||
|
||||
// Tests that get<N>(t) returns the N-th (0-based) field of tuple t.
|
||||
TEST_F(BigTupleTest, get) {
|
||||
EXPECT_EQ(1, get<0>(a_));
|
||||
EXPECT_EQ(2, get<9>(a_));
|
||||
|
||||
// Tests that get() works on a const tuple too.
|
||||
const BigTuple a(a_);
|
||||
EXPECT_EQ(1, get<0>(a));
|
||||
EXPECT_EQ(2, get<9>(a));
|
||||
}
|
||||
|
||||
// Tests comparing big tuples.
|
||||
TEST_F(BigTupleTest, Comparisons) {
|
||||
EXPECT_TRUE(a_ == a_);
|
||||
EXPECT_FALSE(a_ != a_);
|
||||
|
||||
EXPECT_TRUE(a_ != b_);
|
||||
EXPECT_FALSE(a_ == b_);
|
||||
}
|
||||
|
||||
TEST(MakeTupleTest, WorksForScalarTypes) {
|
||||
tuple<bool, int> a;
|
||||
a = make_tuple(true, 5);
|
||||
EXPECT_TRUE(get<0>(a));
|
||||
EXPECT_EQ(5, get<1>(a));
|
||||
|
||||
tuple<char, int, long> b;
|
||||
b = make_tuple('a', 'b', 5);
|
||||
EXPECT_EQ('a', get<0>(b));
|
||||
EXPECT_EQ('b', get<1>(b));
|
||||
EXPECT_EQ(5, get<2>(b));
|
||||
}
|
||||
|
||||
TEST(MakeTupleTest, WorksForPointers) {
|
||||
int a[] = { 1, 2, 3, 4 };
|
||||
const char* const str = "hi";
|
||||
int* const p = a;
|
||||
|
||||
tuple<const char*, int*> t;
|
||||
t = make_tuple(str, p);
|
||||
EXPECT_EQ(str, get<0>(t));
|
||||
EXPECT_EQ(p, get<1>(t));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -36,6 +36,7 @@ import sys
|
||||
|
||||
IS_WINDOWS = os.name == 'nt'
|
||||
IS_CYGWIN = os.name == 'posix' and 'CYGWIN' in os.uname()[0]
|
||||
IS_OS2 = os.name == 'os2'
|
||||
|
||||
import atexit
|
||||
import shutil
|
||||
@@ -164,7 +165,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
|
||||
|
||||
path = os.path.abspath(os.path.join(build_dir or GetBuildDir(),
|
||||
executable_name))
|
||||
if (IS_WINDOWS or IS_CYGWIN) and not path.endswith('.exe'):
|
||||
if (IS_WINDOWS or IS_CYGWIN or IS_OS2) and not path.endswith('.exe'):
|
||||
path += '.exe'
|
||||
|
||||
if not os.path.exists(path):
|
||||
|
||||
Reference in New Issue
Block a user