Makes gtest work with Sun Studio. Patch submitted by Hady Zalek.
This commit is contained in:
parent
75e2713e45
commit
e9f093ae15
|
@ -47,10 +47,6 @@
|
||||||
|
|
||||||
#if GTEST_HAS_PARAM_TEST
|
#if GTEST_HAS_PARAM_TEST
|
||||||
|
|
||||||
#if GTEST_HAS_RTTI
|
|
||||||
#include <typeinfo> // NOLINT
|
|
||||||
#endif // GTEST_HAS_RTTI
|
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
@ -63,24 +59,6 @@ namespace internal {
|
||||||
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
|
GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
|
||||||
const char* file, int line);
|
const char* file, int line);
|
||||||
|
|
||||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
|
||||||
//
|
|
||||||
// Downcasts the pointer of type Base to Derived.
|
|
||||||
// Derived must be a subclass of Base. The parameter MUST
|
|
||||||
// point to a class of type Derived, not any subclass of it.
|
|
||||||
// When RTTI is available, the function performs a runtime
|
|
||||||
// check to enforce this.
|
|
||||||
template <class Derived, class Base>
|
|
||||||
Derived* CheckedDowncastToActualType(Base* base) {
|
|
||||||
#if GTEST_HAS_RTTI
|
|
||||||
GTEST_CHECK_(typeid(*base) == typeid(Derived));
|
|
||||||
Derived* derived = dynamic_cast<Derived*>(base); // NOLINT
|
|
||||||
#else
|
|
||||||
Derived* derived = static_cast<Derived*>(base); // Poor man's downcast.
|
|
||||||
#endif // GTEST_HAS_RTTI
|
|
||||||
return derived;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename> class ParamGeneratorInterface;
|
template <typename> class ParamGeneratorInterface;
|
||||||
template <typename> class ParamGenerator;
|
template <typename> class ParamGenerator;
|
||||||
|
|
||||||
|
|
|
@ -358,6 +358,12 @@
|
||||||
|
|
||||||
#endif // GTEST_HAS_RTTI
|
#endif // GTEST_HAS_RTTI
|
||||||
|
|
||||||
|
// It's this header's responsibility to #include <typeinfo> when RTTI
|
||||||
|
// is enabled.
|
||||||
|
#if GTEST_HAS_RTTI
|
||||||
|
#include <typeinfo>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Determines whether Google Test can use the pthreads library.
|
// Determines whether Google Test can use the pthreads library.
|
||||||
#ifndef GTEST_HAS_PTHREAD
|
#ifndef GTEST_HAS_PTHREAD
|
||||||
// The user didn't tell us explicitly, so we assume pthreads support is
|
// The user didn't tell us explicitly, so we assume pthreads support is
|
||||||
|
@ -493,10 +499,12 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Determines whether to support Combine(). This only makes sense when
|
// Determines whether to support Combine(). This only makes sense when
|
||||||
// value-parameterized tests are enabled.
|
// value-parameterized tests are enabled. The implementation doesn't
|
||||||
#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE
|
// work on Sun Studio since it doesn't understand templated conversion
|
||||||
|
// operators.
|
||||||
|
#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
|
||||||
#define GTEST_HAS_COMBINE 1
|
#define GTEST_HAS_COMBINE 1
|
||||||
#endif // GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE
|
#endif
|
||||||
|
|
||||||
// Determines whether the system compiler uses UTF-16 for encoding wide strings.
|
// Determines whether the system compiler uses UTF-16 for encoding wide strings.
|
||||||
#define GTEST_WIDE_STRING_USES_UTF16_ \
|
#define GTEST_WIDE_STRING_USES_UTF16_ \
|
||||||
|
@ -774,6 +782,23 @@ inline void FlushInfoLog() { fflush(NULL); }
|
||||||
GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
|
GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
|
||||||
<< gtest_error
|
<< gtest_error
|
||||||
|
|
||||||
|
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
|
||||||
|
//
|
||||||
|
// Downcasts the pointer of type Base to Derived.
|
||||||
|
// Derived must be a subclass of Base. The parameter MUST
|
||||||
|
// point to a class of type Derived, not any subclass of it.
|
||||||
|
// When RTTI is available, the function performs a runtime
|
||||||
|
// check to enforce this.
|
||||||
|
template <class Derived, class Base>
|
||||||
|
Derived* CheckedDowncastToActualType(Base* base) {
|
||||||
|
#if GTEST_HAS_RTTI
|
||||||
|
GTEST_CHECK_(typeid(*base) == typeid(Derived));
|
||||||
|
return dynamic_cast<Derived*>(base); // NOLINT
|
||||||
|
#else
|
||||||
|
return static_cast<Derived*>(base); // Poor man's downcast.
|
||||||
|
#endif // GTEST_HAS_RTTI
|
||||||
|
}
|
||||||
|
|
||||||
#if GTEST_HAS_STREAM_REDIRECTION_
|
#if GTEST_HAS_STREAM_REDIRECTION_
|
||||||
|
|
||||||
// Defines the stderr capturer:
|
// Defines the stderr capturer:
|
||||||
|
@ -888,15 +913,11 @@ class ThreadWithParam : public ThreadWithParamBase {
|
||||||
param_(param),
|
param_(param),
|
||||||
thread_can_start_(thread_can_start),
|
thread_can_start_(thread_can_start),
|
||||||
finished_(false) {
|
finished_(false) {
|
||||||
|
ThreadWithParamBase* const base = this;
|
||||||
// The thread can be created only after all fields except thread_
|
// The thread can be created only after all fields except thread_
|
||||||
// have been initialized.
|
// have been initialized.
|
||||||
GTEST_CHECK_POSIX_SUCCESS_(
|
GTEST_CHECK_POSIX_SUCCESS_(
|
||||||
// TODO(vladl@google.com): Use implicit_cast instead of static_cast
|
pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
|
||||||
// when it is moved over from Google Mock.
|
|
||||||
pthread_create(&thread_,
|
|
||||||
0,
|
|
||||||
&ThreadFuncWithCLinkage,
|
|
||||||
static_cast<ThreadWithParamBase*>(this)));
|
|
||||||
}
|
}
|
||||||
~ThreadWithParam() { Join(); }
|
~ThreadWithParam() { Join(); }
|
||||||
|
|
||||||
|
@ -1024,6 +1045,23 @@ class GTestMutexLock {
|
||||||
|
|
||||||
typedef GTestMutexLock MutexLock;
|
typedef GTestMutexLock MutexLock;
|
||||||
|
|
||||||
|
// Helpers for ThreadLocal.
|
||||||
|
|
||||||
|
// pthread_key_create() requires DeleteThreadLocalValue() to have
|
||||||
|
// C-linkage. Therefore it cannot be templatized to access
|
||||||
|
// ThreadLocal<T>. Hence the need for class
|
||||||
|
// ThreadLocalValueHolderBase.
|
||||||
|
class ThreadLocalValueHolderBase {
|
||||||
|
public:
|
||||||
|
virtual ~ThreadLocalValueHolderBase() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Called by pthread to delete thread-local data stored by
|
||||||
|
// pthread_setspecific().
|
||||||
|
extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
|
||||||
|
delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
|
||||||
|
}
|
||||||
|
|
||||||
// Implements thread-local storage on pthreads-based systems.
|
// Implements thread-local storage on pthreads-based systems.
|
||||||
//
|
//
|
||||||
// // Thread 1
|
// // Thread 1
|
||||||
|
@ -1062,23 +1100,37 @@ class ThreadLocal {
|
||||||
void set(const T& value) { *pointer() = value; }
|
void set(const T& value) { *pointer() = value; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Holds a value of type T.
|
||||||
|
class ValueHolder : public ThreadLocalValueHolderBase {
|
||||||
|
public:
|
||||||
|
explicit ValueHolder(const T& value) : value_(value) {}
|
||||||
|
|
||||||
|
T* pointer() { return &value_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
T value_;
|
||||||
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
|
||||||
|
};
|
||||||
|
|
||||||
static pthread_key_t CreateKey() {
|
static pthread_key_t CreateKey() {
|
||||||
pthread_key_t key;
|
pthread_key_t key;
|
||||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_key_create(&key, &DeleteData));
|
GTEST_CHECK_POSIX_SUCCESS_(
|
||||||
|
pthread_key_create(&key, &DeleteThreadLocalValue));
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
T* GetOrCreateValue() const {
|
T* GetOrCreateValue() const {
|
||||||
T* const value = static_cast<T*>(pthread_getspecific(key_));
|
ThreadLocalValueHolderBase* const holder =
|
||||||
if (value != NULL)
|
static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
|
||||||
return value;
|
if (holder != NULL) {
|
||||||
|
return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
|
||||||
T* const new_value = new T(default_);
|
|
||||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, new_value));
|
|
||||||
return new_value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DeleteData(void* data) { delete static_cast<T*>(data); }
|
ValueHolder* const new_holder = new ValueHolder(default_);
|
||||||
|
ThreadLocalValueHolderBase* const holder_base = new_holder;
|
||||||
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
|
||||||
|
return new_holder->pointer();
|
||||||
|
}
|
||||||
|
|
||||||
// A key pthreads uses for looking up per-thread values.
|
// A key pthreads uses for looking up per-thread values.
|
||||||
const pthread_key_t key_;
|
const pthread_key_t key_;
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!!
|
// This file was GENERATED by command:
|
||||||
|
// pump.py gtest-type-util.h.pump
|
||||||
|
// DO NOT EDIT BY HAND!!!
|
||||||
|
|
||||||
// Copyright 2008 Google Inc.
|
// Copyright 2008 Google Inc.
|
||||||
// All Rights Reserved.
|
// All Rights Reserved.
|
||||||
|
@ -53,8 +55,6 @@
|
||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
#endif // __GLIBCXX__
|
#endif // __GLIBCXX__
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,6 @@ $var n = 50 $$ Maximum length of type lists we want to support.
|
||||||
#include <cxxabi.h>
|
#include <cxxabi.h>
|
||||||
#endif // __GLIBCXX__
|
#endif // __GLIBCXX__
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user