• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bblanchon / ArduinoJson / 5313785987

pending completion
5313785987

push

github

bblanchon
Extract `arrayEquals()` and `objectEquals()`

28 of 28 new or added lines in 4 files covered. (100.0%)

3362 of 3383 relevant lines covered (99.38%)

6246.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.18
/src/ArduinoJson/Collection/CollectionFunctions.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Collection/CollectionData.hpp>
8

9
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
10

11
inline VariantData* collectionAddElement(CollectionData* array,
68,515✔
12
                                         ResourceManager* resources) {
13
  if (!array)
68,515✔
14
    return nullptr;
5✔
15
  auto slot = resources->allocVariant();
68,510✔
16
  if (!slot)
68,510✔
17
    return nullptr;
19✔
18
  array->add(slot);
68,491✔
19
  return slot->data();
68,491✔
20
}
21

22
template <typename TAdaptedString>
23
inline VariantData* collectionAddMember(CollectionData* obj, TAdaptedString key,
783✔
24
                                        ResourceManager* resources) {
25
  ARDUINOJSON_ASSERT(!key.isNull());
26
  ARDUINOJSON_ASSERT(obj != nullptr);
27
  auto slot = resources->allocVariant();
783✔
28
  if (!slot)
783✔
29
    return nullptr;
3✔
30
  if (key.isLinked())
780✔
31
    slot->setKey(key.data());
720✔
32
  else {
33
    auto storedKey = resources->saveString(key);
60✔
34
    if (!storedKey)
60✔
35
      return nullptr;
1✔
36
    slot->setKey(storedKey);
59✔
37
  }
38
  obj->add(slot);
779✔
39
  return slot->data();
779✔
40
}
41

42
inline void collectionClear(CollectionData* c, ResourceManager* resources) {
41✔
43
  if (!c)
41✔
44
    return;
2✔
45
  for (auto slot = c->head(); slot; slot = slot->next())
43✔
46
    slotRelease(slot, resources);
4✔
47
  c->clear();
39✔
48
}
49

50
inline bool collectionCopy(CollectionData* dst, const CollectionData* src,
39✔
51
                           ResourceManager* resources) {
52
  if (!dst || !src)
39✔
53
    return false;
2✔
54

55
  collectionClear(dst, resources);
37✔
56

57
  for (VariantSlot* s = src->head(); s; s = s->next()) {
58✔
58
    VariantData* var;
59
    if (s->key() != 0) {
25✔
60
      JsonString key(s->key(),
61
                     s->ownsKey() ? JsonString::Copied : JsonString::Linked);
19✔
62
      var = collectionAddMember(dst, adaptString(key), resources);
19✔
63
    } else {
64
      var = collectionAddElement(dst, resources);
6✔
65
    }
66
    if (!variantCopyFrom(var, s->data(), resources))
25✔
67
      return false;
4✔
68
  }
69
  return true;
33✔
70
}
71

72
template <typename TAdaptedString>
73
inline VariantData* collectionGetMember(const CollectionData* obj,
312✔
74
                                        TAdaptedString key) {
75
  if (!obj)
312✔
76
    return nullptr;
×
77
  return slotData(obj->get(key));
312✔
78
}
79

80
inline void collectionRemove(CollectionData* data, VariantSlot* slot,
44✔
81
                             ResourceManager* resources) {
82
  if (!data || !slot)
44✔
83
    return;
4✔
84
  data->remove(slot);
40✔
85
  slotRelease(slot, resources);
40✔
86
}
87

88
inline void collectionRemoveElement(CollectionData* array, size_t index,
11✔
89
                                    ResourceManager* resources) {
90
  if (!array)
11✔
91
    return;
1✔
92
  collectionRemove(array, array->get(index), resources);
10✔
93
}
94

95
template <typename TAdaptedString>
96
inline void collectionRemoveMember(CollectionData* obj, TAdaptedString key,
26✔
97
                                   ResourceManager* resources) {
98
  if (!obj)
26✔
99
    return;
1✔
100
  collectionRemove(obj, obj->get(key), resources);
25✔
101
}
102

103
ARDUINOJSON_END_PRIVATE_NAMESPACE
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc