void test_o_document_value_create() { struct o_document_value *val = o_document_value_bool(1); assert_true(o_document_value_get_bool(val) == 1, "bool value not is the expected"); o_document_value_free(val); val = o_document_value_int(10); assert_true(o_document_value_get_int(val) == 10, "int value not is the expected"); o_document_value_free(val); val = o_document_value_long(10); assert_true(o_document_value_get_long(val) == 10, "long value not is the expected"); o_document_value_free(val); val = o_document_value_short(10); assert_true(o_document_value_get_short(val) == 10, "short value not is the expected"); o_document_value_free(val); val = o_document_value_string("aaaaaa-"); assert_true(strcmp(o_document_value_get_string(val), "aaaaaa-") == 0, "string value not is the expected"); o_document_value_free(val); val = o_document_value_float(10.5); assert_true(o_document_value_get_float(val) == 10.5, "float value not is the expected"); o_document_value_free(val); val = o_document_value_double(10.5); assert_true(o_document_value_get_double(val) == 10.5, "double value not is the expected"); o_document_value_free(val); val = o_document_value_date(10); assert_true(o_document_value_get_date(val) == 10, "date value not is the expected"); o_document_value_free(val); //fake pointer only test!! struct o_document *doc = o_document_new(); val = o_document_value_embedded(doc); assert_true(o_document_value_get_embedded(val) == doc, "embedded document value not is the expected"); o_document_value_free(val); val = o_document_value_link((struct o_record *)doc); assert_true(o_document_value_get_link(val) == (struct o_record *)doc, "link document value not is the expected"); o_document_value_free(val); o_document_release(doc); struct o_document_value * arr[3] = { 0, 0, 0 }; val = o_document_value_array(arr, 3); int size; struct o_document_value **resarr = o_document_value_get_array(val,&size); assert_true(size == 3, "Array size of document value not is the expected"); int i; for (i = 0; i < 3; i++) assert_true(arr[i] == resarr[i], "Array content of document value not is the expected"); o_document_value_free(val); }
struct o_document * o_document_copy(struct o_document * doc) { struct o_document * new_doc = o_document_new(); int i; int size; char ** keys = o_map_string_keys(doc->fields, &size); for (i = 0; i < size; ++i) o_map_string_put(new_doc->fields, keys[i], o_map_string_get(new_doc->fields, keys[i])); return new_doc; }
void test_o_database_document_open_save_load_close() { struct o_database_error_handler *errorHandler = o_database_error_handler_new(o_db_error_handler_function, 0); struct o_database_document * db = o_database_document_new_error_handler("remote:127.0.0.1/temp", errorHandler); o_database_document_open(db, "admin", "admin"); struct o_document * doc = o_document_new(); o_document_field_set(doc, "prova", o_document_value_string("prova")); struct o_record_id * id; o_database_document_save(db, doc, &id); struct o_document *readed_doc = o_database_document_load(db, id); struct o_document_value* readed_val = o_document_field_get(doc, "prova"); assert_true(strcmp(o_document_value_get_string(readed_val), "prova") == 0, "the writed document not is the same of loaded"); o_document_release(doc); o_document_release(readed_doc); o_database_document_close(db); o_database_document_free(db); }