| 1 |
#include "config.h" |
| 2 |
|
| 3 |
#include "torture.h" |
| 4 |
#define LIBSSH_STATIC |
| 5 |
|
| 6 |
const char template[] = "temp_dir_XXXXXX"; |
| 7 |
|
| 8 |
static int setup(void **state) |
| 9 |
{ |
| 10 |
char *temp_dir = NULL; |
| 11 |
|
| 12 |
temp_dir = torture_make_temp_dir(template); |
| 13 |
assert_non_null(temp_dir); |
| 14 |
|
| 15 |
*state = (void *)temp_dir; |
| 16 |
|
| 17 |
return 0; |
| 18 |
} |
| 19 |
|
| 20 |
static int teardown(void **state) |
| 21 |
{ |
| 22 |
char *temp_dir = *((char **)state); |
| 23 |
|
| 24 |
torture_rmdirs((const char *)temp_dir); |
| 25 |
|
| 26 |
free(temp_dir); |
| 27 |
|
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
static void torture_back_and_forth(void **state) |
| 32 |
{ |
| 33 |
char *temp_dir = *((char **)state); |
| 34 |
char *cwd = NULL; |
| 35 |
char *after_change = NULL; |
| 36 |
char *after_changing_back = NULL; |
| 37 |
int rc = 0; |
| 38 |
|
| 39 |
cwd = torture_get_current_working_dir(); |
| 40 |
assert_non_null(cwd); |
| 41 |
|
| 42 |
printf("Current dir: %s\n", cwd); |
| 43 |
|
| 44 |
rc = torture_change_dir(temp_dir); |
| 45 |
assert_int_equal(rc, 0); |
| 46 |
|
| 47 |
after_change = torture_get_current_working_dir(); |
| 48 |
assert_non_null(after_change); |
| 49 |
|
| 50 |
printf("Current dir after change: %s\n", after_change); |
| 51 |
|
| 52 |
rc = torture_change_dir(cwd); |
| 53 |
assert_int_equal(rc, 0); |
| 54 |
|
| 55 |
after_changing_back = torture_get_current_working_dir(); |
| 56 |
assert_non_null(after_changing_back); |
| 57 |
|
| 58 |
printf("Back to dir: %s\n", after_changing_back); |
| 59 |
|
| 60 |
SAFE_FREE(cwd); |
| 61 |
SAFE_FREE(after_change); |
| 62 |
SAFE_FREE(after_changing_back); |
| 63 |
} |
| 64 |
|
| 65 |
int torture_run_tests(void) |
| 66 |
{ |
| 67 |
int rc; |
| 68 |
struct CMUnitTest tests[] = { |
| 69 |
cmocka_unit_test_setup_teardown(torture_back_and_forth, |
| 70 |
setup, teardown), |
| 71 |
}; |
| 72 |
|
| 73 |
torture_filter_tests(tests); |
| 74 |
rc = cmocka_run_group_tests(tests, NULL, NULL); |
| 75 |
|
| 76 |
return rc; |
| 77 |
} |
| 78 |
|