aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/t-encrypt.c28
-rw-r--r--tests/t-verify.c85
3 files changed, 113 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index eab4df3c..aced4007 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to create Makefile.in
-TESTS = t-encrypt
+TESTS = t-encrypt t-verify
INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/intl
diff --git a/tests/t-encrypt.c b/tests/t-encrypt.c
index 8f6e5c5d..d99beff0 100644
--- a/tests/t-encrypt.c
+++ b/tests/t-encrypt.c
@@ -31,6 +31,23 @@
exit (1); } \
} while(0)
+static void
+print_data ( GpgmeData dh )
+{
+ char buf[100];
+ size_t nread;
+ GpgmeError err;
+
+ err = gpgme_rewind_data ( dh );
+ fail_if_err (err);
+ while ( !(err = gpgme_read_data ( dh, buf, 100, &nread )) ) {
+ fwrite ( buf, nread, 1, stdout );
+ }
+ if (err != GPGME_EOF)
+ fail_if_err (err);
+}
+
+
int
main (int argc, char **argv )
@@ -40,10 +57,11 @@ main (int argc, char **argv )
GpgmeData in, out;
GpgmeRecipientSet rset;
+ do {
err = gpgme_new_context (&ctx);
fail_if_err (err);
- err = gpgme_new_data ( &in, "Hallo Leute", 11, 0 );
+ err = gpgme_new_data ( &in, "Hallo Leute\n", 12, 0 );
fail_if_err (err);
err = gpgme_new_data ( &out, NULL, 0,0 );
@@ -53,16 +71,24 @@ main (int argc, char **argv )
fail_if_err (err);
err = gpgme_add_recipient (rset, "Bob");
fail_if_err (err);
+ err = gpgme_add_recipient (rset, "Alpha");
+ fail_if_err (err);
err = gpgme_encrypt (ctx, rset, in, out );
fail_if_err (err);
+ fflush (NULL);
+ fputs ("Begin Result:\n", stdout );
+ print_data (out);
+ fputs ("End Result.\n", stdout );
gpgme_release_recipient_set (rset);
gpgme_release_data (in);
gpgme_release_data (out);
gpgme_release_context (ctx);
+ } while ( argc > 1 && !strcmp( argv[1], "--loop" ) );
+
return 0;
}
diff --git a/tests/t-verify.c b/tests/t-verify.c
new file mode 100644
index 00000000..3a948afd
--- /dev/null
+++ b/tests/t-verify.c
@@ -0,0 +1,85 @@
+/* t-verify.c - regression test
+ * Copyright (C) 2000 Werner Koch (dd9jn)
+ *
+ * This file is part of GPGME.
+ *
+ * GPGME 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GPGME 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "../gpgme/gpgme.h"
+
+static const char test_text1[] = "Just GNU it!\n";
+static const char test_text1f[]= "Just GNU it?\n";
+static const char test_sig1[] =
+"-----BEGIN PGP SIGNATURE-----\n"
+"\n"
+"iEYEABECAAYFAjoKgjIACgkQLXJ8x2hpdzQMSwCeO/xUrhysZ7zJKPf/FyXA//u1\n"
+"ZgIAn0204PBR7yxSdQx6CFxugstNqmRv\n"
+"=yku6\n"
+"-----END PGP SIGNATURE-----\n"
+;
+
+
+#define fail_if_err(a) do { if(a) { \
+ fprintf (stderr, "%s:%d: GpgmeError %s\n", \
+ __FILE__, __LINE__, gpgme_strerror(a)); \
+ exit (1); } \
+ } while(0)
+
+
+int
+main (int argc, char **argv )
+{
+ GpgmeCtx ctx;
+ GpgmeError err;
+ GpgmeData sig, text;
+
+ err = gpgme_new_context (&ctx);
+ fail_if_err (err);
+
+ do {
+ err = gpgme_new_data ( &text, test_text1, strlen (test_text1), 0 );
+ fail_if_err (err);
+ err = gpgme_new_data ( &sig, test_sig1, strlen (test_sig1), 0 );
+ fail_if_err (err);
+
+ puts ("checking a valid message:\n");
+ err = gpgme_verify (ctx, sig, text );
+ fail_if_err (err);
+
+ puts ("checking a manipulated message:\n");
+ gpgme_release_data (text);
+ err = gpgme_new_data ( &text, test_text1f, strlen (test_text1f), 0 );
+ fail_if_err (err);
+ gpgme_rewind_data ( sig );
+ err = gpgme_verify (ctx, sig, text );
+ fail_if_err (err);
+
+ gpgme_release_data (sig);
+ gpgme_release_data (text);
+
+} while ( argc > 1 && !strcmp( argv[1], "--loop" ) );
+ gpgme_release_context (ctx);
+
+ return 0;
+}
+
+
+