Greenbone Vulnerability Management Libraries 22.41.0
vtparser_tests.c File Reference
#include "../base/nvti.h"
#include "vtparser.c"
#include <cgreen/assertions.h>
#include <cgreen/cgreen.h>
#include <cgreen/constraint_syntax_helpers.h>
#include <cgreen/internal/c_assertions.h>
#include <cgreen/mocks.h>
Include dependency graph for vtparser_tests.c:

Go to the source code of this file.

Macros

#define VT_NAME   "Example: Security Advisory for eg (EXAMPLE-2025-cb7b)"
#define VT

Functions

 Describe (vtparser)
 BeforeEach (vtparser)
 AfterEach (vtparser)
static FILE * memopen (const gchar *str)
 Ensure (vtparser, parse_vt_json_parses_a_vt)
int main (int argc, char **argv)

Macro Definition Documentation

◆ VT

#define VT

Definition at line 17 of file vtparser_tests.c.

Referenced by Ensure().

◆ VT_NAME

#define VT_NAME   "Example: Security Advisory for eg (EXAMPLE-2025-cb7b)"

Definition at line 15 of file vtparser_tests.c.

Referenced by Ensure().

Function Documentation

◆ AfterEach()

AfterEach ( vtparser )

Definition at line 72 of file vtparser_tests.c.

73{
74}

References AfterEach().

Here is the call graph for this function:

◆ BeforeEach()

BeforeEach ( vtparser )

Definition at line 68 of file vtparser_tests.c.

69{
70}

References BeforeEach().

Here is the call graph for this function:

◆ Describe()

Describe ( vtparser )

References Describe().

Here is the call graph for this function:

◆ Ensure()

Ensure ( vtparser ,
parse_vt_json_parses_a_vt  )

Definition at line 84 of file vtparser_tests.c.

85{
88 FILE *file;
89 nvti_t *nvt;
90 gchar *refs;
91
92 file = memopen ("[" VT "]");
93 assert_that (file, is_not_null);
94
96
97 gvm_json_pull_parser_init (&parser, file);
98
99 gvm_json_pull_parser_next (&parser, &event);
100
101 parse_vt_json (&parser, &event, &nvt);
102 assert_that (nvt, is_not_null);
103 assert_that (nvti_name (nvt), is_equal_to_string (VT_NAME));
104 refs = nvti_refs (nvt, NULL, NULL, 1);
105 assert_that (refs,
106 is_equal_to_string ("cve:CVE-2017-18189,"
107 " 2020-cb7b7181a0:FEDORA,"
108 " https://example.org/ann/EG-IZ3CX:URL"));
109 g_free (refs);
110 nvti_free (nvt);
111
114 fclose (file);
115}
void gvm_json_pull_parser_cleanup(gvm_json_pull_parser_t *parser)
Frees the data of a JSON pull parser.
Definition jsonpull.c:119
void gvm_json_pull_event_cleanup(gvm_json_pull_event_t *event)
Frees all data of JSON pull event data structure.
Definition jsonpull.c:61
void gvm_json_pull_parser_next(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
Get the next event from a JSON pull parser.
Definition jsonpull.c:668
void gvm_json_pull_parser_init(gvm_json_pull_parser_t *parser, FILE *input_stream)
Initializes a JSON pull parser with default buffer sizes.
Definition jsonpull.c:108
void gvm_json_pull_event_init(gvm_json_pull_event_t *event)
Initializes a JSON pull event data structure.
Definition jsonpull.c:50
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
Definition nvti.c:766
struct nvti nvti_t
The structure of a information record that corresponds to a NVT.
gchar * nvti_name(const nvti_t *n)
Get the name.
Definition nvti.c:625
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
Definition nvti.c:570
Event generated by the JSON pull parser.
Definition jsonpull.h:59
A json pull parser.
Definition jsonpull.h:86
int parse_vt_json(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, nvti_t **nvt)
Parse a VT element given in json format.
Definition vtparser.c:239
#define VT
static FILE * memopen(const gchar *str)
#define VT_NAME

References Ensure(), gvm_json_pull_event_cleanup(), gvm_json_pull_event_init(), gvm_json_pull_parser_cleanup(), gvm_json_pull_parser_init(), gvm_json_pull_parser_next(), memopen(), nvti_free(), nvti_name(), nvti_refs(), parse_vt_json(), VT, and VT_NAME.

Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 120 of file vtparser_tests.c.

121{
122 int ret;
123 TestSuite *suite;
124
125 suite = create_test_suite ();
126
127 add_test_with_context (suite, vtparser, parse_vt_json_parses_a_vt);
128
129 if (argc > 1)
130 ret = run_single_test (suite, argv[1], create_text_reporter ());
131 else
132 ret = run_test_suite (suite, create_text_reporter ());
133
134 destroy_test_suite (suite);
135
136 return ret;
137}

References main().

Here is the call graph for this function:

◆ memopen()

FILE * memopen ( const gchar * str)
static

Definition at line 77 of file vtparser_tests.c.

78{
79 return fmemopen ((void *) str, strlen (str), "r");
80}

References memopen().

Referenced by Ensure(), and memopen().

Here is the call graph for this function:
Here is the caller graph for this function: