Debian Codegraph @

tests/DS/ds_sds_index/test_ds_sds_index_multiple.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 struct oscap_source *source = oscap_source_new_from_file(argv[1]);
30 struct ds_sds_session *session = ds_sds_session_new_from_source(source);
31 struct ds_sds_index *idx = ds_sds_session_get_sds_idx(session);
32 struct ds_stream_index_iterator* streams = ds_sds_index_get_streams(idx);
33
34 // number of streams in the collection
35 int nr_streams = 0;
36 while (ds_stream_index_iterator_has_more(streams))
37 {
38 struct ds_stream_index* stream = ds_stream_index_iterator_next(streams);
39 nr_streams++;
40
41 if (nr_streams == 1 &&
42 strcmp(ds_stream_index_get_id(stream), "scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml") != 0)
43 {
44 printf("Failed to read datastream ID correctly. "
45 "Expected 'scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml', "
46 "found '%s'.\n", ds_stream_index_get_id(stream));
47 ds_sds_session_free(session);
48 oscap_source_free(source);
49 return 1;
50 }
51 if (nr_streams == 2 &&
52 strcmp(ds_stream_index_get_id(stream), "scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml_2") != 0)
53 {
54 printf("Failed to read datastream ID correctly. "
55 "Expected 'scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml_2', "
56 "found '%s'.\n", ds_stream_index_get_id(stream));
57 ds_sds_session_free(session);
58 oscap_source_free(source);
59 return 1;
60 }
61 }
62 ds_stream_index_iterator_free(streams);
63
64 if (ds_sds_index_get_stream(idx, "scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml") == NULL)
65 {
66 printf("Attempted to retrieve 'scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml' "
67 "by ID but got NULL as a result!\n");
68 ds_sds_session_free(session);
69 oscap_source_free(source);
70 return 1;
71 }
72 if (ds_sds_index_get_stream(idx, "scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml_2") == NULL)
73 {
74 printf("Attempted to retrieve 'scap_org.open-scap_datastream_from_xccdf_scap-fedora14-xccdf.xml_2' "
75 "by ID but got NULL as a result!\n");
76 ds_sds_session_free(session);
77 oscap_source_free(source);
78 return 1;
79 }
80 if (ds_sds_index_get_stream(idx, "nonexistant_rubbish") != NULL)
81 {
82 printf("Attempted to retrieve a nonexistant stream by ID but got a non-NULL result!\n");
83 ds_sds_session_free(session);
84 oscap_source_free(source);
85 return 1;
86 }
87
88 ds_sds_session_free(session);
89 oscap_source_free(source);
90
91 if (nr_streams != 2)
92 {
93 printf("Expected to read 2 data-streams from the source datastream collection, "
94 "instead read %i!\n", nr_streams);
95 return 1;
96 }
97
98 return 0;
99 }