2017-10-28 15:31:37 +03:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-05-07 15:39:08 +04:00
|
|
|
#define LIBSSH_STATIC
|
2010-12-28 16:15:32 +03:00
|
|
|
|
2020-04-06 13:07:28 +03:00
|
|
|
#include <errno.h>
|
2010-05-07 15:39:08 +04:00
|
|
|
#include "torture.h"
|
2010-12-29 23:02:51 +03:00
|
|
|
#include "libssh/libssh.h"
|
2010-05-07 15:39:08 +04:00
|
|
|
|
2010-12-28 16:15:32 +03:00
|
|
|
static void torture_ssh_init(void **state) {
|
2010-05-07 15:39:08 +04:00
|
|
|
int rc;
|
|
|
|
|
2010-12-28 16:15:32 +03:00
|
|
|
(void) state;
|
2010-05-07 15:39:08 +04:00
|
|
|
|
2010-12-28 16:15:32 +03:00
|
|
|
rc = ssh_init();
|
|
|
|
assert_int_equal(rc, SSH_OK);
|
|
|
|
rc = ssh_finalize();
|
|
|
|
assert_int_equal(rc, SSH_OK);
|
2010-05-07 15:39:08 +04:00
|
|
|
}
|
|
|
|
|
2018-11-12 13:17:20 +03:00
|
|
|
static void torture_ssh_init_after_finalize(void **state) {
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
(void) state;
|
|
|
|
|
|
|
|
rc = ssh_init();
|
|
|
|
assert_int_equal(rc, SSH_OK);
|
|
|
|
rc = ssh_finalize();
|
|
|
|
assert_int_equal(rc, SSH_OK);
|
|
|
|
rc = ssh_init();
|
|
|
|
assert_int_equal(rc, SSH_OK);
|
|
|
|
rc = ssh_finalize();
|
|
|
|
assert_int_equal(rc, SSH_OK);
|
|
|
|
}
|
|
|
|
|
2020-04-06 13:07:28 +03:00
|
|
|
static void torture_is_ssh_initialized(UNUSED_PARAM(void **state)) {
|
|
|
|
|
|
|
|
int rc;
|
|
|
|
bool initialized = false;
|
|
|
|
|
|
|
|
/* Make sure the library is not initialized */
|
|
|
|
while (is_ssh_initialized()) {
|
|
|
|
rc = ssh_finalize();
|
|
|
|
assert_return_code(rc, errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ssh_init();
|
|
|
|
assert_return_code(rc, errno);
|
|
|
|
initialized = is_ssh_initialized();
|
|
|
|
assert_true(initialized);
|
|
|
|
rc = ssh_finalize();
|
|
|
|
assert_return_code(rc, errno);
|
|
|
|
initialized = is_ssh_initialized();
|
|
|
|
assert_false(initialized);
|
|
|
|
}
|
|
|
|
|
2010-12-28 16:15:32 +03:00
|
|
|
int torture_run_tests(void) {
|
2015-09-07 11:39:51 +03:00
|
|
|
int rc;
|
|
|
|
struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(torture_ssh_init),
|
2018-11-12 13:17:20 +03:00
|
|
|
cmocka_unit_test(torture_ssh_init_after_finalize),
|
2020-04-06 13:07:28 +03:00
|
|
|
cmocka_unit_test(torture_is_ssh_initialized),
|
2010-12-28 16:15:32 +03:00
|
|
|
};
|
2015-09-07 11:39:51 +03:00
|
|
|
|
2014-09-02 11:07:17 +04:00
|
|
|
torture_filter_tests(tests);
|
2015-09-07 11:39:51 +03:00
|
|
|
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
|
|
2015-09-09 10:17:46 +03:00
|
|
|
return rc;
|
2010-12-28 16:15:32 +03:00
|
|
|
}
|