mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
tests: Introduce torture_make_temp_dir()
Introduces a function to create temporary dir for testing purposes. Also adds a minimal test for the temporary directory creation. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
1f6b929735
commit
65e16b8d9e
51
tests/unittests/torture_temp_dir.c
Normal file
51
tests/unittests/torture_temp_dir.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "torture.h"
|
||||
#define LIBSSH_STATIC
|
||||
|
||||
const char template[] = "temp_dir_XXXXXX";
|
||||
|
||||
static int setup(void **state)
|
||||
{
|
||||
char *temp_dir = NULL;
|
||||
|
||||
temp_dir = torture_make_temp_dir(template);
|
||||
assert_non_null(temp_dir);
|
||||
|
||||
*state = (void *)temp_dir;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int teardown(void **state)
|
||||
{
|
||||
char *temp_dir = *((char **)state);
|
||||
|
||||
torture_rmdirs((const char *)temp_dir);
|
||||
|
||||
free(temp_dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void torture_create_temp_dir(void **state)
|
||||
{
|
||||
char *temp_dir = *((char **)state);
|
||||
|
||||
printf("Created temp dir: %s\n", temp_dir);
|
||||
}
|
||||
|
||||
int torture_run_tests(void)
|
||||
{
|
||||
int rc;
|
||||
struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(torture_create_temp_dir, setup, teardown),
|
||||
};
|
||||
|
||||
torture_filter_tests(tests);
|
||||
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user