diff options
Diffstat (limited to 'tests/administration_rw_tests.cpp')
| -rw-r--r-- | tests/administration_rw_tests.cpp | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/tests/administration_rw_tests.cpp b/tests/administration_rw_tests.cpp new file mode 100644 index 0000000..6d57596 --- /dev/null +++ b/tests/administration_rw_tests.cpp @@ -0,0 +1,165 @@ +#define _CRT_SECURE_NO_WARNINGS + +#include <stdio.h> + +#include "greatest.h" +#include "timer.h" + +#include "strops.hpp" +#include "administration.hpp" +#include "administration_reader.hpp" +#include "administration_writer.hpp" + +char* test_file_path = "C:\\Users\\aldri\\Desktop\\Vault\\Projects\\accounting\\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_taxbracket(void) +{ + country_tax_bracket pw; + country_tax_bracket pr; + u32 count; + + administration_writer_create(); + + administration_create_empty(test_file_path); + { + pw = administration_tax_bracket_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_bracket_count(); + administration_tax_bracket_add(pw); + + ASSERT_EQ(count+1, administration_tax_bracket_count()); + } + + administration_reader_open_existing(test_file_path); + { + ASSERT_EQ(count+1, administration_tax_bracket_count()); + ASSERT_EQ(1, administration_tax_bracket_get_by_id(&pr, pw.id)); + ASSERT_MEM_EQ(&pw, &pr, sizeof(country_tax_bracket)); + } + + 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(1, 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(1, 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(1, administration_contact_get_by_id(&pr, pw.id)); + ASSERT_MEM_EQ(&pw, &pr, sizeof(contact)); + } + + PASS(); +} + +SUITE(administration_rw) { + SET_SETUP(setup_cb, NULL); + SET_TEARDOWN(teardown_cb, NULL); + + RUN_TEST(_administration_rw_taxbracket); + RUN_TEST(_administration_rw_costcenter); + RUN_TEST(_administration_rw_project); + RUN_TEST(_administration_rw_contact); +} + +GREATEST_MAIN_DEFS(); +int main(int argc, char **argv) { + timer_lib_initialize(); + + GREATEST_MAIN_BEGIN(); + RUN_SUITE(administration_rw); + GREATEST_MAIN_END(); +}
\ No newline at end of file |
