1 /* t-import.c - Regression test.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2003, 2004 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* We need to include config.h so that we know whether we are building
23 with large file system (LFS) support. */
35 #include "t-support.h"
39 check_result (gpgme_import_result_t result, char *fpr, int secret)
41 if (result->considered != 1 && (secret && result->considered != 3))
43 fprintf (stderr, "Unexpected number of considered keys %i\n",
47 if (result->no_user_id != 0)
49 fprintf (stderr, "Unexpected number of user ids %i\n",
53 if ((secret && result->imported != 0)
54 || (!secret && (result->imported != 0 && result->imported != 1)))
56 fprintf (stderr, "Unexpected number of imported keys %i\n",
60 if (result->imported_rsa != 0)
62 fprintf (stderr, "Unexpected number of imported RSA keys %i\n",
63 result->imported_rsa);
66 if ((secret && (result->unchanged != 0 && result->unchanged != 1))
67 || (!secret && ((result->imported == 0 && result->unchanged != 1)
68 || (result->imported == 1 && result->unchanged != 0))))
70 fprintf (stderr, "Unexpected number of unchanged keys %i\n",
74 if (result->new_user_ids != 0)
76 fprintf (stderr, "Unexpected number of new user IDs %i\n",
77 result->new_user_ids);
80 if (result->new_sub_keys != 0)
82 fprintf (stderr, "Unexpected number of new sub keys %i\n",
83 result->new_sub_keys);
87 && ((result->secret_imported == 0 && result->new_signatures != 0)
88 || (result->secret_imported == 1 && result->new_signatures > 1)))
89 || (!secret && result->new_signatures != 0))
91 fprintf (stderr, "Unexpected number of new signatures %i\n",
92 result->new_signatures);
93 if (result->new_signatures == 2)
94 fprintf (stderr, "### ignored due to gpg 1.3.4 problems\n");
98 if (result->new_revocations != 0)
100 fprintf (stderr, "Unexpected number of new revocations %i\n",
101 result->new_revocations);
104 if ((secret && result->secret_read != 1 && result->secret_read != 3)
105 || (!secret && result->secret_read != 0))
107 fprintf (stderr, "Unexpected number of secret keys read %i\n",
108 result->secret_read);
111 if ((secret && result->secret_imported != 0 && result->secret_imported != 1)
112 || (!secret && result->secret_imported != 0))
114 fprintf (stderr, "Unexpected number of secret keys imported %i\n",
115 result->secret_imported);
119 && ((result->secret_imported == 0 && result->secret_unchanged != 1
120 && result->secret_unchanged != 2)
121 || (result->secret_imported == 1 && result->secret_unchanged != 0)))
122 || (!secret && result->secret_unchanged != 0))
124 fprintf (stderr, "Unexpected number of secret keys unchanged %i\n",
125 result->secret_unchanged);
128 if (result->not_imported != 0)
130 fprintf (stderr, "Unexpected number of secret keys not imported %i\n",
131 result->not_imported);
137 || (result->imports->next && result->imports->next->next))
139 fprintf (stderr, "Unexpected number of status reports\n");
145 if (!result->imports || result->imports->next)
147 fprintf (stderr, "Unexpected number of status reports\n");
151 if (strcmp (fpr, result->imports->fpr))
153 fprintf (stderr, "Unexpected fingerprint %s\n",
154 result->imports->fpr);
157 if (result->imports->next && strcmp (fpr, result->imports->next->fpr))
159 fprintf (stderr, "Unexpected fingerprint on second status %s\n",
160 result->imports->next->fpr);
163 if (result->imports->result != 0)
165 fprintf (stderr, "Unexpected status result %s\n",
166 gpgme_strerror (result->imports->result));
171 if (result->secret_imported == 0)
173 if (result->imports->status != GPGME_IMPORT_SECRET)
175 fprintf (stderr, "Unexpected status %i\n",
176 result->imports->status);
182 if (result->imports->status
183 != (GPGME_IMPORT_SECRET | GPGME_IMPORT_NEW)
184 || (result->imports->next
185 && result->imports->next->status != GPGME_IMPORT_SIG))
187 fprintf (stderr, "Unexpected status %i\n",
188 result->imports->status);
195 if ((result->imported == 0 && result->imports->status != 0)
196 || (result->imported == 1
197 && result->imports->status != GPGME_IMPORT_NEW))
199 fprintf (stderr, "Unexpected status %i\n",
200 result->imports->status);
208 main (int argc, char *argv[])
213 gpgme_import_result_t result;
214 const char *pubkey_1_asc = make_filename ("pubkey-1.asc");
215 const char *seckey_1_asc = make_filename ("seckey-1.asc");
217 init_gpgme (GPGME_PROTOCOL_OpenPGP);
219 err = gpgme_new (&ctx);
222 err = gpgme_data_new_from_file (&in, pubkey_1_asc, 1);
225 err = gpgme_op_import (ctx, in);
227 result = gpgme_op_import_result (ctx);
228 check_result (result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", 0);
229 gpgme_data_release (in);
231 err = gpgme_data_new_from_file (&in, seckey_1_asc, 1);
234 err = gpgme_op_import (ctx, in);
236 result = gpgme_op_import_result (ctx);
237 check_result (result, "ADAB7FCC1F4DE2616ECFA402AF82244F9CD9FD55", 1);
238 gpgme_data_release (in);