| 1 |
> |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "crypt-port.h" |
| 20 |
#include <stdio.h> |
| 21 |
#include <stdlib.h> |
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
struct testcase |
| 25 |
{ |
| 26 |
const char *exp_rn; |
| 27 |
const char *exp_ra; |
| 28 |
}; |
| 29 |
|
| 30 |
static const struct testcase testcases[] = |
| 31 |
{ |
| 32 |
{ "", "*0" }, |
| 33 |
{ "*", "*0" }, |
| 34 |
{ "*0", "*0" }, |
| 35 |
}; |
| 36 |
|
| 37 |
int |
| 38 |
main (void) |
| 39 |
{ |
| 40 |
bool ok = true; |
| 41 |
char result[5]; |
| 42 |
|
| 43 |
for (size_t i = 0; i < ARRAY_SIZE (testcases); i++) |
| 44 |
{ |
| 45 |
size_t s = i + 1; |
| 46 |
int j = (int) s; |
| 47 |
char *outbuf = malloc (sizeof (char) * s); |
| 48 |
|
| 49 |
crypt_rn ("@@", "@@", outbuf, j); |
| 50 |
|
| 51 |
if (!strncmp (testcases[i].exp_rn, outbuf, s)) |
| 52 |
{ |
| 53 |
strcpy (result, "PASS"); |
| 54 |
} |
| 55 |
else |
| 56 |
{ |
| 57 |
strcpy (result, "FAIL"); |
| 58 |
ok = false; |
| 59 |
} |
| 60 |
|
| 61 |
printf ("Test %zu.0: %s, expected: \"%-2s\", got: \"%-2s\"\n", |
| 62 |
s, result, testcases[i].exp_rn, outbuf); |
| 63 |
|
| 64 |
crypt_ra ("@@", "@@", (void **) &outbuf, &j); |
| 65 |
|
| 66 |
if (!strncmp (testcases[i].exp_ra, outbuf, strlen(outbuf))) |
| 67 |
{ |
| 68 |
strcpy (result, "PASS"); |
| 69 |
} |
| 70 |
else |
| 71 |
{ |
| 72 |
strcpy (result, "FAIL"); |
| 73 |
ok = false; |
| 74 |
} |
| 75 |
|
| 76 |
printf ("Test %zu.1: %s, expected: \"%-2s\", got: \"%-2s\"\n", |
| 77 |
s, result, testcases[i].exp_ra, outbuf); |
| 78 |
|
| 79 |
j = -1; |
| 80 |
|
| 81 |
crypt_ra ("@@", "@@", (void **) &outbuf, &j); |
| 82 |
|
| 83 |
if (!strncmp (testcases[i].exp_ra, outbuf, strlen(outbuf))) |
| 84 |
{ |
| 85 |
strcpy (result, "PASS"); |
| 86 |
} |
| 87 |
else |
| 88 |
{ |
| 89 |
strcpy (result, "FAIL"); |
| 90 |
ok = false; |
| 91 |
} |
| 92 |
|
| 93 |
printf ("Test %zu.2: %s, expected: \"%-2s\", got: \"%-2s\"\n", |
| 94 |
s, result, testcases[i].exp_ra, outbuf); |
| 95 |
|
| 96 |
free (outbuf); |
| 97 |
outbuf = NULL; |
| 98 |
j = sizeof (struct crypt_data); |
| 99 |
|
| 100 |
crypt_ra ("@@", "@@", (void **) &outbuf, &j); |
| 101 |
|
| 102 |
if (!strncmp (testcases[i].exp_ra, outbuf, strlen(outbuf))) |
| 103 |
{ |
| 104 |
strcpy (result, "PASS"); |
| 105 |
} |
| 106 |
else |
| 107 |
{ |
| 108 |
strcpy (result, "FAIL"); |
| 109 |
ok = false; |
| 110 |
} |
| 111 |
|
| 112 |
printf ("Test %zu.3: %s, expected: \"%-2s\", got: \"%-2s\"\n", |
| 113 |
s, result, testcases[i].exp_ra, outbuf); |
| 114 |
|
| 115 |
free (outbuf); |
| 116 |
} |
| 117 |
|
| 118 |
return ok ? 0 : 1; |
| 119 |
} |