1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#include "../test.h"
#include "isds.c"
static int test_usertype2string_must_fail(const isds_UserType type) {
xmlChar *string;
string = (xmlChar *) isds_UserType2string(type);
if (string)
FAIL_TEST("conversion from isds_UserType to string did not fail");
PASS_TEST;
}
static int test_string2usertype_must_fail(const xmlChar *string) {
isds_error err;
isds_UserType new_type;
err = string2isds_UserType((xmlChar *)string, &new_type);
if (!err)
FAIL_TEST("conversion from string to isds_UserType did not fail");
PASS_TEST;
}
static int test_usertype(const isds_UserType type, const xmlChar *name) {
xmlChar *string;
isds_error err;
isds_UserType new_type;
string = (xmlChar *) isds_UserType2string(type);
if (!string)
FAIL_TEST("conversion from isds_UserType to string failed");
if (xmlStrcmp(name, string))
FAIL_TEST("Wrong to string conversion result: "
"expected=`%s', got=`%s'", name, string);
err = string2isds_UserType(string, &new_type);
if (err)
FAIL_TEST("conversion from string to isds_DbTyoe failed");
if (type != new_type)
FAIL_TEST("double conversion not idempotent: expected=%d, got=%d",
type, new_type);
PASS_TEST;
}
int main(int argc, char **argv) {
INIT_TEST("isds_UserType conversion");
isds_UserType types[] = {
USERTYPE_PRIMARY,
USERTYPE_ENTRUSTED,
USERTYPE_ADMINISTRATOR,
USERTYPE_OFFICIAL,
USERTYPE_OFFICIAL_CERT,
USERTYPE_LIQUIDATOR
};
const xmlChar *names[] = {
BAD_CAST "PRIMARY_USER",
BAD_CAST "ENTRUSTED_USER",
BAD_CAST "ADMINISTRATOR",
BAD_CAST "OFFICIAL",
BAD_CAST "OFFICIAL_CERT",
BAD_CAST "LIQUIDATOR"
};
for (int i = 0; i < sizeof(types)/sizeof(types[0]); i++)
TEST(isds_UserType2string(types[i]), test_usertype, types[i], names[i]);
TEST("1234", test_usertype2string_must_fail, 1234);
TEST("X-Invalid_Type", test_string2usertype_must_fail,
BAD_CAST "X-Invalid_Type");
SUM_TEST();
}
|