]> www.average.org Git - pam_pcsc_cr.git/blob - test_serial.c
bump version
[pam_pcsc_cr.git] / test_serial.c
1 /*
2 Copyright (c) 2013 Eugene Crosser
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12     1. The origin of this software must not be misrepresented; you must
13     not claim that you wrote the original software. If you use this
14     software in a product, an acknowledgment in the product documentation
15     would be appreciated but is not required.
16
17     2. Altered source versions must be plainly marked as such, and must
18     not be misrepresented as being the original software.
19
20     3. This notice may not be removed or altered from any source
21     distribution.
22 */
23
24 #include <stdio.h>
25 #include <string.h>
26 #include "serial.h"
27
28 int main(int argc, char *argv[])
29 {
30         char *in[] = {
31                 "My",
32                 "Little",
33                 "Pony",
34                 NULL,
35         };
36         char buffer[256];
37         int i, rc;
38         serializer_t srl;
39
40         serial_init(&srl, buffer, sizeof(buffer));
41         for (i = 0; in[i]; i++) {
42                 int size = strlen(in[i]);
43                 if ((rc = serial_put(&srl, in[i], size)) != size) {
44                         printf("serial_put(..., \"%s\", %d) = %d\n",
45                                 in[i], size, rc);
46                         return 1;
47                 }
48         }
49         if ((rc = serial_put(&srl, NULL, 0)) != 0) {
50                 printf("serial_put(..., NULL, 0) = %d\n", rc);
51                 return 1;
52         }
53         printf("serialized size=%d\n", serial_size(&srl));
54         serial_init(&srl, buffer, sizeof(buffer));
55         for (i = 0; i < 4; i++) {
56                 char *item;
57                 int size;
58                 if (serial_get(&srl, (void**)&item, &size)) {
59                         printf("serial_get failed for item %d\n", i);
60                         rc = 1;
61                 } else {
62                         printf("serial_get(...) = %d: \"%.*s\"\n", size, size, item);
63                         if (memcmp(in[i], item, size)) {
64                                 printf("\"%s\" != \"%s\" (%d)\n",
65                                         in[i], item, size);
66                                 rc = 1;
67                         }
68                 }
69         }
70         return rc;
71 }