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