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
|
#include "../../testing/testing.hpp"
#include "../../3party/jansson/myjansson.hpp"
UNIT_TEST(Jansson_Smoke)
{
// char const * str = "{\"location\":{\"latitude\":47.383333,\"longitude\":8.533333,"
// "\"accuracy\":18000.0},\"access_token\":\"2:6aOjM2IAoPMaweWN:txhu5LpkRkLVb3u3\"}";
char const * str = "{\"location\":{\"latitude\":47.3345141,\"longitude\":8.5312839,"
"\"accuracy\":22.0},\"access_token\":\"2:vC65Xv0mxMtsNVf4:hY5YSIkuFfnAU77z\"}";
my::Json root(str);
TEST(json_is_object(root), ());
json_t * location = json_object_get(root, "location");
TEST(json_is_object(location), ());
json_t * lat = json_object_get(location, "latitude");
TEST(json_is_real(lat), ());
TEST_ALMOST_EQUAL(json_real_value(lat), 47.3345141, ());
json_t * lon = json_object_get(location, "longitude");
TEST(json_is_real(lon), ());
TEST_ALMOST_EQUAL(json_real_value(lon), 8.5312839, ());
json_t * acc = json_object_get(location, "accuracy");
TEST(json_is_real(acc), ());
TEST_ALMOST_EQUAL(json_real_value(acc), 22.0, ());
bool wasException = false;
try
{
my::Json invalid("{asd]");
}
catch (my::Json::Exception const &)
{
wasException = true;
}
TEST(wasException, ());
}
|