-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.cpp
More file actions
59 lines (48 loc) · 1.81 KB
/
test.cpp
File metadata and controls
59 lines (48 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "test.h"
#include <sstream>
#ifndef Q_MOC_RUN
# include "parse/jsd.h"
# include "parse/jsd_convenience.h"
# include "stringify/jss.h"
# include "stringify/jss_fusion_adapted_struct.h"
#endif
// TODO: needs more tests
// this does not need to be more complex. works recursively, so other tests will fulfill our needs
struct Object : public JSON::FusionStruct <Object>
, public JSON::ParsableStruct <Object>
{
int id = 5;
std::string str = "Hello";
};
BOOST_FUSION_ADAPT_STRUCT
(
Object,
(int, id)
(std::string, str)
)
#define TEST(O, RESULT_STRING) \
{ \
std::stringstream sstr; \
JSON::stringify (sstr, std::string("name"), O, JSON::DEFAULT_OPTIONS); \
if (sstr.str() != RESULT_STRING) { std::cerr << "[FAIL ] Expected: '" << RESULT_STRING << "' Got: '" << sstr.str() << "'\n"; failed++; }\
else std::cout << "[SUCCESS] " << RESULT_STRING << "\n"; \
}
void testAll()
{
int failed = 0;
TEST(5, "5")
TEST('c', "\"c\"")
TEST(std::string{"Hello"}, "\"Hello\"")
TEST((std::vector <char> {'a', 'b'}), "[\"a\",\"b\"]")
TEST((std::pair <int, float>{3, 2.5f}), "{\"first\":3,\"second\":2.5}")
TEST((std::bitset <3>{5u}), "[1,0,1]")
TEST((std::forward_list <double> {2.3, 1.4, 0.5}), "[2.3,1.4,0.5]")
TEST((std::map<std::string, int>{std::make_pair(std::string("hello"), 4), std::make_pair(std::string("world"), 8)}), "{\"hello\":4,\"world\":8}")
TEST((std::multimap<int, int>{std::make_pair(2, 3), std::make_pair(4, 5)}), "[[2,3],[4,5]]")
// NullptrException
// TEST((nullptr), "")
TEST((std::queue <int>{}), "[]")
TEST((std::set <std::string> {"first", "second"}), "[\"first\",\"second\"]")
TEST((std::tuple <int, float> {2, 1.2f}), "\"name\":{\"_0\":2,\"_1\":1.2}")
TEST(Object{}, "{\"id\":5,\"str\":\"Hello\"}")
}