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

bblanchon / ArduinoJson / 15855466327

24 Jun 2025 03:54PM UTC coverage: 99.311%. First build
15855466327

push

github

bblanchon
Fix JsonVariantTests

4 of 6 new or added lines in 2 files covered. (66.67%)

4038 of 4066 relevant lines covered (99.31%)

10842.85 hits per line

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

94.0
/src/ArduinoJson/Object/ObjectImpl.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2025, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Object/ObjectData.hpp>
8
#include <ArduinoJson/Variant/VariantCompare.hpp>
9
#include <ArduinoJson/Variant/VariantData.hpp>
10

11
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
12

13
template <typename TAdaptedString>
14
inline VariantData* ObjectImpl::getMember(TAdaptedString key) {
4,744✔
15
  auto it = findKey(key);
4,744✔
16
  if (it.done())
4,744✔
17
    return nullptr;
3,482✔
18
  it.next(resources_);
1,262✔
19
  return it.data();
1,262✔
20
}
21

22
template <typename TAdaptedString>
23
VariantData* ObjectImpl::getOrAddMember(TAdaptedString key) {
958✔
24
  auto data = getMember(key);
958✔
25
  if (data)
958✔
26
    return data;
34✔
27
  return addMember(key);
924✔
28
}
29

30
template <typename TAdaptedString>
31
inline ObjectImpl::iterator ObjectImpl::findKey(TAdaptedString key) {
4,774✔
32
  if (key.isNull())
4,774✔
33
    return iterator();
13✔
34
  bool isKey = true;
4,761✔
35
  for (auto it = createIterator(); !it.done(); it.next(resources_)) {
25,603✔
36
    if (isKey && stringEquals(key, adaptString(it->asString(resources_))))
22,130✔
37
      return it;
1,288✔
38
    isKey = !isKey;
20,842✔
39
  }
40
  return iterator();
3,473✔
41
}
42

43
template <typename TAdaptedString>
44
inline void ObjectImpl::removeMember(TAdaptedString key) {
30✔
45
  remove(findKey(key));
30✔
46
}
30✔
47

48
template <typename TAdaptedString>
49
inline VariantData* ObjectImpl::addMember(TAdaptedString key) {
924✔
50
  if (!data_)
924✔
NEW
51
    return nullptr;
×
52
  ARDUINOJSON_ASSERT(resources_ != nullptr);
53

54
  auto keySlot = resources_->allocVariant();
924✔
55
  if (!keySlot)
924✔
56
    return nullptr;
2✔
57

58
  auto valueSlot = resources_->allocVariant();
922✔
59
  if (!valueSlot)
922✔
60
    return nullptr;
1✔
61

62
  if (!keySlot->setString(key, resources_))
921✔
63
    return nullptr;
2✔
64

65
  CollectionImpl::appendPair(keySlot, valueSlot);
919✔
66

67
  return valueSlot.ptr();
919✔
68
}
69

70
inline VariantData* ObjectImpl::addPair(VariantData** value) {
1,336✔
71
  if (!data_)
1,336✔
NEW
72
    return nullptr;
×
73
  ARDUINOJSON_ASSERT(resources_ != nullptr);
74

75
  auto keySlot = resources_->allocVariant();
1,336✔
76
  if (!keySlot)
1,336✔
77
    return nullptr;
4✔
78

79
  auto valueSlot = resources_->allocVariant();
1,332✔
80
  if (!valueSlot)
1,332✔
81
    return nullptr;
×
82
  *value = valueSlot.ptr();
1,332✔
83

84
  CollectionImpl::appendPair(keySlot, valueSlot);
1,332✔
85

86
  return keySlot.ptr();
1,332✔
87
}
88

89
// Returns the size (in bytes) of an object with n members.
90
constexpr size_t sizeofObject(size_t n) {
1,688✔
91
  return 2 * n * sizeof(VariantData);
1,688✔
92
}
93

94
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