From 0690340f5311a795b8c137ff62e02eec675f0cec Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Fri, 30 Aug 2002 02:31:39 +0000 Subject: [PATCH] also test _short functions git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@11315 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/parse-name-test.c | 75 +++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/lib/krb5/parse-name-test.c b/lib/krb5/parse-name-test.c index 3ded057b3..ee9e84f14 100644 --- a/lib/krb5/parse-name-test.c +++ b/lib/krb5/parse-name-test.c @@ -42,24 +42,25 @@ static struct testcase { krb5_realm realm; unsigned ncomponents; char *comp_val[MAX_COMPONENTS]; + int realmp; } tests[] = { - {"", "@", "", 1, {""}}, - {"a", "a@", "", 1, {"a"}}, - {"\\n", "\\n@", "", 1, {"\n"}}, - {"\\ ", "\\ @", "", 1, {" "}}, - {"\\t", "\\t@", "", 1, {"\t"}}, - {"\\b", "\\b@", "", 1, {"\b"}}, - {"\\\\", "\\\\@", "", 1, {"\\"}}, - {"\\/", "\\/@", "", 1, {"/"}}, - {"\\@", "\\@@", "", 1, {"@"}}, - {"@", "@", "", 1, {""}}, - {"a/b", "a/b@", "", 2, {"a", "b"}}, - {"a/", "a/@", "", 2, {"a", ""}}, - {"a\\//\\/", "a\\//\\/@", "", 2, {"a/", "/"}}, - {"/a", "/a@", "", 2, {"", "a"}}, - {"\\@@\\@", "\\@@\\@", "@", 1, {"@"}}, - {"a/b/c", "a/b/c@", "", 3, {"a", "b", "c"}}, - {NULL, NULL, "", 0, {}}}; + {"", "@", "", 1, {""}, FALSE}, + {"a", "a@", "", 1, {"a"}, FALSE}, + {"\\n", "\\n@", "", 1, {"\n"}, FALSE}, + {"\\ ", "\\ @", "", 1, {" "}, FALSE}, + {"\\t", "\\t@", "", 1, {"\t"}, FALSE}, + {"\\b", "\\b@", "", 1, {"\b"}, FALSE}, + {"\\\\", "\\\\@", "", 1, {"\\"}, FALSE}, + {"\\/", "\\/@", "", 1, {"/"}, FALSE}, + {"\\@", "\\@@", "", 1, {"@"}, FALSE}, + {"@", "@", "", 1, {""}, TRUE}, + {"a/b", "a/b@", "", 2, {"a", "b"}, FALSE}, + {"a/", "a/@", "", 2, {"a", ""}, FALSE}, + {"a\\//\\/", "a\\//\\/@", "", 2, {"a/", "/"}, FALSE}, + {"/a", "/a@", "", 2, {"", "a"}, FALSE}, + {"\\@@\\@", "\\@@\\@", "@", 1, {"@"}, TRUE}, + {"a/b/c", "a/b/c@", "", 3, {"a", "b", "c"}, FALSE}, + {NULL, NULL, "", 0, {}}, FALSE}; int main(int argc, char **argv) @@ -115,7 +116,7 @@ main(int argc, char **argv) } } } - for (j = 0; j < strlen(t->input_string); ++j) { + for (j = 0; j < strlen(t->output_string); ++j) { ret = krb5_unparse_name_fixed(context, princ, name_buf, j); if (ret != ERANGE) { @@ -147,6 +148,44 @@ main(int argc, char **argv) s, t->output_string); val = 1; } + free(s); + + if (!t->realmp) { + for (j = 0; j < strlen(t->input_string); ++j) { + ret = krb5_unparse_name_fixed_short(context, princ, + name_buf, j); + if (ret != ERANGE) { + printf ("unparse_name_short %s with length %d" + " should have failed\n", + t->input_string, j); + val = 1; + break; + } + } + ret = krb5_unparse_name_fixed_short(context, princ, + name_buf, sizeof(name_buf)); + if (ret) + krb5_err (context, 1, ret, "krb5_unparse_name_fixed"); + + if (strcmp (t->input_string, name_buf) != 0) { + printf ("failed comparing the re-parsed" + " (\"%s\" should be \"%s\")\n", + name_buf, t->input_string); + val = 1; + } + + ret = krb5_unparse_name_short(context, princ, &s); + if (ret) + krb5_err (context, 1, ret, "krb5_unparse_name_short"); + + if (strcmp (t->input_string, s) != 0) { + printf ("failed comparing the re-parsed" + " (\"%s\" should be \"%s\"\n", + s, t->input_string); + val = 1; + } + free(s); + } krb5_free_principal (context, princ); } return val;