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

OpenLightingProject / ola / 21336882381

25 Jan 2026 05:47PM UTC coverage: 45.06% (-0.7%) from 45.72%
21336882381

Pull #1984

github

web-flow
Merge b8c8613eb into 704337b09
Pull Request #1984: Add conditionals for Protobuf 22+ API changes

8556 of 19814 branches covered (43.18%)

5 of 6 new or added lines in 3 files covered. (83.33%)

324 existing lines in 56 files now uncovered.

22100 of 49046 relevant lines covered (45.06%)

48.42 hits per line

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

79.66
/common/web/SchemaParser.cpp
1
/*
2
 * This library is free software; you can redistribute it and/or
3
 * modify it under the terms of the GNU Lesser General Public
4
 * License as published by the Free Software Foundation; either
5
 * version 2.1 of the License, or (at your option) any later version.
6
 *
7
 * This library is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10
 * Lesser General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU Lesser General Public
13
 * License along with this library; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
 *
16
 * SchemaParser.cpp
17
 * A json-schema Parser.
18
 * Copyright (C) 2014 Simon Newton
19
 */
20
#include "common/web/SchemaParser.h"
21

22
#include <string>
23
#include "ola/Logging.h"
24
#include "ola/StringUtils.h"
25
#include "ola/stl/STLUtils.h"
26
#include "ola/web/Json.h"
27

28
namespace ola {
29
namespace web {
30

31
using std::string;
32

33
SchemaParser::SchemaParser()
306✔
34
    : JsonParserInterface(),
35
      m_pointer_tracker(&m_pointer),
306✔
36
      m_error_logger(&m_pointer) {
306✔
37
}
306✔
38

39
SchemaParser::~SchemaParser() {}
911✔
40

41
void SchemaParser::Begin() {
306✔
42
  m_schema_defs.reset();
306✔
43
  m_root_context.reset();
306✔
44
  m_root_validator.reset();
306✔
45
  STLEmptyStackAndDelete(&m_context_stack);
306✔
46
  m_error_logger.Reset();
306✔
47
}
306✔
48

49
void SchemaParser::End() {}
301✔
50

51
void SchemaParser::String(const string &value) {
369✔
52
  if (m_error_logger.HasError()) {
369✔
53
    return;
54
  }
55

56
  if (!m_root_context.get()) {
271✔
57
    m_error_logger.Error() << "Invalid string for first element: " << value;
1✔
58
    return;
1✔
59
  }
60

61
  m_pointer_tracker.IncrementIndex();
270✔
62

63
  if (m_context_stack.top()) {
270✔
64
    m_context_stack.top()->String(&m_error_logger, value);
270✔
65
  } else {
66
    OLA_INFO << "In null context, skipping value " << value;
×
67
  }
68
}
69

70
void SchemaParser::Number(uint32_t value) {
74✔
71
  return HandleNumber(value);
74✔
72
}
73

74
void SchemaParser::Number(int32_t value) {
30✔
75
  return HandleNumber(value);
30✔
76
}
77

78
void SchemaParser::Number(uint64_t value) {
×
79
  return HandleNumber(value);
×
80
}
81

82
void SchemaParser::Number(int64_t value) {
×
83
  return HandleNumber(value);
×
84
}
85

86
void SchemaParser::Number(const JsonDouble::DoubleRepresentation &rep) {
40✔
87
  double d;
40✔
88
  JsonDouble::AsDouble(rep, &d);
40✔
89
  return HandleNumber(d);
40✔
90
}
91

92
void SchemaParser::Number(double value) {
×
93
  return HandleNumber(value);
×
94
}
95

96
void SchemaParser::Bool(bool value) {
50✔
97
  if (m_error_logger.HasError()) {
50✔
98
    return;
99
  }
100

101
  if (!m_root_context.get()) {
50✔
102
    m_error_logger.Error() << "Invalid bool for first element: " << value;
1✔
103
    return;
1✔
104
  }
105

106
  m_pointer_tracker.IncrementIndex();
49✔
107

108
  if (m_context_stack.top()) {
49✔
109
    m_context_stack.top()->Bool(&m_error_logger, value);
49✔
110
  } else {
111
    OLA_INFO << "In null context, skipping value " << value;
×
112
  }
113
}
114

115
void SchemaParser::Null() {
35✔
116
  if (m_error_logger.HasError()) {
35✔
117
    return;
118
  }
119

120
  if (!m_root_context.get()) {
34✔
121
    m_error_logger.Error() << "Invalid null for first element";
1✔
122
    return;
1✔
123
  }
124

125
  m_pointer_tracker.IncrementIndex();
33✔
126

127
  if (m_context_stack.top()) {
33✔
128
    m_context_stack.top()->Null(&m_error_logger);
33✔
129
  } else {
130
    OLA_INFO << "In null context, skipping null";
×
131
  }
132
}
133

134
void SchemaParser::OpenArray() {
76✔
135
  if (m_error_logger.HasError()) {
76✔
136
    return;
137
  }
138

139
  if (!m_root_context.get()) {
75✔
140
    m_error_logger.Error() << "Invalid array for first element";
2✔
141
    return;
2✔
142
  }
143

144
  m_pointer_tracker.OpenArray();
73✔
145

146
  if (m_context_stack.top()) {
73✔
147
    m_context_stack.push(
146✔
148
        m_context_stack.top()->OpenArray(&m_error_logger));
73✔
149
  } else {
150
    OLA_INFO << "In null context, skipping OpenArray";
×
151
    m_context_stack.push(NULL);
×
152
  }
153
}
154

155
void SchemaParser::CloseArray() {
74✔
156
  if (m_error_logger.HasError() || !m_root_context.get()) {
74✔
157
    return;
158
  }
159

160
  m_pointer_tracker.CloseArray();
37✔
161
  m_context_stack.pop();
37✔
162

163
  if (m_context_stack.top()) {
37✔
164
    m_context_stack.top()->CloseArray(&m_error_logger);
37✔
165
  } else {
166
    OLA_INFO << "In null context, skipping CloseArray";
×
167
  }
168
}
169

170
void SchemaParser::OpenObject() {
475✔
171
  if (m_error_logger.HasError()) {
475✔
172
    return;
173
  }
174

175
  m_pointer_tracker.OpenObject();
474✔
176

177
  if (!m_root_context.get()) {
474✔
178
    m_schema_defs.reset(new SchemaDefinitions());
299✔
179
    m_root_context.reset(new SchemaParseContext(m_schema_defs.get()));
299✔
180
    m_context_stack.push(m_root_context.get());
299✔
181
  } else {
182
    if (m_context_stack.top()) {
175✔
183
      m_context_stack.push(
350✔
184
          m_context_stack.top()->OpenObject(&m_error_logger));
175✔
185
    } else {
186
      OLA_INFO << "In null context, skipping OpenObject";
×
187
      m_context_stack.push(NULL);
×
188
    }
189
  }
190
}
191

192
void SchemaParser::ObjectKey(const string &key) {
754✔
193
  if (m_error_logger.HasError()) {
754✔
194
    return;
195
  }
196

197
  m_pointer_tracker.SetProperty(key);
645✔
198

199
  if (m_context_stack.top()) {
645✔
200
    m_context_stack.top()->ObjectKey(&m_error_logger, key);
645✔
201
  } else {
202
    OLA_INFO << "In null context, skipping key " << key;
×
203
  }
204
}
205

206
void SchemaParser::CloseObject() {
467✔
207
  if (m_error_logger.HasError()) {
467✔
208
    return;
209
  }
210

211
  m_pointer_tracker.CloseObject();
237✔
212

213
  m_context_stack.pop();
237✔
214

215
  if (m_context_stack.empty()) {
237✔
216
    // We're at the root
217
    m_root_validator.reset(m_root_context->GetValidator(&m_error_logger));
95✔
218
  } else {
219
    if (m_context_stack.top()) {
142✔
220
      m_context_stack.top()->CloseObject(&m_error_logger);
142✔
221
    }
222
  }
223
}
224

225
void SchemaParser::SetError(const string &error) {
5✔
226
  m_error_logger.Error() << error;
5✔
227
}
5✔
228

229
bool SchemaParser::IsValidSchema() {
301✔
230
  return m_root_validator.get() != NULL;
301✔
231
}
232

233
string SchemaParser::Error() const {
216✔
234
  return m_error_logger.ErrorString();
216✔
235
}
236

237
ValidatorInterface* SchemaParser::ClaimRootValidator() {
90✔
238
  return m_root_validator.release();
90✔
239
}
240

241
SchemaDefinitions* SchemaParser::ClaimSchemaDefs() {
90✔
242
  return m_schema_defs.release();
90✔
243
}
244

245
template <typename T>
UNCOV
246
void SchemaParser::HandleNumber(T t) {
×
UNCOV
247
  if (m_error_logger.HasError()) {
×
248
    return;
249
  }
250

UNCOV
251
  if (!m_root_context.get()) {
×
UNCOV
252
    m_error_logger.Error() << "Invalid number for first element: " << t;
×
UNCOV
253
    return;
×
254
  }
255

UNCOV
256
  m_pointer_tracker.IncrementIndex();
×
UNCOV
257
  if (m_context_stack.top()) {
×
UNCOV
258
    m_context_stack.top()->Number(&m_error_logger, t);
×
259
  } else {
260
    OLA_INFO << "In null context, skipping number " << t;
×
261
  }
262
}
263
}  // namespace web
264
}  // namespace ola
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

© 2026 Coveralls, Inc