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
9f0824b0
"nndet/vscode:/vscode.git/clone" did not exist on "dbed904cefbf7d201d77dde4f7ace89e4fc23d1b"
Commit
9f0824b0
authored
Mar 22, 2010
by
zhanyong.wan
Browse files
Adds missing gtest DLL exports.
parent
90030d74
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
143 additions
and
693 deletions
+143
-693
CMakeLists.txt
CMakeLists.txt
+14
-11
Makefile.am
Makefile.am
+1
-2
include/gtest/gtest.h
include/gtest/gtest.h
+19
-19
include/gtest/internal/gtest-filepath.h
include/gtest/internal/gtest-filepath.h
+1
-1
include/gtest/internal/gtest-internal.h
include/gtest/internal/gtest-internal.h
+6
-5
include/gtest/internal/gtest-port.h
include/gtest/internal/gtest-port.h
+6
-6
src/gtest-internal-inl.h
src/gtest-internal-inl.h
+44
-28
src/gtest_main.cc
src/gtest_main.cc
+1
-1
test/gtest-filepath_test.cc
test/gtest-filepath_test.cc
+0
-2
test/gtest-options_test.cc
test/gtest-options_test.cc
+42
-97
test/gtest_all_test.cc
test/gtest_all_test.cc
+1
-0
test/gtest_color_test_.cc
test/gtest_color_test_.cc
+8
-5
test/gtest_dll_test_.cc
test/gtest_dll_test_.cc
+0
-509
test/gtest_unittest.cc
test/gtest_unittest.cc
+0
-7
No files found.
CMakeLists.txt
View file @
9f0824b0
...
@@ -124,15 +124,12 @@ target_link_libraries(gtest_main gtest)
...
@@ -124,15 +124,12 @@ target_link_libraries(gtest_main gtest)
option
(
build_gtest_samples
"Build gtest's sample programs."
OFF
)
option
(
build_gtest_samples
"Build gtest's sample programs."
OFF
)
# cxx_executable
(name dir
lib srcs...)
# cxx_executable
_with_flags(name cxx_flags
lib srcs...)
#
#
# creates a named target that depends on the given lib and is built
# creates a named C++ executable that depends on the given library and
# from the given source files. dir/name.cc is implicitly included in
# is built from the given source files with the given compiler flags.
# the source file list.
function
(
cxx_executable_with_flags name cxx_flags lib
)
function
(
cxx_executable_with_flags name dir cxx_flags lib
)
add_executable
(
${
name
}
${
ARGN
}
)
add_executable
(
${
name
}
${
dir
}
/
${
name
}
.cc
${
ARGN
}
)
if
(
cxx_flags
)
if
(
cxx_flags
)
set_target_properties
(
${
name
}
set_target_properties
(
${
name
}
PROPERTIES
PROPERTIES
...
@@ -141,8 +138,14 @@ function(cxx_executable_with_flags name dir cxx_flags lib)
...
@@ -141,8 +138,14 @@ function(cxx_executable_with_flags name dir cxx_flags lib)
target_link_libraries
(
${
name
}
${
lib
}
)
target_link_libraries
(
${
name
}
${
lib
}
)
endfunction
()
endfunction
()
# cxx_executable(name dir lib srcs...)
#
# creates a named target that depends on the given lib and is built
# from the given source files. dir/name.cc is implicitly included in
# the source file list.
function
(
cxx_executable name dir lib
)
function
(
cxx_executable name dir lib
)
cxx_executable_with_flags
(
${
name
}
${
dir
}
"
${
cxx_default
}
"
${
lib
}
${
ARGN
}
)
cxx_executable_with_flags
(
${
name
}
"
${
cxx_default
}
"
${
lib
}
"
${
dir
}
/
${
name
}
.cc"
${
ARGN
}
)
endfunction
()
endfunction
()
if
(
build_gtest_samples
)
if
(
build_gtest_samples
)
...
@@ -273,8 +276,8 @@ if (build_all_gtest_tests)
...
@@ -273,8 +276,8 @@ if (build_all_gtest_tests)
# TODO(vladl): This and the next tests may not run in the hermetic
# TODO(vladl): This and the next tests may not run in the hermetic
# environment on Windows. Re-evaluate and possibly make them
# environment on Windows. Re-evaluate and possibly make them
# platform-conditional after implementing hermetic builds.
# platform-conditional after implementing hermetic builds.
cxx_executable_with_flags
(
gtest_dll_test_
test
"
${
cxx_use_shared_gtest
}
"
cxx_executable_with_flags
(
gtest_dll_test_
"
${
cxx_use_shared_gtest
}
"
gtest_dll
)
gtest_dll
test/gtest_all_test.cc
)
if
(
NOT
(
MSVC
AND
(
MSVC_VERSION EQUAL 1600
)))
if
(
NOT
(
MSVC
AND
(
MSVC_VERSION EQUAL 1600
)))
# The C++ Standard specifies tuple_element<int, class>.
# The C++ Standard specifies tuple_element<int, class>.
...
...
Makefile.am
View file @
9f0824b0
...
@@ -82,8 +82,7 @@ EXTRA_DIST += \
...
@@ -82,8 +82,7 @@ EXTRA_DIST += \
test
/gtest_uninitialized_test_.cc
\
test
/gtest_uninitialized_test_.cc
\
test
/gtest_xml_outfile1_test_.cc
\
test
/gtest_xml_outfile1_test_.cc
\
test
/gtest_xml_outfile2_test_.cc
\
test
/gtest_xml_outfile2_test_.cc
\
test
/gtest_xml_output_unittest_.cc
\
test
/gtest_xml_output_unittest_.cc
test
/gtest_dll_test_.cc
# Python tests that we don't run.
# Python tests that we don't run.
EXTRA_DIST
+=
\
EXTRA_DIST
+=
\
...
...
include/gtest/gtest.h
View file @
9f0824b0
...
@@ -1278,10 +1278,10 @@ AssertionResult CmpHelperEQ(const char* expected_expression,
...
@@ -1278,10 +1278,10 @@ AssertionResult CmpHelperEQ(const char* expected_expression,
// With this overloaded version, we allow anonymous enums to be used
// With this overloaded version, we allow anonymous enums to be used
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
// can be implicitly cast to BiggestInt.
// can be implicitly cast to BiggestInt.
AssertionResult
CmpHelperEQ
(
const
char
*
expected_expression
,
GTEST_API_
AssertionResult
CmpHelperEQ
(
const
char
*
expected_expression
,
const
char
*
actual_expression
,
const
char
*
actual_expression
,
BiggestInt
expected
,
BiggestInt
expected
,
BiggestInt
actual
);
BiggestInt
actual
);
// The helper class for {ASSERT|EXPECT}_EQ. The template argument
// The helper class for {ASSERT|EXPECT}_EQ. The template argument
// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
// lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
...
@@ -1370,21 +1370,21 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
...
@@ -1370,21 +1370,21 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
return AssertionFailure(msg);\
return AssertionFailure(msg);\
}\
}\
}\
}\
AssertionResult CmpHelper##op_name(
const char* expr1, const char* expr2,
\
GTEST_API_
AssertionResult CmpHelper##op_name(\
BiggestInt val1, BiggestInt val2)
;
const char* expr1, const char* expr2,
BiggestInt val1, BiggestInt val2)
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
// Implements the helper function for {ASSERT|EXPECT}_NE
// Implements the helper function for {ASSERT|EXPECT}_NE
GTEST_IMPL_CMP_HELPER_
(
NE
,
!=
)
GTEST_IMPL_CMP_HELPER_
(
NE
,
!=
)
;
// Implements the helper function for {ASSERT|EXPECT}_LE
// Implements the helper function for {ASSERT|EXPECT}_LE
GTEST_IMPL_CMP_HELPER_
(
LE
,
<=
)
GTEST_IMPL_CMP_HELPER_
(
LE
,
<=
)
;
// Implements the helper function for {ASSERT|EXPECT}_LT
// Implements the helper function for {ASSERT|EXPECT}_LT
GTEST_IMPL_CMP_HELPER_
(
LT
,
<
)
GTEST_IMPL_CMP_HELPER_
(
LT
,
<
)
;
// Implements the helper function for {ASSERT|EXPECT}_GE
// Implements the helper function for {ASSERT|EXPECT}_GE
GTEST_IMPL_CMP_HELPER_
(
GE
,
>=
)
GTEST_IMPL_CMP_HELPER_
(
GE
,
>=
)
;
// Implements the helper function for {ASSERT|EXPECT}_GT
// Implements the helper function for {ASSERT|EXPECT}_GT
GTEST_IMPL_CMP_HELPER_
(
GT
,
>
)
GTEST_IMPL_CMP_HELPER_
(
GT
,
>
)
;
#undef GTEST_IMPL_CMP_HELPER_
#undef GTEST_IMPL_CMP_HELPER_
...
@@ -1447,30 +1447,30 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
...
@@ -1447,30 +1447,30 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
//
//
// The {needle,haystack}_expr arguments are the stringified
// The {needle,haystack}_expr arguments are the stringified
// expressions that generated the two real arguments.
// expressions that generated the two real arguments.
AssertionResult
IsSubstring
(
GTEST_API_
AssertionResult
IsSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle
,
const
char
*
haystack
);
const
char
*
needle
,
const
char
*
haystack
);
AssertionResult
IsSubstring
(
GTEST_API_
AssertionResult
IsSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
wchar_t
*
needle
,
const
wchar_t
*
haystack
);
const
wchar_t
*
needle
,
const
wchar_t
*
haystack
);
AssertionResult
IsNotSubstring
(
GTEST_API_
AssertionResult
IsNotSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle
,
const
char
*
haystack
);
const
char
*
needle
,
const
char
*
haystack
);
AssertionResult
IsNotSubstring
(
GTEST_API_
AssertionResult
IsNotSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
wchar_t
*
needle
,
const
wchar_t
*
haystack
);
const
wchar_t
*
needle
,
const
wchar_t
*
haystack
);
AssertionResult
IsSubstring
(
GTEST_API_
AssertionResult
IsSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
::
std
::
string
&
needle
,
const
::
std
::
string
&
haystack
);
const
::
std
::
string
&
needle
,
const
::
std
::
string
&
haystack
);
AssertionResult
IsNotSubstring
(
GTEST_API_
AssertionResult
IsNotSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
::
std
::
string
&
needle
,
const
::
std
::
string
&
haystack
);
const
::
std
::
string
&
needle
,
const
::
std
::
string
&
haystack
);
#if GTEST_HAS_STD_WSTRING
#if GTEST_HAS_STD_WSTRING
AssertionResult
IsSubstring
(
GTEST_API_
AssertionResult
IsSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
::
std
::
wstring
&
needle
,
const
::
std
::
wstring
&
haystack
);
const
::
std
::
wstring
&
needle
,
const
::
std
::
wstring
&
haystack
);
AssertionResult
IsNotSubstring
(
GTEST_API_
AssertionResult
IsNotSubstring
(
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
char
*
needle_expr
,
const
char
*
haystack_expr
,
const
::
std
::
wstring
&
needle
,
const
::
std
::
wstring
&
haystack
);
const
::
std
::
wstring
&
needle
,
const
::
std
::
wstring
&
haystack
);
#endif // GTEST_HAS_STD_WSTRING
#endif // GTEST_HAS_STD_WSTRING
...
...
include/gtest/internal/gtest-filepath.h
View file @
9f0824b0
...
@@ -56,7 +56,7 @@ namespace internal {
...
@@ -56,7 +56,7 @@ namespace internal {
// Names are NOT checked for syntax correctness -- no checking for illegal
// Names are NOT checked for syntax correctness -- no checking for illegal
// characters, malformed paths, etc.
// characters, malformed paths, etc.
class
FilePath
{
class
GTEST_API_
FilePath
{
public:
public:
FilePath
()
:
pathname_
(
""
)
{
}
FilePath
()
:
pathname_
(
""
)
{
}
FilePath
(
const
FilePath
&
rhs
)
:
pathname_
(
rhs
.
pathname_
)
{
}
FilePath
(
const
FilePath
&
rhs
)
:
pathname_
(
rhs
.
pathname_
)
{
}
...
...
include/gtest/internal/gtest-internal.h
View file @
9f0824b0
...
@@ -120,7 +120,7 @@ extern int g_init_gtest_count;
...
@@ -120,7 +120,7 @@ extern int g_init_gtest_count;
// The text used in failure messages to indicate the start of the
// The text used in failure messages to indicate the start of the
// stack trace.
// stack trace.
extern
const
char
kStackTraceMarker
[];
GTEST_API_
extern
const
char
kStackTraceMarker
[];
// A secret type that Google Test users don't know about. It has no
// A secret type that Google Test users don't know about. It has no
// definition on purpose. Therefore it's impossible to create a
// definition on purpose. Therefore it's impossible to create a
...
@@ -157,8 +157,8 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT
...
@@ -157,8 +157,8 @@ char (&IsNullLiteralHelper(...))[2]; // NOLINT
#endif // GTEST_ELLIPSIS_NEEDS_POD_
#endif // GTEST_ELLIPSIS_NEEDS_POD_
// Appends the user-supplied message to the Google-Test-generated message.
// Appends the user-supplied message to the Google-Test-generated message.
String
AppendUserMessage
(
const
String
&
gtest_msg
,
GTEST_API_
String
AppendUserMessage
(
const
String
&
gtest_msg
,
const
Message
&
user_msg
);
const
Message
&
user_msg
);
// A helper class for creating scoped traces in user programs.
// A helper class for creating scoped traces in user programs.
class
GTEST_API_
ScopedTrace
{
class
GTEST_API_
ScopedTrace
{
...
@@ -750,7 +750,8 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
...
@@ -750,7 +750,8 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> {
// For example, if Foo() calls Bar(), which in turn calls
// For example, if Foo() calls Bar(), which in turn calls
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
String
GetCurrentOsStackTraceExceptTop
(
UnitTest
*
unit_test
,
int
skip_count
);
GTEST_API_
String
GetCurrentOsStackTraceExceptTop
(
UnitTest
*
unit_test
,
int
skip_count
);
// Helpers for suppressing warnings on unreachable code or constant
// Helpers for suppressing warnings on unreachable code or constant
// condition.
// condition.
...
@@ -766,7 +767,7 @@ inline bool AlwaysFalse() { return !AlwaysTrue(); }
...
@@ -766,7 +767,7 @@ inline bool AlwaysFalse() { return !AlwaysTrue(); }
// doesn't use global state (and therefore can't interfere with user
// doesn't use global state (and therefore can't interfere with user
// code). Unlike rand_r(), it's portable. An LCG isn't very random,
// code). Unlike rand_r(), it's portable. An LCG isn't very random,
// but it's good enough for our purposes.
// but it's good enough for our purposes.
class
Random
{
class
GTEST_API_
Random
{
public:
public:
static
const
UInt32
kMaxRange
=
1u
<<
31
;
static
const
UInt32
kMaxRange
=
1u
<<
31
;
...
...
include/gtest/internal/gtest-port.h
View file @
9f0824b0
...
@@ -782,10 +782,10 @@ inline void FlushInfoLog() { fflush(NULL); }
...
@@ -782,10 +782,10 @@ inline void FlushInfoLog() { fflush(NULL); }
// CaptureStderr - starts capturing stderr.
// CaptureStderr - starts capturing stderr.
// GetCapturedStderr - stops capturing stderr and returns the captured string.
// GetCapturedStderr - stops capturing stderr and returns the captured string.
//
//
void
CaptureStdout
();
GTEST_API_
void
CaptureStdout
();
String
GetCapturedStdout
();
GTEST_API_
String
GetCapturedStdout
();
void
CaptureStderr
();
GTEST_API_
void
CaptureStderr
();
String
GetCapturedStderr
();
GTEST_API_
String
GetCapturedStderr
();
#endif // GTEST_HAS_STREAM_REDIRECTION_
#endif // GTEST_HAS_STREAM_REDIRECTION_
...
@@ -1135,7 +1135,7 @@ class ThreadLocal {
...
@@ -1135,7 +1135,7 @@ class ThreadLocal {
// Returns the number of threads running in the process, or 0 to indicate that
// Returns the number of threads running in the process, or 0 to indicate that
// we cannot detect it.
// we cannot detect it.
size_t
GetThreadCount
();
GTEST_API_
size_t
GetThreadCount
();
// Passing non-POD classes through ellipsis (...) crashes the ARM
// Passing non-POD classes through ellipsis (...) crashes the ARM
// compiler and generates a warning in Sun Studio. The Nokia Symbian
// compiler and generates a warning in Sun Studio. The Nokia Symbian
...
@@ -1414,7 +1414,7 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value);
...
@@ -1414,7 +1414,7 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value);
// Parses a bool/Int32/string from the environment variable
// Parses a bool/Int32/string from the environment variable
// corresponding to the given Google Test flag.
// corresponding to the given Google Test flag.
bool
BoolFromGTestEnv
(
const
char
*
flag
,
bool
default_val
);
bool
BoolFromGTestEnv
(
const
char
*
flag
,
bool
default_val
);
Int32
Int32FromGTestEnv
(
const
char
*
flag
,
Int32
default_val
);
GTEST_API_
Int32
Int32FromGTestEnv
(
const
char
*
flag
,
Int32
default_val
);
const
char
*
StringFromGTestEnv
(
const
char
*
flag
,
const
char
*
default_val
);
const
char
*
StringFromGTestEnv
(
const
char
*
flag
,
const
char
*
default_val
);
}
// namespace internal
}
// namespace internal
...
...
src/gtest-internal-inl.h
View file @
9f0824b0
...
@@ -78,7 +78,7 @@ namespace internal {
...
@@ -78,7 +78,7 @@ namespace internal {
// The value of GetTestTypeId() as seen from within the Google Test
// The value of GetTestTypeId() as seen from within the Google Test
// library. This is solely for testing GetTestTypeId().
// library. This is solely for testing GetTestTypeId().
extern
const
TypeId
kTestTypeIdInGoogleTest
;
GTEST_API_
extern
const
TypeId
kTestTypeIdInGoogleTest
;
// Names of the flags (needed for parsing Google Test flags).
// Names of the flags (needed for parsing Google Test flags).
const
char
kAlsoRunDisabledTestsFlag
[]
=
"also_run_disabled_tests"
;
const
char
kAlsoRunDisabledTestsFlag
[]
=
"also_run_disabled_tests"
;
...
@@ -98,8 +98,25 @@ const char kThrowOnFailureFlag[] = "throw_on_failure";
...
@@ -98,8 +98,25 @@ const char kThrowOnFailureFlag[] = "throw_on_failure";
// A valid random seed must be in [1, kMaxRandomSeed].
// A valid random seed must be in [1, kMaxRandomSeed].
const
int
kMaxRandomSeed
=
99999
;
const
int
kMaxRandomSeed
=
99999
;
// g_help_flag is true iff the --help flag or an equivalent form is
// specified on the command line.
GTEST_API_
extern
bool
g_help_flag
;
// Returns the current time in milliseconds.
// Returns the current time in milliseconds.
TimeInMillis
GetTimeInMillis
();
GTEST_API_
TimeInMillis
GetTimeInMillis
();
// Returns true iff Google Test should use colors in the output.
GTEST_API_
bool
ShouldUseColor
(
bool
stdout_is_tty
);
// Formats the given time in milliseconds as seconds.
GTEST_API_
std
::
string
FormatTimeInMillisAsSeconds
(
TimeInMillis
ms
);
// Parses a string for an Int32 flag, in the form of "--flag=value".
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
GTEST_API_
bool
ParseInt32Flag
(
const
char
*
str
,
const
char
*
flag
,
Int32
*
value
);
// Returns a random seed in range [1, kMaxRandomSeed] based on the
// Returns a random seed in range [1, kMaxRandomSeed] based on the
// given --gtest_random_seed flag value.
// given --gtest_random_seed flag value.
...
@@ -199,7 +216,7 @@ class GTestFlagSaver {
...
@@ -199,7 +216,7 @@ class GTestFlagSaver {
// If the code_point is not a valid Unicode code point
// If the code_point is not a valid Unicode code point
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output
// as '(Invalid Unicode 0xXXXXXXXX)'.
// as '(Invalid Unicode 0xXXXXXXXX)'.
char
*
CodePointToUtf8
(
UInt32
code_point
,
char
*
str
);
GTEST_API_
char
*
CodePointToUtf8
(
UInt32
code_point
,
char
*
str
);
// Converts a wide string to a narrow string in UTF-8 encoding.
// Converts a wide string to a narrow string in UTF-8 encoding.
// The wide string is assumed to have the following encoding:
// The wide string is assumed to have the following encoding:
...
@@ -214,10 +231,7 @@ char* CodePointToUtf8(UInt32 code_point, char* str);
...
@@ -214,10 +231,7 @@ char* CodePointToUtf8(UInt32 code_point, char* str);
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
// and contains invalid UTF-16 surrogate pairs, values in those pairs
// and contains invalid UTF-16 surrogate pairs, values in those pairs
// will be encoded as individual Unicode characters from Basic Normal Plane.
// will be encoded as individual Unicode characters from Basic Normal Plane.
String
WideStringToUtf8
(
const
wchar_t
*
str
,
int
num_chars
);
GTEST_API_
String
WideStringToUtf8
(
const
wchar_t
*
str
,
int
num_chars
);
// Returns the number of active threads, or 0 when there is an error.
size_t
GetThreadCount
();
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
// if the variable is present. If a file already exists at this location, this
// if the variable is present. If a file already exists at this location, this
...
@@ -231,19 +245,21 @@ void WriteToShardStatusFileIfNeeded();
...
@@ -231,19 +245,21 @@ void WriteToShardStatusFileIfNeeded();
// an error and exits. If in_subprocess_for_death_test, sharding is
// an error and exits. If in_subprocess_for_death_test, sharding is
// disabled because it must only be applied to the original test
// disabled because it must only be applied to the original test
// process. Otherwise, we could filter out death tests we intended to execute.
// process. Otherwise, we could filter out death tests we intended to execute.
bool
ShouldShard
(
const
char
*
total_shards_str
,
const
char
*
shard_index_str
,
GTEST_API_
bool
ShouldShard
(
const
char
*
total_shards_str
,
bool
in_subprocess_for_death_test
);
const
char
*
shard_index_str
,
bool
in_subprocess_for_death_test
);
// Parses the environment variable var as an Int32. If it is unset,
// Parses the environment variable var as an Int32. If it is unset,
// returns default_val. If it is not an Int32, prints an error and
// returns default_val. If it is not an Int32, prints an error and
// and aborts.
// and aborts.
Int32
Int32FromEnvOrDie
(
const
char
*
env_var
,
Int32
default_val
);
GTEST_API_
Int32
Int32FromEnvOrDie
(
const
char
*
env_var
,
Int32
default_val
);
// Given the total number of shards, the shard index, and the test id,
// Given the total number of shards, the shard index, and the test id,
// returns true iff the test should be run on this shard. The test id is
// returns true iff the test should be run on this shard. The test id is
// some arbitrary but unique non-negative integer assigned to each test
// some arbitrary but unique non-negative integer assigned to each test
// method. Assumes that 0 <= shard_index < total_shards.
// method. Assumes that 0 <= shard_index < total_shards.
bool
ShouldRunTestOnShard
(
int
total_shards
,
int
shard_index
,
int
test_id
);
GTEST_API_
bool
ShouldRunTestOnShard
(
int
total_shards
,
int
shard_index
,
int
test_id
);
// STL container utilities.
// STL container utilities.
...
@@ -413,7 +429,7 @@ class TestInfoImpl {
...
@@ -413,7 +429,7 @@ class TestInfoImpl {
// test filter using either GTEST_FILTER or --gtest_filter. If both
// test filter using either GTEST_FILTER or --gtest_filter. If both
// the variable and the flag are present, the latter overrides the
// the variable and the flag are present, the latter overrides the
// former.
// former.
class
UnitTestOptions
{
class
GTEST_API_
UnitTestOptions
{
public:
public:
// Functions for processing the gtest_output flag.
// Functions for processing the gtest_output flag.
...
@@ -455,7 +471,7 @@ class UnitTestOptions {
...
@@ -455,7 +471,7 @@ class UnitTestOptions {
// Returns the current application's name, removing directory path if that
// Returns the current application's name, removing directory path if that
// is present. Used by UnitTestOptions::GetOutputFile.
// is present. Used by UnitTestOptions::GetOutputFile.
FilePath
GetCurrentExecutableName
();
GTEST_API_
FilePath
GetCurrentExecutableName
();
// The role interface for getting the OS stack trace as a string.
// The role interface for getting the OS stack trace as a string.
class
OsStackTraceGetterInterface
{
class
OsStackTraceGetterInterface
{
...
@@ -546,7 +562,7 @@ class DefaultPerThreadTestPartResultReporter
...
@@ -546,7 +562,7 @@ class DefaultPerThreadTestPartResultReporter
// the methods under a mutex, as this class is not accessible by a
// the methods under a mutex, as this class is not accessible by a
// user and the UnitTest class that delegates work to this class does
// user and the UnitTest class that delegates work to this class does
// proper locking.
// proper locking.
class
UnitTestImpl
{
class
GTEST_API_
UnitTestImpl
{
public:
public:
explicit
UnitTestImpl
(
UnitTest
*
parent
);
explicit
UnitTestImpl
(
UnitTest
*
parent
);
virtual
~
UnitTestImpl
();
virtual
~
UnitTestImpl
();
...
@@ -938,24 +954,24 @@ inline UnitTestImpl* GetUnitTestImpl() {
...
@@ -938,24 +954,24 @@ inline UnitTestImpl* GetUnitTestImpl() {
// Internal helper functions for implementing the simple regular
// Internal helper functions for implementing the simple regular
// expression matcher.
// expression matcher.
bool
IsInSet
(
char
ch
,
const
char
*
str
);
GTEST_API_
bool
IsInSet
(
char
ch
,
const
char
*
str
);
bool
IsDigit
(
char
ch
);
GTEST_API_
bool
IsDigit
(
char
ch
);
bool
IsPunct
(
char
ch
);
GTEST_API_
bool
IsPunct
(
char
ch
);
bool
IsRepeat
(
char
ch
);
GTEST_API_
bool
IsRepeat
(
char
ch
);
bool
IsWhiteSpace
(
char
ch
);
GTEST_API_
bool
IsWhiteSpace
(
char
ch
);
bool
IsWordChar
(
char
ch
);
GTEST_API_
bool
IsWordChar
(
char
ch
);
bool
IsValidEscape
(
char
ch
);
GTEST_API_
bool
IsValidEscape
(
char
ch
);
bool
AtomMatchesChar
(
bool
escaped
,
char
pattern
,
char
ch
);
GTEST_API_
bool
AtomMatchesChar
(
bool
escaped
,
char
pattern
,
char
ch
);
bool
ValidateRegex
(
const
char
*
regex
);
GTEST_API_
bool
ValidateRegex
(
const
char
*
regex
);
bool
MatchRegexAtHead
(
const
char
*
regex
,
const
char
*
str
);
GTEST_API_
bool
MatchRegexAtHead
(
const
char
*
regex
,
const
char
*
str
);
bool
MatchRepetitionAndRegexAtHead
(
GTEST_API_
bool
MatchRepetitionAndRegexAtHead
(
bool
escaped
,
char
ch
,
char
repeat
,
const
char
*
regex
,
const
char
*
str
);
bool
escaped
,
char
ch
,
char
repeat
,
const
char
*
regex
,
const
char
*
str
);
bool
MatchRegexAnywhere
(
const
char
*
regex
,
const
char
*
str
);
GTEST_API_
bool
MatchRegexAnywhere
(
const
char
*
regex
,
const
char
*
str
);
// Parses the command line for Google Test flags, without initializing
// Parses the command line for Google Test flags, without initializing
// other parts of Google Test.
// other parts of Google Test.
void
ParseGoogleTestFlagsOnly
(
int
*
argc
,
char
**
argv
);
GTEST_API_
void
ParseGoogleTestFlagsOnly
(
int
*
argc
,
char
**
argv
);
void
ParseGoogleTestFlagsOnly
(
int
*
argc
,
wchar_t
**
argv
);
GTEST_API_
void
ParseGoogleTestFlagsOnly
(
int
*
argc
,
wchar_t
**
argv
);
#if GTEST_HAS_DEATH_TEST
#if GTEST_HAS_DEATH_TEST
...
...
src/gtest_main.cc
View file @
9f0824b0
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
GTEST_API_
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
std
::
cout
<<
"Running main() from gtest_main.cc
\n
"
;
std
::
cout
<<
"Running main() from gtest_main.cc
\n
"
;
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
...
...
test/gtest-filepath_test.cc
View file @
9f0824b0
...
@@ -688,5 +688,3 @@ TEST(FilePathTest, IsRootDirectory) {
...
@@ -688,5 +688,3 @@ TEST(FilePathTest, IsRootDirectory) {
}
// namespace
}
// namespace
}
// namespace internal
}
// namespace internal
}
// namespace testing
}
// namespace testing
#undef GTEST_PATH_SEP_
test/gtest-options_test.cc
View file @
9f0824b0
...
@@ -89,61 +89,38 @@ TEST(XmlOutputTest, GetOutputFileSingleFile) {
...
@@ -89,61 +89,38 @@ TEST(XmlOutputTest, GetOutputFileSingleFile) {
}
}
TEST
(
XmlOutputTest
,
GetOutputFileFromDirectoryPath
)
{
TEST
(
XmlOutputTest
,
GetOutputFileFromDirectoryPath
)
{
#if GTEST_OS_WINDOWS
GTEST_FLAG
(
output
)
=
"xml:path"
GTEST_PATH_SEP_
;
GTEST_FLAG
(
output
)
=
"xml:path
\\
"
;
const
std
::
string
expected_output_file
=
GetAbsolutePathOf
(
FilePath
(
std
::
string
(
"path"
)
+
GTEST_PATH_SEP_
+
GetCurrentExecutableName
().
c_str
()
+
".xml"
)).
c_str
();
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
EXPECT_TRUE
(
#if GTEST_OS_WINDOWS
_strcmpi
(
output_file
.
c_str
(),
EXPECT_STRCASEEQ
(
expected_output_file
.
c_str
(),
output_file
.
c_str
());
GetAbsolutePathOf
(
FilePath
(
"path
\\
gtest-options_test.xml"
)).
c_str
())
==
0
||
_strcmpi
(
output_file
.
c_str
(),
GetAbsolutePathOf
(
FilePath
(
"path
\\
gtest-options-ex_test.xml"
)).
c_str
())
==
0
||
_strcmpi
(
output_file
.
c_str
(),
GetAbsolutePathOf
(
FilePath
(
"path
\\
gtest_all_test.xml"
)).
c_str
())
==
0
)
<<
" output_file = "
<<
output_file
;
#else
#else
GTEST_FLAG
(
output
)
=
"xml:path/"
;
EXPECT_EQ
(
expected_output_file
,
output_file
.
c_str
());
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
// TODO(wan@google.com): libtool causes the test binary file to be
// named lt-gtest-options_test. Therefore the output file may be
// named .../lt-gtest-options_test.xml. We should remove this
// hard-coded logic when Chandler Carruth's libtool replacement is
// ready.
EXPECT_TRUE
(
output_file
==
GetAbsolutePathOf
(
FilePath
(
"path/gtest-options_test.xml"
)).
c_str
()
||
output_file
==
GetAbsolutePathOf
(
FilePath
(
"path/lt-gtest-options_test.xml"
)).
c_str
()
||
output_file
==
GetAbsolutePathOf
(
FilePath
(
"path/gtest_all_test.xml"
)).
c_str
()
||
output_file
==
GetAbsolutePathOf
(
FilePath
(
"path/lt-gtest_all_test.xml"
)).
c_str
())
<<
" output_file = "
<<
output_file
;
#endif
#endif
}
}
TEST
(
OutputFileHelpersTest
,
GetCurrentExecutableName
)
{
TEST
(
OutputFileHelpersTest
,
GetCurrentExecutableName
)
{
const
FilePath
executable
=
GetCurrentExecutableName
();
const
std
::
string
exe_str
=
GetCurrentExecutableName
().
c_str
();
const
char
*
const
exe_str
=
executable
.
c_str
();
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
ASSERT_TRUE
(
_strcmpi
(
"gtest-options_test"
,
exe_str
)
==
0
||
const
bool
success
=
_strcmpi
(
"gtest-options-ex_test"
,
exe_str
)
==
0
||
_strcmpi
(
"gtest-options_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest_all_test"
,
exe_str
)
==
0
)
_strcmpi
(
"gtest-options-ex_test"
,
exe_str
.
c_str
())
==
0
||
<<
"GetCurrentExecutableName() returns "
<<
exe_str
;
_strcmpi
(
"gtest_all_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest_dll_test"
,
exe_str
.
c_str
())
==
0
;
#else
#else
// TODO(wan@google.com): remove the hard-coded "lt-" prefix when
// TODO(wan@google.com): remove the hard-coded "lt-" prefix when
// Chandler Carruth's libtool replacement is ready.
// Chandler Carruth's libtool replacement is ready.
EXPECT_TRUE
(
String
(
exe_str
)
==
"gtest-options_test"
||
const
bool
success
=
String
(
exe_str
)
==
"
lt-
gtest-options_test"
||
exe_str
==
"gtest-options_test"
||
String
(
exe_str
)
==
"gtest_all_test"
||
exe_str
==
"gtest_all_test"
||
String
(
exe_str
)
==
"lt-gtest_all_test"
)
exe_str
==
"lt-gtest_all_test"
||
<<
"GetCurrentExecutableName() returns "
<<
exe_
st
r
;
exe_str
==
"gtest_dll_te
st
"
;
#endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
if
(
!
success
)
FAIL
()
<<
"GetCurrentExecutableName() returns "
<<
exe_str
;
}
}
class
XmlOutputChangeDirTest
:
public
Test
{
class
XmlOutputChangeDirTest
:
public
Test
{
...
@@ -185,40 +162,17 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
...
@@ -185,40 +162,17 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativeFile) {
}
}
TEST_F
(
XmlOutputChangeDirTest
,
PreserveOriginalWorkingDirWithRelativePath
)
{
TEST_F
(
XmlOutputChangeDirTest
,
PreserveOriginalWorkingDirWithRelativePath
)
{
#if GTEST_OS_WINDOWS
GTEST_FLAG
(
output
)
=
"xml:path"
GTEST_PATH_SEP_
;
GTEST_FLAG
(
output
)
=
"xml:path
\\
"
;
const
std
::
string
expected_output_file
=
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
std
::
string
(
"path"
)
+
GTEST_PATH_SEP_
+
GetCurrentExecutableName
().
c_str
()
+
".xml"
)).
c_str
();
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
EXPECT_TRUE
(
#if GTEST_OS_WINDOWS
_strcmpi
(
output_file
.
c_str
(),
EXPECT_STRCASEEQ
(
expected_output_file
.
c_str
(),
output_file
.
c_str
());
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
"path
\\
gtest-options_test.xml"
)).
c_str
())
==
0
||
_strcmpi
(
output_file
.
c_str
(),
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
"path
\\
gtest-options-ex_test.xml"
)).
c_str
())
==
0
||
_strcmpi
(
output_file
.
c_str
(),
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
"path
\\
gtest_all_test.xml"
)).
c_str
())
==
0
)
<<
" output_file = "
<<
output_file
;
#else
#else
GTEST_FLAG
(
output
)
=
"xml:path/"
;
EXPECT_EQ
(
expected_output_file
,
output_file
.
c_str
());
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
// TODO(wan@google.com): libtool causes the test binary file to be
// named lt-gtest-options_test. Therefore the output file may be
// named .../lt-gtest-options_test.xml. We should remove this
// hard-coded logic when Chandler Carruth's libtool replacement is
// ready.
EXPECT_TRUE
(
output_file
==
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
"path/gtest-options_test.xml"
)).
c_str
()
||
output_file
==
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
"path/lt-gtest-options_test.xml"
)).
c_str
()
||
output_file
==
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
"path/gtest_all_test.xml"
)).
c_str
()
||
output_file
==
FilePath
::
ConcatPaths
(
original_working_dir_
,
FilePath
(
"path/lt-gtest_all_test.xml"
)).
c_str
())
<<
" output_file = "
<<
output_file
;
#endif
#endif
}
}
...
@@ -236,29 +190,20 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
...
@@ -236,29 +190,20 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
TEST_F
(
XmlOutputChangeDirTest
,
PreserveOriginalWorkingDirWithAbsolutePath
)
{
TEST_F
(
XmlOutputChangeDirTest
,
PreserveOriginalWorkingDirWithAbsolutePath
)
{
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
GTEST_FLAG
(
output
)
=
"xml:c:
\\
tmp
\\
"
;
const
std
::
string
path
=
"c:
\\
tmp
\\
"
;
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
EXPECT_TRUE
(
_strcmpi
(
output_file
.
c_str
(),
FilePath
(
"c:
\\
tmp
\\
gtest-options_test.xml"
).
c_str
())
==
0
||
_strcmpi
(
output_file
.
c_str
(),
FilePath
(
"c:
\\
tmp
\\
gtest-options-ex_test.xml"
).
c_str
())
==
0
||
_strcmpi
(
output_file
.
c_str
(),
FilePath
(
"c:
\\
tmp
\\
gtest_all_test.xml"
).
c_str
())
==
0
)
<<
" output_file = "
<<
output_file
;
#else
#else
GTEST_FLAG
(
output
)
=
"xml:/tmp/"
;
const
std
::
string
path
=
"/tmp/"
;
#endif
GTEST_FLAG
(
output
)
=
"xml:"
+
path
;
const
std
::
string
expected_output_file
=
path
+
GetCurrentExecutableName
().
c_str
()
+
".xml"
;
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
const
String
&
output_file
=
UnitTestOptions
::
GetAbsolutePathToOutputFile
();
// TODO(wan@google.com): libtool causes the test binary file to be
// named lt-gtest-options_test. Therefore the output file may be
#if GTEST_OS_WINDOWS
// named .../lt-gtest-options_test.xml. We should remove this
EXPECT_STRCASEEQ
(
expected_output_file
.
c_str
(),
output_file
.
c_str
());
// hard-coded logic when Chandler Carruth's libtool replacement is
#else
// ready.
EXPECT_EQ
(
expected_output_file
,
output_file
.
c_str
());
EXPECT_TRUE
(
output_file
==
"/tmp/gtest-options_test.xml"
||
output_file
==
"/tmp/lt-gtest-options_test.xml"
||
output_file
==
"/tmp/gtest_all_test.xml"
||
output_file
==
"/tmp/lt-gtest_all_test.xml"
)
<<
" output_file = "
<<
output_file
;
#endif
#endif
}
}
...
...
test/gtest_all_test.cc
View file @
9f0824b0
...
@@ -45,3 +45,4 @@
...
@@ -45,3 +45,4 @@
#include "test/gtest-typed-test2_test.cc"
#include "test/gtest-typed-test2_test.cc"
#include "test/gtest_unittest.cc"
#include "test/gtest_unittest.cc"
#include "test/production.cc"
#include "test/production.cc"
#include "src/gtest_main.cc"
test/gtest_color_test_.cc
View file @
9f0824b0
...
@@ -37,11 +37,14 @@
...
@@ -37,11 +37,14 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
namespace
testing
{
// Indicates that this translation unit is part of Google Test's
namespace
internal
{
// implementation. It must come before gtest-internal-inl.h is
bool
ShouldUseColor
(
bool
stdout_is_tty
);
// included, or there will be a compiler error. This trick is to
}
// namespace internal
// prevent a user from accidentally including gtest-internal-inl.h in
}
// namespace testing
// his code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
using
testing
::
internal
::
ShouldUseColor
;
using
testing
::
internal
::
ShouldUseColor
;
...
...
test/gtest_dll_test_.cc
deleted
100644 → 0
View file @
90030d74
// Copyright 2009 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.
//
// Author: vladl@google.com (Vlad Losev)
//
// Tests for Google Test itself. This verifies that Google Test can be
// linked into an executable successfully when built as a shared library (a
// DLL on Windows). The test is not meant to check the success of test
// assertions employed in it. It only checks that constructs in them can be
// successfully linked.
//
// If you add new features to Google Test's documented interface, you need to
// add tests exercising them to this file.
//
// If you start having 'unresolved external symbol' linker errors in this file
// after the changes you have made, you have to modify your source code to
// export the new symbols.
#include <gtest/gtest.h>
#include <gtest/gtest-spi.h>
#if GTEST_OS_WINDOWS
#include <windows.h>
#endif
#include <vector>
using
::
std
::
vector
;
using
::
std
::
tr1
::
tuple
;
using
::
testing
::
AddGlobalTestEnvironment
;
using
::
testing
::
AssertionFailure
;
using
::
testing
::
AssertionResult
;
using
::
testing
::
AssertionSuccess
;
using
::
testing
::
DoubleLE
;
using
::
testing
::
EmptyTestEventListener
;
using
::
testing
::
Environment
;
using
::
testing
::
ExitedWithCode
;
using
::
testing
::
FloatLE
;
using
::
testing
::
GTEST_FLAG
(
also_run_disabled_tests
);
using
::
testing
::
GTEST_FLAG
(
break_on_failure
);
using
::
testing
::
GTEST_FLAG
(
catch_exceptions
);
using
::
testing
::
GTEST_FLAG
(
color
);
using
::
testing
::
GTEST_FLAG
(
filter
);
using
::
testing
::
GTEST_FLAG
(
output
);
using
::
testing
::
GTEST_FLAG
(
print_time
);
using
::
testing
::
GTEST_FLAG
(
random_seed
);
using
::
testing
::
GTEST_FLAG
(
repeat
);
using
::
testing
::
GTEST_FLAG
(
shuffle
);
using
::
testing
::
GTEST_FLAG
(
stack_trace_depth
);
using
::
testing
::
GTEST_FLAG
(
throw_on_failure
);
using
::
testing
::
InitGoogleTest
;
using
::
testing
::
Message
;
using
::
testing
::
Test
;
using
::
testing
::
TestCase
;
using
::
testing
::
TestEventListener
;
using
::
testing
::
TestEventListeners
;
using
::
testing
::
TestInfo
;
using
::
testing
::
TestPartResult
;
using
::
testing
::
TestProperty
;
using
::
testing
::
TestResult
;
using
::
testing
::
UnitTest
;
using
::
testing
::
internal
::
AlwaysTrue
;
using
::
testing
::
internal
::
AlwaysFalse
;
#if GTEST_HAS_PARAM_TEST
using
::
testing
::
Bool
;
using
::
testing
::
Combine
;
using
::
testing
::
TestWithParam
;
using
::
testing
::
Values
;
using
::
testing
::
ValuesIn
;
#endif // GTEST_HAS_PARAM_TEST
#if GTEST_HAS_TYPED_TEST
using
::
testing
::
Types
;
#endif // GTEST_HAS_TYPED_TEST
// Tests linking of TEST constructs.
TEST
(
TestMacroTest
,
LinksSuccessfully
)
{
}
// Tests linking of TEST_F constructs.
class
FixtureTest
:
public
Test
{
};
TEST_F
(
FixtureTest
,
LinksSuccessfully
)
{
}
// Tests linking of value parameterized tests.
#if GTEST_HAS_PARAM_TEST
class
IntParamTest
:
public
TestWithParam
<
int
>
{};
TEST_P
(
IntParamTest
,
LinksSuccessfully
)
{}
const
int
c_array
[]
=
{
1
,
2
};
INSTANTIATE_TEST_CASE_P
(
ValuesInCArrayTest
,
IntParamTest
,
ValuesIn
(
c_array
));
INSTANTIATE_TEST_CASE_P
(
ValuesInIteratorPairTest
,
IntParamTest
,
ValuesIn
(
c_array
,
c_array
+
2
));
vector
<
int
>
stl_vector
(
c_array
,
c_array
+
2
);
INSTANTIATE_TEST_CASE_P
(
ValuesInStlVectorTest
,
IntParamTest
,
ValuesIn
(
stl_vector
));
class
BoolParamTest
:
public
TestWithParam
<
bool
>
{};
INSTANTIATE_TEST_CASE_P
(
BoolTest
,
BoolParamTest
,
Bool
());
INSTANTIATE_TEST_CASE_P
(
ValuesTest
,
IntParamTest
,
Values
(
1
,
2
));
#if GTEST_HAS_COMBINE
class
CombineTest
:
public
TestWithParam
<
tuple
<
int
,
bool
>
>
{};
INSTANTIATE_TEST_CASE_P
(
CombineTest
,
CombineTest
,
Combine
(
Values
(
1
),
Bool
()));
#endif // GTEST_HAS_COMBINE
#endif // GTEST_HAS_PARAM_TEST
// Tests linking of typed tests.
#if GTEST_HAS_TYPED_TEST
template
<
typename
T
>
class
TypedTest
:
public
Test
{};
TYPED_TEST_CASE
(
TypedTest
,
Types
<
int
>
);
TYPED_TEST
(
TypedTest
,
LinksSuccessfully
)
{}
#endif // GTEST_HAS_TYPED_TEST
// Tests linking of type-parameterized tests.
#if GTEST_HAS_TYPED_TEST_P
template
<
typename
T
>
class
TypeParameterizedTest
:
public
Test
{};
TYPED_TEST_CASE_P
(
TypeParameterizedTest
);
TYPED_TEST_P
(
TypeParameterizedTest
,
LinksSuccessfully
)
{}
REGISTER_TYPED_TEST_CASE_P
(
TypeParameterizedTest
,
LinksSuccessfully
);
INSTANTIATE_TYPED_TEST_CASE_P
(
Char
,
TypeParameterizedTest
,
Types
<
char
>
);
#endif // GTEST_HAS_TYPED_TEST_P
// Tests linking of explicit success or failure.
TEST
(
ExplicitSuccessFailureTest
,
ExplicitSuccessAndFailure
)
{
if
(
AlwaysTrue
())
SUCCEED
()
<<
"This is a success statement"
;
if
(
AlwaysFalse
())
{
ADD_FAILURE
()
<<
"This is a non-fatal failure assertion"
;
FAIL
()
<<
"This is a fatal failure assertion"
;
}
}
// Tests linking of Boolean assertions.
AssertionResult
IsEven
(
int
n
)
{
if
(
n
%
2
==
0
)
return
AssertionSuccess
()
<<
n
<<
" is even"
;
else
return
AssertionFailure
()
<<
n
<<
" is odd"
;
}
TEST
(
BooleanAssertionTest
,
LinksSuccessfully
)
{
EXPECT_TRUE
(
true
)
<<
"true is true"
;
EXPECT_FALSE
(
false
)
<<
"false is not true"
;
ASSERT_TRUE
(
true
);
ASSERT_FALSE
(
false
);
EXPECT_TRUE
(
IsEven
(
2
));
EXPECT_FALSE
(
IsEven
(
3
));
}
// Tests linking of predicate assertions.
bool
IsOdd
(
int
n
)
{
return
n
%
2
!=
0
;
}
bool
Ge
(
int
val1
,
int
val2
)
{
return
val1
>=
val2
;
}
TEST
(
PredicateAssertionTest
,
LinksSuccessfully
)
{
EXPECT_PRED1
(
IsOdd
,
1
);
EXPECT_PRED2
(
Ge
,
2
,
1
);
}
AssertionResult
AddToFive
(
const
char
*
val1_expr
,
const
char
*
val2_expr
,
int
val1
,
int
val2
)
{
if
(
val1
+
val2
==
5
)
return
AssertionSuccess
();
return
AssertionFailure
()
<<
val1_expr
<<
" and "
<<
val2_expr
<<
" ("
<<
val1
<<
" and "
<<
val2
<<
") "
<<
"do not add up to five, as their sum is "
<<
val1
+
val2
;
}
TEST
(
PredicateFormatterAssertionTest
,
LinksSuccessfully
)
{
EXPECT_PRED_FORMAT2
(
AddToFive
,
1
+
2
,
2
);
}
// Tests linking of comparison assertions.
TEST
(
ComparisonAssertionTest
,
LinksSuccessfully
)
{
EXPECT_EQ
(
1
,
1
);
EXPECT_NE
(
1
,
2
);
EXPECT_LT
(
1
,
2
);
EXPECT_LE
(
1
,
1
);
EXPECT_GT
(
2
,
1
);
EXPECT_GE
(
2
,
1
);
EXPECT_EQ
(
'\n'
,
'\n'
);
EXPECT_NE
(
'\n'
,
'\r'
);
EXPECT_LT
(
'\n'
,
'a'
);
EXPECT_LE
(
'\n'
,
'b'
);
EXPECT_GT
(
'a'
,
'\t'
);
EXPECT_GE
(
'b'
,
'\t'
);
}
TEST
(
StringComparisonAssertionTest
,
LinksSuccessfully
)
{
EXPECT_STREQ
(
"test"
,
"test"
);
EXPECT_STRNE
(
"test"
,
"prod"
);
char
test_str
[
5
]
=
"test"
;
char
prod_str
[
5
]
=
"prod"
;
EXPECT_STREQ
(
test_str
,
test_str
);
EXPECT_STRNE
(
test_str
,
prod_str
);
EXPECT_STRCASEEQ
(
"test"
,
"TEST"
);
EXPECT_STRCASENE
(
"test"
,
"prod"
);
wchar_t
test_wstr
[
5
]
=
L"test"
;
wchar_t
prod_wstr
[
5
]
=
L"prod"
;
EXPECT_STREQ
(
L"test"
,
L"test"
);
EXPECT_STRNE
(
L"test"
,
L"prod"
);
EXPECT_STREQ
(
test_wstr
,
test_wstr
);
EXPECT_STRNE
(
test_wstr
,
prod_wstr
);
#if GTEST_HAS_STD_STRING
EXPECT_EQ
(
"test"
,
::
std
::
string
(
"test"
));
EXPECT_NE
(
"test"
,
::
std
::
string
(
"prod"
));
EXPECT_EQ
(
::
std
::
string
(
"test"
),
"test"
);
EXPECT_NE
(
::
std
::
string
(
"prod"
),
"test"
);
EXPECT_EQ
(
test_str
,
::
std
::
string
(
"test"
));
EXPECT_NE
(
test_str
,
::
std
::
string
(
"prod"
));
EXPECT_EQ
(
::
std
::
string
(
"test"
),
test_str
);
EXPECT_NE
(
::
std
::
string
(
"prod"
),
test_str
);
EXPECT_EQ
(
::
std
::
string
(
"test"
),
::
std
::
string
(
"test"
));
EXPECT_NE
(
::
std
::
string
(
"test"
),
::
std
::
string
(
"prod"
));
#endif // GTEST_HAS_STD_STRING
#if GTEST_HAS_STD_WSTRING
EXPECT_EQ
(
L"test"
,
::
std
::
wstring
(
L"test"
));
EXPECT_NE
(
L"test"
,
::
std
::
wstring
(
L"prod"
));
EXPECT_EQ
(
::
std
::
wstring
(
L"test"
),
L"test"
);
EXPECT_NE
(
::
std
::
wstring
(
L"prod"
),
L"test"
);
EXPECT_EQ
(
test_wstr
,
::
std
::
wstring
(
L"test"
));
EXPECT_NE
(
test_wstr
,
::
std
::
wstring
(
L"prod"
));
EXPECT_EQ
(
::
std
::
wstring
(
L"test"
),
test_wstr
);
EXPECT_NE
(
::
std
::
wstring
(
L"prod"
),
test_wstr
);
EXPECT_EQ
(
::
std
::
wstring
(
L"test"
),
::
std
::
wstring
(
L"test"
));
EXPECT_NE
(
::
std
::
wstring
(
L"test"
),
::
std
::
wstring
(
L"prod"
));
#endif // GTEST_HAS_STD_WSTRING
}
// Tests linking of floating point assertions.
TEST
(
FloatingPointComparisonAssertionTest
,
LinksSuccessfully
)
{
EXPECT_FLOAT_EQ
(
0.0
f
,
0.0
f
);
EXPECT_DOUBLE_EQ
(
0.0
,
0.0
);
EXPECT_NEAR
(
0.0
,
0.1
,
0.2
);
EXPECT_PRED_FORMAT2
(
::
testing
::
FloatLE
,
0.0
f
,
0.01
f
);
EXPECT_PRED_FORMAT2
(
::
testing
::
DoubleLE
,
0.0
,
0.001
);
}
#if GTEST_OS_WINDOWS
// Tests linking of HRESULT assertions.
TEST
(
HresultAssertionTest
,
LinksSuccessfully
)
{
EXPECT_HRESULT_SUCCEEDED
(
S_OK
);
EXPECT_HRESULT_FAILED
(
E_FAIL
);
}
#endif // GTEST_OS_WINDOWS
#if GTEST_HAS_EXCEPTIONS
// Tests linking of exception assertions.
TEST
(
ExceptionAssertionTest
,
LinksSuccessfully
)
{
EXPECT_THROW
(
throw
1
,
int
);
EXPECT_ANY_THROW
(
throw
1
);
EXPECT_NO_THROW
(
std
::
vector
<
int
>
v
);
}
#endif // GTEST_HAS_EXCEPTIONS
// Tests linking of death test assertions.
TEST
(
DeathTestAssertionDeathTest
,
LinksSuccessfully
)
{
EXPECT_DEATH_IF_SUPPORTED
(
exit
(
1
),
""
);
#if GTEST_HAS_DEATH_TEST
EXPECT_EXIT
(
exit
(
1
),
ExitedWithCode
(
1
),
""
);
#endif // GTEST_HAS_DEATH_TEST
}
// Tests linking of SCOPED_TRACE.
void
Sub
()
{
EXPECT_EQ
(
1
,
1
);
}
TEST
(
ScopedTraceTest
,
LinksSuccessfully
)
{
SCOPED_TRACE
(
"X"
);
Sub
();
}
// Tests linking of failure absence assertions.
TEST
(
NoFailureAssertionTest
,
LinksSuccessfully
)
{
EXPECT_NO_FATAL_FAILURE
(
IsEven
(
2
));
}
// Tests linking of HasFatalFailure.
TEST
(
HasFatalFailureTest
,
LinksSuccessfully
)
{
EXPECT_FALSE
(
HasFatalFailure
());
EXPECT_FALSE
(
HasNonfatalFailure
());
EXPECT_FALSE
(
HasFailure
());
}
// Tests linking of RecordProperty.
TEST
(
RecordPropertyTest
,
LinksSuccessfully
)
{
RecordProperty
(
"DummyPropery"
,
"DummyValue"
);
}
// Tests linking of environments.
class
MyEnvironment
:
public
Environment
{};
Environment
*
const
environment
=
AddGlobalTestEnvironment
(
new
MyEnvironment
);
// Tests linking of flags.
TEST
(
FlagTest
,
LinksSuccessfully
)
{
Message
message
;
message
<<
GTEST_FLAG
(
filter
);
message
<<
GTEST_FLAG
(
also_run_disabled_tests
);
message
<<
GTEST_FLAG
(
repeat
);
message
<<
GTEST_FLAG
(
shuffle
);
message
<<
GTEST_FLAG
(
random_seed
);
message
<<
GTEST_FLAG
(
color
);
message
<<
GTEST_FLAG
(
print_time
);
message
<<
GTEST_FLAG
(
output
);
message
<<
GTEST_FLAG
(
break_on_failure
);
message
<<
GTEST_FLAG
(
throw_on_failure
);
message
<<
GTEST_FLAG
(
catch_exceptions
);
message
<<
GTEST_FLAG
(
stack_trace_depth
);
}
// Tests linking of failure catching assertions.
void
FunctionWithFailure
()
{
FAIL
();
}
TEST
(
FailureCatchingAssertionTest
,
LinksCorrectly
)
{
EXPECT_FATAL_FAILURE
(
FunctionWithFailure
(),
""
);
EXPECT_NONFATAL_FAILURE
(
ADD_FAILURE
(),
""
);
EXPECT_FATAL_FAILURE_ON_ALL_THREADS
(
FunctionWithFailure
(),
""
);
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS
(
ADD_FAILURE
(),
""
);
}
// Tests linking of the reflection API.
TEST
(
ReflectionApiTest
,
LinksCorrectly
)
{
// UnitTest API.
UnitTest
*
unit_test
=
UnitTest
::
GetInstance
();
unit_test
->
original_working_dir
();
EXPECT_TRUE
(
unit_test
->
current_test_case
()
!=
NULL
);
EXPECT_TRUE
(
unit_test
->
current_test_info
()
!=
NULL
);
EXPECT_NE
(
0
,
unit_test
->
random_seed
());
EXPECT_GE
(
unit_test
->
successful_test_case_count
(),
0
);
EXPECT_EQ
(
0
,
unit_test
->
failed_test_case_count
());
EXPECT_GE
(
unit_test
->
total_test_case_count
(),
0
);
EXPECT_GT
(
unit_test
->
test_case_to_run_count
(),
0
);
EXPECT_GE
(
unit_test
->
successful_test_count
(),
0
);
EXPECT_EQ
(
0
,
unit_test
->
failed_test_count
());
EXPECT_EQ
(
0
,
unit_test
->
disabled_test_count
());
EXPECT_GT
(
unit_test
->
total_test_count
(),
0
);
EXPECT_GT
(
unit_test
->
test_to_run_count
(),
0
);
EXPECT_GE
(
unit_test
->
elapsed_time
(),
0
);
EXPECT_TRUE
(
unit_test
->
Passed
());
EXPECT_FALSE
(
unit_test
->
Failed
());
EXPECT_TRUE
(
unit_test
->
GetTestCase
(
0
)
!=
NULL
);
// TestCase API.
const
TestCase
*
const
test_case
=
unit_test
->
current_test_case
();
EXPECT_STRNE
(
""
,
test_case
->
name
());
const
char
*
const
test_case_comment
=
test_case
->
comment
();
EXPECT_TRUE
(
test_case
->
should_run
());
EXPECT_GE
(
test_case
->
successful_test_count
(),
0
);
EXPECT_EQ
(
0
,
test_case
->
failed_test_count
());
EXPECT_EQ
(
0
,
test_case
->
disabled_test_count
());
EXPECT_GT
(
test_case
->
test_to_run_count
(),
0
);
EXPECT_GT
(
test_case
->
total_test_count
(),
0
);
EXPECT_TRUE
(
test_case
->
Passed
());
EXPECT_FALSE
(
test_case
->
Failed
());
EXPECT_GE
(
test_case
->
elapsed_time
(),
0
);
EXPECT_TRUE
(
test_case
->
GetTestInfo
(
0
)
!=
NULL
);
// TestInfo API.
const
TestInfo
*
const
test_info
=
unit_test
->
current_test_info
();
EXPECT_STRNE
(
""
,
test_info
->
test_case_name
());
EXPECT_STRNE
(
""
,
test_info
->
name
());
EXPECT_STREQ
(
test_case_comment
,
test_info
->
test_case_comment
());
const
char
*
const
comment
=
test_info
->
comment
();
EXPECT_TRUE
(
comment
==
NULL
||
strlen
(
comment
)
>=
0
);
EXPECT_TRUE
(
test_info
->
should_run
());
EXPECT_TRUE
(
test_info
->
result
()
!=
NULL
);
// TestResult API.
const
TestResult
*
const
test_result
=
test_info
->
result
();
SUCCEED
()
<<
"This generates a successful test part instance for API testing"
;
RecordProperty
(
"Test Name"
,
"Test Value"
);
EXPECT_EQ
(
1
,
test_result
->
total_part_count
());
EXPECT_EQ
(
1
,
test_result
->
test_property_count
());
EXPECT_TRUE
(
test_result
->
Passed
());
EXPECT_FALSE
(
test_result
->
Failed
());
EXPECT_FALSE
(
test_result
->
HasFatalFailure
());
EXPECT_FALSE
(
test_result
->
HasNonfatalFailure
());
EXPECT_GE
(
test_result
->
elapsed_time
(),
0
);
const
TestPartResult
&
test_part_result
=
test_result
->
GetTestPartResult
(
0
);
const
TestProperty
&
test_property
=
test_result
->
GetTestProperty
(
0
);
// TestPartResult API.
EXPECT_EQ
(
TestPartResult
::
kSuccess
,
test_part_result
.
type
());
EXPECT_STRNE
(
""
,
test_part_result
.
file_name
());
EXPECT_GT
(
test_part_result
.
line_number
(),
0
);
EXPECT_STRNE
(
""
,
test_part_result
.
summary
());
EXPECT_STRNE
(
""
,
test_part_result
.
message
());
EXPECT_TRUE
(
test_part_result
.
passed
());
EXPECT_FALSE
(
test_part_result
.
failed
());
EXPECT_FALSE
(
test_part_result
.
nonfatally_failed
());
EXPECT_FALSE
(
test_part_result
.
fatally_failed
());
// TestProperty API.
EXPECT_STREQ
(
"Test Name"
,
test_property
.
key
());
EXPECT_STREQ
(
"Test Value"
,
test_property
.
value
());
}
// Tests linking of the event listener API.
class
MyListener
:
public
TestEventListener
{
virtual
void
OnTestProgramStart
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnTestIterationStart
(
const
UnitTest
&
/*unit_test*/
,
int
/*iteration*/
)
{}
virtual
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnTestCaseStart
(
const
TestCase
&
/*test_case*/
)
{}
virtual
void
OnTestStart
(
const
TestInfo
&
/*test_info*/
)
{}
virtual
void
OnTestPartResult
(
const
TestPartResult
&
/*test_part_result*/
)
{}
virtual
void
OnTestEnd
(
const
TestInfo
&
/*test_info*/
)
{}
virtual
void
OnTestCaseEnd
(
const
TestCase
&
/*test_case*/
)
{}
virtual
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnTestIterationEnd
(
const
UnitTest
&
/*unit_test*/
,
int
/*iteration*/
)
{}
virtual
void
OnTestProgramEnd
(
const
UnitTest
&
/*unit_test*/
)
{}
};
class
MyOtherListener
:
public
EmptyTestEventListener
{};
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
void
(
*
wide_init_google_test
)(
int
*
,
wchar_t
**
)
=
&
testing
::
InitGoogleTest
;
// Ensures the linker doesn't throw away reference to wide InitGoogleTest.
GTEST_CHECK_
(
wide_init_google_test
!=
NULL
);
TestEventListeners
&
listeners
=
UnitTest
::
GetInstance
()
->
listeners
();
TestEventListener
*
listener
=
new
MyListener
;
listeners
.
Append
(
listener
);
listeners
.
Release
(
listener
);
listeners
.
Append
(
new
MyOtherListener
);
listener
=
listeners
.
default_result_printer
();
listener
=
listeners
.
default_xml_generator
();
int
ret_val
=
RUN_ALL_TESTS
();
static_cast
<
void
>
(
ret_val
);
return
0
;
}
test/gtest_unittest.cc
View file @
9f0824b0
...
@@ -76,13 +76,6 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
...
@@ -76,13 +76,6 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
namespace
testing
{
namespace
testing
{
namespace
internal
{
namespace
internal
{
bool
ShouldUseColor
(
bool
stdout_is_tty
);
::
std
::
string
FormatTimeInMillisAsSeconds
(
TimeInMillis
ms
);
bool
ParseInt32Flag
(
const
char
*
str
,
const
char
*
flag
,
Int32
*
value
);
// Used for testing the flag parsing.
extern
bool
g_help_flag
;
// Provides access to otherwise private parts of the TestEventListeners class
// Provides access to otherwise private parts of the TestEventListeners class
// that are needed to test it.
// that are needed to test it.
class
TestEventListenersAccessor
{
class
TestEventListenersAccessor
{
...
...
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