1 /* t-eventloop.c - Regression test.
2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 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. */
33 #include <sys/types.h>
34 #include <sys/select.h>
38 #include "t-support.h"
41 /* Stripped down version of gpgme/wait.c. */
49 struct op_result op_result;
60 struct one_fd fdlist[FDLIST_MAX];
63 add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc, void *fnc_data,
66 struct one_fd *fds = data;
69 for (i = 0; i < FDLIST_MAX; i++)
76 fds[i].fnc_data = fnc_data;
81 return gpgme_err_make (GPG_ERR_SOURCE_USER_1, GPG_ERR_GENERAL);
87 remove_io_cb (void *tag)
89 struct one_fd *fd = tag;
95 io_event (void *data, gpgme_event_io_t type, void *type_data)
97 struct op_result *result = data;
99 if (type == GPGME_EVENT_DONE)
102 result->err = * (gpgme_error_t *) type_data;
117 for (i = 0; i < FDLIST_MAX; i++)
118 if (fdlist[i].fd != -1)
119 FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds);
123 n = select (FD_SETSIZE, &rfds, &wfds, NULL, 0);
125 while (n < 0 && errno == EINTR);
128 return n; /* Error or timeout. */
130 for (i = 0; i < FDLIST_MAX && n; i++)
132 if (fdlist[i].fd != -1)
134 if (FD_ISSET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds))
139 (*fdlist[i].fnc) (fdlist[i].fnc_data, fdlist[i].fd);
155 while (n >= 0 && !op_result.done);
160 struct gpgme_io_cbs io_cbs =
171 main (int argc, char *argv[])
175 gpgme_data_t in, out;
176 gpgme_key_t key[3] = { NULL, NULL, NULL };
179 init_gpgme (GPGME_PROTOCOL_OpenPGP);
181 for (i = 0; i < FDLIST_MAX; i++)
184 err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
187 err = gpgme_new (&ctx);
189 gpgme_set_armor (ctx, 1);
190 gpgme_set_io_cbs (ctx, &io_cbs);
193 err = gpgme_data_new_from_mem (&in, "Hallo Leute\n", 12, 0);
196 err = gpgme_data_new (&out);
199 err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734",
202 err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",
206 err = gpgme_op_encrypt_start (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out);
210 fail_if_err (op_result.err);
214 fputs ("Begin Result:\n", stdout);
216 fputs ("End Result.\n", stdout);
218 gpgme_key_unref (key[0]);
219 gpgme_key_unref (key[1]);
220 gpgme_data_release (in);
221 gpgme_data_release (out);