Mercurial > archived > louis > perso > liblxcstats
comparison tests/strsplit.c @ 4:50215911acb3
Add a strsplit() function and stop to build probes into a separate library
author | Louis Opter <louis@dotcloud.com> |
---|---|
date | Sat, 01 Jan 2011 16:01:19 +0100 |
parents | |
children | 8d8c49b066d4 |
comparison
equal
deleted
inserted
replaced
3:2cb8a6cbe468 | 4:50215911acb3 |
---|---|
1 #include <err.h> | |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <string.h> | |
5 | |
6 #include "lxcstats.h" | |
7 #include "_lxcstats.h" | |
8 | |
9 void | |
10 check(const char *field, const char *ref) | |
11 { | |
12 printf("comparing: [%s] with reference: [%s].\n", field, ref); | |
13 if (strcmp(field, ref)) | |
14 exit(EXIT_FAILURE); | |
15 } | |
16 | |
17 int | |
18 main(void) | |
19 { | |
20 char usage[] = "system: 4242\nuser: 4242"; | |
21 char test[] = " \tword1 word2 \f\tword3\n"; | |
22 char *fields[4]; | |
23 | |
24 if (_lxcst_strsplit(usage, fields, sizeof(fields) / sizeof(fields[0])) != 4) | |
25 errx(EXIT_FAILURE, "invalid number of fields."); | |
26 check(fields[0], "system:"); | |
27 check(fields[1], "4242"); | |
28 check(fields[2], "user:"); | |
29 check(fields[3], "4242"); | |
30 | |
31 if (_lxcst_strsplit(test, fields, sizeof(fields) / sizeof(fields[0])) != 3) | |
32 errx(EXIT_FAILURE, "invalid number of fields."); | |
33 check(fields[0], "word1"); | |
34 check(fields[1], "word2"); | |
35 check(fields[2], "word3"); | |
36 | |
37 return (EXIT_SUCCESS); | |
38 } |