Commit 96f7ba83 authored by Gennadiy Civil's avatar Gennadiy Civil Committed by GitHub
Browse files

Merge branch 'master' into wrong-version-reported

parents b74070cf 675686a1
...@@ -6,13 +6,13 @@ This guide will explain how to use the Google Testing Framework in your Xcode pr ...@@ -6,13 +6,13 @@ This guide will explain how to use the Google Testing Framework in your Xcode pr
Here is the quick guide for using Google Test in your Xcode project. Here is the quick guide for using Google Test in your Xcode project.
1. Download the source from the [website](http://code.google.com/p/googletest) using this command: `svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only` 1. Download the source from the [website](http://code.google.com/p/googletest) using this command: `svn checkout http://googletest.googlecode.com/svn/trunk/ googletest-read-only`.
1. Open up the `gtest.xcodeproj` in the `googletest-read-only/xcode/` directory and build the gtest.framework. 1. Open up the `gtest.xcodeproj` in the `googletest-read-only/xcode/` directory and build the gtest.framework.
1. Create a new "Shell Tool" target in your Xcode project called something like "UnitTests" 1. Create a new "Shell Tool" target in your Xcode project called something like "UnitTests".
1. Add the gtest.framework to your project and add it to the "Link Binary with Libraries" build phase of "UnitTests" 1. Add the gtest.framework to your project and add it to the "Link Binary with Libraries" build phase of "UnitTests".
1. Add your unit test source code to the "Compile Sources" build phase of "UnitTests" 1. Add your unit test source code to the "Compile Sources" build phase of "UnitTests".
1. Edit the "UnitTests" executable and add an environment variable named "DYLD\_FRAMEWORK\_PATH" with a value equal to the path to the framework containing the gtest.framework relative to the compiled executable. 1. Edit the "UnitTests" executable and add an environment variable named "DYLD\_FRAMEWORK\_PATH" with a value equal to the path to the framework containing the gtest.framework relative to the compiled executable.
1. Build and Go 1. Build and Go.
The following sections further explain each of the steps listed above in depth, describing in more detail how to complete it including some variations. The following sections further explain each of the steps listed above in depth, describing in more detail how to complete it including some variations.
...@@ -66,7 +66,7 @@ If you haven't set up the DYLD\_FRAMEWORK\_PATH, correctly, you might get a mess ...@@ -66,7 +66,7 @@ If you haven't set up the DYLD\_FRAMEWORK\_PATH, correctly, you might get a mess
Reason: image not found Reason: image not found
``` ```
To correct this problem, got to the directory containing the executable named in "Referenced from:" value in the error message above. Then, with the terminal in this location, find the relative path to the directory containing the gtest.framework. That is the value you'll need to set as the DYLD\_FRAMEWORK\_PATH. To correct this problem, go to to the directory containing the executable named in "Referenced from:" value in the error message above. Then, with the terminal in this location, find the relative path to the directory containing the gtest.framework. That is the value you'll need to set as the DYLD\_FRAMEWORK\_PATH.
# Build and Go # # Build and Go #
......
...@@ -151,10 +151,10 @@ template <typename T> ...@@ -151,10 +151,10 @@ template <typename T>
class TypeWithoutFormatter<T, kProtobuf> { class TypeWithoutFormatter<T, kProtobuf> {
public: public:
static void PrintValue(const T& value, ::std::ostream* os) { static void PrintValue(const T& value, ::std::ostream* os) {
const ::testing::internal::string short_str = value.ShortDebugString(); std::string pretty_str = value.ShortDebugString();
const ::testing::internal::string pretty_str = if (pretty_str.length() > kProtobufOneLinerMaxLength) {
short_str.length() <= kProtobufOneLinerMaxLength ? pretty_str = "\n" + value.DebugString();
short_str : ("\n" + value.DebugString()); }
*os << ("<" + pretty_str + ">"); *os << ("<" + pretty_str + ">");
} }
}; };
...@@ -364,11 +364,18 @@ class UniversalPrinter; ...@@ -364,11 +364,18 @@ class UniversalPrinter;
template <typename T> template <typename T>
void UniversalPrint(const T& value, ::std::ostream* os); void UniversalPrint(const T& value, ::std::ostream* os);
enum DefaultPrinterType {
kPrintContainer,
kPrintPointer,
kPrintFunctionPointer,
kPrintOther,
};
template <DefaultPrinterType type> struct WrapPrinterType {};
// Used to print an STL-style container when the user doesn't define // Used to print an STL-style container when the user doesn't define
// a PrintTo() for it. // a PrintTo() for it.
template <typename C> template <typename C>
void DefaultPrintTo(IsContainer /* dummy */, void DefaultPrintTo(WrapPrinterType<kPrintContainer> /* dummy */,
false_type /* is not a pointer */,
const C& container, ::std::ostream* os) { const C& container, ::std::ostream* os) {
const size_t kMaxCount = 32; // The maximum number of elements to print. const size_t kMaxCount = 32; // The maximum number of elements to print.
*os << '{'; *os << '{';
...@@ -401,40 +408,38 @@ void DefaultPrintTo(IsContainer /* dummy */, ...@@ -401,40 +408,38 @@ void DefaultPrintTo(IsContainer /* dummy */,
// implementation-defined. Therefore they will be printed as raw // implementation-defined. Therefore they will be printed as raw
// bytes.) // bytes.)
template <typename T> template <typename T>
void DefaultPrintTo(IsNotContainer /* dummy */, void DefaultPrintTo(WrapPrinterType<kPrintPointer> /* dummy */,
true_type /* is a pointer */,
T* p, ::std::ostream* os) { T* p, ::std::ostream* os) {
if (p == NULL) { if (p == NULL) {
*os << "NULL"; *os << "NULL";
} else { } else {
// C++ doesn't allow casting from a function pointer to any object // T is not a function type. We just call << to print p,
// pointer. // relying on ADL to pick up user-defined << for their pointer
// // types, if any.
// IsTrue() silences warnings: "Condition is always true", *os << p;
// "unreachable code". }
if (IsTrue(ImplicitlyConvertible<T*, const void*>::value)) { }
// T is not a function type. We just call << to print p, template <typename T>
// relying on ADL to pick up user-defined << for their pointer void DefaultPrintTo(WrapPrinterType<kPrintFunctionPointer> /* dummy */,
// types, if any. T* p, ::std::ostream* os) {
*os << p; if (p == NULL) {
} else { *os << "NULL";
// T is a function type, so '*os << p' doesn't do what we want } else {
// (it just prints p as bool). We want to print p as a const // T is a function type, so '*os << p' doesn't do what we want
// void*. However, we cannot cast it to const void* directly, // (it just prints p as bool). We want to print p as a const
// even using reinterpret_cast, as earlier versions of gcc // void*. However, we cannot cast it to const void* directly,
// (e.g. 3.4.5) cannot compile the cast when p is a function // even using reinterpret_cast, as earlier versions of gcc
// pointer. Casting to UInt64 first solves the problem. // (e.g. 3.4.5) cannot compile the cast when p is a function
*os << reinterpret_cast<const void*>( // pointer. Casting to UInt64 first solves the problem.
reinterpret_cast<internal::UInt64>(p)); *os << reinterpret_cast<const void*>(
} reinterpret_cast<internal::UInt64>(p));
} }
} }
// Used to print a non-container, non-pointer value when the user // Used to print a non-container, non-pointer value when the user
// doesn't define PrintTo() for it. // doesn't define PrintTo() for it.
template <typename T> template <typename T>
void DefaultPrintTo(IsNotContainer /* dummy */, void DefaultPrintTo(WrapPrinterType<kPrintOther> /* dummy */,
false_type /* is not a pointer */,
const T& value, ::std::ostream* os) { const T& value, ::std::ostream* os) {
::testing_internal::DefaultPrintNonContainerTo(value, os); ::testing_internal::DefaultPrintNonContainerTo(value, os);
} }
...@@ -452,11 +457,8 @@ void DefaultPrintTo(IsNotContainer /* dummy */, ...@@ -452,11 +457,8 @@ void DefaultPrintTo(IsNotContainer /* dummy */,
// wants). // wants).
template <typename T> template <typename T>
void PrintTo(const T& value, ::std::ostream* os) { void PrintTo(const T& value, ::std::ostream* os) {
// DefaultPrintTo() is overloaded. The type of its first two // DefaultPrintTo() is overloaded. The type of its first argument
// arguments determine which version will be picked. If T is an // determines which version will be picked.
// STL-style container, the version for container will be called; if
// T is a pointer, the pointer version will be called; otherwise the
// generic version will be called.
// //
// Note that we check for container types here, prior to we check // Note that we check for container types here, prior to we check
// for protocol message types in our operator<<. The rationale is: // for protocol message types in our operator<<. The rationale is:
...@@ -468,13 +470,24 @@ void PrintTo(const T& value, ::std::ostream* os) { ...@@ -468,13 +470,24 @@ void PrintTo(const T& value, ::std::ostream* os) {
// elements; therefore we check for container types here to ensure // elements; therefore we check for container types here to ensure
// that our format is used. // that our format is used.
// //
// The second argument of DefaultPrintTo() is needed to bypass a bug // Note that MSVC and clang-cl do allow an implicit conversion from
// in Symbian's C++ compiler that prevents it from picking the right // pointer-to-function to pointer-to-object, but clang-cl warns on it.
// overload between: // So don't use ImplicitlyConvertible if it can be helped since it will
// // cause this warning, and use a separate overload of DefaultPrintTo for
// PrintTo(const T& x, ...); // function pointers so that the `*os << p` in the object pointer overload
// PrintTo(T* x, ...); // doesn't cause that warning either.
DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os); DefaultPrintTo(
WrapPrinterType<sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)
? kPrintContainer : !is_pointer<T>::value
? kPrintOther
#if GTEST_LANG_CXX11
: std::is_function<typename std::remove_pointer<T>::type>::value
#else
: !internal::ImplicitlyConvertible<T, const void*>::value
#endif
? kPrintFunctionPointer
: kPrintPointer>(),
value, os);
} }
// The following list of PrintTo() overloads tells // The following list of PrintTo() overloads tells
...@@ -805,7 +818,7 @@ class UniversalTersePrinter<const char*> { ...@@ -805,7 +818,7 @@ class UniversalTersePrinter<const char*> {
if (str == NULL) { if (str == NULL) {
*os << "NULL"; *os << "NULL";
} else { } else {
UniversalPrint(string(str), os); UniversalPrint(std::string(str), os);
} }
} }
}; };
......
...@@ -97,13 +97,12 @@ class GTEST_API_ SingleFailureChecker { ...@@ -97,13 +97,12 @@ class GTEST_API_ SingleFailureChecker {
public: public:
// The constructor remembers the arguments. // The constructor remembers the arguments.
SingleFailureChecker(const TestPartResultArray* results, SingleFailureChecker(const TestPartResultArray* results,
TestPartResult::Type type, TestPartResult::Type type, const std::string& substr);
const string& substr);
~SingleFailureChecker(); ~SingleFailureChecker();
private: private:
const TestPartResultArray* const results_; const TestPartResultArray* const results_;
const TestPartResult::Type type_; const TestPartResult::Type type_;
const string substr_; const std::string substr_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
}; };
......
...@@ -242,7 +242,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); ...@@ -242,7 +242,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \ typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
} \ } \
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) \ static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) \
GTEST_ATTRIBUTE_UNUSED = \ GTEST_ATTRIBUTE_UNUSED_ = \
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\
__FILE__, __LINE__, #__VA_ARGS__) __FILE__, __LINE__, #__VA_ARGS__)
......
...@@ -1287,7 +1287,7 @@ class GTEST_API_ UnitTest { ...@@ -1287,7 +1287,7 @@ class GTEST_API_ UnitTest {
internal::UnitTestImpl* impl() { return impl_; } internal::UnitTestImpl* impl() { return impl_; }
const internal::UnitTestImpl* impl() const { return impl_; } const internal::UnitTestImpl* impl() const { return impl_; }
// These classes and funcions are friends as they need to access private // These classes and functions are friends as they need to access private
// members of UnitTest. // members of UnitTest.
friend class Test; friend class Test;
friend class internal::AssertHelper; friend class internal::AssertHelper;
...@@ -2194,7 +2194,7 @@ bool StaticAssertTypeEq() { ...@@ -2194,7 +2194,7 @@ bool StaticAssertTypeEq() {
// name of the test within the test case. // name of the test within the test case.
// //
// A test fixture class must be declared earlier. The user should put // A test fixture class must be declared earlier. The user should put
// his test code between braces after using this macro. Example: // the test code between braces after using this macro. Example:
// //
// class FooTest : public testing::Test { // class FooTest : public testing::Test {
// protected: // protected:
...@@ -2217,6 +2217,10 @@ bool StaticAssertTypeEq() { ...@@ -2217,6 +2217,10 @@ bool StaticAssertTypeEq() {
GTEST_TEST_(test_fixture, test_name, test_fixture, \ GTEST_TEST_(test_fixture, test_name, test_fixture, \
::testing::internal::GetTypeId<test_fixture>()) ::testing::internal::GetTypeId<test_fixture>())
// Returns a path to temporary directory.
// Tries to determine an appropriate directory for the platform.
GTEST_API_ std::string TempDir();
} // namespace testing } // namespace testing
// Use this function in main() to run all tests. It returns 0 if all // Use this function in main() to run all tests. It returns 0 if all
......
...@@ -61,6 +61,9 @@ ...@@ -61,6 +61,9 @@
// GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) // GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
// GTEST_LOCK_EXCLUDED_(locks) // GTEST_LOCK_EXCLUDED_(locks)
// //
// Exporting API symbols:
// GTEST_API_ - Specifier for exported symbols.
//
// ** Custom implementation starts here ** // ** Custom implementation starts here **
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
......
...@@ -33,6 +33,10 @@ ...@@ -33,6 +33,10 @@
// GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of // GTEST_OS_STACK_TRACE_GETTER_ - The name of an implementation of
// OsStackTraceGetterInterface. // OsStackTraceGetterInterface.
// //
// GTEST_CUSTOM_TEMPDIR_FUNCTION_ - An override for testing::TempDir().
// See testing::TempDir for semantics and
// signature.
//
// ** Custom implementation starts here ** // ** Custom implementation starts here **
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
......
...@@ -175,7 +175,7 @@ namespace edit_distance { ...@@ -175,7 +175,7 @@ namespace edit_distance {
// Returns the optimal edits to go from 'left' to 'right'. // Returns the optimal edits to go from 'left' to 'right'.
// All edits cost the same, with replace having lower priority than // All edits cost the same, with replace having lower priority than
// add/remove. // add/remove.
// Simple implementation of the WagnerFischer algorithm. // Simple implementation of the Wagner-Fischer algorithm.
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm // See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
enum EditType { kMatch, kAdd, kRemove, kReplace }; enum EditType { kMatch, kAdd, kRemove, kReplace };
GTEST_API_ std::vector<EditType> CalculateOptimalEdits( GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
...@@ -502,9 +502,10 @@ typedef void (*SetUpTestCaseFunc)(); ...@@ -502,9 +502,10 @@ typedef void (*SetUpTestCaseFunc)();
typedef void (*TearDownTestCaseFunc)(); typedef void (*TearDownTestCaseFunc)();
struct CodeLocation { struct CodeLocation {
CodeLocation(const string& a_file, int a_line) : file(a_file), line(a_line) {} CodeLocation(const std::string& a_file, int a_line)
: file(a_file), line(a_line) {}
string file; std::string file;
int line; int line;
}; };
......
...@@ -472,7 +472,7 @@ class ParameterizedTestCaseInfoBase { ...@@ -472,7 +472,7 @@ class ParameterizedTestCaseInfoBase {
virtual ~ParameterizedTestCaseInfoBase() {} virtual ~ParameterizedTestCaseInfoBase() {}
// Base part of test case name for display purposes. // Base part of test case name for display purposes.
virtual const string& GetTestCaseName() const = 0; virtual const std::string& GetTestCaseName() const = 0;
// Test case id to verify identity. // Test case id to verify identity.
virtual TypeId GetTestCaseTypeId() const = 0; virtual TypeId GetTestCaseTypeId() const = 0;
// UnitTest class invokes this method to register tests in this // UnitTest class invokes this method to register tests in this
...@@ -511,7 +511,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { ...@@ -511,7 +511,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
: test_case_name_(name), code_location_(code_location) {} : test_case_name_(name), code_location_(code_location) {}
// Test case base name for display purposes. // Test case base name for display purposes.
virtual const string& GetTestCaseName() const { return test_case_name_; } virtual const std::string& GetTestCaseName() const { return test_case_name_; }
// Test case id to verify identity. // Test case id to verify identity.
virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); } virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
// TEST_P macro uses AddTestPattern() to record information // TEST_P macro uses AddTestPattern() to record information
...@@ -529,11 +529,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { ...@@ -529,11 +529,10 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
} }
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information // INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
// about a generator. // about a generator.
int AddTestCaseInstantiation(const string& instantiation_name, int AddTestCaseInstantiation(const std::string& instantiation_name,
GeneratorCreationFunc* func, GeneratorCreationFunc* func,
ParamNameGeneratorFunc* name_func, ParamNameGeneratorFunc* name_func,
const char* file, const char* file, int line) {
int line) {
instantiations_.push_back( instantiations_.push_back(
InstantiationInfo(instantiation_name, func, name_func, file, line)); InstantiationInfo(instantiation_name, func, name_func, file, line));
return 0; // Return value used only to run this method in namespace scope. return 0; // Return value used only to run this method in namespace scope.
...@@ -550,13 +549,13 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { ...@@ -550,13 +549,13 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
for (typename InstantiationContainer::iterator gen_it = for (typename InstantiationContainer::iterator gen_it =
instantiations_.begin(); gen_it != instantiations_.end(); instantiations_.begin(); gen_it != instantiations_.end();
++gen_it) { ++gen_it) {
const string& instantiation_name = gen_it->name; const std::string& instantiation_name = gen_it->name;
ParamGenerator<ParamType> generator((*gen_it->generator)()); ParamGenerator<ParamType> generator((*gen_it->generator)());
ParamNameGeneratorFunc* name_func = gen_it->name_func; ParamNameGeneratorFunc* name_func = gen_it->name_func;
const char* file = gen_it->file; const char* file = gen_it->file;
int line = gen_it->line; int line = gen_it->line;
string test_case_name; std::string test_case_name;
if ( !instantiation_name.empty() ) if ( !instantiation_name.empty() )
test_case_name = instantiation_name + "/"; test_case_name = instantiation_name + "/";
test_case_name += test_info->test_case_base_name; test_case_name += test_info->test_case_base_name;
...@@ -609,8 +608,8 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { ...@@ -609,8 +608,8 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
test_base_name(a_test_base_name), test_base_name(a_test_base_name),
test_meta_factory(a_test_meta_factory) {} test_meta_factory(a_test_meta_factory) {}
const string test_case_base_name; const std::string test_case_base_name;
const string test_base_name; const std::string test_base_name;
const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory; const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
}; };
typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer; typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
...@@ -651,7 +650,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { ...@@ -651,7 +650,7 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
return true; return true;
} }
const string test_case_name_; const std::string test_case_name_;
CodeLocation code_location_; CodeLocation code_location_;
TestInfoContainer tests_; TestInfoContainer tests_;
InstantiationContainer instantiations_; InstantiationContainer instantiations_;
......
...@@ -84,6 +84,8 @@ ...@@ -84,6 +84,8 @@
# define GTEST_OS_HPUX 1 # define GTEST_OS_HPUX 1
#elif defined __native_client__ #elif defined __native_client__
# define GTEST_OS_NACL 1 # define GTEST_OS_NACL 1
#elif defined __NetBSD__
# define GTEST_OS_NETBSD 1
#elif defined __OpenBSD__ #elif defined __OpenBSD__
# define GTEST_OS_OPENBSD 1 # define GTEST_OS_OPENBSD 1
#elif defined __QNX__ #elif defined __QNX__
......
...@@ -128,6 +128,7 @@ ...@@ -128,6 +128,7 @@
// GTEST_OS_MAC - Mac OS X // GTEST_OS_MAC - Mac OS X
// GTEST_OS_IOS - iOS // GTEST_OS_IOS - iOS
// GTEST_OS_NACL - Google Native Client (NaCl) // GTEST_OS_NACL - Google Native Client (NaCl)
// GTEST_OS_NETBSD - NetBSD
// GTEST_OS_OPENBSD - OpenBSD // GTEST_OS_OPENBSD - OpenBSD
// GTEST_OS_QNX - QNX // GTEST_OS_QNX - QNX
// GTEST_OS_SOLARIS - Sun Solaris // GTEST_OS_SOLARIS - Sun Solaris
...@@ -607,7 +608,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -607,7 +608,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
// to your compiler flags. // to your compiler flags.
# define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \ # define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \
|| GTEST_OS_QNX || GTEST_OS_FREEBSD || GTEST_OS_NACL) || GTEST_OS_QNX || GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD)
#endif // GTEST_HAS_PTHREAD #endif // GTEST_HAS_PTHREAD
#if GTEST_HAS_PTHREAD #if GTEST_HAS_PTHREAD
...@@ -622,7 +623,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -622,7 +623,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Determines if hash_map/hash_set are available. // Determines if hash_map/hash_set are available.
// Only used for testing against those containers. // Only used for testing against those containers.
#if !defined(GTEST_HAS_HASH_MAP_) #if !defined(GTEST_HAS_HASH_MAP_)
# if _MSC_VER # if defined(_MSC_VER) && (_MSC_VER < 1900)
# define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available. # define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available.
# define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available. # define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available.
# endif // _MSC_VER # endif // _MSC_VER
...@@ -800,7 +801,7 @@ using ::std::tuple_size; ...@@ -800,7 +801,7 @@ using ::std::tuple_size;
(GTEST_OS_MAC && !GTEST_OS_IOS) || \ (GTEST_OS_MAC && !GTEST_OS_IOS) || \
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \ GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD) GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD || GTEST_OS_NETBSD)
# define GTEST_HAS_DEATH_TEST 1 # define GTEST_HAS_DEATH_TEST 1
#endif #endif
...@@ -874,6 +875,23 @@ using ::std::tuple_size; ...@@ -874,6 +875,23 @@ using ::std::tuple_size;
# define GTEST_ATTRIBUTE_UNUSED_ # define GTEST_ATTRIBUTE_UNUSED_
#endif #endif
// Use this annotation before a function that takes a printf format string.
#if defined(__GNUC__) && !defined(COMPILER_ICC)
# if defined(__MINGW_PRINTF_FORMAT)
// MinGW has two different printf implementations. Ensure the format macro
// matches the selected implementation. See
// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/.
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
__attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \
first_to_check)))
# else
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
__attribute__((__format__(__printf__, string_index, first_to_check)))
# endif
#else
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
#endif
// A macro to disallow operator= // A macro to disallow operator=
// This should be used in the private: declarations for a class. // This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_ASSIGN_(type)\ #define GTEST_DISALLOW_ASSIGN_(type)\
...@@ -930,6 +948,11 @@ using ::std::tuple_size; ...@@ -930,6 +948,11 @@ using ::std::tuple_size;
#endif // GTEST_HAS_SEH #endif // GTEST_HAS_SEH
// GTEST_API_ qualifies all symbols that must be exported. The definitions below
// are guarded by #ifndef to give embedders a chance to define GTEST_API_ in
// gtest/internal/custom/gtest-port.h
#ifndef GTEST_API_
#ifdef _MSC_VER #ifdef _MSC_VER
# if GTEST_LINKED_AS_SHARED_LIBRARY # if GTEST_LINKED_AS_SHARED_LIBRARY
# define GTEST_API_ __declspec(dllimport) # define GTEST_API_ __declspec(dllimport)
...@@ -940,9 +963,11 @@ using ::std::tuple_size; ...@@ -940,9 +963,11 @@ using ::std::tuple_size;
# define GTEST_API_ __attribute__((visibility ("default"))) # define GTEST_API_ __attribute__((visibility ("default")))
#endif // _MSC_VER #endif // _MSC_VER
#endif // GTEST_API_
#ifndef GTEST_API_ #ifndef GTEST_API_
# define GTEST_API_ # define GTEST_API_
#endif #endif // GTEST_API_
#ifdef __GNUC__ #ifdef __GNUC__
// Ask the compiler to never inline a given function. // Ask the compiler to never inline a given function.
...@@ -1428,9 +1453,6 @@ GTEST_API_ std::string GetCapturedStderr(); ...@@ -1428,9 +1453,6 @@ GTEST_API_ std::string GetCapturedStderr();
#endif // GTEST_HAS_STREAM_REDIRECTION #endif // GTEST_HAS_STREAM_REDIRECTION
// Returns a path to temporary directory.
GTEST_API_ std::string TempDir();
// Returns the size (in bytes) of a file. // Returns the size (in bytes) of a file.
GTEST_API_ size_t GetFileSize(FILE* file); GTEST_API_ size_t GetFileSize(FILE* file);
...@@ -2188,12 +2210,13 @@ class ThreadLocal { ...@@ -2188,12 +2210,13 @@ class ThreadLocal {
GTEST_API_ 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 before 12u4. The Nokia Symbian
// and the IBM XL C/C++ compiler try to instantiate a copy constructor // and the IBM XL C/C++ compiler try to instantiate a copy constructor
// for objects passed through ellipsis (...), failing for uncopyable // for objects passed through ellipsis (...), failing for uncopyable
// objects. We define this to ensure that only POD is passed through // objects. We define this to ensure that only POD is passed through
// ellipsis on these systems. // ellipsis on these systems.
#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC) #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || \
(defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5130)
// We lose support for NULL detection where the compiler doesn't like // We lose support for NULL detection where the compiler doesn't like
// passing non-POD classes through ellipsis (...). // passing non-POD classes through ellipsis (...).
# define GTEST_ELLIPSIS_NEEDS_POD_ 1 # define GTEST_ELLIPSIS_NEEDS_POD_ 1
...@@ -2395,7 +2418,7 @@ inline int Close(int fd) { return close(fd); } ...@@ -2395,7 +2418,7 @@ inline int Close(int fd) { return close(fd); }
inline const char* StrError(int errnum) { return strerror(errnum); } inline const char* StrError(int errnum) { return strerror(errnum); }
#endif #endif
inline const char* GetEnv(const char* name) { inline const char* GetEnv(const char* name) {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE | GTEST_OS_WINDOWS_RT #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
// We are on Windows CE, which has no environment variables. // We are on Windows CE, which has no environment variables.
static_cast<void>(name); // To prevent 'unused argument' warning. static_cast<void>(name); // To prevent 'unused argument' warning.
return NULL; return NULL;
...@@ -2559,6 +2582,11 @@ GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); ...@@ -2559,6 +2582,11 @@ GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
std::string StringFromGTestEnv(const char* flag, const char* default_val); std::string StringFromGTestEnv(const char* flag, const char* default_val);
} // namespace internal } // namespace internal
// Returns a path to temporary directory.
// Tries to determine an appropriate directory for the platform.
GTEST_API_ std::string TempDir();
} // namespace testing } // namespace testing
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
...@@ -55,7 +55,7 @@ bool IsPrime(int n) { ...@@ -55,7 +55,7 @@ bool IsPrime(int n) {
// Try to divide n by every odd number i, starting from 3 // Try to divide n by every odd number i, starting from 3
for (int i = 3; ; i += 2) { for (int i = 3; ; i += 2) {
// We only have to try i up to the squre root of n // We only have to try i up to the square root of n
if (i > n/i) break; if (i > n/i) break;
// Now, we have i <= n/i < n. // Now, we have i <= n/i < n.
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "gtest/gtest.h" #include "gtest/gtest.h"
using ::testing::EmptyTestEventListener; using ::testing::EmptyTestEventListener;
using ::testing::InitGoogleTest; using ::testing::InitGoogleTest;
using ::testing::Test; using ::testing::Test;
...@@ -46,7 +45,6 @@ using ::testing::TestPartResult; ...@@ -46,7 +45,6 @@ using ::testing::TestPartResult;
using ::testing::UnitTest; using ::testing::UnitTest;
namespace { namespace {
// We will track memory used by this class. // We will track memory used by this class.
class Water { class Water {
public: public:
...@@ -106,7 +104,6 @@ TEST(ListenersTest, LeaksWater) { ...@@ -106,7 +104,6 @@ TEST(ListenersTest, LeaksWater) {
Water* water = new Water; Water* water = new Water;
EXPECT_TRUE(water != NULL); EXPECT_TRUE(water != NULL);
} }
} // namespace } // namespace
int main(int argc, char **argv) { int main(int argc, char **argv) {
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include <limits.h> #include <limits.h>
#include "sample1.h" #include "sample1.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace {
// Step 2. Use the TEST macro to define your tests. // Step 2. Use the TEST macro to define your tests.
// //
...@@ -139,6 +139,7 @@ TEST(IsPrimeTest, Positive) { ...@@ -139,6 +139,7 @@ TEST(IsPrimeTest, Positive) {
EXPECT_FALSE(IsPrime(6)); EXPECT_FALSE(IsPrime(6));
EXPECT_TRUE(IsPrime(23)); EXPECT_TRUE(IsPrime(23));
} }
} // namespace
// Step 3. Call RUN_ALL_TESTS() in main(). // Step 3. Call RUN_ALL_TESTS() in main().
// //
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
#include "sample2.h" #include "sample2.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace {
// In this example, we test the MyString class (a simple string). // In this example, we test the MyString class (a simple string).
// Tests the default c'tor. // Tests the default c'tor.
...@@ -107,3 +107,4 @@ TEST(MyString, Set) { ...@@ -107,3 +107,4 @@ TEST(MyString, Set) {
s.Set(NULL); s.Set(NULL);
EXPECT_STREQ(NULL, s.c_string()); EXPECT_STREQ(NULL, s.c_string());
} }
} // namespace
...@@ -65,14 +65,14 @@ ...@@ -65,14 +65,14 @@
#include "sample3-inl.h" #include "sample3-inl.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace {
// To use a test fixture, derive a class from testing::Test. // To use a test fixture, derive a class from testing::Test.
class QueueTest : public testing::Test { class QueueTestSmpl3 : public testing::Test {
protected: // You should make the members protected s.t. they can be protected: // You should make the members protected s.t. they can be
// accessed from sub-classes. // accessed from sub-classes.
// virtual void SetUp() will be called before each test is run. You // virtual void SetUp() will be called before each test is run. You
// should define it if you need to initialize the varaibles. // should define it if you need to initialize the variables.
// Otherwise, this can be skipped. // Otherwise, this can be skipped.
virtual void SetUp() { virtual void SetUp() {
q1_.Enqueue(1); q1_.Enqueue(1);
...@@ -120,13 +120,13 @@ class QueueTest : public testing::Test { ...@@ -120,13 +120,13 @@ class QueueTest : public testing::Test {
// instead of TEST. // instead of TEST.
// Tests the default c'tor. // Tests the default c'tor.
TEST_F(QueueTest, DefaultConstructor) { TEST_F(QueueTestSmpl3, DefaultConstructor) {
// You can access data in the test fixture here. // You can access data in the test fixture here.
EXPECT_EQ(0u, q0_.Size()); EXPECT_EQ(0u, q0_.Size());
} }
// Tests Dequeue(). // Tests Dequeue().
TEST_F(QueueTest, Dequeue) { TEST_F(QueueTestSmpl3, Dequeue) {
int * n = q0_.Dequeue(); int * n = q0_.Dequeue();
EXPECT_TRUE(n == NULL); EXPECT_TRUE(n == NULL);
...@@ -144,8 +144,9 @@ TEST_F(QueueTest, Dequeue) { ...@@ -144,8 +144,9 @@ TEST_F(QueueTest, Dequeue) {
} }
// Tests the Queue::Map() function. // Tests the Queue::Map() function.
TEST_F(QueueTest, Map) { TEST_F(QueueTestSmpl3, Map) {
MapTester(&q0_); MapTester(&q0_);
MapTester(&q1_); MapTester(&q1_);
MapTester(&q2_); MapTester(&q2_);
} }
} // namespace
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "sample4.h" #include "sample4.h"
namespace {
// Tests the Increment() method. // Tests the Increment() method.
TEST(Counter, Increment) { TEST(Counter, Increment) {
Counter c; Counter c;
...@@ -43,3 +43,4 @@ TEST(Counter, Increment) { ...@@ -43,3 +43,4 @@ TEST(Counter, Increment) {
EXPECT_EQ(1, c.Increment()); EXPECT_EQ(1, c.Increment());
EXPECT_EQ(2, c.Increment()); EXPECT_EQ(2, c.Increment());
} }
} // namespace
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#include "sample3-inl.h" #include "sample3-inl.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "sample1.h" #include "sample1.h"
namespace {
// In this sample, we want to ensure that every test finishes within // In this sample, we want to ensure that every test finishes within
// ~5 seconds. If a test takes longer to run, we consider it a // ~5 seconds. If a test takes longer to run, we consider it a
// failure. // failure.
...@@ -191,7 +191,7 @@ TEST_F(QueueTest, Dequeue) { ...@@ -191,7 +191,7 @@ TEST_F(QueueTest, Dequeue) {
EXPECT_EQ(1u, q2_.Size()); EXPECT_EQ(1u, q2_.Size());
delete n; delete n;
} }
} // namespace
// If necessary, you can derive further test fixtures from a derived // If necessary, you can derive further test fixtures from a derived
// fixture itself. For example, you can derive another fixture from // fixture itself. For example, you can derive another fixture from
// QueueTest. Google Test imposes no limit on how deep the hierarchy // QueueTest. Google Test imposes no limit on how deep the hierarchy
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "prime_tables.h" #include "prime_tables.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace {
// First, we define some factory functions for creating instances of // First, we define some factory functions for creating instances of
// the implementations. You may be able to skip this step if all your // the implementations. You may be able to skip this step if all your
// implementations can be constructed the same way. // implementations can be constructed the same way.
...@@ -222,3 +222,4 @@ INSTANTIATE_TYPED_TEST_CASE_P(OnTheFlyAndPreCalculated, // Instance name ...@@ -222,3 +222,4 @@ INSTANTIATE_TYPED_TEST_CASE_P(OnTheFlyAndPreCalculated, // Instance name
PrimeTableImplementations); // Type list PrimeTableImplementations); // Type list
#endif // GTEST_HAS_TYPED_TEST_P #endif // GTEST_HAS_TYPED_TEST_P
} // namespace
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include "prime_tables.h" #include "prime_tables.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace {
#if GTEST_HAS_PARAM_TEST #if GTEST_HAS_PARAM_TEST
using ::testing::TestWithParam; using ::testing::TestWithParam;
...@@ -65,9 +65,9 @@ PrimeTable* CreatePreCalculatedPrimeTable() { ...@@ -65,9 +65,9 @@ PrimeTable* CreatePreCalculatedPrimeTable() {
// can refer to the test parameter by GetParam(). In this case, the test // can refer to the test parameter by GetParam(). In this case, the test
// parameter is a factory function which we call in fixture's SetUp() to // parameter is a factory function which we call in fixture's SetUp() to
// create and store an instance of PrimeTable. // create and store an instance of PrimeTable.
class PrimeTableTest : public TestWithParam<CreatePrimeTableFunc*> { class PrimeTableTestSmpl7 : public TestWithParam<CreatePrimeTableFunc*> {
public: public:
virtual ~PrimeTableTest() { delete table_; } virtual ~PrimeTableTestSmpl7() { delete table_; }
virtual void SetUp() { table_ = (*GetParam())(); } virtual void SetUp() { table_ = (*GetParam())(); }
virtual void TearDown() { virtual void TearDown() {
delete table_; delete table_;
...@@ -78,7 +78,7 @@ class PrimeTableTest : public TestWithParam<CreatePrimeTableFunc*> { ...@@ -78,7 +78,7 @@ class PrimeTableTest : public TestWithParam<CreatePrimeTableFunc*> {
PrimeTable* table_; PrimeTable* table_;
}; };
TEST_P(PrimeTableTest, ReturnsFalseForNonPrimes) { TEST_P(PrimeTableTestSmpl7, ReturnsFalseForNonPrimes) {
EXPECT_FALSE(table_->IsPrime(-5)); EXPECT_FALSE(table_->IsPrime(-5));
EXPECT_FALSE(table_->IsPrime(0)); EXPECT_FALSE(table_->IsPrime(0));
EXPECT_FALSE(table_->IsPrime(1)); EXPECT_FALSE(table_->IsPrime(1));
...@@ -87,7 +87,7 @@ TEST_P(PrimeTableTest, ReturnsFalseForNonPrimes) { ...@@ -87,7 +87,7 @@ TEST_P(PrimeTableTest, ReturnsFalseForNonPrimes) {
EXPECT_FALSE(table_->IsPrime(100)); EXPECT_FALSE(table_->IsPrime(100));
} }
TEST_P(PrimeTableTest, ReturnsTrueForPrimes) { TEST_P(PrimeTableTestSmpl7, ReturnsTrueForPrimes) {
EXPECT_TRUE(table_->IsPrime(2)); EXPECT_TRUE(table_->IsPrime(2));
EXPECT_TRUE(table_->IsPrime(3)); EXPECT_TRUE(table_->IsPrime(3));
EXPECT_TRUE(table_->IsPrime(5)); EXPECT_TRUE(table_->IsPrime(5));
...@@ -96,7 +96,7 @@ TEST_P(PrimeTableTest, ReturnsTrueForPrimes) { ...@@ -96,7 +96,7 @@ TEST_P(PrimeTableTest, ReturnsTrueForPrimes) {
EXPECT_TRUE(table_->IsPrime(131)); EXPECT_TRUE(table_->IsPrime(131));
} }
TEST_P(PrimeTableTest, CanGetNextPrime) { TEST_P(PrimeTableTestSmpl7, CanGetNextPrime) {
EXPECT_EQ(2, table_->GetNextPrime(0)); EXPECT_EQ(2, table_->GetNextPrime(0));
EXPECT_EQ(3, table_->GetNextPrime(2)); EXPECT_EQ(3, table_->GetNextPrime(2));
EXPECT_EQ(5, table_->GetNextPrime(3)); EXPECT_EQ(5, table_->GetNextPrime(3));
...@@ -112,10 +112,9 @@ TEST_P(PrimeTableTest, CanGetNextPrime) { ...@@ -112,10 +112,9 @@ TEST_P(PrimeTableTest, CanGetNextPrime) {
// //
// Here, we instantiate our tests with a list of two PrimeTable object // Here, we instantiate our tests with a list of two PrimeTable object
// factory functions: // factory functions:
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(OnTheFlyAndPreCalculated, PrimeTableTestSmpl7,
OnTheFlyAndPreCalculated, Values(&CreateOnTheFlyPrimeTable,
PrimeTableTest, &CreatePreCalculatedPrimeTable<1000>));
Values(&CreateOnTheFlyPrimeTable, &CreatePreCalculatedPrimeTable<1000>));
#else #else
...@@ -128,3 +127,4 @@ INSTANTIATE_TEST_CASE_P( ...@@ -128,3 +127,4 @@ INSTANTIATE_TEST_CASE_P(
TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {} TEST(DummyTest, ValueParameterizedTestsAreNotSupportedOnThisPlatform) {}
#endif // GTEST_HAS_PARAM_TEST #endif // GTEST_HAS_PARAM_TEST
} // namespace
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment