MQTTSuite
Loading...
Searching...
No Matches
issue-70-root-schema-constructor.cpp File Reference
#include <nlohmann/json-schema.hpp>
#include <iostream>
Include dependency graph for issue-70-root-schema-constructor.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{issue-70-root-schema-constructor.cpp}::store_ptr_err_handler

Namespaces

namespace  anonymous_namespace{issue-70-root-schema-constructor.cpp}

Macros

#define EXPECT_EQ(a, b)

Functions

int main (void)

Variables

static int error_count
static json anonymous_namespace{issue-70-root-schema-constructor.cpp}::person_schema
static json_validator validator (person_schema)

Macro Definition Documentation

◆ EXPECT_EQ

#define EXPECT_EQ ( a,
b )
Value:
do { \
if (a != b) { \
std::cerr << "Failed: '" << a << "' != '" << b << "'\n"; \
} \
} while (0)
static int error_count

Definition at line 7 of file issue-70-root-schema-constructor.cpp.

7#define EXPECT_EQ(a, b) \
8 do { \
9 if (a != b) { \
10 std::cerr << "Failed: '" << a << "' != '" << b << "'\n"; \
11 error_count++; \
12 } \
13 } while (0)

Function Documentation

◆ main()

int main ( void )

Definition at line 75 of file issue-70-root-schema-constructor.cpp.

76{
78
79 validator.validate({{"age", 42}, {"name", "John"}}, err); // OK
80 EXPECT_EQ(err.failed_pointers.size(), 0);
81 err.reset();
82
83 validator.validate({{"age", 42}}, err); // no name
84
85 EXPECT_EQ(err.failed_pointers.size(), 1);
86 EXPECT_EQ(err.failed_pointers[0].to_string(), "");
87 err.reset();
88
89 validator.validate({{"street", "Boulevard"}}, err); // no name and no age
90 EXPECT_EQ(err.failed_pointers.size(), 3);
91 EXPECT_EQ(err.failed_pointers[0].to_string(), "");
92 EXPECT_EQ(err.failed_pointers[1].to_string(), "");
93 EXPECT_EQ(err.failed_pointers[2].to_string(), "");
94 err.reset();
95
96 validator.validate({{"age", 42}, {"name", 12}}, err); // name must be a string
97 EXPECT_EQ(err.failed_pointers.size(), 1);
98 EXPECT_EQ(err.failed_pointers[0].to_string(), "/name");
99 err.reset();
100
101 validator.validate({
102 {"age", 42},
103 {"name", "John"},
104 {"phones", {1234, "223"}},
105 },
106 err); // name must be a string
107 EXPECT_EQ(err.failed_pointers.size(), 1);
108 EXPECT_EQ(err.failed_pointers[0].to_string(), "/phones/1");
109 err.reset();
110
111 validator.validate({
112 {"age", 42},
113 {"name", "John"},
114 {"phones", {0}},
115 {"post-code", 12345},
116 },
117 err); // name must be a string
118 EXPECT_EQ(err.failed_pointers.size(), 1);
119 EXPECT_EQ(err.failed_pointers[0].to_string(), "");
120 err.reset();
121
122 return error_count;
123}
nlohmann::json_schema::json_validator validator
std::vector< nlohmann::json::json_pointer > failed_pointers
#define EXPECT_EQ(a, b)

References error_count, anonymous_namespace{issue-70-root-schema-constructor.cpp}::store_ptr_err_handler::failed_pointers, anonymous_namespace{issue-70-root-schema-constructor.cpp}::store_ptr_err_handler::reset(), nlohmann::json_schema::json_validator::validate(), and validator.

Here is the call graph for this function:

Variable Documentation

◆ error_count

int error_count
static

Definition at line 5 of file issue-70-root-schema-constructor.cpp.

Referenced by main().

◆ validator