Supports building gtest as a DLL (by Vlad Losev).

This commit is contained in:
zhanyong.wan
2010-03-05 21:21:06 +00:00
parent 542b41e5d0
commit 83589cca34
14 changed files with 180 additions and 110 deletions

View File

@@ -64,7 +64,7 @@ const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
// by wait(2)
// exit code: The integer code passed to exit(3), _exit(2), or
// returned from main()
class DeathTest {
class GTEST_API_ DeathTest {
public:
// Create returns false if there was an error determining the
// appropriate action to take for the current death test; for example,
@@ -147,7 +147,7 @@ class DefaultDeathTestFactory : public DeathTestFactory {
// Returns true if exit_status describes a process that was terminated
// by a signal, or exited normally with a nonzero exit code.
bool ExitedUnsuccessfully(int exit_status);
GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
// ASSERT_EXIT*, and EXPECT_EXIT*.

View File

@@ -161,7 +161,7 @@ String AppendUserMessage(const String& gtest_msg,
const Message& user_msg);
// A helper class for creating scoped traces in user programs.
class ScopedTrace {
class GTEST_API_ ScopedTrace {
public:
// The c'tor pushes the given source file location and message onto
// a trace stack maintained by Google Test.
@@ -240,8 +240,8 @@ inline String FormatForFailureMessage(T* pointer) {
#endif // GTEST_NEEDS_IS_POINTER_
// These overloaded versions handle narrow and wide characters.
String FormatForFailureMessage(char ch);
String FormatForFailureMessage(wchar_t wchar);
GTEST_API_ String FormatForFailureMessage(char ch);
GTEST_API_ String FormatForFailureMessage(wchar_t wchar);
// When this operand is a const char* or char*, and the other operand
// is a ::std::string or ::string, we print this operand as a C string
@@ -287,17 +287,18 @@ GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted)
// The ignoring_case parameter is true iff the assertion is a
// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
// be inserted into the message.
AssertionResult EqFailure(const char* expected_expression,
const char* actual_expression,
const String& expected_value,
const String& actual_value,
bool ignoring_case);
GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
const char* actual_expression,
const String& expected_value,
const String& actual_value,
bool ignoring_case);
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
String GetBoolAssertionFailureMessage(const AssertionResult& assertion_result,
const char* expression_text,
const char* actual_predicate_value,
const char* expected_predicate_value);
GTEST_API_ String GetBoolAssertionFailureMessage(
const AssertionResult& assertion_result,
const char* expression_text,
const char* actual_predicate_value,
const char* expected_predicate_value);
// This template class represents an IEEE floating-point number
// (either single-precision or double-precision, depending on the
@@ -517,7 +518,7 @@ TypeId GetTypeId() {
// ::testing::Test, as the latter may give the wrong result due to a
// suspected linker bug when compiling Google Test as a Mac OS X
// framework.
TypeId GetTestTypeId();
GTEST_API_ TypeId GetTestTypeId();
// Defines the abstract factory interface that creates instances
// of a Test object.
@@ -550,8 +551,10 @@ class TestFactoryImpl : public TestFactoryBase {
// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
// We pass a long instead of HRESULT to avoid causing an
// include dependency for the HRESULT type.
AssertionResult IsHRESULTSuccess(const char* expr, long hr); // NOLINT
AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT
GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
long hr); // NOLINT
GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
long hr); // NOLINT
#endif // GTEST_OS_WINDOWS
@@ -590,7 +593,7 @@ typedef void (*TearDownTestCaseFunc)();
// factory: pointer to the factory that creates a test object.
// The newly created TestInfo instance will assume
// ownership of the factory object.
TestInfo* MakeAndRegisterTestInfo(
GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
const char* test_case_name, const char* name,
const char* test_case_comment, const char* comment,
TypeId fixture_class_id,
@@ -606,7 +609,7 @@ bool SkipPrefix(const char* prefix, const char** pstr);
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
// State of the definition of a type-parameterized test case.
class TypedTestCasePState {
class GTEST_API_ TypedTestCasePState {
public:
TypedTestCasePState() : registered_(false) {}
@@ -753,7 +756,7 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count);
// condition.
// Always returns true.
bool AlwaysTrue();
GTEST_API_ bool AlwaysTrue();
// Always returns false.
inline bool AlwaysFalse() { return !AlwaysTrue(); }

View File

@@ -77,7 +77,7 @@ namespace testing {
namespace internal {
// Protects copying of all linked_ptr objects.
GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex);
GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex);
// This is used internally by all instances of linked_ptr<>. It needs to be
// a non-template class because different types of linked_ptr<> can refer to

View File

@@ -60,8 +60,8 @@ namespace internal {
// fixture class for the same test case. This may happen when
// TEST_P macro is used to define two tests with the same name
// but in different namespaces.
void ReportInvalidTestCaseType(const char* test_case_name,
const char* file, int line);
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
const char* file, int line);
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//

View File

@@ -66,6 +66,13 @@
// Test's own tr1 tuple implementation should be
// used. Unused when the user sets
// GTEST_HAS_TR1_TUPLE to 0.
// GTEST_LINKED_AS_SHARED_LIBRARY
// - Define to 1 when compiling tests that use
// Google Test as a shared library (known as
// DLL on Windows).
// GTEST_CREATE_SHARED_LIBRARY
// - Define to 1 when compiling Google Test itself
// as a shared library.
// This header defines the following utilities:
//
@@ -558,6 +565,20 @@
#endif // GTEST_HAS_SEH
#ifdef _MSC_VER
#if GTEST_LINKED_AS_SHARED_LIBRARY
#define GTEST_API_ __declspec(dllimport)
#elif GTEST_CREATE_SHARED_LIBRARY
#define GTEST_API_ __declspec(dllexport)
#endif
#endif // _MSC_VER
#ifndef GTEST_API_
#define GTEST_API_
#endif
namespace testing {
class Message;
@@ -570,7 +591,7 @@ typedef ::std::stringstream StrStream;
// A helper for suppressing warnings on constant condition. It just
// returns 'condition'.
bool IsTrue(bool condition);
GTEST_API_ bool IsTrue(bool condition);
// Defines scoped_ptr.
@@ -612,7 +633,7 @@ class scoped_ptr {
// A simple C++ wrapper for <regex.h>. It uses the POSIX Enxtended
// Regular Expression syntax.
class RE {
class GTEST_API_ RE {
public:
// Constructs an RE from a string.
RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT
@@ -688,7 +709,7 @@ enum GTestLogSeverity {
// Formats log entry severity, provides a stream object for streaming the
// log message, and terminates the message with a newline when going out of
// scope.
class GTestLog {
class GTEST_API_ GTestLog {
public:
GTestLog(GTestLogSeverity severity, const char* file, int line);
@@ -1330,19 +1351,19 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
#define GTEST_FLAG(name) FLAGS_gtest_##name
// Macros for declaring flags.
#define GTEST_DECLARE_bool_(name) extern bool GTEST_FLAG(name)
#define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
#define GTEST_DECLARE_int32_(name) \
extern ::testing::internal::Int32 GTEST_FLAG(name)
GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
#define GTEST_DECLARE_string_(name) \
extern ::testing::internal::String GTEST_FLAG(name)
GTEST_API_ extern ::testing::internal::String GTEST_FLAG(name)
// Macros for defining flags.
#define GTEST_DEFINE_bool_(name, default_val, doc) \
bool GTEST_FLAG(name) = (default_val)
GTEST_API_ bool GTEST_FLAG(name) = (default_val)
#define GTEST_DEFINE_int32_(name, default_val, doc) \
::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
#define GTEST_DEFINE_string_(name, default_val, doc) \
::testing::internal::String GTEST_FLAG(name) = (default_val)
GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
// to *value and returns true; otherwise leaves *value unchanged and returns

View File

@@ -73,7 +73,7 @@ namespace internal {
//
// In order to make the representation efficient, the d'tor of String
// is not virtual. Therefore DO NOT INHERIT FROM String.
class String {
class GTEST_API_ String {
public:
// Static utility methods
@@ -326,7 +326,7 @@ inline ::std::ostream& operator<<(::std::ostream& os, const String& str) {
// Gets the content of the StrStream's buffer as a String. Each '\0'
// character in the buffer is replaced with "\\0".
String StrStreamToString(StrStream* stream);
GTEST_API_ String StrStreamToString(StrStream* stream);
// Converts a streamable value to a String. A NULL pointer is
// converted to "(null)". When the input value is a ::string,