]> git.proxmox.com Git - mirror_corosync-qdevice.git/blob - qdevices/test-dynar-getopt-lex.c
init: Fix init scripts to work with containers
[mirror_corosync-qdevice.git] / qdevices / test-dynar-getopt-lex.c
1 /*
2 * Copyright (c) 2015-2016 Red Hat, Inc.
3 *
4 * All rights reserved.
5 *
6 * Author: Jan Friesse (jfriesse@redhat.com)
7 *
8 * This software licensed under BSD license, the text of which follows:
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the Red Hat, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <stdio.h>
36 #include <assert.h>
37 #include <string.h>
38
39 #include "dynar.h"
40 #include "dynar-str.h"
41 #include "dynar-getopt-lex.h"
42
43 int
44 main(void)
45 {
46 struct dynar input_str;
47 struct dynar_getopt_lex lex;
48
49 dynar_init(&input_str, 128);
50
51 assert(dynar_str_catf(&input_str, "option=value") != -1);
52 dynar_getopt_lex_init(&lex, &input_str);
53 assert(dynar_getopt_lex_token_next(&lex) == 0);
54 assert(strcmp(dynar_data(&lex.option), "option") == 0);
55 assert(strcmp(dynar_data(&lex.value), "value") == 0);
56 assert(dynar_getopt_lex_token_next(&lex) == 0);
57 assert(strcmp(dynar_data(&lex.option), "") == 0);
58 assert(strcmp(dynar_data(&lex.value), "") == 0);
59 dynar_getopt_lex_destroy(&lex);
60
61 assert(dynar_str_cpy(&input_str, "") == 0);
62 assert(dynar_str_catf(&input_str, "option1=value1,option2=value2") != -1);
63 dynar_getopt_lex_init(&lex, &input_str);
64 assert(dynar_getopt_lex_token_next(&lex) == 0);
65 assert(strcmp(dynar_data(&lex.option), "option1") == 0);
66 assert(strcmp(dynar_data(&lex.value), "value1") == 0);
67 assert(dynar_getopt_lex_token_next(&lex) == 0);
68 assert(strcmp(dynar_data(&lex.option), "option2") == 0);
69 assert(strcmp(dynar_data(&lex.value), "value2") == 0);
70 assert(dynar_getopt_lex_token_next(&lex) == 0);
71 assert(strcmp(dynar_data(&lex.option), "") == 0);
72 assert(strcmp(dynar_data(&lex.value), "") == 0);
73 dynar_getopt_lex_destroy(&lex);
74
75 assert(dynar_str_cpy(&input_str, "") == 0);
76 assert(dynar_str_catf(&input_str, "option1=value1,option2=value2,option3=value3") != -1);
77 dynar_getopt_lex_init(&lex, &input_str);
78 assert(dynar_getopt_lex_token_next(&lex) == 0);
79 assert(strcmp(dynar_data(&lex.option), "option1") == 0);
80 assert(strcmp(dynar_data(&lex.value), "value1") == 0);
81 assert(dynar_getopt_lex_token_next(&lex) == 0);
82 assert(strcmp(dynar_data(&lex.option), "option2") == 0);
83 assert(strcmp(dynar_data(&lex.value), "value2") == 0);
84 assert(dynar_getopt_lex_token_next(&lex) == 0);
85 assert(strcmp(dynar_data(&lex.option), "option3") == 0);
86 assert(strcmp(dynar_data(&lex.value), "value3") == 0);
87 assert(dynar_getopt_lex_token_next(&lex) == 0);
88 assert(strcmp(dynar_data(&lex.option), "") == 0);
89 assert(strcmp(dynar_data(&lex.value), "") == 0);
90 dynar_getopt_lex_destroy(&lex);
91
92 assert(dynar_str_cpy(&input_str, "") == 0);
93 assert(dynar_str_catf(&input_str, "option1,option2=value2") != -1);
94 dynar_getopt_lex_init(&lex, &input_str);
95 assert(dynar_getopt_lex_token_next(&lex) == 0);
96 assert(strcmp(dynar_data(&lex.option), "option1") == 0);
97 assert(strcmp(dynar_data(&lex.value), "") == 0);
98 assert(dynar_getopt_lex_token_next(&lex) == 0);
99 assert(strcmp(dynar_data(&lex.option), "option2") == 0);
100 assert(strcmp(dynar_data(&lex.value), "value2") == 0);
101 assert(dynar_getopt_lex_token_next(&lex) == 0);
102 assert(strcmp(dynar_data(&lex.option), "") == 0);
103 assert(strcmp(dynar_data(&lex.value), "") == 0);
104 dynar_getopt_lex_destroy(&lex);
105
106 dynar_destroy(&input_str);
107
108 return (0);
109 }