From 9b8664daf17dac9efb1f4add9d00c562e4ddbf40 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 1 Nov 2025 08:58:34 +0100 Subject: fix tests --- TODO | 5 ++++ run.bat | 3 ++- src/administration_writer.cpp | 48 +++++++++++++++++++++++++++++++-------- src/countries.cpp | 2 ++ src/countries/nl.cpp | 2 ++ tests/administration_rw_tests.cpp | 12 ++-------- tests/test_helper.cpp | 35 ---------------------------- 7 files changed, 51 insertions(+), 56 deletions(-) diff --git a/TODO b/TODO index e30ccac..8a68caa 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ TODO: +Fix: + Refactor: - Refactor zip writing to be faster @@ -11,6 +13,9 @@ Improvements: - "price includes tax" toggle that recalculates billing item tax, net and total Features: +- Timeline for invoice modifications (e.g. edited, status changed, paid) +- When creating a new openbooks file, user should only be able to set company info before anything else. +- Show AI balance available in settings page - Handle invalid api key response from AI backends and display in settings UI - error log for tax report to display invoices not yet supported for tax generation or invoices with invalid tax rates - minimum invoice date for tax report generation, show warnings for unsupported invoices diff --git a/run.bat b/run.bat index 164f84a..1f13fcc 100644 --- a/run.bat +++ b/run.bat @@ -42,10 +42,11 @@ set LIB_SOURCES=libs\imgui-1.92.1\backends\imgui_impl_dx11.cpp^ @set LIBS=opengl32.lib Advapi32.lib Shell32.lib Ole32.lib User32.lib Pathcch.lib D3D11.lib Comdlg32.lib Kernel32.lib /LIBPATH:"libs/openssl-3.6.0-beta1/x64/lib" libssl.lib libcrypto.lib @set FLAGS=/nologo /Ob0 /MD /Oy- /Zi /FS /W4 /EHsc /utf-8 /F16000000 @set INCLUDE_DIRS=/I"libs/imgui-1.92.1" /I"libs/imgui-1.92.1/backends" /I"/" /I"libs/openssl-3.6.0-beta1/x64/include" /I"libs/cpp-httplib" /I"libs/timer_lib" /I"libs/greatest" /I"libs/simclist-1.5" /I"libs/tinyfiledialogs" /I"libs/zip/src" /I"libs/xml.c/src" /I"libs/" /Iinclude -@set DEFINITIONS=/D_BUILD_DATE_=\"%date%\" /D_COMMIT_=\"%COMMIT_ID%\" /D_PLATFORM_=\"win64\" /D_CRT_SECURE_NO_WARNINGS +@set DEFINITIONS=/D_PLATFORM_=\"win64\" /D_CRT_SECURE_NO_WARNINGS if "%1"=="-t" @set SOURCES= tests\main.cpp src\administration.cpp src\administration_writer.cpp src\administration_reader.cpp src\strops.cpp src\logger.cpp src\locales.cpp src\locales\*.cpp src\ai_providers\*.cpp src\importer.cpp src\memops.cpp src\countries.cpp if "%1"=="-t" @set OUT_EXE=accounting_tests +if "%1"=="-t" @set DEFINITIONS=/D_PLATFORM_=\"win64\" /D_CRT_SECURE_NO_WARNINGS /D_TESTING_MODE_ cl %FLAGS% %INCLUDE_DIRS% %DEFINITIONS% %SOURCES% %LIB_SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fd%OUT_DIR%/vc140.pdb /Fo%OUT_DIR%/ /link %LIBS% if "%1"=="-r" call "%OUT_DIR%/%OUT_EXE%.exe" C:\Users\aldri\Desktop\Vault\Projects\accounting\build\example.openbook diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp index c45ec6e..c699a0a 100644 --- a/src/administration_writer.cpp +++ b/src/administration_writer.cpp @@ -54,8 +54,12 @@ static void on_administration_data_changed() if (_write_completed_ev) _write_completed_ev(); }); - auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(); delete f; return 0; }; + auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(); return 0; }; thrd_t thr; thrd_create(&thr, trampoline, 0); + + #ifdef _TESTING_MODE_ + thrd_join(thr, 0); + #endif } static void on_administration_data_deleted(char id[MAX_LEN_ID]) @@ -75,8 +79,12 @@ static void on_administration_data_deleted(char id[MAX_LEN_ID]) if (_write_completed_ev) _write_completed_ev(); }); - auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); delete f; return 0; }; + auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); return 0; }; thrd_t thr; thrd_create(&thr, trampoline, (void*)id_copy); + + #ifdef _TESTING_MODE_ + thrd_join(thr, 0); + #endif } static void on_invoice_changed(invoice* inv) @@ -97,8 +105,12 @@ static void on_invoice_changed(invoice* inv) if (_write_completed_ev) _write_completed_ev(); }); - auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); delete f; return 0; }; + auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); return 0; }; thrd_t thr; thrd_create(&thr, trampoline, (void*)inv_copy2); + + #ifdef _TESTING_MODE_ + thrd_join(thr, 0); + #endif } static void on_contact_changed_changed(contact* cc) @@ -107,19 +119,23 @@ static void on_contact_changed_changed(contact* cc) contact* cc_copy = (contact*)memops::alloc(sizeof(contact)); memops::copy(cc_copy, cc, sizeof(contact)); - + auto* func = new auto([](void* arg) { contact* cc = (contact*)arg; administration_writer::save_contact_blocking(*cc); administration_writer::save_administration_info_blocking(); memops::unalloc(arg); - + _is_writing = false; if (_write_completed_ev) _write_completed_ev(); }); - auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); delete f; return 0; }; + auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); return 0; }; thrd_t thr; thrd_create(&thr, trampoline, (void*)cc_copy); + + #ifdef _TESTING_MODE_ + thrd_join(thr, 0); + #endif } static void on_taxrate_changed_changed(tax_rate* rate) @@ -139,8 +155,12 @@ static void on_taxrate_changed_changed(tax_rate* rate) if (_write_completed_ev) _write_completed_ev(); }); - auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); delete f; return 0; }; + auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); return 0; }; thrd_t thr; thrd_create(&thr, trampoline, (void*)rate_copy); + + #ifdef _TESTING_MODE_ + thrd_join(thr, 0); + #endif } static void on_costcenter_changed_changed(cost_center* cc) @@ -159,8 +179,12 @@ static void on_costcenter_changed_changed(cost_center* cc) if (_write_completed_ev) _write_completed_ev(); }); - auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); delete f; return 0; }; + auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); return 0; }; thrd_t thr; thrd_create(&thr, trampoline, (void*)cc_copy); + + #ifdef _TESTING_MODE_ + thrd_join(thr, 0); + #endif } static void on_project_changed_changed(project* pp) @@ -180,8 +204,12 @@ static void on_project_changed_changed(project* pp) if (_write_completed_ev) _write_completed_ev(); }); - auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); delete f; return 0; }; - thrd_t thr; thrd_create(&thr, trampoline, (void*)pp_copy); + auto trampoline = [](void* arg) -> int { auto* f = static_cast(arg); (*f)(arg); return 0; }; + thrd_t thr; thrd_create(&thr, trampoline, (void*)pp_copy); + + #ifdef _TESTING_MODE_ + thrd_join(thr, 0); + #endif } bool administration_writer::create() diff --git a/src/countries.cpp b/src/countries.cpp index 337b10b..34aacf1 100644 --- a/src/countries.cpp +++ b/src/countries.cpp @@ -312,5 +312,7 @@ u32 country::get_available_tax_rates(char* country_code, tax_rate* buffer, u32 b s32 index = get_index_by_country_code(country_code); assert(index != -1); + if (!country_map[index].get_available_tax_rates) return 0; + return country_map[index].get_available_tax_rates(buffer, buffer_size); } \ No newline at end of file diff --git a/src/countries/nl.cpp b/src/countries/nl.cpp index c4abc9d..8a56e71 100644 --- a/src/countries/nl.cpp +++ b/src/countries/nl.cpp @@ -30,6 +30,7 @@ #include #include "countries.hpp" +#include "memops.hpp" #include "strops.hpp" time_t _nl_get_default_invoice_expire_duration() @@ -172,6 +173,7 @@ static tax_rate _create_tax_rate(tax_rate_type type, char* internal_code, char* static tax_rate _create_tax_rate(tax_rate_type type, char* internal_code, float rate, ...) { tax_rate result; + memops::zero(&result, sizeof(tax_rate)); result.type = type; result.tax_section_count = 0; result.rate = rate; diff --git a/tests/administration_rw_tests.cpp b/tests/administration_rw_tests.cpp index 794c12a..be52f5f 100644 --- a/tests/administration_rw_tests.cpp +++ b/tests/administration_rw_tests.cpp @@ -18,20 +18,13 @@ static void teardown_cb(void *data) { 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(); - pw.rate = 10.0f; - pw.type = tax_rate_type::TAX_RATE_OUTGOING_INVOICE; - strops::copy(pw.internal_code, "NL/21", sizeof(pw.internal_code)); - strops::copy(pw.category_code, "S", sizeof(pw.category_code)); - strops::copy(pw.tax_sections[pw.tax_section_count++], "NL/1a", MAX_LEN_SHORT_DESC); - + administration::tax_rate_get_by_internal_code(&pw, "NL/21"); count = administration::tax_rate_count(); administration::tax_rate_enable(pw); @@ -41,8 +34,7 @@ TEST _administration_rw_taxrate(void) 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_internal_code(&pr, pw.internal_code)); - ASSERT_MEM_EQ(&pw, &pr, sizeof(tax_rate)); + ASSERT_EQ(A_ERR_SUCCESS, administration::tax_rate_is_enabled(pw)); } PASS(); diff --git a/tests/test_helper.cpp b/tests/test_helper.cpp index 980fe8c..c99bdd0 100644 --- a/tests/test_helper.cpp +++ b/tests/test_helper.cpp @@ -48,41 +48,6 @@ static contact _create_nl_consumer() return pw; } - -static billing_item _create_bi1() -{ - billing_item item = administration::billing_item_create_empty(); - item.amount = 1; - item.amount_is_percentage = 0; - strops::copy(item.description, "Shampoo", MAX_LEN_LONG_DESC); - item.net_per_item = 10.00f; - item.discount = 2.0f; - item.discount_is_percentage = 0; - - tax_rate rate; - administration::tax_rate_get_by_internal_code(&rate, "NL/21"); - strops::copy(item.tax_internal_code, rate.internal_code, MAX_LEN_SHORT_DESC); - - return item; -} - -static billing_item _create_bi2() -{ - billing_item item = administration::billing_item_create_empty(); - item.amount = 2; - item.amount_is_percentage = 0; - strops::copy(item.description, "Soap", MAX_LEN_LONG_DESC); - item.net_per_item = 5.00f; - item.discount = 5.0f; - item.discount_is_percentage = 1; - - tax_rate rate; - administration::tax_rate_get_by_internal_code(&rate, "NL/21"); - strops::copy(item.tax_internal_code, rate.internal_code, MAX_LEN_SHORT_DESC); - - return item; -} - static billing_item _create_bi3() { billing_item item = administration::billing_item_create_empty(); -- cgit v1.2.3-70-g09d2