Debian Codegraph @

tests/API/OVAL/schema_version/test_schema_version.c

raw symbols SCIP
1 /*
2 * Copyright 2015 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * "Jan Černý" <[email protected]m>
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include "OVAL/public/oval_schema_version.h"
30 #include <stddef.h>
31 #include <assert.h>
32 #include "util.h"
33 #include "public/oscap_debug.h"
34
35 static const char *cmp_to_cstr(int cmp)
36 {
37 if (cmp == 0) {
38 return "is same as";
39 } else if (cmp < 0) {
40 return "is older than";
41 }
42 return "is newer than";
43 }
44
45 int main(int argc, char **argv)
46 {
47 if (argc != 4) {
48 printf("Not enough arguments\n");
49 return 1;
50 }
51 oscap_set_verbose(NULL, NULL);
52 const char *v1_str = argv[1];
53 const char *v2_str = argv[2];
54 int expected_result = atoi(argv[3]);
55 oval_schema_version_t v1 = oval_schema_version_from_cstr(v1_str);
56 oval_schema_version_t v2 = oval_schema_version_from_cstr(v2_str);
57 int cmp = oval_schema_version_cmp(v1, v2);
58 int retval;
59 if (cmp == expected_result) {
60 retval = 0;
61 printf("\tPASS\t%s %s %s\n", v1_str, cmp_to_cstr(cmp), v2_str);
62 } else {
63 retval = 1;
64 printf("\tFAIL\t%s %s %s but expected result is '%s'\n", v1_str,
65 cmp_to_cstr(cmp), v2_str, cmp_to_cstr(expected_result));
66 }
67 return retval;
68 }