File tree Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -26,13 +26,22 @@ class DynamicJsonArray : public JsonArray {
26
26
JsonArray::operator =(other);
27
27
}
28
28
29
- using JsonArray::operator =;
30
-
31
29
DynamicJsonArray& operator =(const DynamicJsonArray& other) {
30
+ _buffer.clear ();
32
31
JsonArray::operator =(other);
33
32
return *this ;
34
33
}
35
34
35
+ DynamicJsonArray& operator =(const JsonArray& other) {
36
+ _buffer.clear ();
37
+ JsonArray::operator =(other);
38
+ return *this ;
39
+ }
40
+
41
+ size_t memoryUsage () const {
42
+ return _buffer.size () + sizeof (JsonArray);
43
+ }
44
+
36
45
Internals::DynamicJsonBuffer& buffer () {
37
46
return _buffer;
38
47
}
Original file line number Diff line number Diff line change @@ -24,6 +24,18 @@ class StaticJsonArray : public JsonArray {
24
24
JsonArray::operator =(other);
25
25
}
26
26
27
+ StaticJsonArray<CAPACITY>& operator =(const StaticJsonArray<CAPACITY>& other) {
8000
28
+ _buffer.clear ();
29
+ JsonArray::operator =(other);
30
+ return *this ;
31
+ }
32
+
33
+ StaticJsonArray<CAPACITY>& operator =(const JsonArray& other) {
34
+ _buffer.clear ();
35
+ JsonArray::operator =(other);
36
+ return *this ;
37
+ }
38
+
27
39
size_t memoryUsage () const {
28
40
return _buffer.size () + sizeof (JsonArray);
29
41
}
Original file line number Diff line number Diff line change @@ -16,11 +16,15 @@ TArray buildArray() {
16
16
return array;
17
17
}
18
18
19
- void validateArray (JsonArray& array) {
19
+ template <typename TArray>
20
+ void validateArray (TArray& array) {
20
21
CHECK (array.size () == 2 );
21
22
REQUIRE (array[0 ] == 42 );
22
- REQUIRE (array[1 ].is <JsonObject>());
23
+ REQUIRE (array[1 ].template is <JsonObject>());
23
24
REQUIRE (array[1 ][" hello" ] == std::string (" world" ));
25
+
26
+ const int expectedSize = JSON_ARRAY_SIZE (2 ) + JSON_OBJECT_SIZE (1 );
27
+ REQUIRE (expectedSize == array.memoryUsage ());
24
28
}
25
29
26
30
TEST_CASE (" DynamicJsonArray::operator=()" ) {
@@ -39,3 +43,20 @@ TEST_CASE("DynamicJsonArray::operator=()") {
39
43
validateArray (array);
40
44
}
41
45
}
46
+
47
+ TEST_CASE (" StaticJsonArray::operator=()" ) {
48
+ const size_t SIZE = JSON_ARRAY_SIZE (2 ) + JSON_OBJECT_SIZE (1 );
49
+ StaticJsonArray<SIZE> array;
50
+ array.add (666 );
51
+ array.add (666 );
52
+
53
+ SECTION (" operator=(const DynamicJsonArray&)" ) {
54
+ array = buildArray<DynamicJsonArray>();
55
+ validateArray (array);
56
+ }
57
+
58
+ SECTION (" operator=(const StaticJsonArray<N>&)" ) {
59
+ array = buildArray<StaticJsonArray<SIZE> >();
60
+ validateArray (array);
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments