Added RECEIVER and GUARDIAN user types.
[libisds.git] / test / offline / isds-usertype.c
blob1723a5365a93181a755631f3b51bb183d36fbef3
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,
59 USERTYPE_RECEIVER,
60 USERTYPE_GUARDIAN
63 const xmlChar *names[] = {
64 BAD_CAST "PRIMARY_USER",
65 BAD_CAST "ENTRUSTED_USER",
66 BAD_CAST "ADMINISTRATOR",
67 BAD_CAST "OFFICIAL",
68 BAD_CAST "OFFICIAL_CERT",
69 BAD_CAST "LIQUIDATOR",
70 BAD_CAST "RECEIVER",
71 BAD_CAST "GUARDIAN"
75 for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); i++)
76 TEST(isds_UserType2string(types[i]), test_usertype, types[i], names[i]);
78 TEST("1234", test_usertype2string_must_fail, 1234);
80 TEST("X-Invalid_Type", test_string2usertype_must_fail,
81 BAD_CAST "X-Invalid_Type");
83 SUM_TEST();