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

Go to the source code of this file.

Functions

static void EXPECT_EQ (const std::string &a, const std::string &b)
static void EXPECT_EQ (const nlohmann::json_uri &a, const std::string &b)
static void paths (json_uri start, const std::string &full, const std::string &full_path, const std::string &no_path)
static void pointer_plain_name (json_uri start, const std::string &full, const std::string &full_path, const std::string &no_path)
int main (void)

Variables

static int errors

Function Documentation

◆ EXPECT_EQ() [1/2]

void EXPECT_EQ ( const nlohmann::json_uri & a,
const std::string & b )
static

Definition at line 27 of file uri.cpp.

28{
29 EXPECT_EQ(a.to_string(), b);
30}
#define EXPECT_EQ(a, b)
std::string to_string() const
Definition json-uri.cpp:118

References EXPECT_EQ(), and nlohmann::json_uri::to_string().

Referenced by paths(), and pointer_plain_name().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EXPECT_EQ() [2/2]

void EXPECT_EQ ( const std::string & a,
const std::string & b )
static

Definition at line 19 of file uri.cpp.

20{
21 if (a != b) {
22 std::cerr << "Failed: '" << a << "' != '" << b << "'\n";
23 errors++;
24 }
25}
static int errors
Definition uri.cpp:17

References errors.

Referenced by EXPECT_EQ(), and pointer_plain_name().

Here is the caller graph for this function:

◆ main()

int main ( void )

Definition at line 86 of file uri.cpp.

87{
88 json_uri empty("");
89 paths(empty,
90 "",
91 "",
92 "");
93
94 json_uri http("http://json-schema.org/draft-07/schema#");
95 paths(http,
96 "http://json-schema.org/draft-07/schema",
97 "http://json-schema.org/draft-07",
98 "http://json-schema.org");
99
101 "http://json-schema.org/draft-07/schema",
102 "http://json-schema.org/draft-07",
103 "http://json-schema.org");
104
105 return errors;
106}
static void pointer_plain_name(json_uri start, const std::string &full, const std::string &full_path, const std::string &no_path)
Definition uri.cpp:61
static void paths(json_uri start, const std::string &full, const std::string &full_path, const std::string &no_path)
Definition uri.cpp:32

References errors, nlohmann::json_uri::json_uri(), paths(), and pointer_plain_name().

Here is the call graph for this function:

◆ paths()

void paths ( json_uri start,
const std::string & full,
const std::string & full_path,
const std::string & no_path )
static

Definition at line 32 of file uri.cpp.

36{
37 EXPECT_EQ(start, full + " # ");
38
39 auto a = start.derive("other.json");
40 EXPECT_EQ(a, full_path + "/other.json # ");
41
42 auto b = a.derive("base.json");
43 EXPECT_EQ(b, full_path + "/base.json # ");
44
45 auto c = b.derive("subdir/base.json");
46 EXPECT_EQ(c, full_path + "/subdir/base.json # ");
47
48 auto d = c.derive("subdir2/base.json");
49 EXPECT_EQ(d, full_path + "/subdir/subdir2/base.json # ");
50
51 auto e = c.derive("/subdir2/base.json");
52 EXPECT_EQ(e, no_path + "/subdir2/base.json # ");
53
54 auto f = c.derive("new.json");
55 EXPECT_EQ(f, full_path + "/subdir/new.json # ");
56
57 auto g = c.derive("/new.json");
58 EXPECT_EQ(g, no_path + "/new.json # ");
59}
json_uri derive(const std::string &uri) const

References nlohmann::json_uri::derive(), and EXPECT_EQ().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pointer_plain_name()

void pointer_plain_name ( json_uri start,
const std::string & full,
const std::string & full_path,
const std::string & no_path )
static

Definition at line 61 of file uri.cpp.

65{
66 auto a = start.derive("#/json/path");
67 EXPECT_EQ(a, full + " # /json/path");
68
69 a = start.derive("#/json/special_%22");
70 EXPECT_EQ(a, full + " # /json/special_\"");
71
72 a = a.derive("#foo");
73 EXPECT_EQ(a, full + " # foo");
74
75 a = a.derive("#foo/looks_like_json/poiner/but/isnt");
76 EXPECT_EQ(a, full + " # foo/looks_like_json/poiner/but/isnt");
77 EXPECT_EQ(a.identifier(), "foo/looks_like_json/poiner/but/isnt");
78 EXPECT_EQ(a.pointer().to_string(), "");
79
80 a = a.derive("#/looks_like_json/poiner/and/it/is");
81 EXPECT_EQ(a, full + " # /looks_like_json/poiner/and/it/is");
82 EXPECT_EQ(a.pointer().to_string(), "/looks_like_json/poiner/and/it/is");
83 EXPECT_EQ(a.identifier(), "");
84}

References nlohmann::json_uri::derive(), EXPECT_EQ(), EXPECT_EQ(), nlohmann::json_uri::identifier(), and nlohmann::json_uri::pointer().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ errors

int errors
static

Definition at line 17 of file uri.cpp.

Referenced by EXPECT_EQ(), and main().