aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-02-06 15:33:17 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-02-06 16:35:54 +0100
commit22b1e5bc7c32e24b7b39435af2321ba281018dd6 (patch)
tree1044323d86bb262961da5f55b3668ef99d9eb693 /tests
parent38d6d38c1fcc9d323a062c413a5c0b6b8ef6590c (diff)
downloadlibssh-22b1e5bc7c32e24b7b39435af2321ba281018dd6.tar.gz
libssh-22b1e5bc7c32e24b7b39435af2321ba281018dd6.tar.xz
libssh-22b1e5bc7c32e24b7b39435af2321ba281018dd6.zip
tests: Added test for sftp directory functions.
Diffstat (limited to 'tests')
-rw-r--r--tests/client/CMakeLists.txt1
-rw-r--r--tests/client/torture_sftp_dir.c67
-rw-r--r--tests/torture.c5
3 files changed, 73 insertions, 0 deletions
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt
index 820df172..cfce09ea 100644
--- a/tests/client/CMakeLists.txt
+++ b/tests/client/CMakeLists.txt
@@ -7,4 +7,5 @@ add_cmockery_test(torture_knownhosts torture_knownhosts.c ${TORTURE_LIBRARY})
add_cmockery_test(torture_proxycommand torture_proxycommand.c ${TORTURE_LIBRARY})
if (WITH_SFTP)
add_cmockery_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
+ add_cmockery_test(torture_sftp_dir torture_sftp_dir.c ${TORTURE_LIBRARY})
endif (WITH_SFTP)
diff --git a/tests/client/torture_sftp_dir.c b/tests/client/torture_sftp_dir.c
new file mode 100644
index 00000000..68e59848
--- /dev/null
+++ b/tests/client/torture_sftp_dir.c
@@ -0,0 +1,67 @@
+#define LIBSSH_STATIC
+
+#include "torture.h"
+#include "sftp.c"
+
+static void setup(void **state) {
+ ssh_session session;
+ struct torture_sftp *t;
+ char *host;
+ char *user;
+ char *password;
+
+ host = getenv("TORTURE_HOST");
+ if (host == NULL) {
+ host = (char *) "localhost";
+ }
+
+ user = getenv("TORTURE_USER");
+ password = getenv("TORTURE_PASSWORD");
+
+ session = torture_ssh_session(host, user, password);
+ t = torture_sftp_session(session);
+ assert_false(t == NULL);
+
+ *state = t;
+}
+
+static void teardown(void **state) {
+ struct torture_sftp *t = *state;
+
+ torture_rmdirs(t->testdir);
+ torture_sftp_close(t);
+}
+
+static void torture_sftp_mkdir(void **state) {
+ struct torture_sftp *t = *state;
+ char tmpdir[128];
+ int rc;
+
+ snprintf(tmpdir, sizeof(tmpdir), "%s/mkdir_test", t->testdir);
+
+ rc = sftp_mkdir(t->sftp, tmpdir, 0755);
+ assert_true(rc == 0);
+
+ /* check if it really has been created */
+ assert_true(torture_isdir(tmpdir));
+
+ rc = sftp_rmdir(t->sftp, tmpdir);
+ assert_true(rc == 0);
+
+ /* check if it has been deleted */
+ assert_false(torture_isdir(tmpdir));
+}
+
+int torture_run_tests(void) {
+ int rc;
+ const UnitTest tests[] = {
+ unit_test_setup_teardown(torture_sftp_mkdir, setup, teardown)
+ };
+
+ ssh_init();
+
+ rc = run_tests(tests);
+ ssh_finalize();
+
+ return rc;
+}
diff --git a/tests/torture.c b/tests/torture.c
index 92d9c97a..1354752c 100644
--- a/tests/torture.c
+++ b/tests/torture.c
@@ -202,6 +202,7 @@ struct torture_sftp *torture_sftp_session(ssh_session session) {
struct torture_sftp *t;
char template[] = "/tmp/ssh_torture_XXXXXX";
char *p;
+ int rc;
if (session == NULL) {
return NULL;
@@ -218,6 +219,10 @@ struct torture_sftp *torture_sftp_session(ssh_session session) {
goto failed;
}
+ rc = sftp_init(t->sftp);
+ if (rc < 0) {
+ goto failed;
+ }
p = mkdtemp(template);
if (p == NULL) {