initial PAM module
[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;
34                 int size;
35                 if (serial_get(&srl, (void**)&item, &size)) {
36                         printf("serial_get failed for item %d\n", i);
37                         rc = 1;
38                 } else {
39                         printf("serial_get(...) = %d: \"%.*s\"\n", size, size, item);
40                         if (memcmp(in[i], item, size)) {
41                                 printf("\"%s\" != \"%s\" (%d)\n",
42                                         in[i], item, size);
43                                 rc = 1;
44                         }
45                 }
46         }
47         return rc;
48 }