MQTTSuite
Loading...
Searching...
No Matches
issue-117-format-error.cpp File Reference
#include "nlohmann/json-schema.hpp"
#include "nlohmann/json.hpp"
#include <iostream>
Include dependency graph for issue-117-format-error.cpp:

Go to the source code of this file.

Macros

#define CHECK_THROW(x, msg)
#define CHECK_NO_THROW(x, msg)

Functions

int main ()

Variables

static int error_count = 0
json schema_with_format

Macro Definition Documentation

◆ CHECK_NO_THROW

#define CHECK_NO_THROW ( x,
msg )
Value:
{ \
bool fail = false; \
std::string exception_error; \
try { \
x; \
} catch (std::exception & e) { \
fail = true; \
exception_error = e.what(); \
} \
if (fail == true) { \
std::cout << msg << ": " << exception_error << std::endl; \
} \
}
static int error_count

Definition at line 23 of file issue-117-format-error.cpp.

23#define CHECK_NO_THROW(x, msg) \
24 { \
25 bool fail = false; \
26 std::string exception_error; \
27 try { \
28 x; \
29 } catch (std::exception & e) { \
30 fail = true; \
31 exception_error = e.what(); \
32 } \
33 if (fail == true) { \
34 ++error_count; \
35 std::cout << msg << ": " << exception_error << std::endl; \
36 } \
37 }

◆ CHECK_THROW

#define CHECK_THROW ( x,
msg )
Value:
{ \
bool fail = false; \
try { \
x; \
} catch (std::exception &) { \
fail = true; \
} \
if (fail == false) { \
std::cout << msg << std::endl; \
} \
}

Definition at line 9 of file issue-117-format-error.cpp.

9#define CHECK_THROW(x, msg) \
10 { \
11 bool fail = false; \
12 try { \
13 x; \
14 } catch (std::exception &) { \
15 fail = true; \
16 } \
17 if (fail == false) { \
18 ++error_count; \
19 std::cout << msg << std::endl; \
20 } \
21 }

Function Documentation

◆ main()

int main ( void )

Definition at line 54 of file issue-117-format-error.cpp.

55{
56 // check that if we get validator without format checker we get error at schema loading
57 validator without_format_checker;
58
59 CHECK_THROW(without_format_checker.set_root_schema(schema_with_format), "validator without format checker must fail at schema loading");
60
61 // check that with format checker all works fine
62 validator with_format_checker{nullptr, [](const std::string &, const std::string &) {}};
63
64 CHECK_NO_THROW(with_format_checker.set_root_schema(schema_with_format), "schema must be succesed by validator with format checker");
65
66 CHECK_NO_THROW(with_format_checker.validate(json{{"str", "placeholder"}}), "validator must not throw while validation schema with format");
67
68 return error_count;
69}
nlohmann::json_schema::json_validator validator
nlohmann::json json
#define CHECK_THROW(x, msg)
#define CHECK_NO_THROW(x, msg)
json schema_with_format

References error_count, nlohmann::json_schema::json_validator::json_validator(), schema_with_format, nlohmann::json_schema::json_validator::set_root_schema(), and nlohmann::json_schema::json_validator::validate().

Here is the call graph for this function:

Variable Documentation

◆ error_count

int error_count = 0
static

Definition at line 7 of file issue-117-format-error.cpp.

Referenced by main().

◆ schema_with_format

json schema_with_format
Initial value:
= json::parse(R"(
{
"type": "object",
"properties": {
"str": {
"type": "string",
"format": "placeholder"
}
}
}
)")

Definition at line 42 of file issue-117-format-error.cpp.

Referenced by main().