Ejemplo n.º 1
0
void o_document_deserialize_internal(struct o_document * doc, struct o_input_stream * stream, int embeddd)
{
	struct o_string_buffer * buff = o_string_buffer_new();
	int isfirst = 1;
	int readed;
	do
	{
		readed = o_input_stream_read(stream);
		if (isfirst && readed == '@')
		{
			char * str = o_string_buffer_str(buff);
			doc->class_name = str;
			o_string_buffer_clear(buff);
		}
		else if (readed == ':')
		{
			isfirst = 0;
			char * str = o_string_buffer_str(buff);
			struct o_document_value * val = o_document_value_deserialize(stream);
			o_document_field_set(doc, str, val);
			o_free(str);
			o_string_buffer_clear(buff);
		}
		else if (readed != -1)
		{
			o_string_buffer_append_char(buff, readed);
		}
	} while (readed != -1 && readed != ')');
	o_string_buffer_free(buff);
}
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);
}