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

bblanchon / ArduinoJson / 4766013433

pending completion
4766013433

push

github

Benoit Blanchon
Increase coverage

8 of 8 new or added lines in 3 files covered. (100.0%)

3321 of 3342 relevant lines covered (99.37%)

6648.12 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
                                         MemoryPool* pool) {
13
  if (!array)
68,515✔
14
    return nullptr;
5✔
15
  auto slot = pool->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,
784✔
24
                                        MemoryPool* pool) {
25
  ARDUINOJSON_ASSERT(!key.isNull());
26
  ARDUINOJSON_ASSERT(obj != nullptr);
27
  if (!obj)
784✔
28
    return nullptr;
×
29
  auto slot = pool->allocVariant();
784✔
30
  if (!slot)
784✔
31
    return nullptr;
3✔
32
  auto storedKey = storeString(pool, key);
781✔
33
  if (!storedKey)
781✔
34
    return nullptr;
1✔
35
  slot->setKey(storedKey);
780✔
36
  obj->add(slot);
780✔
37
  return slot->data();
780✔
38
}
39

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

48
inline bool collectionCopy(CollectionData* dst, const CollectionData* src,
39✔
49
                           MemoryPool* pool) {
50
  if (!dst || !src)
39✔
51
    return false;
2✔
52

53
  collectionClear(dst, pool);
37✔
54

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

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

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

86
inline void collectionRemoveElement(CollectionData* array, size_t index,
11✔
87
                                    MemoryPool* pool) {
88
  if (!array)
11✔
89
    return;
1✔
90
  collectionRemove(array, array->get(index), pool);
10✔
91
}
92

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

101
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