Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
c955e334
Unverified
Commit
c955e334
authored
Oct 19, 2018
by
Gennadiy Civil
Committed by
GitHub
Oct 19, 2018
Browse files
Merge branch 'master' into python3-tests
parents
3149e0e8
f410177a
Changes
52
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
72 additions
and
564 deletions
+72
-564
googletest/include/gtest/internal/gtest-type-util.h.pump
googletest/include/gtest/internal/gtest-type-util.h.pump
+1
-1
googletest/samples/sample8_unittest.cc
googletest/samples/sample8_unittest.cc
+4
-23
googletest/src/gtest-port.cc
googletest/src/gtest-port.cc
+3
-0
googletest/src/gtest-printers.cc
googletest/src/gtest-printers.cc
+1
-1
googletest/src/gtest.cc
googletest/src/gtest.cc
+2
-2
googletest/test/BUILD.bazel
googletest/test/BUILD.bazel
+2
-5
googletest/test/googletest-filepath-test.cc
googletest/test/googletest-filepath-test.cc
+1
-1
googletest/test/googletest-options-test.cc
googletest/test/googletest-options-test.cc
+6
-0
googletest/test/googletest-param-test-test.cc
googletest/test/googletest-param-test-test.cc
+49
-87
googletest/test/googletest-printers-test.cc
googletest/test/googletest-printers-test.cc
+1
-124
googletest/test/googletest-tuple-test.cc
googletest/test/googletest-tuple-test.cc
+0
-319
googletest/test/gtest_test_utils.py
googletest/test/gtest_test_utils.py
+2
-1
No files found.
googletest/include/gtest/internal/gtest-type-util.h.pump
View file @
c955e334
...
@@ -87,7 +87,7 @@ std::string GetTypeName() {
...
@@ -87,7 +87,7 @@ std::string GetTypeName() {
# if GTEST_HAS_CXXABI_H_
# if GTEST_HAS_CXXABI_H_
using
abi
::
__cxa_demangle
;
using
abi
::
__cxa_demangle
;
# endif // GTEST_HAS_CXXABI_H_
# endif // GTEST_HAS_CXXABI_H_
char
*
const
readable_name
=
__cxa_demangle
(
name
,
0
,
0
,
&
status
);
char
*
const
readable_name
=
__cxa_demangle
(
name
,
nullptr
,
nullptr
,
&
status
);
const
std
::
string
name_str
(
status
==
0
?
readable_name
:
name
);
const
std
::
string
name_str
(
status
==
0
?
readable_name
:
name
);
free
(
readable_name
);
free
(
readable_name
);
return
CanonicalizeForStdLibVersioning
(
name_str
);
return
CanonicalizeForStdLibVersioning
(
name_str
);
...
...
googletest/samples/sample8_unittest.cc
View file @
c955e334
...
@@ -37,7 +37,6 @@
...
@@ -37,7 +37,6 @@
#include "gtest/gtest.h"
#include "gtest/gtest.h"
namespace
{
namespace
{
#if GTEST_HAS_COMBINE
// Suppose we want to introduce a new, improved implementation of PrimeTable
// Suppose we want to introduce a new, improved implementation of PrimeTable
// which combines speed of PrecalcPrimeTable and versatility of
// which combines speed of PrecalcPrimeTable and versatility of
...
@@ -90,19 +89,12 @@ using ::testing::Combine;
...
@@ -90,19 +89,12 @@ using ::testing::Combine;
// PreCalculatedPrimeTable disabled. We do this by defining fixture which will
// PreCalculatedPrimeTable disabled. We do this by defining fixture which will
// accept different combinations of parameters for instantiating a
// accept different combinations of parameters for instantiating a
// HybridPrimeTable instance.
// HybridPrimeTable instance.
class
PrimeTableTest
:
public
TestWithParam
<
::
testing
::
tuple
<
bool
,
int
>
>
{
class
PrimeTableTest
:
public
TestWithParam
<
::
std
::
tuple
<
bool
,
int
>
>
{
protected:
protected:
virtual
void
SetUp
()
{
virtual
void
SetUp
()
{
// This can be written as
bool
force_on_the_fly
;
//
int
max_precalculated
;
// bool force_on_the_fly;
std
::
tie
(
force_on_the_fly
,
max_precalculated
)
=
GetParam
();
// int max_precalculated;
// tie(force_on_the_fly, max_precalculated) = GetParam();
//
// once the Google C++ Style Guide allows use of ::std::tr1::tie.
//
bool
force_on_the_fly
=
::
testing
::
get
<
0
>
(
GetParam
());
int
max_precalculated
=
::
testing
::
get
<
1
>
(
GetParam
());
table_
=
new
HybridPrimeTable
(
force_on_the_fly
,
max_precalculated
);
table_
=
new
HybridPrimeTable
(
force_on_the_fly
,
max_precalculated
);
}
}
virtual
void
TearDown
()
{
virtual
void
TearDown
()
{
...
@@ -160,15 +152,4 @@ INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
...
@@ -160,15 +152,4 @@ INSTANTIATE_TEST_CASE_P(MeaningfulTestParameters,
PrimeTableTest
,
PrimeTableTest
,
Combine
(
Bool
(),
Values
(
1
,
10
)));
Combine
(
Bool
(),
Values
(
1
,
10
)));
#else
// Google Test may not support Combine() with some compilers. If we
// use conditional compilation to compile out all code referring to
// the gtest_main library, MSVC linker will not link that library at
// all and consequently complain about missing entry point defined in
// that library (fatal error LNK1561: entry point must be
// defined). This dummy test keeps gtest_main linked in.
TEST
(
DummyTest
,
CombineIsNotSupportedOnThisPlatform
)
{}
#endif // GTEST_HAS_COMBINE
}
// namespace
}
// namespace
googletest/src/gtest-port.cc
View file @
c955e334
...
@@ -41,6 +41,9 @@
...
@@ -41,6 +41,9 @@
# include <io.h>
# include <io.h>
# include <sys/stat.h>
# include <sys/stat.h>
# include <map> // Used in ThreadLocal.
# include <map> // Used in ThreadLocal.
# ifdef _MSC_VER
# include <crtdbg.h>
# endif // _MSC_VER
#else
#else
# include <unistd.h>
# include <unistd.h>
#endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
...
...
googletest/src/gtest-printers.cc
View file @
c955e334
...
@@ -348,7 +348,7 @@ void PrintTo(const wchar_t* s, ostream* os) {
...
@@ -348,7 +348,7 @@ void PrintTo(const wchar_t* s, ostream* os) {
*
os
<<
"NULL"
;
*
os
<<
"NULL"
;
}
else
{
}
else
{
*
os
<<
ImplicitCast_
<
const
void
*>
(
s
)
<<
" pointing to "
;
*
os
<<
ImplicitCast_
<
const
void
*>
(
s
)
<<
" pointing to "
;
PrintCharsAsStringTo
(
s
,
std
::
wcslen
(
s
),
os
);
PrintCharsAsStringTo
(
s
,
wcslen
(
s
),
os
);
}
}
}
}
#endif // wchar_t is native
#endif // wchar_t is native
...
...
googletest/src/gtest.cc
View file @
c955e334
...
@@ -445,7 +445,7 @@ static ::std::vector<std::string> g_argvs;
...
@@ -445,7 +445,7 @@ static ::std::vector<std::string> g_argvs;
FilePath
GetCurrentExecutableName
()
{
FilePath
GetCurrentExecutableName
()
{
FilePath
result
;
FilePath
result
;
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
|| GTEST_OS_OS2
result
.
Set
(
FilePath
(
GetArgvs
()[
0
]).
RemoveExtension
(
"exe"
));
result
.
Set
(
FilePath
(
GetArgvs
()[
0
]).
RemoveExtension
(
"exe"
));
#else
#else
result
.
Set
(
FilePath
(
GetArgvs
()[
0
]));
result
.
Set
(
FilePath
(
GetArgvs
()[
0
]));
...
@@ -5807,7 +5807,7 @@ static const char kColorEncodedHelpMessage[] =
...
@@ -5807,7 +5807,7 @@ static const char kColorEncodedHelpMessage[] =
" @G--"
GTEST_FLAG_PREFIX_
"output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G"
" @G--"
GTEST_FLAG_PREFIX_
"output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G"
GTEST_PATH_SEP_
"@Y|@G:@YFILE_PATH]@D
\n
"
GTEST_PATH_SEP_
"@Y|@G:@YFILE_PATH]@D
\n
"
" Generate a JSON or XML report in the given directory or with the given
\n
"
" Generate a JSON or XML report in the given directory or with the given
\n
"
" file name. @YFILE_PATH@D defaults to @Gtest_detail
s
.xml@D.
\n
"
" file name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.
\n
"
# if GTEST_CAN_STREAM_RESULTS_
# if GTEST_CAN_STREAM_RESULTS_
" @G--"
GTEST_FLAG_PREFIX_
"stream_result_to=@YHOST@G:@YPORT@D
\n
"
" @G--"
GTEST_FLAG_PREFIX_
"stream_result_to=@YHOST@G:@YPORT@D
\n
"
" Stream test results to the given server.
\n
"
" Stream test results to the given server.
\n
"
...
...
googletest/test/BUILD.bazel
View file @
c955e334
...
@@ -49,7 +49,7 @@ config_setting(
...
@@ -49,7 +49,7 @@ config_setting(
values
=
{
"define"
:
"absl=1"
},
values
=
{
"define"
:
"absl=1"
},
)
)
#on windows exclude gtest-tuple.h
and googletest-tuple-test.cc
#on windows exclude gtest-tuple.h
cc_test
(
cc_test
(
name
=
"gtest_all_test"
,
name
=
"gtest_all_test"
,
size
=
"small"
,
size
=
"small"
,
...
@@ -62,7 +62,6 @@ cc_test(
...
@@ -62,7 +62,6 @@ cc_test(
],
],
exclude
=
[
exclude
=
[
"gtest-unittest-api_test.cc"
,
"gtest-unittest-api_test.cc"
,
"googletest-tuple-test.cc"
,
"googletest/src/gtest-all.cc"
,
"googletest/src/gtest-all.cc"
,
"gtest_all_test.cc"
,
"gtest_all_test.cc"
,
"gtest-death-test_ex_test.cc"
,
"gtest-death-test_ex_test.cc"
,
...
@@ -89,9 +88,7 @@ cc_test(
...
@@ -89,9 +88,7 @@ cc_test(
)
+
select
({
)
+
select
({
"//:windows"
:
[],
"//:windows"
:
[],
"//:windows_msvc"
:
[],
"//:windows_msvc"
:
[],
"//conditions:default"
:
[
"//conditions:default"
:
[],
"googletest-tuple-test.cc"
,
],
}),
}),
copts
=
select
({
copts
=
select
({
"//:windows"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=0"
],
"//:windows"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=0"
],
...
...
googletest/test/googletest-filepath-test.cc
View file @
c955e334
...
@@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
...
@@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
const
FilePath
cwd
=
FilePath
::
GetCurrentDir
();
const
FilePath
cwd
=
FilePath
::
GetCurrentDir
();
posix
::
ChDir
(
original_dir
.
c_str
());
posix
::
ChDir
(
original_dir
.
c_str
());
# if GTEST_OS_WINDOWS
# if GTEST_OS_WINDOWS
|| GTEST_OS_OS2
// Skips the ":".
// Skips the ":".
const
char
*
const
cwd_without_drive
=
strchr
(
cwd
.
c_str
(),
':'
);
const
char
*
const
cwd_without_drive
=
strchr
(
cwd
.
c_str
(),
':'
);
...
...
googletest/test/googletest-options-test.cc
View file @
c955e334
...
@@ -102,6 +102,12 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
...
@@ -102,6 +102,12 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
_strcmpi
(
"gtest-options-ex_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest-options-ex_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest_all_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest_all_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest_dll_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
#elif GTEST_OS_FUCHSIA
const
bool
success
=
exe_str
==
"app"
;
const
bool
success
=
exe_str
==
"app"
;
#else
#else
...
...
googletest/test/googletest-param-test-test.cc
View file @
c955e334
...
@@ -49,19 +49,13 @@ using ::std::sort;
...
@@ -49,19 +49,13 @@ using ::std::sort;
using
::
testing
::
AddGlobalTestEnvironment
;
using
::
testing
::
AddGlobalTestEnvironment
;
using
::
testing
::
Bool
;
using
::
testing
::
Bool
;
using
::
testing
::
Combine
;
using
::
testing
::
Message
;
using
::
testing
::
Message
;
using
::
testing
::
Range
;
using
::
testing
::
Range
;
using
::
testing
::
TestWithParam
;
using
::
testing
::
TestWithParam
;
using
::
testing
::
Values
;
using
::
testing
::
Values
;
using
::
testing
::
ValuesIn
;
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
::
ParamGenerator
;
using
::
testing
::
internal
::
UnitTestOptions
;
using
::
testing
::
internal
::
UnitTestOptions
;
...
@@ -73,49 +67,9 @@ using ::testing::internal::UnitTestOptions;
...
@@ -73,49 +67,9 @@ using ::testing::internal::UnitTestOptions;
// EXPECT_THAT() and the matchers know how to print tuples.
// EXPECT_THAT() and the matchers know how to print tuples.
template
<
typename
T
>
template
<
typename
T
>
::
std
::
string
PrintValue
(
const
T
&
value
)
{
::
std
::
string
PrintValue
(
const
T
&
value
)
{
::
std
::
stringstream
stream
;
return
testing
::
PrintToString
(
value
);
stream
<<
value
;
return
stream
.
str
();
}
# 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
// Verifies that a sequence generated by the generator and accessed
// via the iterator object matches the expected one using Google Test
// via the iterator object matches the expected one using Google Test
// assertions.
// assertions.
...
@@ -450,31 +404,28 @@ TEST(BoolTest, BoolWorks) {
...
@@ -450,31 +404,28 @@ TEST(BoolTest, BoolWorks) {
VerifyGenerator
(
gen
,
expected_values
);
VerifyGenerator
(
gen
,
expected_values
);
}
}
# if GTEST_HAS_COMBINE
// Tests that Combine() with two parameters generates the expected sequence.
// Tests that Combine() with two parameters generates the expected sequence.
TEST
(
CombineTest
,
CombineWithTwoParameters
)
{
TEST
(
CombineTest
,
CombineWithTwoParameters
)
{
const
char
*
foo
=
"foo"
;
const
char
*
foo
=
"foo"
;
const
char
*
bar
=
"bar"
;
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
));
Combine
(
Values
(
foo
,
bar
),
Values
(
3
,
4
));
tuple
<
const
char
*
,
int
>
expected_values
[]
=
{
std
::
tuple
<
const
char
*
,
int
>
expected_values
[]
=
{
make_tuple
(
foo
,
3
),
make_tuple
(
foo
,
4
),
std
::
make_tuple
(
foo
,
3
),
std
::
make_tuple
(
foo
,
4
),
std
::
make_tuple
(
bar
,
3
),
make_tuple
(
bar
,
3
),
make_tuple
(
bar
,
4
)};
std
::
make_tuple
(
bar
,
4
)};
VerifyGenerator
(
gen
,
expected_values
);
VerifyGenerator
(
gen
,
expected_values
);
}
}
// Tests that Combine() with three parameters generates the expected sequence.
// Tests that Combine() with three parameters generates the expected sequence.
TEST
(
CombineTest
,
CombineWithThreeParameters
)
{
TEST
(
CombineTest
,
CombineWithThreeParameters
)
{
const
ParamGenerator
<
tuple
<
int
,
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
const
ParamGenerator
<
std
::
tuple
<
int
,
int
,
int
>
>
gen
=
Values
(
3
,
4
),
Combine
(
Values
(
0
,
1
),
Values
(
3
,
4
),
Values
(
5
,
6
));
Values
(
5
,
6
));
std
::
tuple
<
int
,
int
,
int
>
expected_values
[]
=
{
tuple
<
int
,
int
,
int
>
expected_values
[]
=
{
std
::
make_tuple
(
0
,
3
,
5
),
std
::
make_tuple
(
0
,
3
,
6
),
make_tuple
(
0
,
3
,
5
),
make_tuple
(
0
,
3
,
6
),
std
::
make_tuple
(
0
,
4
,
5
),
std
::
make_tuple
(
0
,
4
,
6
),
make_tuple
(
0
,
4
,
5
),
make_tuple
(
0
,
4
,
6
),
std
::
make_tuple
(
1
,
3
,
5
),
std
::
make_tuple
(
1
,
3
,
6
),
make_tuple
(
1
,
3
,
5
),
make_tuple
(
1
,
3
,
6
),
std
::
make_tuple
(
1
,
4
,
5
),
std
::
make_tuple
(
1
,
4
,
6
)};
make_tuple
(
1
,
4
,
5
),
make_tuple
(
1
,
4
,
6
)};
VerifyGenerator
(
gen
,
expected_values
);
VerifyGenerator
(
gen
,
expected_values
);
}
}
...
@@ -482,10 +433,11 @@ TEST(CombineTest, CombineWithThreeParameters) {
...
@@ -482,10 +433,11 @@ TEST(CombineTest, CombineWithThreeParameters) {
// sequence generates a sequence with the number of elements equal to the
// sequence generates a sequence with the number of elements equal to the
// number of elements in the sequence generated by the second parameter.
// number of elements in the sequence generated by the second parameter.
TEST
(
CombineTest
,
CombineWithFirstParameterSingleValue
)
{
TEST
(
CombineTest
,
CombineWithFirstParameterSingleValue
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
42
),
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Values
(
0
,
1
));
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
);
VerifyGenerator
(
gen
,
expected_values
);
}
}
...
@@ -493,26 +445,27 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) {
...
@@ -493,26 +445,27 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) {
// sequence generates a sequence with the number of elements equal to the
// sequence generates a sequence with the number of elements equal to the
// number of elements in the sequence generated by the first parameter.
// number of elements in the sequence generated by the first parameter.
TEST
(
CombineTest
,
CombineWithSecondParameterSingleValue
)
{
TEST
(
CombineTest
,
CombineWithSecondParameterSingleValue
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Values
(
42
));
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
);
VerifyGenerator
(
gen
,
expected_values
);
}
}
// Tests that when the first parameter produces an empty sequence,
// Tests that when the first parameter produces an empty sequence,
// Combine() produces an empty sequence, too.
// Combine() produces an empty sequence, too.
TEST
(
CombineTest
,
CombineWithFirstParameterEmptyRange
)
{
TEST
(
CombineTest
,
CombineWithFirstParameterEmptyRange
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Range
(
0
,
0
),
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Values
(
0
,
1
));
Combine
(
Range
(
0
,
0
),
Values
(
0
,
1
));
VerifyGeneratorIsEmpty
(
gen
);
VerifyGeneratorIsEmpty
(
gen
);
}
}
// Tests that when the second parameter produces an empty sequence,
// Tests that when the second parameter produces an empty sequence,
// Combine() produces an empty sequence, too.
// Combine() produces an empty sequence, too.
TEST
(
CombineTest
,
CombineWithSecondParameterEmptyRange
)
{
TEST
(
CombineTest
,
CombineWithSecondParameterEmptyRange
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Range
(
1
,
1
));
Combine
(
Values
(
0
,
1
),
Range
(
1
,
1
));
VerifyGeneratorIsEmpty
(
gen
);
VerifyGeneratorIsEmpty
(
gen
);
}
}
...
@@ -521,17 +474,15 @@ TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
...
@@ -521,17 +474,15 @@ TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
TEST
(
CombineTest
,
CombineWithMaxNumberOfParameters
)
{
TEST
(
CombineTest
,
CombineWithMaxNumberOfParameters
)
{
const
char
*
foo
=
"foo"
;
const
char
*
foo
=
"foo"
;
const
char
*
bar
=
"bar"
;
const
char
*
bar
=
"bar"
;
const
ParamGenerator
<
tuple
<
const
char
*
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
const
ParamGenerator
<
int
,
int
>
>
gen
=
Combine
(
Values
(
foo
,
bar
),
std
::
tuple
<
const
char
*
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
>
>
Values
(
1
),
Values
(
2
),
gen
=
Values
(
3
),
Values
(
4
),
Combine
(
Values
(
foo
,
bar
),
Values
(
1
),
Values
(
2
),
Values
(
3
),
Values
(
4
),
Values
(
5
),
Values
(
6
),
Values
(
5
),
Values
(
6
),
Values
(
7
),
Values
(
8
),
Values
(
9
));
Values
(
7
),
Values
(
8
),
Values
(
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
),
tuple
<
const
char
*
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
>
std
::
make_tuple
(
bar
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
)};
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
)};
VerifyGenerator
(
gen
,
expected_values
);
VerifyGenerator
(
gen
,
expected_values
);
}
}
...
@@ -551,12 +502,12 @@ class NonDefaultConstructAssignString {
...
@@ -551,12 +502,12 @@ class NonDefaultConstructAssignString {
};
};
TEST
(
CombineTest
,
NonDefaultConstructAssign
)
{
TEST
(
CombineTest
,
NonDefaultConstructAssign
)
{
const
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>
gen
=
const
ParamGenerator
<
std
::
tuple
<
int
,
NonDefaultConstructAssignString
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
NonDefaultConstructAssignString
(
"A"
),
Combine
(
Values
(
0
,
1
),
Values
(
NonDefaultConstructAssignString
(
"A"
),
NonDefaultConstructAssignString
(
"B"
)));
NonDefaultConstructAssignString
(
"B"
)));
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>::
iterator
it
=
ParamGenerator
<
std
::
tuple
<
int
,
NonDefaultConstructAssignString
>
>::
iterator
gen
.
begin
();
it
=
gen
.
begin
();
EXPECT_EQ
(
0
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
0
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"A"
,
std
::
get
<
1
>
(
*
it
).
str
());
EXPECT_EQ
(
"A"
,
std
::
get
<
1
>
(
*
it
).
str
());
...
@@ -577,7 +528,6 @@ TEST(CombineTest, NonDefaultConstructAssign) {
...
@@ -577,7 +528,6 @@ TEST(CombineTest, NonDefaultConstructAssign) {
EXPECT_TRUE
(
it
==
gen
.
end
());
EXPECT_TRUE
(
it
==
gen
.
end
());
}
}
# endif // GTEST_HAS_COMBINE
// Tests that an generator produces correct sequence after being
// Tests that an generator produces correct sequence after being
// assigned from another generator.
// assigned from another generator.
...
@@ -1081,6 +1031,18 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
...
@@ -1081,6 +1031,18 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
INSTANTIATE_TEST_CASE_P
(
RangeZeroToFive
,
ParameterizedDerivedTest
,
Range
(
0
,
5
));
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
)
{
int
main
(
int
argc
,
char
**
argv
)
{
// Used in TestGenerationTest test case.
// Used in TestGenerationTest test case.
...
...
googletest/test/googletest-printers-test.cc
View file @
c955e334
...
@@ -228,9 +228,7 @@ using ::testing::internal::Strings;
...
@@ -228,9 +228,7 @@ using ::testing::internal::Strings;
using
::
testing
::
internal
::
UniversalPrint
;
using
::
testing
::
internal
::
UniversalPrint
;
using
::
testing
::
internal
::
UniversalPrinter
;
using
::
testing
::
internal
::
UniversalPrinter
;
using
::
testing
::
internal
::
UniversalTersePrint
;
using
::
testing
::
internal
::
UniversalTersePrint
;
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
using
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
;
using
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
;
#endif
// Prints a value to a string using the universal value printer. This
// Prints a value to a string using the universal value printer. This
// is a helper for testing UniversalPrinter<T>::Print() for various types.
// is a helper for testing UniversalPrinter<T>::Print() for various types.
...
@@ -991,67 +989,6 @@ TEST(PrintStlContainerTest, ConstIterator) {
...
@@ -991,67 +989,6 @@ TEST(PrintStlContainerTest, ConstIterator) {
EXPECT_EQ
(
"1-byte object <00>"
,
Print
(
it
));
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.5
F
,
-
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.
// Tests printing ::std::tuples.
// Tuples of various arities.
// Tuples of various arities.
...
@@ -1071,32 +1008,12 @@ TEST(PrintStdTupleTest, VariousSizes) {
...
@@ -1071,32 +1008,12 @@ TEST(PrintStdTupleTest, VariousSizes) {
::
std
::
tuple
<
bool
,
int
,
int
,
int
>
t4
(
false
,
2
,
3
,
4
);
::
std
::
tuple
<
bool
,
int
,
int
,
int
>
t4
(
false
,
2
,
3
,
4
);
EXPECT_EQ
(
"(false, 2, 3, 4)"
,
Print
(
t4
));
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"
;
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
::
std
::
tuple
<
bool
,
char
,
short
,
testing
::
internal
::
Int32
,
// NOLINT
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
std
::
string
>
std
::
string
>
t10
(
false
,
'a'
,
static_cast
<
short
>
(
3
),
4
,
5
,
1.5
F
,
-
2.5
,
str
,
// NOLINT
t10
(
false
,
'a'
,
static_cast
<
short
>
(
3
),
4
,
5
,
1.5
F
,
-
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
)
+
EXPECT_EQ
(
"(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, "
+
PrintPointer
(
str
)
+
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
Print
(
t10
));
Print
(
t10
));
...
@@ -1109,8 +1026,6 @@ TEST(PrintStdTupleTest, NestedTuple) {
...
@@ -1109,8 +1026,6 @@ TEST(PrintStdTupleTest, NestedTuple) {
EXPECT_EQ
(
"((5, true), 'a' (97, 0x61))"
,
Print
(
nested
));
EXPECT_EQ
(
"((5, true), 'a' (97, 0x61))"
,
Print
(
nested
));
}
}
#endif // GTEST_HAS_TR1_TUPLE
TEST
(
PrintNullptrT
,
Basic
)
{
TEST
(
PrintNullptrT
,
Basic
)
{
EXPECT_EQ
(
"(nullptr)"
,
Print
(
nullptr
));
EXPECT_EQ
(
"(nullptr)"
,
Print
(
nullptr
));
}
}
...
@@ -1662,42 +1577,6 @@ TEST(UniversalPrintTest, WorksForCharArray) {
...
@@ -1662,42 +1577,6 @@ TEST(UniversalPrintTest, WorksForCharArray) {
EXPECT_EQ
(
"
\"\\\"
Line
\\
0 1
\\\"\\
nLine 2
\"
"
,
ss2
.
str
());
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
)
{
TEST
(
UniversalTersePrintTupleFieldsToStringsTestWithStd
,
PrintsEmptyTuple
)
{
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
make_tuple
());
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
make_tuple
());
EXPECT_EQ
(
0u
,
result
.
size
());
EXPECT_EQ
(
0u
,
result
.
size
());
...
@@ -1727,8 +1606,6 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
...
@@ -1727,8 +1606,6 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
EXPECT_EQ
(
"
\"
a
\"
"
,
result
[
1
]);
EXPECT_EQ
(
"
\"
a
\"
"
,
result
[
1
]);
}
}
#endif // GTEST_HAS_STD_TUPLE_
#if GTEST_HAS_ABSL
#if GTEST_HAS_ABSL
TEST
(
PrintOptionalTest
,
Basic
)
{
TEST
(
PrintOptionalTest
,
Basic
)
{
...
...
googletest/test/googletest-tuple-test.cc
deleted
100644 → 0
View file @
3149e0e8
// 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
googletest/test/gtest_test_utils.py
View file @
c955e334
...
@@ -36,6 +36,7 @@ import sys
...
@@ -36,6 +36,7 @@ import sys
IS_WINDOWS
=
os
.
name
==
'nt'
IS_WINDOWS
=
os
.
name
==
'nt'
IS_CYGWIN
=
os
.
name
==
'posix'
and
'CYGWIN'
in
os
.
uname
()[
0
]
IS_CYGWIN
=
os
.
name
==
'posix'
and
'CYGWIN'
in
os
.
uname
()[
0
]
IS_OS2
=
os
.
name
==
'os2'
import
atexit
import
atexit
import
shutil
import
shutil
...
@@ -164,7 +165,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
...
@@ -164,7 +165,7 @@ def GetTestExecutablePath(executable_name, build_dir=None):
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
build_dir
or
GetBuildDir
(),
path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
build_dir
or
GetBuildDir
(),
executable_name
))
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'
path
+=
'.exe'
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment