authfile works
[pam_pcsc_cr.git] / test_serial.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "serial.h"
4
5 int main(int argc, char *argv[])
6 {
7         char *in[] = {
8                 "My",
9                 "Little",
10                 "Pony",
11                 NULL,
12         };
13         char buffer[256];
14         int i, rc;
15         serializer_t srl;
16
17         serial_init(&srl, buffer, sizeof(buffer));
18         for (i = 0; in[i]; i++) {
19                 int size = strlen(in[i]);
20                 if ((rc = serial_put(&srl, in[i], size)) != size) {
21                         printf("serial_put(..., \"%s\", %d) = %d\n",
22                                 in[i], size, rc);
23                         return 1;
24                 }
25         }
26         if ((rc = serial_put(&srl, NULL, 0)) != 0) {
27                 printf("serial_put(..., NULL, 0) = %d\n", rc);
28                 return 1;
29         }
30         printf("serialized size=%d\n", serial_size(&srl));
31         serial_init(&srl, buffer, sizeof(buffer));
32         for (i = 0; i < 4; i++) {
33                 char item[32];
34                 memset(item, 0, sizeof(item));
35                 int size = serial_get(&srl, item, sizeof(item));
36                 if (size > sizeof(item)) {
37                         printf("serial_get(..., item, %d) = %d\n",
38                                 (int)sizeof(item), size);
39                         rc = 1;
40                 } else if (size == 0) {
41                         printf("serial_get(...) = 0\n");
42                 } else {
43                         printf("serial_get(...) = %d: \"%s\"\n", size, item);
44                         if (memcmp(in[i], item, size)) {
45                                 printf("\"%s\" != \"%s\" (%d)\n",
46                                         in[i], item, size);
47                                 rc = 1;
48                         }
49                 }
50         }
51         return rc;
52 }