From 901ea927ce87fe739ff2688d43bfdc3eae506b1e Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Sat, 23 May 2015 19:23:35 -0500
Subject: flesh out libtls test program a bit, move to tests

---
 libtls-standalone/Makefile.am       |  2 +-
 libtls-standalone/app/Makefile.am   |  6 -----
 libtls-standalone/app/test.c        |  6 -----
 libtls-standalone/configure.ac      |  2 +-
 libtls-standalone/src/Makefile.am   |  2 +-
 libtls-standalone/tests/Makefile.am |  7 +++++
 libtls-standalone/tests/test.c      | 51 +++++++++++++++++++++++++++++++++++++
 7 files changed, 61 insertions(+), 15 deletions(-)
 delete mode 100644 libtls-standalone/app/Makefile.am
 delete mode 100644 libtls-standalone/app/test.c
 create mode 100644 libtls-standalone/tests/Makefile.am
 create mode 100644 libtls-standalone/tests/test.c

diff --git a/libtls-standalone/Makefile.am b/libtls-standalone/Makefile.am
index 66fe845..2581717 100644
--- a/libtls-standalone/Makefile.am
+++ b/libtls-standalone/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = include compat src app man
+SUBDIRS = include compat src tests man
 ACLOCAL_AMFLAGS = -I m4
 
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/libtls-standalone/app/Makefile.am b/libtls-standalone/app/Makefile.am
deleted file mode 100644
index 75a3dd6..0000000
--- a/libtls-standalone/app/Makefile.am
+++ /dev/null
@@ -1,6 +0,0 @@
-AM_CFLAGS = -I$(top_srcdir)/include
-
-bin_PROGRAMS = test
-
-test_SOURCES = test.c
-test_LDADD = -lcrypto -lssl $(top_builddir)/src/libtls.la
diff --git a/libtls-standalone/app/test.c b/libtls-standalone/app/test.c
deleted file mode 100644
index e3c3f76..0000000
--- a/libtls-standalone/app/test.c
+++ /dev/null
@@ -1,6 +0,0 @@
-#include <tls.h>
-
-int main()
-{
-	tls_init();
-}
diff --git a/libtls-standalone/configure.ac b/libtls-standalone/configure.ac
index e8fb24e..ebdd850 100644
--- a/libtls-standalone/configure.ac
+++ b/libtls-standalone/configure.ac
@@ -42,10 +42,10 @@ CHECK_LIBC_CRYPTO_COMPAT
 AC_CONFIG_FILES([
 	Makefile
 	include/Makefile
-	app/Makefile
 	compat/Makefile
 	man/Makefile
 	src/Makefile
+	tests/Makefile
 	libtls.pc
 ])
 
diff --git a/libtls-standalone/src/Makefile.am b/libtls-standalone/src/Makefile.am
index e821186..7844525 100644
--- a/libtls-standalone/src/Makefile.am
+++ b/libtls-standalone/src/Makefile.am
@@ -3,7 +3,7 @@ AM_CFLAGS = -I$(top_srcdir)/include
 lib_LTLIBRARIES = libtls.la
 
 libtls_la_LDFLAGS = -version-info @LIBTLS_VERSION@ -no-undefined
-libtls_la_LIBADD = -lcrypto -lssl $(PLATFORM_LDADD)
+libtls_la_LIBADD = -lcrypto -lssl -lcrypto $(PLATFORM_LDADD)
 libtls_la_LIBADD += $(top_builddir)/compat/libcompat.la
 libtls_la_LIBADD += $(top_builddir)/compat/libcompatnoopt.la
 
diff --git a/libtls-standalone/tests/Makefile.am b/libtls-standalone/tests/Makefile.am
new file mode 100644
index 0000000..1a08aef
--- /dev/null
+++ b/libtls-standalone/tests/Makefile.am
@@ -0,0 +1,7 @@
+AM_CFLAGS = -I$(top_srcdir)/include
+
+check_PROGRAMS = test
+
+TESTS = test
+test_SOURCES = test.c
+test_LDADD = -lcrypto -lssl $(top_builddir)/src/libtls.la
diff --git a/libtls-standalone/tests/test.c b/libtls-standalone/tests/test.c
new file mode 100644
index 0000000..b2b7c67
--- /dev/null
+++ b/libtls-standalone/tests/test.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <tls.h>
+
+int main()
+{
+	struct tls *tls;
+	struct tls_config *tls_config;
+	size_t written, read;
+	char buf[4096];
+
+	if (tls_init() != 0) {
+		fprintf(stderr, "tls_init failed");
+		return 1;
+	}
+
+	if ((tls = tls_client()) == NULL)
+		goto err;
+
+	if ((tls_config = tls_config_new()) == NULL)
+		goto err;
+
+	if (tls_config_set_ciphers(tls_config, "compat") != 0)
+		goto err;
+
+	tls_config_insecure_noverifycert(tls_config);
+	tls_config_insecure_noverifyname(tls_config);
+
+	if (tls_configure(tls, tls_config) != 0)
+		goto err;
+
+	if (tls_connect(tls, "google.com", "443") != 0)
+		goto err;
+
+	if (tls_write(tls, "GET /\r\n", 7, &written) != 0)
+		goto err;
+
+	if (tls_read(tls, buf, sizeof(buf), &read) != 0)
+		goto err;
+
+	buf[read - 1] = '\0';
+	puts(buf);
+
+	if (tls_close(tls) != 0)
+		goto err;
+
+	return 0;
+
+err:
+	fprintf(stderr, "%s\n", tls_error(tls));
+	return 0;
+}
-- 
cgit v1.2.3-55-g6feb