tests/test_json.c

changeset 966
1aa7ec3e46e7
parent 946
b428424c0214
equal deleted inserted replaced
965:dfdfedbe2c86 966:1aa7ec3e46e7
70 CX_TEST_ASSERT(cxJsonIsObject(obj)); 70 CX_TEST_ASSERT(cxJsonIsObject(obj));
71 71
72 CxJsonValue *message = cxJsonObjGet(obj, "message"); 72 CxJsonValue *message = cxJsonObjGet(obj, "message");
73 CX_TEST_ASSERT(cxJsonIsString(message)); 73 CX_TEST_ASSERT(cxJsonIsString(message));
74 CX_TEST_ASSERT(0 == cx_strcmp( 74 CX_TEST_ASSERT(0 == cx_strcmp(
75 cx_strcast(cxJsonAsString(message)), 75 cxJsonAsCxString(message),
76 cx_str("success")) 76 cx_str("success"))
77 ); 77 );
78 78
79 CxJsonValue *position = cxJsonObjGet(obj, "position"); 79 CxJsonValue *position = cxJsonObjGet(obj, "position");
80 CX_TEST_ASSERT(cxJsonIsObject(position)); 80 CX_TEST_ASSERT(cxJsonIsObject(position));
81 CxJsonValue *longitude = cxJsonObjGet(position, "longitude"); 81 CxJsonValue *longitude = cxJsonObjGet(position, "longitude");
82 CX_TEST_ASSERT(cxJsonIsNumber(longitude)); 82 CX_TEST_ASSERT(cxJsonIsNumber(longitude));
83 CX_TEST_ASSERT(!cxJsonIsInteger(longitude));
83 CX_TEST_ASSERT(cxJsonAsDouble(longitude) == -94.7099); 84 CX_TEST_ASSERT(cxJsonAsDouble(longitude) == -94.7099);
85 CX_TEST_ASSERT(cxJsonAsInteger(longitude) == -94);
84 CxJsonValue *latitude = cxJsonObjGet(position, "latitude"); 86 CxJsonValue *latitude = cxJsonObjGet(position, "latitude");
85 CX_TEST_ASSERT(cxJsonIsNumber(latitude)); 87 CX_TEST_ASSERT(cxJsonIsNumber(latitude));
88 CX_TEST_ASSERT(!cxJsonIsInteger(latitude));
86 CX_TEST_ASSERT(cxJsonAsDouble(latitude) == 51.5539); 89 CX_TEST_ASSERT(cxJsonAsDouble(latitude) == 51.5539);
90 CX_TEST_ASSERT(cxJsonAsInteger(latitude) == 51);
87 91
88 CxJsonValue *timestamp = cxJsonObjGet(obj, "timestamp"); 92 CxJsonValue *timestamp = cxJsonObjGet(obj, "timestamp");
89 CX_TEST_ASSERT(cxJsonIsInteger(timestamp)); 93 CX_TEST_ASSERT(cxJsonIsInteger(timestamp));
94 CX_TEST_ASSERT(cxJsonIsNumber(timestamp));
90 CX_TEST_ASSERT(cxJsonAsInteger(timestamp) == 1729348561); 95 CX_TEST_ASSERT(cxJsonAsInteger(timestamp) == 1729348561);
96 CX_TEST_ASSERT(cxJsonAsDouble(timestamp) == 1729348561.0);
91 97
92 CxJsonValue *alive = cxJsonObjGet(obj, "alive"); 98 CxJsonValue *alive = cxJsonObjGet(obj, "alive");
93 CX_TEST_ASSERT(cxJsonIsBool(alive)); 99 CX_TEST_ASSERT(cxJsonIsBool(alive));
94 CX_TEST_ASSERT(cxJsonIsTrue(alive)); 100 CX_TEST_ASSERT(cxJsonIsTrue(alive));
95 CX_TEST_ASSERT(!cxJsonIsFalse(alive)); 101 CX_TEST_ASSERT(!cxJsonIsFalse(alive));
138 CX_TEST_ASSERT(obj); 144 CX_TEST_ASSERT(obj);
139 145
140 CxJsonValue *message = cxJsonObjGet(obj, "message"); 146 CxJsonValue *message = cxJsonObjGet(obj, "message");
141 CX_TEST_ASSERT(cxJsonIsString(message)); 147 CX_TEST_ASSERT(cxJsonIsString(message));
142 CX_TEST_ASSERT(0 == cx_strcmp( 148 CX_TEST_ASSERT(0 == cx_strcmp(
143 cx_strcast(cxJsonAsString(message)), 149 cxJsonAsCxString(message),
144 cx_str("success")) 150 cx_str("success"))
145 ); 151 );
146 CxJsonValue *timestamp = cxJsonObjGet(obj, "__timestamp"); 152 CxJsonValue *timestamp = cxJsonObjGet(obj, "__timestamp");
147 CX_TEST_ASSERT(message->type == CX_JSON_STRING); 153 CX_TEST_ASSERT(message->type == CX_JSON_STRING);
148 CX_TEST_ASSERT(cxJsonIsInteger(timestamp)); 154 CX_TEST_ASSERT(cxJsonIsInteger(timestamp));

mercurial