Skip to content

Commit bd693e0

Browse files
authored
Merge pull request #195 from wravery/reset-test-state
Reset the mock service state for each test
2 parents 7d56338 + 1a531c7 commit bd693e0

File tree

6 files changed

+209
-178
lines changed

6 files changed

+209
-178
lines changed

test/ClientTests.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,25 @@ class ClientCase : public ::testing::Test
3030
std::string fakeFolderId("fakeFolderId");
3131
_fakeFolderId.resize(fakeFolderId.size());
3232
std::copy(fakeFolderId.cbegin(), fakeFolderId.cend(), _fakeFolderId.begin());
33+
}
3334

35+
void SetUp() override
36+
{
3437
auto query = std::make_shared<today::Query>(
35-
[]() -> std::vector<std::shared_ptr<today::Appointment>> {
38+
[this]() -> std::vector<std::shared_ptr<today::Appointment>> {
3639
++_getAppointmentsCount;
3740
return { std::make_shared<today::Appointment>(response::IdType(_fakeAppointmentId),
3841
"tomorrow",
3942
"Lunch?",
4043
false) };
4144
},
42-
[]() -> std::vector<std::shared_ptr<today::Task>> {
45+
[this]() -> std::vector<std::shared_ptr<today::Task>> {
4346
++_getTasksCount;
4447
return { std::make_shared<today::Task>(response::IdType(_fakeTaskId),
4548
"Don't forget",
4649
true) };
4750
},
48-
[]() -> std::vector<std::shared_ptr<today::Folder>> {
51+
[this]() -> std::vector<std::shared_ptr<today::Folder>> {
4952
++_getUnreadCountsCount;
5053
return { std::make_shared<today::Folder>(response::IdType(_fakeFolderId),
5154
"\"Fake\" Inbox",
@@ -71,34 +74,33 @@ class ClientCase : public ::testing::Test
7174
_service = std::make_shared<today::Operations>(query, mutation, subscription);
7275
}
7376

77+
void TearDown() override
78+
{
79+
_service.reset();
80+
}
81+
7482
static void TearDownTestCase()
7583
{
7684
_fakeAppointmentId.clear();
7785
_fakeTaskId.clear();
7886
_fakeFolderId.clear();
79-
_service.reset();
8087
}
8188

8289
protected:
8390
static response::IdType _fakeAppointmentId;
8491
static response::IdType _fakeTaskId;
8592
static response::IdType _fakeFolderId;
8693

87-
static std::shared_ptr<today::Operations> _service;
88-
static size_t _getAppointmentsCount;
89-
static size_t _getTasksCount;
90-
static size_t _getUnreadCountsCount;
94+
std::shared_ptr<today::Operations> _service {};
95+
size_t _getAppointmentsCount {};
96+
size_t _getTasksCount {};
97+
size_t _getUnreadCountsCount {};
9198
};
9299

93100
response::IdType ClientCase::_fakeAppointmentId;
94101
response::IdType ClientCase::_fakeTaskId;
95102
response::IdType ClientCase::_fakeFolderId;
96103

97-
std::shared_ptr<today::Operations> ClientCase::_service;
98-
size_t ClientCase::_getAppointmentsCount = 0;
99-
size_t ClientCase::_getTasksCount = 0;
100-
size_t ClientCase::_getUnreadCountsCount = 0;
101-
102104
TEST_F(ClientCase, QueryEverything)
103105
{
104106
using namespace client::query::Query;
@@ -109,28 +111,28 @@ TEST_F(ClientCase, QueryEverything)
109111
auto state = std::make_shared<today::RequestState>(1);
110112
auto result =
111113
_service->resolve({ query, {}, std::move(variables), std::launch::async, state }).get();
112-
EXPECT_EQ(size_t(1), _getAppointmentsCount)
114+
EXPECT_EQ(size_t { 1 }, _getAppointmentsCount)
113115
<< "today service lazy loads the appointments and caches the result";
114-
EXPECT_EQ(size_t(1), _getTasksCount)
116+
EXPECT_EQ(size_t { 1 }, _getTasksCount)
115117
<< "today service lazy loads the tasks and caches the result";
116-
EXPECT_EQ(size_t(1), _getUnreadCountsCount)
118+
EXPECT_EQ(size_t { 1 }, _getUnreadCountsCount)
117119
<< "today service lazy loads the unreadCounts and caches the result";
118-
EXPECT_EQ(size_t(1), state->appointmentsRequestId)
120+
EXPECT_EQ(size_t { 1 }, state->appointmentsRequestId)
119121
<< "today service passed the same RequestState";
120-
EXPECT_EQ(size_t(1), state->tasksRequestId) << "today service passed the same RequestState";
121-
EXPECT_EQ(size_t(1), state->unreadCountsRequestId)
122+
EXPECT_EQ(size_t { 1 }, state->tasksRequestId) << "today service passed the same RequestState";
123+
EXPECT_EQ(size_t { 1 }, state->unreadCountsRequestId)
122124
<< "today service passed the same RequestState";
123-
EXPECT_EQ(size_t(1), state->loadAppointmentsCount) << "today service called the loader once";
124-
EXPECT_EQ(size_t(1), state->loadTasksCount) << "today service called the loader once";
125-
EXPECT_EQ(size_t(1), state->loadUnreadCountsCount) << "today service called the loader once";
125+
EXPECT_EQ(size_t { 1 }, state->loadAppointmentsCount) << "today service called the loader once";
126+
EXPECT_EQ(size_t { 1 }, state->loadTasksCount) << "today service called the loader once";
127+
EXPECT_EQ(size_t { 1 }, state->loadUnreadCountsCount) << "today service called the loader once";
126128

127129
try
128130
{
129131
ASSERT_TRUE(result.type() == response::Type::Map);
130132
auto serviceResponse = client::parseServiceResponse(std::move(result));
131133
const auto response = parseResponse(std::move(serviceResponse.data));
132134

133-
EXPECT_EQ(size_t {}, serviceResponse.errors.size()) << "no errors expected";
135+
EXPECT_EQ(size_t { 0 }, serviceResponse.errors.size()) << "no errors expected";
134136

135137
ASSERT_TRUE(response.appointments.edges.has_value()) << "appointments should be set";
136138
ASSERT_EQ(size_t { 1 }, response.appointments.edges->size())
@@ -210,7 +212,7 @@ TEST_F(ClientCase, MutateCompleteTask)
210212
auto serviceResponse = client::parseServiceResponse(std::move(result));
211213
const auto response = parseResponse(std::move(serviceResponse.data));
212214

213-
EXPECT_EQ(size_t {}, serviceResponse.errors.size()) << "no errors expected";
215+
EXPECT_EQ(size_t { 0 }, serviceResponse.errors.size()) << "no errors expected";
214216

215217
const auto& completedTask = response.completedTask;
216218
const auto& task = completedTask.completedTask;
@@ -258,7 +260,7 @@ TEST_F(ClientCase, SubscribeNextAppointmentChangeDefault)
258260
auto serviceResponse = client::parseServiceResponse(std::move(result));
259261
const auto response = parseResponse(std::move(serviceResponse.data));
260262

261-
EXPECT_EQ(size_t {}, serviceResponse.errors.size()) << "no errors expected";
263+
EXPECT_EQ(size_t { 0 }, serviceResponse.errors.size()) << "no errors expected";
262264

263265
const auto& appointmentNode = response.nextAppointment;
264266
ASSERT_TRUE(appointmentNode.has_value()) << "should get back a task";

test/NoIntrospectionTests.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,25 @@ class NoIntrospectionServiceCase : public ::testing::Test
3232
std::string fakeFolderId("fakeFolderId");
3333
_fakeFolderId.resize(fakeFolderId.size());
3434
std::copy(fakeFolderId.cbegin(), fakeFolderId.cend(), _fakeFolderId.begin());
35+
}
3536

37+
void SetUp() override
38+
{
3639
auto query = std::make_shared<today::Query>(
37-
[]() -> std::vector<std::shared_ptr<today::Appointment>> {
40+
[this]() -> std::vector<std::shared_ptr<today::Appointment>> {
3841
++_getAppointmentsCount;
3942
return { std::make_shared<today::Appointment>(response::IdType(_fakeAppointmentId),
4043
"tomorrow",
4144
"Lunch?",
4245
false) };
4346
},
44-
[]() -> std::vector<std::shared_ptr<today::Task>> {
47+
[this]() -> std::vector<std::shared_ptr<today::Task>> {
4548
++_getTasksCount;
4649
return { std::make_shared<today::Task>(response::IdType(_fakeTaskId),
4750
"Don't forget",
4851
true) };
4952
},
50-
[]() -> std::vector<std::shared_ptr<today::Folder>> {
53+
[this]() -> std::vector<std::shared_ptr<today::Folder>> {
5154
++_getUnreadCountsCount;
5255
return { std::make_shared<today::Folder>(response::IdType(_fakeFolderId),
5356
"\"Fake\" Inbox",
@@ -73,33 +76,33 @@ class NoIntrospectionServiceCase : public ::testing::Test
7376
_service = std::make_shared<today::Operations>(query, mutation, subscription);
7477
}
7578

79+
void TearDown() override
80+
{
81+
_service.reset();
82+
}
83+
7684
static void TearDownTestCase()
7785
{
7886
_fakeAppointmentId.clear();
7987
_fakeTaskId.clear();
8088
_fakeFolderId.clear();
81-
_service.reset();
8289
}
8390

8491
protected:
8592
static response::IdType _fakeAppointmentId;
8693
static response::IdType _fakeTaskId;
8794
static response::IdType _fakeFolderId;
8895

89-
static std::shared_ptr<today::Operations> _service;
90-
static size_t _getAppointmentsCount;
91-
static size_t _getTasksCount;
92-
static size_t _getUnreadCountsCount;
96+
std::shared_ptr<today::Operations> _service {};
97+
size_t _getAppointmentsCount {};
98+
size_t _getTasksCount {};
99+
size_t _getUnreadCountsCount {};
93100
};
94101

95102
response::IdType NoIntrospectionServiceCase::_fakeAppointmentId;
96103
response::IdType NoIntrospectionServiceCase::_fakeTaskId;
97104
response::IdType NoIntrospectionServiceCase::_fakeFolderId;
98105

99-
std::shared_ptr<today::Operations> NoIntrospectionServiceCase::_service;
100-
size_t NoIntrospectionServiceCase::_getAppointmentsCount = 0;
101-
size_t NoIntrospectionServiceCase::_getTasksCount = 0;
102-
size_t NoIntrospectionServiceCase::_getUnreadCountsCount = 0;
103106
size_t today::NextAppointmentChange::_notifySubscribeCount = 0;
104107
size_t today::NextAppointmentChange::_subscriptionCount = 0;
105108
size_t today::NextAppointmentChange::_notifyUnsubscribeCount = 0;
@@ -146,20 +149,20 @@ TEST_F(NoIntrospectionServiceCase, QueryEverything)
146149
_service->resolve(
147150
{ query, "Everything"sv, std::move(variables), std::launch::async, state })
148151
.get();
149-
EXPECT_EQ(size_t(1), _getAppointmentsCount)
152+
EXPECT_EQ(size_t { 1 }, _getAppointmentsCount)
150153
<< "today service lazy loads the appointments and caches the result";
151-
EXPECT_EQ(size_t(1), _getTasksCount)
154+
EXPECT_EQ(size_t { 1 }, _getTasksCount)
152155
<< "today service lazy loads the tasks and caches the result";
153-
EXPECT_EQ(size_t(1), _getUnreadCountsCount)
156+
EXPECT_EQ(size_t { 1 }, _getUnreadCountsCount)
154157
<< "today service lazy loads the unreadCounts and caches the result";
155-
EXPECT_EQ(size_t(1), state->appointmentsRequestId)
158+
EXPECT_EQ(size_t { 1 }, state->appointmentsRequestId)
156159
<< "today service passed the same RequestState";
157-
EXPECT_EQ(size_t(1), state->tasksRequestId) << "today service passed the same RequestState";
158-
EXPECT_EQ(size_t(1), state->unreadCountsRequestId)
160+
EXPECT_EQ(size_t { 1 }, state->tasksRequestId) << "today service passed the same RequestState";
161+
EXPECT_EQ(size_t { 1 }, state->unreadCountsRequestId)
159162
<< "today service passed the same RequestState";
160-
EXPECT_EQ(size_t(1), state->loadAppointmentsCount) << "today service called the loader once";
161-
EXPECT_EQ(size_t(1), state->loadTasksCount) << "today service called the loader once";
162-
EXPECT_EQ(size_t(1), state->loadUnreadCountsCount) << "today service called the loader once";
163+
EXPECT_EQ(size_t { 1 }, state->loadAppointmentsCount) << "today service called the loader once";
164+
EXPECT_EQ(size_t { 1 }, state->loadTasksCount) << "today service called the loader once";
165+
EXPECT_EQ(size_t { 1 }, state->loadUnreadCountsCount) << "today service called the loader once";
163166

164167
try
165168
{

test/PegtlCombinedTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ using namespace tao::graphqlpeg;
1414

1515
TEST(PegtlCombinedCase, AnalyzeMixedGrammar)
1616
{
17-
ASSERT_EQ(size_t {}, analyze<mixed_document>(true))
17+
ASSERT_EQ(size_t { 0 }, analyze<mixed_document>(true))
1818
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
1919
}

test/PegtlExecutableTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@ TEST(PegtlExecutableCase, ParseVariableDefaultEmptyList)
136136

137137
TEST(PegtlExecutableCase, AnalyzeExecutableGrammar)
138138
{
139-
ASSERT_EQ(size_t {}, analyze<executable_document>(true))
139+
ASSERT_EQ(size_t { 0 }, analyze<executable_document>(true))
140140
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
141141
}

test/PegtlSchemaTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,6 @@ TEST(PegtlSchemaCase, ParseTodaySchema)
219219

220220
TEST(PegtlSchemaCase, AnalyzeSchemaGrammar)
221221
{
222-
ASSERT_EQ(size_t {}, analyze<schema_document>(true))
222+
ASSERT_EQ(size_t { 0 }, analyze<schema_document>(true))
223223
<< "there shouldn't be any infinite loops in the PEG version of the grammar";
224224
}

0 commit comments

Comments
 (0)