summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/administration_rw_tests.cpp119
-rw-r--r--tests/administration_validation_tests.cpp8
-rw-r--r--tests/main.cpp2
-rw-r--r--tests/peppol_write_tests.cpp123
-rw-r--r--tests/test_helper.cpp223
5 files changed, 329 insertions, 146 deletions
diff --git a/tests/administration_rw_tests.cpp b/tests/administration_rw_tests.cpp
index ba5507e..b09fd9e 100644
--- a/tests/administration_rw_tests.cpp
+++ b/tests/administration_rw_tests.cpp
@@ -1,16 +1,3 @@
-#define _CRT_SECURE_NO_WARNINGS
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "greatest.h"
-#include "timer.h"
-
-#include "strops.hpp"
-#include "administration.hpp"
-#include "administration_reader.hpp"
-#include "administration_writer.hpp"
-
#ifdef _WIN32
#include <io.h> // for _unlink
#define unlink _unlink
@@ -18,8 +5,6 @@
#include <unistd.h> // for unlink
#endif
-char* test_file_path = "build\\test.openbook";
-
static void setup_cb(void *data) {
(void)data;
unlink(test_file_path);
@@ -174,6 +159,109 @@ TEST _administration_rw_info(void)
PASS();
}
+TEST _administration_rw_invoice(void)
+{
+ u32 count;
+ invoice inv;
+ invoice invr;
+
+ administration_writer_create();
+
+ administration_create_default(test_file_path);
+ {
+ contact pw = administration_contact_create_empty();
+ strops_copy(pw.name, "Piet Pinda", sizeof(pw.name));
+ strops_copy(pw.address.address1, "Address 1", sizeof(pw.address.address1));
+ strops_copy(pw.address.country_code, "NL", sizeof(pw.address.country_code));
+ strops_copy(pw.address.city, "Amsterdam", sizeof(pw.address.city));
+ strops_copy(pw.address.postal, "1234AA", sizeof(pw.address.postal));
+ strops_copy(pw.taxid, "T123", sizeof(pw.taxid));
+ strops_copy(pw.businessid, "B321", sizeof(pw.businessid));
+ strops_copy(pw.email, "test@test.com", sizeof(pw.email));
+ pw.type = contact_type::CONTACT_BUSINESS;
+
+ inv = administration_invoice_create_empty();
+ inv.supplier = pw;
+ inv.customer = pw;
+ 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_bi3(&inv));
+ administration_billing_item_add_to_invoice(&inv, _create_bi4(&inv));
+ administration_billing_item_add_to_invoice(&inv, _create_bi5(&inv));
+ administration_billing_item_add_to_invoice(&inv, _create_bi6(&inv));
+
+ count = administration_invoice_count();
+ ASSERT_EQ(administration_invoice_add(&inv), A_ERR_SUCCESS);
+ ASSERT_EQ(count+1, administration_invoice_count());
+ }
+
+ administration_reader_open_existing(test_file_path);
+ {
+ ASSERT_EQ(count+1, administration_invoice_count());
+ ASSERT_EQ(A_ERR_SUCCESS, administration_invoice_get_by_id(&invr, inv.id));
+
+ ASSERT_STR_EQ(invr.id, inv.id);
+ ASSERT_STR_EQ(invr.sequential_number, inv.sequential_number);
+ ASSERT_STR_EQ(invr.customer_id, inv.customer_id);
+ ASSERT_STR_EQ(invr.supplier_id, inv.supplier_id);
+
+ ASSERT_EQ(invr.issued_at, inv.issued_at);
+ ASSERT_EQ(invr.expires_at, inv.expires_at);
+ ASSERT_EQ(invr.delivered_at, inv.delivered_at);
+ ASSERT_STR_EQ(invr.document, inv.document);
+ ASSERT_STR_EQ(invr.project_id, inv.project_id);
+ ASSERT_STR_EQ(invr.cost_center_id, inv.cost_center_id);
+
+ ASSERT_EQ(administration_billing_item_count(&inv), administration_billing_item_count(&invr));
+
+ int num_items = administration_billing_item_count(&inv);
+ for (int i = 0; i < num_items; i++)
+ {
+ billing_item* b1 = (billing_item*)list_get_at(&inv.billing_items, i);
+ billing_item* b2 = (billing_item*)list_get_at(&invr.billing_items, i);
+
+ ASSERT_STR_EQ(b1->id, b2->id);
+ ASSERT_EQ(b1->amount, b2->amount);
+ ASSERT_EQ(b1->amount_is_percentage, b2->amount_is_percentage);
+ ASSERT_STR_EQ(b1->description, b2->description);
+ ASSERT_EQ(b1->net_per_item, b2->net_per_item);
+ ASSERT_EQ(b1->discount, b2->discount);
+ ASSERT_EQ(b1->discount_is_percentage, b2->discount_is_percentage);
+ ASSERT_EQ(b1->allowance, b2->allowance);
+ ASSERT_EQ(b1->net, b2->net);
+ ASSERT_STR_EQ(b1->currency, b2->currency);
+ ASSERT_STR_EQ(b1->tax_rate_id, b2->tax_rate_id);
+ ASSERT_EQ(b1->tax, b2->tax);
+ ASSERT_EQ(b1->total, b2->total);
+ }
+
+ ASSERT_EQ(invr.orig_total, inv.orig_total);
+ ASSERT_EQ(invr.orig_tax, inv.orig_tax);
+ ASSERT_EQ(invr.orig_net, inv.orig_net);
+ ASSERT_EQ(invr.orig_allowance, inv.orig_allowance);
+
+ ASSERT_EQ(invr.total, inv.total);
+ ASSERT_EQ(invr.tax, inv.tax);
+ ASSERT_EQ(invr.net, inv.net);
+ ASSERT_EQ(invr.allowance, inv.allowance);
+
+ ASSERT_STR_EQ(invr.currency, inv.currency);
+ ASSERT_EQ(invr.is_triangulation, inv.is_triangulation);
+ ASSERT_EQ(invr.status, inv.status);
+ ASSERT_EQ(invr.is_outgoing, inv.is_outgoing);
+ ASSERT_MEM_EQ(&invr.payment_means, &inv.payment_means, sizeof(payment_information));
+ ASSERT_MEM_EQ(&invr.supplier, &inv.supplier, sizeof(contact));
+ ASSERT_MEM_EQ(&invr.customer, &inv.customer, sizeof(contact));
+ ASSERT_MEM_EQ(&invr.addressee, &inv.addressee, sizeof(contact));
+ }
+
+ PASS();
+}
+
SUITE(administration_rw) {
SET_SETUP(setup_cb, NULL);
SET_TEARDOWN(teardown_cb, NULL);
@@ -183,4 +271,5 @@ SUITE(administration_rw) {
RUN_TEST(_administration_rw_project);
RUN_TEST(_administration_rw_contact);
RUN_TEST(_administration_rw_info);
+ RUN_TEST(_administration_rw_invoice);
} \ No newline at end of file
diff --git a/tests/administration_validation_tests.cpp b/tests/administration_validation_tests.cpp
index f307d2d..f406efd 100644
--- a/tests/administration_validation_tests.cpp
+++ b/tests/administration_validation_tests.cpp
@@ -1,11 +1,3 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "greatest.h"
-#include "timer.h"
-
-#include "strops.hpp"
-#include "administration.hpp"
// Project
//////////////////
diff --git a/tests/main.cpp b/tests/main.cpp
index 234c92d..358ca2e 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -1,3 +1,5 @@
+#include "test_helper.cpp"
+
#include "administration_rw_tests.cpp"
#include "administration_validation_tests.cpp"
#include "peppol_write_tests.cpp"
diff --git a/tests/peppol_write_tests.cpp b/tests/peppol_write_tests.cpp
index c00b53b..fb74ed7 100644
--- a/tests/peppol_write_tests.cpp
+++ b/tests/peppol_write_tests.cpp
@@ -1,126 +1,3 @@
-#include <malloc.h>
-
-#include "zip.h"
-#include "xml.h"
-
-char* validation_file = "libs\\PEPPOL-EN16931-UBL.sch";
-char* result_file = "build\\invoice_report.xml";
-char* extract_dir = "build\\extracted";
-
-static contact _create_nl_business()
-{
- contact pw = administration_contact_create_empty();
- strops_copy(pw.name, "Piet Pinda", sizeof(pw.name));
- strops_copy(pw.address.address1, "Address 1", sizeof(pw.address.address1));
- strops_copy(pw.address.country_code, "NL", sizeof(pw.address.country_code));
- strops_copy(pw.address.city, "Amsterdam", sizeof(pw.address.city));
- strops_copy(pw.address.postal, "1234AA", sizeof(pw.address.postal));
- strops_copy(pw.taxid, "T123", sizeof(pw.taxid));
- strops_copy(pw.businessid, "B321", sizeof(pw.businessid));
- strops_copy(pw.email, "test@test.com", sizeof(pw.email));
- pw.type = contact_type::CONTACT_BUSINESS;
- return pw;
-}
-
-static contact _create_nl_consumer()
-{
- contact pw = _create_nl_business();
- pw.type = contact_type::CONTACT_CONSUMER;
- 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};
- u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
- tax_rate rand_rate = buffer[tax_rate_count-1];
- strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
-
- return item;
-}
-
-static billing_item _create_bi2(invoice *inv)
-{
- 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 buffer[20];
- char* _country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code};
- u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
- tax_rate rand_rate = buffer[tax_rate_count-1];
- 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, extract_dir, 0, 0);
-
- char command[200];
- snprintf(command, 200, "java -jar libs\\schxslt-cli.jar -d %s\\%s.xml -s %s -o %s > NUL 2>&1",
- extract_dir, id, validation_file, result_file);
- system(command);
-
- FILE* file = fopen(result_file, "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);
-
- size_t num_attributes = xml_node_attributes(node);
- for (int x = 0; x < num_attributes; x++)
- {
- struct xml_string* attr_name = xml_node_attribute_name(node, x);
- size_t b_length = xml_string_length(attr_name);
- uint8_t* b_buffer = (uint8_t*)alloca((b_length + 1) * sizeof(uint8_t));
- xml_string_copy(attr_name, b_buffer, b_length);
- b_buffer[b_length] = 0;
-
- if (strcmp((char*)b_buffer, "location") == 0) {
- struct xml_string* attr_content = xml_node_attribute_content(node, x);
-
- size_t a_length = xml_string_length(attr_content);
- uint8_t* a_buffer = (uint8_t*)alloca((a_length + 1) * sizeof(uint8_t));
- xml_string_copy(attr_content, a_buffer, a_length);
- a_buffer[a_length] = 0;
-
- printf("FAILURE: %s @ %s\n", content, (char*)a_buffer);
- }
- }
-
- result = 0;
- }
- }
-
- return result;
-}
//////////////////
// Netherlands
diff --git a/tests/test_helper.cpp b/tests/test_helper.cpp
new file mode 100644
index 0000000..aedaccc
--- /dev/null
+++ b/tests/test_helper.cpp
@@ -0,0 +1,223 @@
+#define _CRT_SECURE_NO_WARNINGS
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <malloc.h>
+
+#include "zip.h"
+#include "xml.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 = "build\\test.openbook";
+char* validation_file = "libs\\PEPPOL-EN16931-UBL.sch";
+char* result_file = "build\\invoice_report.xml";
+char* extract_dir = "build\\extracted";
+
+static contact _create_nl_business()
+{
+ contact pw = administration_contact_create_empty();
+ strops_copy(pw.name, "Dutch Company BV", sizeof(pw.name));
+ strops_copy(pw.address.address1, "Address 1", sizeof(pw.address.address1));
+ strops_copy(pw.address.country_code, "NL", sizeof(pw.address.country_code));
+ strops_copy(pw.address.city, "Amsterdam", sizeof(pw.address.city));
+ strops_copy(pw.address.region, "Noord-Holland", sizeof(pw.address.region));
+ strops_copy(pw.address.postal, "1234AA", sizeof(pw.address.postal));
+ strops_copy(pw.taxid, "T123", sizeof(pw.taxid));
+ strops_copy(pw.businessid, "B321", sizeof(pw.businessid));
+ strops_copy(pw.email, "test@test.com", sizeof(pw.email));
+ strops_copy(pw.phone_number, "+311234567", sizeof(pw.phone_number));
+ strops_copy(pw.bank_account, "IBAN123456789", sizeof(pw.bank_account));
+ pw.type = contact_type::CONTACT_BUSINESS;
+ return pw;
+}
+
+static contact _create_nl_consumer()
+{
+ contact pw = administration_contact_create_empty();
+ strops_copy(pw.name, "Piet Pinda", sizeof(pw.name));
+ strops_copy(pw.address.address1, "Address 2", sizeof(pw.address.address1));
+ strops_copy(pw.address.country_code, "NL", sizeof(pw.address.country_code));
+ strops_copy(pw.address.city, "Maastricht", sizeof(pw.address.city));
+ strops_copy(pw.address.region, "Limburg", sizeof(pw.address.region));
+ strops_copy(pw.address.postal, "4321AA", sizeof(pw.address.postal));
+ strops_copy(pw.email, "test@test.com", sizeof(pw.email));
+ strops_copy(pw.phone_number, "+317654321", sizeof(pw.phone_number));
+ pw.type = contact_type::CONTACT_CONSUMER;
+ 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};
+ u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
+ tax_rate rand_rate = buffer[tax_rate_count-1];
+ strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
+
+ return item;
+}
+
+static billing_item _create_bi2(invoice *inv)
+{
+ 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 buffer[20];
+ char* _country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code};
+ u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
+ tax_rate rand_rate = buffer[tax_rate_count-1];
+ strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
+
+ return item;
+}
+
+static billing_item _create_bi3(invoice *inv)
+{
+ billing_item item = administration_billing_item_create_empty();
+ item.amount = 1;
+ item.amount_is_percentage = 0;
+ strops_copy(item.description, "Guacamole", 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};
+ u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
+ tax_rate rand_rate = buffer[tax_rate_count-1];
+ strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
+
+ return item;
+}
+
+static billing_item _create_bi4(invoice *inv)
+{
+ billing_item item = administration_billing_item_create_empty();
+ item.amount = 3;
+ item.amount_is_percentage = 0;
+ strops_copy(item.description, "Bananas", MAX_LEN_LONG_DESC);
+ item.net_per_item = 4.00f;
+ item.discount = 0.0f;
+ item.discount_is_percentage = 0;
+
+ tax_rate buffer[20];
+ char* _country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code};
+ u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
+ tax_rate rand_rate = buffer[tax_rate_count-1];
+ strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
+
+ return item;
+}
+
+static billing_item _create_bi5(invoice *inv)
+{
+ billing_item item = administration_billing_item_create_empty();
+ item.amount = 5;
+ item.amount_is_percentage = 0;
+ strops_copy(item.description, "Apple", MAX_LEN_LONG_DESC);
+ item.net_per_item = 1.00f;
+ item.discount = 5.0f;
+ item.discount_is_percentage = 1;
+
+ tax_rate buffer[20];
+ char* _country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code};
+ u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
+ tax_rate rand_rate = buffer[tax_rate_count-1];
+ strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
+
+ return item;
+}
+
+static billing_item _create_bi6(invoice *inv)
+{
+ billing_item item = administration_billing_item_create_empty();
+ item.amount = 10;
+ item.amount_is_percentage = 1;
+ strops_copy(item.description, "Tip", MAX_LEN_LONG_DESC);
+ item.net_per_item = 50.00f;
+ item.discount = 0.0f;
+ item.discount_is_percentage = 0;
+
+ tax_rate buffer[20];
+ char* _country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code};
+ u32 tax_rate_count = administration_tax_rate_get_by_country(buffer, 2, _country_codes);
+ tax_rate rand_rate = buffer[tax_rate_count-1];
+ 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, extract_dir, 0, 0);
+
+ char command[200];
+ snprintf(command, 200, "java -jar libs\\schxslt-cli.jar -d %s\\%s.xml -s %s -o %s > NUL 2>&1",
+ extract_dir, id, validation_file, result_file);
+ system(command);
+
+ FILE* file = fopen(result_file, "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);
+
+ size_t num_attributes = xml_node_attributes(node);
+ for (int x = 0; x < num_attributes; x++)
+ {
+ struct xml_string* attr_name = xml_node_attribute_name(node, x);
+ size_t b_length = xml_string_length(attr_name);
+ uint8_t* b_buffer = (uint8_t*)alloca((b_length + 1) * sizeof(uint8_t));
+ xml_string_copy(attr_name, b_buffer, b_length);
+ b_buffer[b_length] = 0;
+
+ if (strcmp((char*)b_buffer, "location") == 0) {
+ struct xml_string* attr_content = xml_node_attribute_content(node, x);
+
+ size_t a_length = xml_string_length(attr_content);
+ uint8_t* a_buffer = (uint8_t*)alloca((a_length + 1) * sizeof(uint8_t));
+ xml_string_copy(attr_content, a_buffer, a_length);
+ a_buffer[a_length] = 0;
+
+ printf("FAILURE: %s @ %s\n", content, (char*)a_buffer);
+ }
+ }
+
+ result = 0;
+ }
+ }
+
+ return result;
+} \ No newline at end of file