aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_program.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-05-29 00:46:26 +0000
committerChristian Grothoff <christian@grothoff.org>2009-05-29 00:46:26 +0000
commit0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9 (patch)
tree6b552f40eb089db96409a312a98d9b12bd669102 /src/util/test_program.c
downloadgnunet-0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9.tar.gz
gnunet-0a217a8df1657b4334b55b0e4a6c7837a8dbcfd9.zip
ng
Diffstat (limited to 'src/util/test_program.c')
-rw-r--r--src/util/test_program.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/util/test_program.c b/src/util/test_program.c
new file mode 100644
index 000000000..dee602e2a
--- /dev/null
+++ b/src/util/test_program.c
@@ -0,0 +1,94 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file util/test_program.c
22 * @brief tests for program.c
23 */
24#include "platform.h"
25#include "gnunet_common.h"
26#include "gnunet_program_lib.h"
27#include "gnunet_scheduler_lib.h"
28#include "gnunet_time_lib.h"
29
30static int setme;
31
32static struct GNUNET_GETOPT_CommandLineOption options[] = {
33 {'n', "name", NULL, "description", 0, &GNUNET_GETOPT_set_one, &setme},
34 GNUNET_GETOPT_OPTION_END
35};
36
37/**
38 * Main function that will be run.
39 */
40static void
41runner (void *cls,
42 struct GNUNET_SCHEDULER_Handle *sched,
43 char *const *args,
44 const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
45{
46 int *ok = cls;
47 GNUNET_assert (setme == 1);
48 GNUNET_assert (sched != NULL);
49 GNUNET_assert (0 == strcmp (args[0], "extra"));
50 GNUNET_assert (args[1] == NULL);
51 GNUNET_assert (0 == strcmp (cfgfile, "test_program_data.conf"));
52
53 *ok = 0;
54}
55
56
57/**
58 * Main method, starts scheduler with task1,
59 * checks that "ok" is correct at the end.
60 */
61static int
62check ()
63{
64 int ok = 1;
65 char *const argv[] = {
66 "test_program",
67 "-c",
68 "test_program_data.conf",
69 "-L",
70 "WARNING",
71 "-n",
72 "extra",
73 NULL
74 };
75 GNUNET_assert (GNUNET_OK ==
76 GNUNET_PROGRAM_run (7,
77 argv,
78 "test_program",
79 "A test", options, &runner, &ok));
80 return ok;
81}
82
83int
84main (int argc, char *argv[])
85{
86 int ret = 0;
87
88 GNUNET_log_setup ("test_program", "WARNING", NULL);
89 ret += check ();
90
91 return ret;
92}
93
94/* end of test_program.c */