Tizen 2.0 Release
[external/libgnutls26.git] / tests / simple.c
1 /*
2  * Copyright (C) 2004, 2005, 2008, 2009, 2010 Free Software Foundation,
3  * Inc.
4  *
5  * Author: Simon Josefsson
6  *
7  * This file is part of GnuTLS.
8  *
9  * GnuTLS is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * GnuTLS is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GnuTLS; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29
30 #include "utils.h"
31
32 void
33 doit (void)
34 {
35   if (debug)
36     {
37       printf ("GnuTLS header version %s.\n", GNUTLS_VERSION);
38       printf ("GnuTLS library version %s.\n", gnutls_check_version (NULL));
39     }
40
41   if (!gnutls_check_version (GNUTLS_VERSION))
42     fail ("gnutls_check_version ERROR\n");
43
44   {
45     const gnutls_pk_algorithm_t *algs;
46     size_t i;
47     int pk;
48
49     algs = gnutls_pk_list ();
50     if (!algs)
51       fail ("gnutls_pk_list return NULL\n");
52
53     for (i = 0; algs[i]; i++)
54       {
55         if (debug)
56           printf ("pk_list[%d] = %d = %s = %d\n", (int) i, algs[i],
57                   gnutls_pk_algorithm_get_name (algs[i]),
58                   gnutls_pk_get_id (gnutls_pk_algorithm_get_name (algs[i])));
59         if (gnutls_pk_get_id (gnutls_pk_algorithm_get_name (algs[i]))
60             != algs[i])
61           fail ("gnutls_pk id's doesn't match\n");
62       }
63
64     pk = gnutls_pk_get_id ("foo");
65     if (pk != GNUTLS_PK_UNKNOWN)
66       fail ("gnutls_pk unknown test failed (%d)\n", pk);
67
68     if (debug)
69       success ("gnutls_pk_list ok\n");
70   }
71
72   {
73     const gnutls_sign_algorithm_t *algs;
74     size_t i;
75     int pk;
76
77     algs = gnutls_sign_list ();
78     if (!algs)
79       fail ("gnutls_sign_list return NULL\n");
80
81     for (i = 0; algs[i]; i++)
82       {
83         if (debug)
84           printf ("sign_list[%d] = %d = %s = %d\n", (int) i, algs[i],
85                   gnutls_sign_algorithm_get_name (algs[i]),
86                   gnutls_sign_get_id (gnutls_sign_algorithm_get_name
87                                       (algs[i])));
88         if (gnutls_sign_get_id (gnutls_sign_algorithm_get_name (algs[i])) !=
89             algs[i])
90           fail ("gnutls_sign id's doesn't match\n");
91       }
92
93     pk = gnutls_sign_get_id ("foo");
94     if (pk != GNUTLS_PK_UNKNOWN)
95       fail ("gnutls_sign unknown test failed (%d)\n", pk);
96
97     if (debug)
98       success ("gnutls_sign_list ok\n");
99   }
100 }