Subject: [libssh2] Self tests (was: Re: Libgcrypt support)

[libssh2] Self tests (was: Re: Libgcrypt support)

From: Simon Josefsson <simon_at_josefsson.org>
Date: Mon, 08 Jan 2007 15:59:17 +0100

Simon Josefsson <simon_at_josefsson.org> writes:

> I have built libssh2 with both libgcrypt and OpenSSL with this patch
> installed, and it seems to work fine (tested using curl, since there
> are no self tests in libssh2 itself, hint, hint, nudge, nudge :)).

Here is a starter for a directory tests/ which could contain self
tests. The first self-test below just tests startup/shutdown of the
library, but that may catch some fatal errors, and it is useful to run
it under valgrind or similar, to catch memory leaks. We can add more
tests in the future, and I'll probably work on those tests later on
too...

Thoughts? Comments? Any objections?

/Simon

Index: configure.in
===================================================================
RCS file: /cvsroot/libssh2/libssh2/configure.in,v
retrieving revision 1.32
diff -u -p -r1.32 configure.in
--- configure.in 13 Dec 2006 08:45:49 -0000 1.32
+++ configure.in 8 Jan 2007 14:57:17 -0000
@@ -254,5 +267,6 @@ AC_C_CONST
 AC_C_INLINE
 
 AC_CONFIG_FILES([Makefile
- src/Makefile])
+ src/Makefile
+ tests/Makefile])
 AC_OUTPUT
Index: Makefile.am
===================================================================
RCS file: /cvsroot/libssh2/libssh2/Makefile.am,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile.am
--- Makefile.am 7 Dec 2006 15:53:01 -0000 1.3
+++ Makefile.am 8 Jan 2007 14:57:17 -0000
@@ -1,6 +1,6 @@
 AUTOMAKE_OPTIONS = foreign nostdinc
 
-SUBDIRS = src
+SUBDIRS = src tests
 
 include_HEADERS = include/libssh2.h include/libssh2_publickey.h \
  include/libssh2_sftp.h
Index: Makefile.am
===================================================================
RCS file: Makefile.am
diff -N Makefile.am
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Makefile.am 8 Jan 2007 14:58:09 -0000
@@ -0,0 +1,7 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+AM_LDFLAGS = -no-install
+LDADD = ../src/libssh2.la
+
+ctests = simple$(EXEEXT)
+TESTS = $(ctests)
+check_PROGRAMS = $(ctests)
Index: simple.c
===================================================================
RCS file: simple.c
diff -N simple.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ simple.c 8 Jan 2007 14:58:09 -0000
@@ -0,0 +1,56 @@
+/* Copyright (C) 2007 The Written Word, Inc. All rights reserved.
+ * Author: Simon Josefsson
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * Neither the name of the copyright holder nor the names
+ * of any other contributors may be used to endorse or
+ * promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+
+#include "libssh2.h"
+
+int main(int argc, char *argv[])
+{
+ LIBSSH2_SESSION *session;
+
+ session = libssh2_session_init();
+ if (!session)
+ {
+ fprintf (stderr, "libssh2_session_init() failed\n");
+ return 1;
+ }
+
+ libssh2_session_free(session);
+
+ return 0;
+}

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-01-08