summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2015-11-16 16:30:37 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2015-11-20 14:16:15 +0100
commite52a7a2db355663f3e42ab54311ccc08f837dcd7 (patch)
tree3cc5c977707641fd8e0440f7844bbb22c34b29fa
parent41b3be9b042e65df0ff59ee84ce5baa53985d658 (diff)
downloadgnutls-e52a7a2db355663f3e42ab54311ccc08f837dcd7.tar.gz
tests: added check for overriding global initialization
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/global-init-override.c63
2 files changed, 66 insertions, 1 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 402ec1244d..9b5cd5a060 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -84,7 +84,9 @@ ctests = mini-record-2 simple gc set_pkcs12_cred certder certuniqueid \
mini-cert-status mini-rsa-psk global-init sec-params \
fips-test mini-global-load name-constraints x509-extensions \
long-session-id mini-x509-callbacks-intr \
- crlverify init_fds mini-rehandshake-2 sign-md5-rep
+ crlverify init_fds mini-rehandshake-2 sign-md5-rep global-init-override
+
+mini_dtls_pthread_LDADD = $(LDADD) -lpthread
if ENABLE_OCSP
ctests += ocsp
diff --git a/tests/global-init-override.c b/tests/global-init-override.c
new file mode 100644
index 0000000000..f7024f9bef
--- /dev/null
+++ b/tests/global-init-override.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2008-2012 Free Software Foundation, Inc.
+ *
+ * Author: Joe Orton
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GnuTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/* Parts copied from GnuTLS example programs. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+#include "utils.h"
+
+/* We test whether implicit global initialization can be overriden */
+
+GNUTLS_SKIP_GLOBAL_INIT
+
+void doit(void)
+{
+ int ret;
+ gnutls_x509_crt_t crt;
+
+ ret = gnutls_x509_crt_init(&crt);
+ if (ret >= 0) {
+ fail("Library is already initialized\n");
+ }
+
+ gnutls_global_init();
+
+ ret = gnutls_x509_crt_init(&crt);
+ if (ret < 0) {
+ fail("Could not init certificate!\n");
+ }
+ gnutls_x509_crt_deinit(crt);
+
+ gnutls_global_deinit();
+}