int test_sky_get_property_message_pack() { cleantmp(); sky_get_property_message *message = sky_get_property_message_create(); message->property_id = 20; FILE *file = fopen("tmp/message", "w"); mu_assert_bool(sky_get_property_message_pack(message, file) == 0); fclose(file); mu_assert_file("tmp/message", "tests/fixtures/get_property_message/0/message"); sky_get_property_message_free(message); return 0; }
int test_sky_peach_message_pack() { cleantmp(); sky_peach_message *message = sky_peach_message_create(); message->query = bfromcstr("class Foo{ public Int x; }"); FILE *file = fopen("tmp/message", "w"); mu_assert_bool(sky_peach_message_pack(message, file) == 0); fclose(file); mu_assert_file("tmp/message", "tests/fixtures/peach_message/0/message"); sky_peach_message_free(message); return 0; }
int test_sky_message_header_unpack() { FILE *file = fopen("tests/fixtures/message_header/0/message", "r"); sky_message_header *header = sky_message_header_create(); mu_assert_bool(sky_message_header_unpack(header, file) == 0); fclose(file); mu_assert_int64_equals(header->version, 1LL); mu_assert_bstring(header->name, "eadd"); mu_assert_bstring(header->table_name, "bar"); sky_message_header_free(header); return 0; }
int test_sky_cursor_set_double() { size_t sz; sky_cursor *cursor = sky_cursor_new(-1, 0); sky_cursor_set_property(cursor, -1, offsetof(test2_t, double_value), sizeof(double), "float"); sky_cursor_set_data_sz(cursor, sizeof(test2_t)); mu_assert_int_equals(cursor->property_zero_descriptor[-1].offset, 16); sky_cursor_set_value(cursor, cursor->data, -1, DOUBLE_DATA, &sz); mu_assert_long_equals(sz, 9L); mu_assert_bool(fabs(((test2_t*)cursor->data)->double_value - 100.2) < 0.1); sky_cursor_free(cursor); return 0; }
int test_sky_data_file_load_empty() { cleantmp(); int rc; sky_data_file *data_file = sky_data_file_create(); data_file->block_size = 128; data_file->path = bfromcstr("tmp/data"); data_file->header_path = bfromcstr("tmp/header"); rc = sky_data_file_load(data_file); mu_assert_int_equals(rc, 0); mu_assert_bool(data_file->data != NULL); mu_assert_bool(data_file->data_fd != 0); mu_assert_long_equals(data_file->data_length, 128L); mu_assert_bool(data_file->blocks != NULL); mu_assert_int_equals(data_file->block_count, 1); mu_assert_file("tmp/data", "tests/fixtures/data_files/0/data"); mu_assert_file("tmp/header", "tests/fixtures/data_files/0/header"); rc = sky_data_file_unload(data_file); mu_assert_int_equals(rc, 0); mu_assert_bool(data_file->data == NULL); mu_assert_bool(data_file->data_fd == 0); mu_assert_long_equals(data_file->data_length, 0L); mu_assert_bool(data_file->blocks == NULL); mu_assert_int_equals(data_file->block_count, 0); sky_data_file_free(data_file); return 0; }
int test_sky_create_table_message_unpack() { FILE *file = fopen("tests/fixtures/create_table_message/0/message", "r"); sky_create_table_message *message = sky_create_table_message_create(); message->data_path = bfromcstr("/tmp/data"); message->table = sky_table_create(); mu_assert_bool(sky_create_table_message_unpack(message, file) == 0); fclose(file); mu_assert_bstring(message->table->path, "/tmp/data/foo"); sky_table_free(message->table); sky_create_table_message_free(message); return 0; }
int test_sky_cursor_set_string() { size_t sz; sky_cursor *cursor = sky_cursor_new(0, 1); sky_cursor_set_data_sz(cursor, sizeof(test2_t)); sky_cursor_set_property(cursor, 1, offsetof(test2_t, string_value), sizeof(sky_string), "string"); mu_assert_int_equals(cursor->property_zero_descriptor[1].offset, 32); sky_cursor_set_value(cursor, cursor->data, 1, STRING_DATA, &sz); mu_assert_long_equals(sz, 4L); mu_assert_int_equals(((test2_t*)cursor->data)->string_value.length, 3); mu_assert_bool(((test2_t*)cursor->data)->string_value.data == &STRING_DATA[1]); sky_cursor_free(cursor); return 0; }
int test_sky_create_table_message_process() { cleantmp(); sky_server *server = sky_server_create(NULL); server->path = bfromcstr("tmp"); sky_message_header *header = sky_message_header_create(); FILE *input = fopen("tests/fixtures/create_table_message/1/input", "r"); FILE *output = fopen("tmp/output", "w"); int rc = sky_create_table_message_process(server, header, NULL, input, output); mu_assert_int_equals(rc, 0); struct tagbstring foo_db_path = bsStatic("tmp/foo"); struct tagbstring foo_db_0_path = bsStatic("tmp/foo/0"); struct tagbstring foo_db_9_path = bsStatic("tmp/foo/9"); mu_assert_bool(sky_file_exists(&foo_db_path)); mu_assert_bool(sky_file_exists(&foo_db_0_path)); mu_assert_bool(sky_file_exists(&foo_db_9_path)); mu_assert_file("tmp/output", "tests/fixtures/create_table_message/1/output"); sky_message_header_free(header); sky_server_free(server); return 0; }
int test_sky_message_header_pack() { cleantmp(); sky_message_header *header = sky_message_header_create(); header->version = 1; header->name = bfromcstr("eadd"); header->table_name = bfromcstr("bar"); FILE *file = fopen("tmp/message", "w"); mu_assert_bool(sky_message_header_pack(header, file) == 0); fclose(file); mu_assert_file("tmp/message", "tests/fixtures/message_header/0/message"); sky_message_header_free(header); return 0; }
int test_sky_create_table_message_pack() { cleantmp(); sky_create_table_message *message = sky_create_table_message_create(); message->data_path = bfromcstr("/tmp/data"); message->table = sky_table_create(); message->table->path = bfromcstr("/tmp/data/foo"); message->table->default_tablet_count = 10; FILE *file = fopen("tmp/message", "w"); mu_assert_bool(sky_create_table_message_pack(message, file) == 0); fclose(file); mu_assert_file("tmp/message", "tests/fixtures/create_table_message/0/message"); sky_table_free(message->table); sky_create_table_message_free(message); return 0; }
int test_sky_importer_import() { cleantmp(); sky_importer *importer = sky_importer_create(); importer->path = bfromcstr("tmp"); FILE *file = fopen("tests/fixtures/importer/0/data.json", "r"); int rc = sky_importer_import(importer, file); mu_assert_int_equals(rc, 0); fclose(file); // Validate. mu_assert_bool(importer->table != NULL); mu_assert_int_equals(importer->table->default_block_size, 128); mu_assert_file("tmp/actions", "tests/fixtures/importer/0/table/actions"); mu_assert_file("tmp/properties", "tests/fixtures/importer/0/table/properties"); mu_assert_file("tmp/0/data", "tests/fixtures/importer/0/table/0/data"); mu_assert_file("tmp/0/header", "tests/fixtures/importer/0/table/0/header"); sky_importer_free(importer); return 0; }
int test_sky_path_iterator_data_file_next() { loadtmp("tests/fixtures/path_iterator/1"); int rc; void *ptr; sky_data_file *data_file = sky_data_file_create(); data_file->path = bfromcstr("tmp/data"); data_file->header_path = bfromcstr("tmp/header"); sky_data_file_load(data_file); sky_path_iterator *iterator = sky_path_iterator_create(); sky_path_iterator_set_data_file(iterator, data_file); mu_assert(iterator->block == NULL, ""); mu_assert(iterator->data_file == data_file, ""); mu_assert_int_equals(iterator->block_index, 0); // Path 1 rc = sky_path_iterator_get_ptr(iterator, &ptr); mu_assert_int_equals(rc, 0); mu_assert_long_equals(ptr-data_file->data, 0L); mu_assert_int_equals(iterator->current_object_id, 2); mu_assert_bool(!iterator->eof); // Path 2 rc = sky_path_iterator_next(iterator); mu_assert_int_equals(rc, 0); mu_assert_int_equals(iterator->byte_index, 19); mu_assert_int_equals(iterator->current_object_id, 3); mu_assert_bool(!iterator->eof); rc = sky_path_iterator_get_ptr(iterator, &ptr); mu_assert_int_equals(rc, 0); mu_assert_long_equals(ptr-data_file->data, 19L); // Path 3 (Spanned) rc = sky_path_iterator_next(iterator); mu_assert_int_equals(rc, 0); mu_assert_int_equals(iterator->byte_index, 0); mu_assert_int_equals(iterator->current_object_id, 4); mu_assert_bool(!iterator->eof); rc = sky_path_iterator_get_ptr(iterator, &ptr); mu_assert_int_equals(rc, 0); mu_assert_long_equals(ptr-data_file->data, 64L); // Path 4 rc = sky_path_iterator_next(iterator); mu_assert_int_equals(rc, 0); mu_assert_int_equals(iterator->byte_index, 0); mu_assert_int_equals(iterator->current_object_id, 5); mu_assert_bool(!iterator->eof); rc = sky_path_iterator_get_ptr(iterator, &ptr); mu_assert_int_equals(rc, 0); mu_assert_long_equals(ptr-data_file->data, 128L); // EOF rc = sky_path_iterator_next(iterator); mu_assert_int_equals(rc, 0); mu_assert_int_equals(iterator->byte_index, 0); mu_assert_bool(iterator->eof); sky_path_iterator_free(iterator); sky_data_file_free(data_file); return 0; }
int test_sky_cursor_sessionize() { // Setup data object. sky_cursor *cursor = sky_cursor_new(-2, 1); sky_cursor_set_timestamp_offset(cursor, offsetof(test_t, timestamp)); sky_cursor_set_ts_offset(cursor, offsetof(test_t, ts)); sky_cursor_set_property(cursor, -2, offsetof(test_t, action_int), sizeof(int32_t), "integer"); sky_cursor_set_property(cursor, -1, offsetof(test_t, action), sizeof(sky_string), "string"); sky_cursor_set_property(cursor, 1, offsetof(test_t, object_int), sizeof(int32_t), "integer"); sky_cursor_set_data_sz(cursor, sizeof(test_t)); // Initialize data and set a 10 second idle time. sky_cursor_set_ptr(cursor, DATA1, DATA1_LENGTH); sky_cursor_set_session_idle(cursor, 10); mu_assert_int_equals(cursor->session_event_index, -1); ASSERT_OBJ_STATE2(cursor->data, 0, "", 0LL, 0LL); // Pre-session mu_assert_bool(sky_lua_cursor_next_event(cursor) == false); mu_assert_int_equals(cursor->session_event_index, -1); ASSERT_OBJ_STATE2(cursor->data, 0, "", 0LL, 0LL); // Session 1 mu_assert_bool(sky_lua_cursor_next_session(cursor)); mu_assert_int_equals(cursor->session_event_index, -1); ASSERT_OBJ_STATE2(cursor->data, 0, "", 0LL, 0LL); // Session 1, Event 1 mu_assert_bool(sky_lua_cursor_next_event(cursor)); mu_assert_int_equals(cursor->session_event_index, 0); ASSERT_OBJ_STATE2(cursor->data, 0, "A1", 1000LL, 0LL); // Session 1, Event 2 mu_assert_bool(sky_lua_cursor_next_event(cursor)); mu_assert_int_equals(cursor->session_event_index, 1); ASSERT_OBJ_STATE2(cursor->data, 1, "A2", 1000LL, 100LL); // Session 1, Event 3 mu_assert_bool(sky_lua_cursor_next_event(cursor)); mu_assert_int_equals(cursor->session_event_index, 2); ASSERT_OBJ_STATE2(cursor->data, 10, "A3", 1000LL, 200LL); // Prevent next session! mu_assert_bool(sky_lua_cursor_next_event(cursor) == false); mu_assert_int_equals(cursor->session_event_index, 2); ASSERT_OBJ_STATE2(cursor->data, 10, "A3", 1000LL, 200LL); // Session 2 (Single Event) mu_assert_bool(sky_lua_cursor_next_session(cursor)); mu_assert_bool(sky_lua_cursor_next_event(cursor)); mu_assert_int_equals(cursor->session_event_index, 0); ASSERT_OBJ_STATE2(cursor->data, 20, "A1", 1000LL, 300LL); mu_assert_bool(sky_lua_cursor_next_event(cursor) == false); // Session 3 (with same data) mu_assert_bool(sky_lua_cursor_next_session(cursor)); mu_assert_int_equals(cursor->session_event_index, -1); ASSERT_OBJ_STATE2(cursor->data, 20, "A1", 1000LL, 300LL); // Session 3, Event 1 mu_assert_bool(sky_lua_cursor_next_event(cursor)); mu_assert_int_equals(cursor->session_event_index, 0); ASSERT_OBJ_STATE2(cursor->data, 60, "A1", 2000LL, 0LL); // Session 3, Event 2 mu_assert_bool(sky_lua_cursor_next_event(cursor)); mu_assert_int_equals(cursor->session_event_index, 1); ASSERT_OBJ_STATE2(cursor->data, 63, "A2", 2000LL, 400LL); // Prevent next session! mu_assert_bool(sky_lua_cursor_next_event(cursor) == false); mu_assert_bool(sky_lua_cursor_next_session(cursor) == false); // EOF! mu_assert_bool(cursor->eof == true); mu_assert_bool(cursor->in_session == false); // Reuse cursor. sky_cursor_set_ptr(cursor, DATA1, DATA1_LENGTH); mu_assert_int_equals(cursor->session_event_index, -1); mu_assert_bool(sky_lua_cursor_next_event(cursor)); mu_assert_int_equals(cursor->session_event_index, 0); ASSERT_OBJ_STATE2(cursor->data, 0, "A1", 1000LL, 0LL); sky_cursor_free(cursor); return 0; }