Branch data Line data Source code
1 : : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 : : /*
3 : : Copyright (C) 2010 Collabora Ltd
4 : :
5 : : The Gnome Keyring Library is free software; you can redistribute it and/or
6 : : modify it under the terms of the GNU Library General Public License as
7 : : published by the Free Software Foundation; either version 2 of the
8 : : License, or (at your option) any later version.
9 : :
10 : : The Gnome Keyring Library is distributed in the hope that it will be useful,
11 : : but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : : Library General Public License for more details.
14 : :
15 : : You should have received a copy of the GNU Library General Public
16 : : License along with the Gnome Library; see the file COPYING.LIB. If not,
17 : : see <http://www.gnu.org/licenses/>.
18 : :
19 : : Author: Stef Walter <stefw@collabora.co.uk>
20 : : */
21 : :
22 : : #include "config.h"
23 : :
24 : : #include "gcr/gcr.h"
25 : : #include "gcr/gcr-internal.h"
26 : :
27 : : #include "gck/gck-test.h"
28 : :
29 : : #include "egg/egg-testing.h"
30 : :
31 : : #include <glib.h>
32 : :
33 : : #include <errno.h>
34 : :
35 : : typedef struct {
36 : : gpointer cert_data;
37 : : gsize n_cert_data;
38 : : } Test;
39 : :
40 : : static void
41 : 2 : setup (Test *test, gconstpointer unused)
42 : : {
43 [ - + ]: 2 : if (!g_file_get_contents (SRCDIR "/gcr/fixtures/der-certificate.crt", (gchar**)&test->cert_data,
44 : : &test->n_cert_data, NULL))
45 : 0 : g_assert_not_reached ();
46 [ - + ]: 2 : g_assert (test->cert_data);
47 : 2 : }
48 : :
49 : : static void
50 : 2 : teardown (Test *test, gconstpointer unused)
51 : : {
52 : 2 : g_free (test->cert_data);
53 : 2 : }
54 : :
55 : : static void
56 : 1 : test_new (Test *test, gconstpointer unused)
57 : : {
58 : : GcrCertificate *cert;
59 : : gconstpointer der;
60 : : gsize n_der;
61 : :
62 : 1 : cert = gcr_simple_certificate_new (test->cert_data, test->n_cert_data);
63 [ - + + - : 1 : g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert));
+ - - + ]
64 : :
65 : 1 : der = gcr_certificate_get_der_data (cert, &n_der);
66 [ - + ]: 1 : g_assert (der);
67 [ + - + - ]: 1 : egg_assert_cmpmem (der, n_der, ==, test->cert_data, test->n_cert_data);
68 : :
69 : 1 : g_object_unref (cert);
70 : 1 : }
71 : :
72 : : static void
73 : 1 : test_new_static (Test *test, gconstpointer unused)
74 : : {
75 : : GcrCertificate *cert;
76 : : gconstpointer der;
77 : : gsize n_der;
78 : :
79 : 1 : cert = gcr_simple_certificate_new_static (test->cert_data, test->n_cert_data);
80 [ - + + - : 1 : g_assert (GCR_IS_SIMPLE_CERTIFICATE (cert));
+ - - + ]
81 : :
82 : 1 : der = gcr_certificate_get_der_data (cert, &n_der);
83 [ - + ]: 1 : g_assert (der);
84 [ - + ]: 1 : egg_assert_cmpsize (n_der, ==, test->n_cert_data);
85 [ - + ]: 1 : g_assert (der == test->cert_data); /* Must be same pointer */
86 : :
87 : 1 : g_object_unref (cert);
88 : 1 : }
89 : :
90 : : int
91 : 1 : main (int argc, char **argv)
92 : : {
93 : 1 : g_test_init (&argc, &argv, NULL);
94 : 1 : g_set_prgname ("test-simple-certificate");
95 : :
96 : 1 : g_test_add ("/gcr/simple-certificate/new", Test, NULL, setup, test_new, teardown);
97 : 1 : g_test_add ("/gcr/simple-certificate/new_static", Test, NULL, setup, test_new_static, teardown);
98 : :
99 : 1 : return g_test_run ();
100 : : }
|