Skip to content

Commit 91a5359

Browse files
committed
Add tests for shared_ptr<Value> field results
1 parent e181977 commit 91a5359

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

samples/today/TodayMock.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ namespace graphql::today {
2121
Appointment::Appointment(
2222
response::IdType&& id, std::string&& when, std::string&& subject, bool isNow)
2323
: _id(std::move(id))
24-
, _when(std::move(when))
25-
, _subject(std::move(subject))
24+
, _when(std::make_shared<response::Value>(std::move(when)))
25+
, _subject(std::make_shared<response::Value>(std::move(subject)))
2626
, _isNow(isNow)
2727
{
2828
}
2929

3030
Task::Task(response::IdType&& id, std::string&& title, bool isComplete)
3131
: _id(std::move(id))
32-
, _title(std::move(title))
32+
, _title(std::make_shared<response::Value>(std::move(title)))
3333
, _isComplete(isComplete)
3434
{
3535
}
3636

3737
Folder::Folder(response::IdType&& id, std::string&& name, int unreadCount)
3838
: _id(std::move(id))
39-
, _name(std::move(name))
39+
, _name(std::make_shared<response::Value>(std::move(name)))
4040
, _unreadCount(unreadCount)
4141
{
4242
}

samples/today/TodayMock.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,20 @@
88

99
#include "TodaySchema.h"
1010

11-
#include "QueryObject.h"
11+
#include "AppointmentEdgeObject.h"
12+
#include "AppointmentObject.h"
13+
#include "FolderEdgeObject.h"
14+
#include "FolderObject.h"
1215
#include "MutationObject.h"
13-
#include "SubscriptionObject.h"
1416
#include "NodeObject.h"
1517
#include "PageInfoObject.h"
16-
#include "AppointmentEdgeObject.h"
18+
#include "QueryObject.h"
19+
#include "SubscriptionObject.h"
1720
#include "TaskEdgeObject.h"
18-
#include "FolderEdgeObject.h"
19-
#include "AppointmentObject.h"
2021
#include "TaskObject.h"
21-
#include "FolderObject.h"
2222

2323
#include <atomic>
24+
#include <memory>
2425
#include <stack>
2526

2627
namespace graphql::today {
@@ -146,14 +147,14 @@ class Appointment
146147
return _id;
147148
}
148149

149-
std::optional<response::Value> getWhen() const noexcept
150+
std::shared_ptr<const response::Value> getWhen() const noexcept
150151
{
151-
return std::make_optional<response::Value>(std::string(_when));
152+
return _when;
152153
}
153154

154-
std::optional<std::string> getSubject() const noexcept
155+
std::shared_ptr<const response::Value> getSubject() const noexcept
155156
{
156-
return std::make_optional<std::string>(_subject);
157+
return _subject;
157158
}
158159

159160
bool getIsNow() const noexcept
@@ -168,8 +169,8 @@ class Appointment
168169

169170
private:
170171
response::IdType _id;
171-
std::string _when;
172-
std::string _subject;
172+
std::shared_ptr<const response::Value> _when;
173+
std::shared_ptr<const response::Value> _subject;
173174
bool _isNow;
174175
};
175176

@@ -247,9 +248,9 @@ class Task
247248
return _id;
248249
}
249250

250-
std::optional<std::string> getTitle() const noexcept
251+
std::shared_ptr<const response::Value> getTitle() const noexcept
251252
{
252-
return std::make_optional<std::string>(_title);
253+
return _title;
253254
}
254255

255256
bool getIsComplete() const noexcept
@@ -259,7 +260,7 @@ class Task
259260

260261
private:
261262
response::IdType _id;
262-
std::string _title;
263+
std::shared_ptr<const response::Value> _title;
263264
bool _isComplete;
264265
TaskState _state = TaskState::New;
265266
};
@@ -337,9 +338,9 @@ class Folder
337338
return _id;
338339
}
339340

340-
std::optional<std::string> getName() const noexcept
341+
std::shared_ptr<const response::Value> getName() const noexcept
341342
{
342-
return std::make_optional<std::string>(_name);
343+
return _name;
343344
}
344345

345346
int getUnreadCount() const noexcept
@@ -349,7 +350,7 @@ class Folder
349350

350351
private:
351352
response::IdType _id;
352-
std::string _name;
353+
std::shared_ptr<const response::Value> _name;
353354
int _unreadCount;
354355
};
355356

0 commit comments

Comments
 (0)