summaryrefslogtreecommitdiff
path: root/tests/peppol_write_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/peppol_write_tests.cpp')
-rw-r--r--tests/peppol_write_tests.cpp86
1 files changed, 75 insertions, 11 deletions
diff --git a/tests/peppol_write_tests.cpp b/tests/peppol_write_tests.cpp
index 8e8c102..e77f128 100644
--- a/tests/peppol_write_tests.cpp
+++ b/tests/peppol_write_tests.cpp
@@ -1,20 +1,38 @@
+#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, "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.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));
pw.type = contact_type::CONTACT_BUSINESS;
return pw;
}
+static contact _create_nl_consumer()
+{
+ contact pw = administration_contact_create_empty();
+ strops_copy(pw.name, "Hans Klok", 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, "Amsterdam", sizeof(pw.address.city));
+ strops_copy(pw.address.postal, "4321AA", sizeof(pw.address.postal));
+ pw.type = contact_type::CONTACT_CONSUMER;
+ return pw;
+}
+
static billing_item _create_bi1(invoice *inv)
{
billing_item item = administration_billing_item_create_empty();
@@ -38,10 +56,14 @@ 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");
+ zip_extract(test_file_path, extract_dir, 0, 0);
- FILE* file = fopen("build\\invoice_report.xml", "r");
+ 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);
@@ -56,7 +78,28 @@ static bool _test_peppol_file(char* id)
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);
+
+ 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;
}
}
@@ -67,10 +110,10 @@ static bool _test_peppol_file(char* id)
//////////////////
// Netherlands
//////////////////
-TEST _peppol_write_outgoing_nl2nl_b2b(void)
+TEST _peppol_write_nl2nl_b2b(void)
{
administration_writer_create();
- administration_create_empty(test_file_path);
+ administration_create_default(test_file_path);
invoice inv = administration_invoice_create_empty();
inv.supplier = _create_nl_business();
@@ -82,11 +125,32 @@ TEST _peppol_write_outgoing_nl2nl_b2b(void)
inv.expires_at = inv.issued_at + 1000;
administration_billing_item_add_to_invoice(&inv, _create_bi1(&inv));
- administration_invoice_add(&inv);
+ ASSERT_EQ(administration_invoice_add(&inv), A_ERR_SUCCESS);
+
+ if (_test_peppol_file(inv.id)) { PASS(); } else { FAIL(); }
+}
+
+TEST _peppol_write_nl2nl_b2c(void)
+{
+ administration_writer_create();
+ administration_create_default(test_file_path);
+
+ invoice inv = administration_invoice_create_empty();
+ inv.supplier = _create_nl_business();
+ inv.customer = _create_nl_consumer();
+ 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));
+ ASSERT_EQ(administration_invoice_add(&inv), A_ERR_SUCCESS);
if (_test_peppol_file(inv.id)) { PASS(); } else { FAIL(); }
}
SUITE(peppol_write) {
- RUN_TEST(_peppol_write_outgoing_nl2nl_b2b);
+ RUN_TEST(_peppol_write_nl2nl_b2b);
+ RUN_TEST(_peppol_write_nl2nl_b2c);
} \ No newline at end of file