Fixes threading annotations and compatibility with C++11, which doesn't

allow exepctions to be thrown in a destructor.
This commit is contained in:
zhanyong.wan 2012-05-31 20:37:13 +00:00
parent cdb24f86d5
commit a3b859162d
3 changed files with 16 additions and 10 deletions

View File

@ -3530,7 +3530,7 @@ void StreamingListener::MakeConnection() {
// Pushes the given source file location and message onto a per-thread // Pushes the given source file location and message onto a per-thread
// trace stack maintained by Google Test. // trace stack maintained by Google Test.
ScopedTrace::ScopedTrace(const char* file, int line, const Message& message) ScopedTrace::ScopedTrace(const char* file, int line, const Message& message)
GTEST_LOCK_EXCLUDED_(UnitTest::mutex_) { GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) {
TraceInfo trace; TraceInfo trace;
trace.file = file; trace.file = file;
trace.line = line; trace.line = line;
@ -3541,7 +3541,7 @@ ScopedTrace::ScopedTrace(const char* file, int line, const Message& message)
// Pops the info pushed by the c'tor. // Pops the info pushed by the c'tor.
ScopedTrace::~ScopedTrace() ScopedTrace::~ScopedTrace()
GTEST_LOCK_EXCLUDED_(UnitTest::mutex_) { GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) {
UnitTest::GetInstance()->PopGTestTrace(); UnitTest::GetInstance()->PopGTestTrace();
} }

View File

@ -117,14 +117,17 @@ class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
'"CxxExceptionInConstructorTest" (no quotes) ' '"CxxExceptionInConstructorTest" (no quotes) '
'appears on the same line as words "called unexpectedly"') 'appears on the same line as words "called unexpectedly"')
def testCatchesCxxExceptionsInFixtureDestructor(self): if ('CxxExceptionInDestructorTest.ThrowsExceptionInDestructor' in
self.assert_('C++ exception with description ' EX_BINARY_OUTPUT):
'"Standard C++ exception" thrown '
'in the test fixture\'s destructor' def testCatchesCxxExceptionsInFixtureDestructor(self):
in EX_BINARY_OUTPUT) self.assert_('C++ exception with description '
self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() ' '"Standard C++ exception" thrown '
'called as expected.' 'in the test fixture\'s destructor'
in EX_BINARY_OUTPUT) in EX_BINARY_OUTPUT)
self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() '
'called as expected.'
in EX_BINARY_OUTPUT)
def testCatchesCxxExceptionsInSetUpTestCase(self): def testCatchesCxxExceptionsInSetUpTestCase(self):
self.assert_('C++ exception with description "Standard C++ exception"' self.assert_('C++ exception with description "Standard C++ exception"'

View File

@ -137,6 +137,8 @@ TEST_F(CxxExceptionInConstructorTest, ThrowsExceptionInConstructor) {
<< "called unexpectedly."; << "called unexpectedly.";
} }
// Exceptions in destructors are not supported in C++11.
#if !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
class CxxExceptionInDestructorTest : public Test { class CxxExceptionInDestructorTest : public Test {
public: public:
static void TearDownTestCase() { static void TearDownTestCase() {
@ -153,6 +155,7 @@ class CxxExceptionInDestructorTest : public Test {
}; };
TEST_F(CxxExceptionInDestructorTest, ThrowsExceptionInDestructor) {} TEST_F(CxxExceptionInDestructorTest, ThrowsExceptionInDestructor) {}
#endif // C++11 mode
class CxxExceptionInSetUpTestCaseTest : public Test { class CxxExceptionInSetUpTestCaseTest : public Test {
public: public: