Greenbone Vulnerability Management Libraries 22.32.0
uuidutils_tests.c File Reference
#include "uuidutils.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
Include dependency graph for uuidutils_tests.c:

Go to the source code of this file.

Functions

static bool is_between (char value, char lower, char upper)
 Describe (uuidutils)
 BeforeEach (uuidutils)
 AfterEach (uuidutils)
 Ensure (uuidutils, gvm_uuid_make_returns_valid_string)
 Ensure (uuidutils, gvm_uuid_make_generates_unique_values)
 Ensure (uuidutils, gvm_uuid_make_generates_valid_format)
int main (int argc, char **argv)

Function Documentation

◆ AfterEach()

AfterEach ( uuidutils )

Definition at line 22 of file uuidutils_tests.c.

23{
24}

◆ BeforeEach()

BeforeEach ( uuidutils )

Definition at line 18 of file uuidutils_tests.c.

19{
20}

◆ Describe()

Describe ( uuidutils )

◆ Ensure() [1/3]

Ensure ( uuidutils ,
gvm_uuid_make_generates_unique_values  )

Definition at line 38 of file uuidutils_tests.c.

39{
40 char *uuid1, *uuid2;
41
42 uuid1 = gvm_uuid_make ();
43 uuid2 = gvm_uuid_make ();
44
45 assert_that (uuid1, is_not_null);
46 assert_that (uuid2, is_not_null);
47 assert_that (uuid1, is_not_equal_to_string (uuid2));
48
49 free (uuid1);
50 free (uuid2);
51}
char * gvm_uuid_make(void)
Make a new universal identifier.
Definition uuidutils.c:30

References gvm_uuid_make().

Here is the call graph for this function:

◆ Ensure() [2/3]

Ensure ( uuidutils ,
gvm_uuid_make_generates_valid_format  )

Definition at line 53 of file uuidutils_tests.c.

54{
55 char *uuid;
56 int i;
57
58 uuid = gvm_uuid_make ();
59 assert_that (uuid, is_not_null);
60
61 // Check length
62 assert_that (strlen (uuid), is_equal_to (36));
63
64 // Check format: 8-4-4-4-12 hexadecimal characters with 4 hyphens
65 for (i = 0; i < 36; i++)
66 {
67 if (i == 8 || i == 13 || i == 18 || i == 23)
68 assert_that (uuid[i], is_equal_to ('-'));
69 else
70 assert_that (is_between (uuid[i], '0', '9')
71 || is_between (uuid[i], 'a', 'f'),
72 is_true);
73 }
74
75 free (uuid);
76}
static bool is_between(char value, char lower, char upper)

References gvm_uuid_make(), and is_between().

Here is the call graph for this function:

◆ Ensure() [3/3]

Ensure ( uuidutils ,
gvm_uuid_make_returns_valid_string  )

Definition at line 28 of file uuidutils_tests.c.

29{
30 char *uuid;
31
32 uuid = gvm_uuid_make ();
33 assert_that (uuid, is_not_null);
34 assert_that (strlen (uuid), is_equal_to (36));
35 free (uuid);
36}

References gvm_uuid_make().

Here is the call graph for this function:

◆ is_between()

bool is_between ( char value,
char lower,
char upper )
static

Definition at line 12 of file uuidutils_tests.c.

13{
14 return value >= lower && value <= upper;
15}

Referenced by Ensure().

Here is the caller graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 81 of file uuidutils_tests.c.

82{
83 int ret;
84 TestSuite *suite;
85
86 suite = create_test_suite ();
87
88 add_test_with_context (suite, uuidutils, gvm_uuid_make_returns_valid_string);
89 add_test_with_context (suite, uuidutils,
90 gvm_uuid_make_generates_unique_values);
91 add_test_with_context (suite, uuidutils,
92 gvm_uuid_make_generates_valid_format);
93
94 if (argc > 1)
95 ret = run_single_test (suite, argv[1], create_text_reporter ());
96 else
97 ret = run_test_suite (suite, create_text_reporter ());
98
99 destroy_test_suite (suite);
100
101 return ret;
102}