mirror of
https://github.com/vale981/libblobpack
synced 2025-03-05 09:51:42 -05:00
improve code coverage
This commit is contained in:
parent
7a997fc419
commit
2518b00fad
3 changed files with 14 additions and 5 deletions
|
@ -231,7 +231,6 @@ void blob_close_table(struct blob *buf, blob_offset_t offset){
|
||||||
blob_field_set_raw_len(attr, len);
|
blob_field_set_raw_len(attr, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct blob_field *blob_put_float(struct blob *buf, double value){
|
struct blob_field *blob_put_float(struct blob *buf, double value){
|
||||||
uint32_t val = cpu_to_be32(pack754_32((float)value));
|
uint32_t val = cpu_to_be32(pack754_32((float)value));
|
||||||
return blob_put(buf, BLOB_FIELD_FLOAT32, &val, sizeof(val));
|
return blob_put(buf, BLOB_FIELD_FLOAT32, &val, sizeof(val));
|
||||||
|
@ -243,6 +242,7 @@ struct blob_field *blob_put_double(struct blob *buf, double value){
|
||||||
}
|
}
|
||||||
|
|
||||||
struct blob_field *blob_put_real(struct blob *buf, double value){
|
struct blob_field *blob_put_real(struct blob *buf, double value){
|
||||||
|
if((float)value == value) return blob_put_float(buf, value);
|
||||||
return blob_put_double(buf, value);
|
return blob_put_double(buf, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
test/json.c
13
test/json.c
|
@ -26,14 +26,19 @@ int main(){
|
||||||
blob_close_table(&blob, o);
|
blob_close_table(&blob, o);
|
||||||
|
|
||||||
o = blob_open_array(&blob);
|
o = blob_open_array(&blob);
|
||||||
blob_put_int(&blob, 1);
|
blob_put_int(&blob, 100);
|
||||||
blob_put_int(&blob, 2);
|
blob_put_int(&blob, 200);
|
||||||
blob_put_int(&blob, 3);
|
blob_put_int(&blob, 1000);
|
||||||
|
blob_put_int(&blob, 70000);
|
||||||
|
blob_put_int(&blob, 5000000000lu);
|
||||||
blob_close_array(&blob, o);
|
blob_close_array(&blob, o);
|
||||||
|
|
||||||
|
struct blob_field *out[8];
|
||||||
|
TEST(blob_field_parse(blob_head(&blob), "isifssta", out, 8));
|
||||||
|
|
||||||
char *json = blob_to_json(&blob);
|
char *json = blob_to_json(&blob);
|
||||||
|
|
||||||
TEST(strcmp("[1,\"foo\",243,3.141593e+00,\"copyme\",\"copyme\",{\"one\":1,\"two\":2,\"three\":3},[1,2,3]]", json) == 0);
|
TEST(strcmp("[1,\"foo\",243,3.141593e+00,\"copyme\",\"copyme\",{\"one\":1,\"two\":2,\"three\":3},[100,200,1000,70000,5000000000]]", json) == 0);
|
||||||
|
|
||||||
struct blob b2;
|
struct blob b2;
|
||||||
blob_init_from_json(&b2, json);
|
blob_init_from_json(&b2, json);
|
||||||
|
|
|
@ -22,6 +22,8 @@ int main(){
|
||||||
blob_put_int(&blob, 100);
|
blob_put_int(&blob, 100);
|
||||||
blob_put_int(&blob, 200);
|
blob_put_int(&blob, 200);
|
||||||
blob_put_int(&blob, 1000);
|
blob_put_int(&blob, 1000);
|
||||||
|
blob_put_int(&blob, 70000);
|
||||||
|
blob_put_int(&blob, 5000000000lu);
|
||||||
blob_put_string(&blob, "3.14");
|
blob_put_string(&blob, "3.14");
|
||||||
blob_put_int(&blob, 5000000000lu);
|
blob_put_int(&blob, 5000000000lu);
|
||||||
blob_put_real(&blob, M_PI);
|
blob_put_real(&blob, M_PI);
|
||||||
|
@ -63,6 +65,8 @@ int main(){
|
||||||
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 100);
|
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 100);
|
||||||
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 200);
|
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 200);
|
||||||
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 1000);
|
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 1000);
|
||||||
|
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 70000);
|
||||||
|
TEST(blob_field_get_real(child = blob_field_next_child(root, child)) == 5000000000lu);
|
||||||
TEST(is_equal(blob_field_get_real(child = blob_field_next_child(root, child)), 3.14f));
|
TEST(is_equal(blob_field_get_real(child = blob_field_next_child(root, child)), 3.14f));
|
||||||
TEST(blob_field_get_int(child = blob_field_next_child(root, child)) == 5000000000lu);
|
TEST(blob_field_get_int(child = blob_field_next_child(root, child)) == 5000000000lu);
|
||||||
TEST(is_equal(blob_field_get_real(child = blob_field_next_child(root, child)), M_PI));
|
TEST(is_equal(blob_field_get_real(child = blob_field_next_child(root, child)), M_PI));
|
||||||
|
|
Loading…
Add table
Reference in a new issue