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_action_file_save() { int rc; struct tagbstring path = bsStatic("tmp/actions"); // Initialize action file. sky_action_file *action_file = sky_action_file_create(); sky_action_file_set_path(action_file, &path); // Action 1 sky_action *action1 = sky_action_create(); action1->name = bfromcstr("foo"); rc = sky_action_file_add_action(action_file, action1); mu_assert_int_equals(rc, 0); mu_assert_int_equals(action_file->action_count, 1); // Action 2 sky_action *action2 = sky_action_create(); action2->name = bfromcstr("this_is_a_really_long_action_name_woohoo"); rc = sky_action_file_add_action(action_file, action2); mu_assert_int_equals(rc, 0); mu_assert_int_equals(action_file->action_count, 2); // Save rc = sky_action_file_save(action_file); mu_assert_int_equals(rc, 0); mu_assert_file("tmp/actions", "tests/fixtures/action_files/0"); sky_action_file_free(action_file); return 0; }
int test_sky_add_event_message_pack() { cleantmp(); sky_add_event_message *message = create_message_with_data(); FILE *file = fopen("tmp/message", "w"); mu_assert_bool(sky_add_event_message_pack(message, file) == 0); fclose(file); mu_assert_file("tmp/message", "tests/fixtures/add_event_message/0/message"); sky_add_event_message_free(message); return 0; }
int test_sky_get_actions_message_process() { loadtmp("tests/fixtures/get_actions_message/1/table"); sky_server *server = sky_server_create(NULL); sky_message_header *header = sky_message_header_create(); sky_table *table = sky_table_create(); table->path = bfromcstr("tmp"); sky_table_open(table); FILE *input = fopen("tests/fixtures/get_actions_message/1/input", "r"); FILE *output = fopen("tmp/output", "w"); int rc = sky_get_actions_message_process(server, header, table, input, output); mu_assert_int_equals(rc, 0); mu_assert_file("tmp/actions", "tests/fixtures/get_actions_message/1/table/actions"); mu_assert_file("tmp/output", "tests/fixtures/get_actions_message/1/output"); sky_table_free(table); sky_message_header_free(header); sky_server_free(server); return 0; }
int test_sky_get_actions_message_pack() { cleantmp(); sky_get_actions_message *message = sky_get_actions_message_create(); FILE *file = fopen("tmp/message", "w"); mu_assert_bool(sky_get_actions_message_pack(message, file) == 0); fclose(file); mu_assert_file("tmp/message", "tests/fixtures/get_actions_message/0/message"); sky_get_actions_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_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_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_add_event_message_worker_write() { sky_add_event_message *message = sky_add_event_message_create(); sky_worker *worker = sky_worker_create(); worker->data = (void*)message; worker->output = fopen("tmp/output", "w"); int rc = sky_add_event_message_worker_write(worker, worker->output); mu_assert_int_equals(rc, 0); sky_add_event_message_free(message); sky_worker_free(worker); mu_assert_file("tmp/output", "tests/fixtures/add_event_message/1/output"); 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_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_peach_message_process() { importtmp("tests/fixtures/peach_message/1/import.json"); sky_table *table = sky_table_create(); table->path = bfromcstr("tmp"); sky_table_open(table); // NOTE: The table contains two properties: foo (String) and this_is_a_really...(Int) sky_peach_message *message = sky_peach_message_create(); message->query = bfromcstr( "[Hashable(\"id\")]\n" "[Serializable]\n" "class Result {\n" " public Int id;\n" " public Int count;\n" " public Int objectTotal;\n" " public Int actionTotal;\n" "}\n" "Cursor cursor = path.events();\n" "for each (Event event in cursor) {\n" " String dynamic_prop2 = event.this_is_a_really_long_property_name_woohoo;\n" " Result item = data.get(event.actionId);\n" " item.count = item.count + 1;\n" " item.objectTotal = item.objectTotal + event.object_prop;\n" " item.actionTotal = item.actionTotal + event.action_prop;\n" "}\n" "return;" ); FILE *output = fopen("tmp/output", "w"); mu_assert(sky_peach_message_process(message, table, output) == 0, ""); fclose(output); mu_assert_file("tmp/output", "tests/fixtures/peach_message/1/output"); sky_peach_message_free(message); sky_table_free(table); return 0; }