[gnome-keyring/trust-store: 20/26] [gcr] GcrSimpleCertificate tests.



commit 44153b4b098468c775bd54587ccf0d3c4d9af32a
Author: Stef Walter <stefw collabora co uk>
Date:   Mon Dec 6 21:12:17 2010 +0000

    [gcr] GcrSimpleCertificate tests.

 gcr/gcr-simple-certificate.c        |    4 +-
 gcr/tests/Makefile.am               |    1 +
 gcr/tests/test-simple-certificate.c |   84 +++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 3 deletions(-)
---
diff --git a/gcr/gcr-simple-certificate.c b/gcr/gcr-simple-certificate.c
index 482593f..c9521c0 100644
--- a/gcr/gcr-simple-certificate.c
+++ b/gcr/gcr-simple-certificate.c
@@ -25,8 +25,6 @@
 #include "gcr-internal.h"
 #include "gcr-simple-certificate.h"
 
-#include "egg/egg-hex.h"
-
 #include <string.h>
 
 struct _GcrSimpleCertificatePrivate {
@@ -71,7 +69,7 @@ gcr_simple_certificate_class_init (GcrSimpleCertificateClass *klass)
 	_gcr_initialize ();
 }
 
-static const guchar* 
+static const guchar*
 gcr_simple_certificate_real_get_der_data (GcrCertificate *base, gsize *n_data)
 {
 	GcrSimpleCertificate *self = GCR_SIMPLE_CERTIFICATE (base);
diff --git a/gcr/tests/Makefile.am b/gcr/tests/Makefile.am
index 4726bfc..e55c99d 100644
--- a/gcr/tests/Makefile.am
+++ b/gcr/tests/Makefile.am
@@ -2,6 +2,7 @@
 # Test files should be listed in order they need to run
 TESTING_FILES = \
 	unit-test-certificate.c \
+	test-simple-certificate.c \
 	test-trust.c \
 	unit-test-parser.c
 
diff --git a/gcr/tests/test-simple-certificate.c b/gcr/tests/test-simple-certificate.c
new file mode 100644
index 0000000..3bc18dd
--- /dev/null
+++ b/gcr/tests/test-simple-certificate.c
@@ -0,0 +1,84 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+   Copyright (C) 2010 Collabora Ltd
+
+   The Gnome Keyring Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Keyring Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+
+   Author: Stef Walter <stefw collabora co uk>
+*/
+
+#include "config.h"
+
+#include "test-suite.h"
+
+#include "gcr.h"
+#include "gcr/gcr-internal.h"
+
+#include "gck/gck-test.h"
+
+#include "pkcs11/pkcs11n.h"
+
+#include <glib.h>
+
+static gpointer cert_data;
+static gsize n_cert_data;
+
+TESTING_SETUP (simple_certificate)
+{
+	cert_data = testing_data_read ("der-certificate.crt", &n_cert_data);
+	g_assert (cert_data);
+}
+
+TESTING_TEARDOWN (simple_certificate)
+{
+	g_free (cert_data);
+	cert_data = NULL;
+	n_cert_data = 0;
+}
+
+TESTING_TEST (simple_certificate_new)
+{
+	GcrCertificate *cert;
+	gconstpointer der;
+	gsize n_der;
+
+	cert = gcr_simple_certificate_new (cert_data, n_cert_data);
+	g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert));
+
+	der = gcr_certificate_get_der_data (cert, &n_der);
+	g_assert (der);
+	g_assert_cmpsize (n_der, ==, n_cert_data);
+	g_assert (memcmp (der, cert_data, n_der) == 0);
+
+	g_object_unref (cert);
+}
+
+TESTING_TEST (simple_certificate_new_static)
+{
+	GcrCertificate *cert;
+	gconstpointer der;
+	gsize n_der;
+
+	cert = gcr_simple_certificate_new_static (cert_data, n_cert_data);
+	g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert));
+
+	der = gcr_certificate_get_der_data (cert, &n_der);
+	g_assert (der);
+	g_assert_cmpsize (n_der, ==, n_cert_data);
+	g_assert (der == cert_data); /* Must be same pointer */
+
+	g_object_unref (cert);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]