Skip to content

Commit beca0cb

Browse files
committed
fix unit tests now that exceptions are enabled.
1 parent ceb99d0 commit beca0cb

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

app/tests/thread_test.cc

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
#include "gmock/gmock.h"
2121
#include "gtest/gtest.h"
2222

23+
#define EXPECT_SYSTEM_ERROR(statement, error_code) \
24+
EXPECT_THROW({\
25+
try { \
26+
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
27+
} \
28+
catch(const std::system_error &exception) {\
29+
EXPECT_EQ(error_code, exception.code());\
30+
throw;\
31+
}\
32+
}, std::system_error)
33+
2334
namespace {
2435

2536
using ::testing::Eq;
@@ -107,66 +118,66 @@ TEST(ThreadDeathTest, MovingIntoRunningThreadShouldAbort) {
107118
}
108119

109120
TEST(ThreadDeathTest, JoinEmptyThreadShouldAbort) {
110-
ASSERT_DEATH(
121+
EXPECT_SYSTEM_ERROR(
111122
{
112123
firebase::Thread thread;
113124
thread.Join();
114125
},
115-
"");
126+
std::errc::invalid_argument);
116127
}
117128

118129
TEST(ThreadDeathTest, JoinThreadMultipleTimesShouldAbort) {
119-
ASSERT_DEATH(
130+
EXPECT_SYSTEM_ERROR(
120131
{
121132
firebase::Thread thread([] {});
122133

123134
thread.Join();
124135
thread.Join();
125136
},
126-
"");
137+
std::errc::invalid_argument);
127138
}
128139

129140
TEST(ThreadDeathTest, JoinDetachedThreadShouldAbort) {
130-
ASSERT_DEATH(
141+
EXPECT_SYSTEM_ERROR(
131142
{
132143
firebase::Thread thread([] {});
133144

134145
thread.Detach();
135146
thread.Join();
136147
},
137-
"");
148+
std::errc::invalid_argument);
138149
}
139150

140151
TEST(ThreadDeathTest, DetachJoinedThreadShouldAbort) {
141-
ASSERT_DEATH(
152+
EXPECT_SYSTEM_ERROR(
142153
{
143154
firebase::Thread thread([] {});
144155

145156
thread.Join();
146157
thread.Detach();
147158
},
148-
"");
159+
std::errc::invalid_argument);
149160
}
150161

151162
TEST(ThreadDeathTest, DetachEmptyThreadShouldAbort) {
152-
ASSERT_DEATH(
163+
EXPECT_SYSTEM_ERROR(
153164
{
154165
firebase::Thread thread;
155166

156167
thread.Detach();
157168
},
158-
"");
169+
std::errc::invalid_argument);
159170
}
160171

161172
TEST(ThreadDeathTest, DetachThreadMultipleTimesShouldAbort) {
162-
ASSERT_DEATH(
173+
EXPECT_SYSTEM_ERROR(
163174
{
164175
firebase::Thread thread([] {});
165176

166177
thread.Detach();
167178
thread.Detach();
168179
},
169-
"");
180+
std::errc::invalid_argument);
170181
}
171182

172183
TEST(ThreadDeathTest, WhenJoinableThreadIsDestructedShouldAbort) {

0 commit comments

Comments
 (0)