diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/main.cpp | 2 | ||||
| -rw-r--r-- | tests/peppol_write_tests.cpp | 92 |
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp index fd3557a..234c92d 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,5 +1,6 @@ #include "administration_rw_tests.cpp" #include "administration_validation_tests.cpp" +#include "peppol_write_tests.cpp" GREATEST_MAIN_DEFS(); int main(int argc, char **argv) { @@ -8,5 +9,6 @@ int main(int argc, char **argv) { GREATEST_MAIN_BEGIN(); RUN_SUITE(administration_rw); RUN_SUITE(administration_validate); + RUN_SUITE(peppol_write); GREATEST_MAIN_END(); }
\ No newline at end of file diff --git a/tests/peppol_write_tests.cpp b/tests/peppol_write_tests.cpp new file mode 100644 index 0000000..8e8c102 --- /dev/null +++ b/tests/peppol_write_tests.cpp @@ -0,0 +1,92 @@ +#include "zip.h" +#include "xml.h" + +static contact _create_nl_business() +{ + contact 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)); + strops_copy(pw.taxid, "T123", sizeof(pw.taxid)); + strops_copy(pw.businessid, "B321", sizeof(pw.businessid)); + pw.type = contact_type::CONTACT_BUSINESS; + return pw; +} + +static billing_item _create_bi1(invoice *inv) +{ + 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 buffer[20]; + char* country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code}; + administration_tax_rate_get_by_country(buffer, 2, country_codes); + tax_rate rand_rate = buffer[0]; + strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID); + + return item; +} + +static bool _test_peppol_file(char* id) +{ + bool result = 1; + + zip_extract(test_file_path, "build\\extracted", 0, 0); + system("java -jar libs\\schxslt-cli.jar -d build\\extracted\\I\\2.xml -s libs\\PEPPOL-EN16931-UBL.sch -o build\\invoice_report.xml > NUL 2>&1"); + + FILE* file = fopen("build\\invoice_report.xml", "r"); + struct xml_document* document = xml_open_document(file); + + struct xml_node* root = xml_document_root(document); + + size_t num_children = xml_node_children(root); + for (int i = 0; i < num_children; i++) + { + struct xml_node* node = xml_node_child(root, i); + + char* name = (char*)xml_easy_name(node); + + if (strcmp(name, "svrl:failed-assert") == 0) { + struct xml_node* text_node = xml_easy_child(node, (uint8_t *)"svrl:text", 0); + char* content = (char*)xml_easy_content(text_node); + printf("FAILURE: %s\n", content); + result = 0; + } + } + + return result; +} + +////////////////// +// Netherlands +////////////////// +TEST _peppol_write_outgoing_nl2nl_b2b(void) +{ + administration_writer_create(); + administration_create_empty(test_file_path); + + invoice inv = administration_invoice_create_empty(); + inv.supplier = _create_nl_business(); + inv.customer = _create_nl_business(); + inv.is_outgoing = 1; + inv.status = invoice_status::INVOICE_CONCEPT; + inv.issued_at = time(NULL); + inv.delivered_at = inv.issued_at; + inv.expires_at = inv.issued_at + 1000; + + administration_billing_item_add_to_invoice(&inv, _create_bi1(&inv)); + administration_invoice_add(&inv); + + if (_test_peppol_file(inv.id)) { PASS(); } else { FAIL(); } +} + +SUITE(peppol_write) { + RUN_TEST(_peppol_write_outgoing_nl2nl_b2b); +}
\ No newline at end of file |
