Debian Codegraph @

tests/unittests/torture_temp_file.c

raw
1 #include "config.h"
2
3 #include "torture.h"
4 #define LIBSSH_STATIC
5
6 const char template[] = "temp_file_XXXXXX";
7
8 static int setup(void **state)
9 {
10 char *file_name = NULL;
11
12 file_name = torture_create_temp_file(template);
13 assert_non_null(file_name);
14
15 *state = (void *)file_name;
16
17 return 0;
18 }
19
20 static int teardown(void **state)
21 {
22 int rc;
23 char *file_name = *((char **)state);
24
25 assert_non_null(file_name);
26
27 rc = unlink(file_name);
28 assert_int_equal(rc, 0);
29
30 SAFE_FREE(file_name);
31
32 return 0;
33 }
34
35
36 static void torture_temp_file(void **state)
37 {
38 char *file_name = *((char **)state);
39 FILE *fp = NULL;
40
41 assert_non_null(file_name);
42
43 fp = fopen(file_name, "r");
44 assert_non_null(fp);
45
46 fclose(fp);
47
48 printf("Created temp file: %s\n", file_name);
49 }
50
51 int torture_run_tests(void)
52 {
53 int rc;
54 struct CMUnitTest tests[] = {
55 cmocka_unit_test_setup_teardown(torture_temp_file, setup, teardown),
56 };
57
58 torture_filter_tests(tests);
59 rc = cmocka_run_group_tests(tests, NULL, NULL);
60
61 return rc;
62 }
63