Debian Codegraph @

tests/DS/ds_sds_index/test_ds_sds_index.c

raw symbols SCIP
1 /*
2 * Copyright 2012 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * Authors:
6 * Martin Preisler <[email protected]>
7 */
8
9 #ifdef HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16
17 #include "scap_ds.h"
18 #include "common/list.h"
19 #include "oscap_source.h"
20 #include "ds_sds_session.h"
21
22 int main(int argc, char **argv)
23 {
24 if (argc != 2)
25 {
26 printf("Invalid arguments, usage: ./test_ds_sds_index FILE");
27 return 2;
28 }
29
30 struct oscap_source *source = oscap_source_new_from_file(argv[1]);
31 struct ds_sds_session *session = ds_sds_session_new_from_source(source);
32 struct ds_sds_index *idx = ds_sds_session_get_sds_idx(session);
33 struct ds_stream_index_iterator* streams = ds_sds_index_get_streams(idx);
34
35 // number of streams in the collection
36 int nr_streams = 0;
37
38 while (ds_stream_index_iterator_has_more(streams))
39 {
40 struct ds_stream_index* stream = ds_stream_index_iterator_next(streams);
41 nr_streams++;
42
43 if (strcmp(ds_stream_index_get_id(stream),
44 "scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml") != 0)
45 {
46 printf("Failed to read datastream ID correctly. "
47 "Expected 'scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml', "
48 "found '%s'.\n", ds_stream_index_get_id(stream));
49 ds_sds_session_free(session);
50 oscap_source_free(source);
51 return 1;
52 }
53 if (strcmp(ds_stream_index_get_timestamp(stream),
54 "2012-11-01T12:22:58") != 0)
55 {
56 printf("Failed to read datastream timestamp correctly. "
57 "Expected '2012-11-01T12:22:58', "
58 "found '%s'.\n", ds_stream_index_get_timestamp(stream));
59 ds_sds_session_free(session);
60 oscap_source_free(source);
61 return 1;
62 }
63 if (strcmp(ds_stream_index_get_version(stream),
64 "1.2") != 0)
65 {
66 printf("Failed to read datastream scap-version correctly. "
67 "Expected '1.2', "
68 "found '%s'.\n", ds_stream_index_get_version(stream));
69 ds_sds_session_free(session);
70 oscap_source_free(source);
71 return 1;
72 }
73 }
74 ds_stream_index_iterator_free(streams);
75
76 if (ds_sds_index_get_stream(idx, "scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml") == NULL)
77 {
78 printf("Attempted to retrieve 'scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml' "
79 "by ID but got NULL as a result!\n");
80 ds_sds_session_free(session);
81 oscap_source_free(source);
82 return 1;
83 }
84 if (ds_sds_index_get_stream(idx, "nonexistant_rubbish") != NULL)
85 {
86 printf("Attempted to retrieve a nonexistant stream by ID but got a non-NULL result!\n");
87 ds_sds_session_free(session);
88 oscap_source_free(source);
89 return 1;
90 }
91
92 ds_sds_session_free(session);
93 oscap_source_free(source);
94
95 if (nr_streams != 1)
96 {
97 printf("Expected to read 1 data-stream from the source datastream collection, "
98 "instead read %i!\n", nr_streams);
99 return 1;
100 }
101
102 return 0;
103 }