test: Add tests for isd_get_commercial_credit()
[libisds.git] / test / offline / isds-dbtype.c
blob67b8a53a7c67b0e0e9b82f4e195cc7c5c59db153
1 #include "../test.h"
2 #include "isds.c"
4 static int test_dbtype2string_must_fail(const isds_DbType type) {
5 xmlChar *string;
7 string = (xmlChar *) isds_DbType2string(type);
8 if (string)
9 FAIL_TEST("conversion from isds_DbType to string did not fail");
11 PASS_TEST;
14 static int test_string2dbtype_must_fail(const xmlChar *string) {
15 isds_error err;
16 isds_DbType new_type;
18 err = string2isds_DbType((xmlChar *)string, &new_type);
19 if (!err)
20 FAIL_TEST("conversion from string to isds_DbTyoe did not fail");
22 PASS_TEST;
25 static int test_dbtype(const isds_DbType type, const xmlChar *name) {
26 xmlChar *string;
27 isds_error err;
28 isds_DbType new_type;
30 string = (xmlChar *) isds_DbType2string(type);
31 if (!string)
32 FAIL_TEST("conversion from isds_DbType to string failed");
34 if (xmlStrcmp(name, string))
35 FAIL_TEST("Wrong to string conversion result");
37 err = string2isds_DbType(string, &new_type);
38 if (err)
39 FAIL_TEST("conversion from string to isds_DbTyoe failed");
41 if (type != new_type)
42 FAIL_TEST("double conversion not idempotent");
44 PASS_TEST;
47 int main(int argc, char **argv) {
48 INIT_TEST("isds_DbType conversion");
50 isds_DbType types[] = {
51 DBTYPE_OVM,
52 DBTYPE_OVM_NOTAR,
53 DBTYPE_OVM_EXEKUT,
54 DBTYPE_OVM_REQ,
55 DBTYPE_PO,
56 DBTYPE_PO_ZAK,
57 DBTYPE_PO_REQ,
58 DBTYPE_PFO,
59 DBTYPE_PFO_ADVOK,
60 DBTYPE_PFO_DANPOR,
61 DBTYPE_PFO_INSSPR,
62 DBTYPE_FO
65 const xmlChar *names[] = {
66 BAD_CAST "OVM",
67 BAD_CAST "OVM_NOTAR",
68 BAD_CAST "OVM_EXEKUT",
69 BAD_CAST "OVM_REQ",
70 BAD_CAST "PO",
71 BAD_CAST "PO_ZAK",
72 BAD_CAST "PO_REQ",
73 BAD_CAST "PFO",
74 BAD_CAST "PFO_ADVOK",
75 BAD_CAST "PFO_DANPOR",
76 BAD_CAST "PFO_INSSPR",
77 BAD_CAST "FO"
80 TEST("DBTYPE_SYSTEM", test_dbtype2string_must_fail, DBTYPE_SYSTEM);
82 for (int i = 0; i < sizeof(types)/sizeof(types[0]); i++)
83 TEST(isds_DbType2string(types[i]), test_dbtype, types[i], names[i]);
85 TEST("1234", test_dbtype2string_must_fail, 1234);
87 TEST("X-Invalid_Type", test_string2dbtype_must_fail,
88 BAD_CAST "X-Invalid_Type");
90 SUM_TEST();