Repository navigation
Expand file tree
/
Copy pathIssue10.cpp
More file actions
68 lines (53 loc) · 1.43 KB
/
Copy pathIssue10.cpp
File metadata and controls
68 lines (53 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright Benoit Blanchon 2014-2016
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
// If you like this project, please add a star!
#include <gtest/gtest.h>
#include <ArduinoJson.h>
struct Person {
int id;
char name[32];
};
class Issue10 : public testing::Test {
protected:
virtual void SetUp() {
Person boss;
boss.id = 1;
strcpy(boss.name, "Jeff");
Person employee;
employee.id = 2;
strcpy(employee.name, "John");
persons[0] = boss;
persons[1] = employee;
}
template <typename T>
void checkJsonString(const T &p) {
char buffer[256];
p.printTo(buffer, sizeof(buffer));
EXPECT_STREQ("[{\"id\":1,\"name\":\"Jeff\"},{\"id\":2,\"name\":\"John\"}]",
buffer);
}
StaticJsonBuffer<JSON_ARRAY_SIZE(2) + 2 * JSON_OBJECT_SIZE(2)> json;
Person persons[2];
};
TEST_F(Issue10, PopulateArrayByAddingAnObject) {
JsonArray &array = json.createArray();
for (int i = 0; i < 2; i++) {
JsonObject &object = json.createObject();
object["id"] = persons[i].id;
object["name"] = persons[i].name;
array.add(object);
}
checkJsonString(array);
}
TEST_F(Issue10, PopulateArrayByCreatingNestedObjects) {
JsonArray &array = json.createArray();
for (int i = 0; i < 2; i++) {
JsonObject &object = array.createNestedObject();
object["id"] = persons[i].id;
object["name"] = persons[i].name;
}
checkJsonString(array);
}