test: Silent warnings in offile tests
[libisds.git] / test / offline / isds-usertype.c
blobe5bd31583e7d1c32345809856992331f4bd7840c
1 #include "../test.h"
2 #include "isds.c"
4 static int test_usertype2string_must_fail(const isds_UserType type) {
5 xmlChar *string;
7 string = (xmlChar *) isds_UserType2string(type);
8 if (string)
9 FAIL_TEST("conversion from isds_UserType to string did not fail");
11 PASS_TEST;
14 static int test_string2usertype_must_fail(const xmlChar *string) {
15 isds_error err;
16 isds_UserType new_type;
18 err = string2isds_UserType((xmlChar *)string, &new_type);
19 if (!err)
20 FAIL_TEST("conversion from string to isds_UserType did not fail");
22 PASS_TEST;
25 static int test_usertype(const isds_UserType type, const xmlChar *name) {
26 xmlChar *string;
27 isds_error err;
28 isds_UserType new_type;
30 string = (xmlChar *) isds_UserType2string(type);
31 if (!string)
32 FAIL_TEST("conversion from isds_UserType to string failed");
34 if (xmlStrcmp(name, string))
35 FAIL_TEST("Wrong to string conversion result: "
36 "expected=`%s', got=`%s'", name, string);
38 err = string2isds_UserType(string, &new_type);
39 if (err)
40 FAIL_TEST("conversion from string to isds_DbTyoe failed");
42 if (type != new_type)
43 FAIL_TEST("double conversion not idempotent: expected=%d, got=%d",
44 type, new_type);
46 PASS_TEST;
49 int main(void) {
50 INIT_TEST("isds_UserType conversion");
52 isds_UserType types[] = {
53 USERTYPE_PRIMARY,
54 USERTYPE_ENTRUSTED,
55 USERTYPE_ADMINISTRATOR,
56 USERTYPE_OFFICIAL,
57 USERTYPE_OFFICIAL_CERT,
58 USERTYPE_LIQUIDATOR
61 const xmlChar *names[] = {
62 BAD_CAST "PRIMARY_USER",
63 BAD_CAST "ENTRUSTED_USER",
64 BAD_CAST "ADMINISTRATOR",
65 BAD_CAST "OFFICIAL",
66 BAD_CAST "OFFICIAL_CERT",
67 BAD_CAST "LIQUIDATOR"
71 for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); i++)
72 TEST(isds_UserType2string(types[i]), test_usertype, types[i], names[i]);
74 TEST("1234", test_usertype2string_must_fail, 1234);
76 TEST("X-Invalid_Type", test_string2usertype_must_fail,
77 BAD_CAST "X-Invalid_Type");
79 SUM_TEST();