File: torture_temp_file.c

package info (click to toggle)
libssh 0.10.6-0%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,004 kB
  • sloc: ansic: 88,777; cpp: 407; sh: 119; makefile: 41; javascript: 20; python: 9
file content (63 lines) | stat: -rw-r--r-- 1,069 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "config.h"

#include "torture.h"
#define LIBSSH_STATIC

const char template[] = "temp_file_XXXXXX";

static int setup(void **state)
{
    char *file_name = NULL;

    file_name  = torture_create_temp_file(template);
    assert_non_null(file_name);

    *state = (void *)file_name;

    return 0;
}

static int teardown(void **state)
{
    int rc;
    char *file_name = *((char **)state);

    assert_non_null(file_name);

    rc = unlink(file_name);
    assert_int_equal(rc, 0);

    SAFE_FREE(file_name);

    return 0;
}


static void torture_temp_file(void **state)
{
    char *file_name = *((char **)state);
    FILE *fp = NULL;

    assert_non_null(file_name);

    fp = fopen(file_name, "r");
    assert_non_null(fp);

    fclose(fp);

    printf("Created temp file: %s\n", file_name);
}

int torture_run_tests(void)
{
    int rc;
    struct CMUnitTest tests[] = {
        cmocka_unit_test_setup_teardown(torture_temp_file, setup, teardown),
    };

    torture_filter_tests(tests);
    rc = cmocka_run_group_tests(tests, NULL, NULL);

    return rc;
}