#define _CRT_SECURE_NO_WARNINGS #include #include #include "greatest.h" #include "timer.h" #include "strops.hpp" #include "administration.hpp" #include "administration_reader.hpp" #include "administration_writer.hpp" #ifdef _WIN32 #include // for _unlink #define unlink _unlink #else #include // for unlink #endif char* test_file_path = "build\\test.openbook"; static void setup_cb(void *data) { (void)data; unlink(test_file_path); } static void teardown_cb(void *data) { (void)data; unlink(test_file_path); } TEST _administration_rw_taxrate(void) { tax_rate pw; tax_rate pr; u32 count; administration_writer_create(); administration_create_empty(test_file_path); { pw = administration_tax_rate_create_empty(); strops_copy(pw.country_code, "NL", sizeof(pw.country_code)); pw.rate = 10.0f; strops_copy(pw.category_code, "S", sizeof(pw.category_code)); count = administration_tax_rate_count(); administration_tax_rate_add(pw); ASSERT_EQ(count+1, administration_tax_rate_count()); } administration_reader_open_existing(test_file_path); { ASSERT_EQ(count+1, administration_tax_rate_count()); ASSERT_EQ(A_ERR_SUCCESS, administration_tax_rate_get_by_id(&pr, pw.id)); ASSERT_MEM_EQ(&pw, &pr, sizeof(tax_rate)); } PASS(); } TEST _administration_rw_costcenter(void) { cost_center pw; cost_center pr; u32 count; administration_writer_create(); administration_create_empty(test_file_path); { pw = administration_cost_center_create_empty(); strops_copy(pw.code, "CODE", sizeof(pw.code)); strops_copy(pw.description, "Description", sizeof(pw.description)); count = administration_cost_center_count(); administration_cost_center_add(pw); ASSERT_EQ(count+1, administration_cost_center_count()); } administration_reader_open_existing(test_file_path); { ASSERT_EQ(count+1, administration_cost_center_count()); ASSERT_EQ(A_ERR_SUCCESS, administration_cost_center_get_by_id(&pr, pw.id)); ASSERT_MEM_EQ(&pw, &pr, sizeof(cost_center)); } PASS(); } TEST _administration_rw_project(void) { project pw; project pr; u32 count; administration_writer_create(); administration_create_empty(test_file_path); { pw = administration_project_create_empty(); strops_copy(pw.description, "Test Project", sizeof(pw.description)); count = administration_project_count(); administration_project_add(pw); ASSERT_EQ(count+1, administration_project_count()); } administration_reader_open_existing(test_file_path); { ASSERT_EQ(count+1, administration_project_count()); ASSERT_EQ(A_ERR_SUCCESS, administration_project_get_by_id(&pr, pw.id)); ASSERT_MEM_EQ(&pw, &pr, sizeof(project)); } PASS(); } TEST _administration_rw_contact(void) { contact pw; contact pr; u32 count; administration_writer_create(); administration_create_empty(test_file_path); { pw = administration_contact_create_empty(); strops_copy(pw.name, "John Johnsson", sizeof(pw.name)); strops_copy(pw.address.address1, "Address 1", sizeof(pw.address.address1)); strops_copy(pw.address.country_code, "FR", sizeof(pw.address.country_code)); strops_copy(pw.address.city, "Paris", sizeof(pw.address.city)); strops_copy(pw.address.postal, "12345", sizeof(pw.address.postal)); pw.type = contact_type::CONTACT_CONSUMER; count = administration_contact_count(); administration_contact_add(pw); ASSERT_EQ(count+1, administration_contact_count()); } administration_reader_open_existing(test_file_path); { ASSERT_EQ(count+1, administration_contact_count()); ASSERT_EQ(A_ERR_SUCCESS, administration_contact_get_by_id(&pr, pw.id)); ASSERT_MEM_EQ(&pw, &pr, sizeof(contact)); } PASS(); } TEST _administration_rw_info(void) { administration_writer_create(); s32 next_id, next_sequence_number; administration_create_empty(test_file_path); { next_id = administration_get_next_id(); next_sequence_number = administration_get_next_sequence_number(); } administration_reader_open_existing(test_file_path); { ASSERT_EQ(next_id, administration_get_next_id()); ASSERT_EQ(next_sequence_number, administration_get_next_sequence_number()); } PASS(); } SUITE(administration_rw) { SET_SETUP(setup_cb, NULL); SET_TEARDOWN(teardown_cb, NULL); RUN_TEST(_administration_rw_taxrate); RUN_TEST(_administration_rw_costcenter); RUN_TEST(_administration_rw_project); RUN_TEST(_administration_rw_contact); RUN_TEST(_administration_rw_info); }