aboutsummaryrefslogtreecommitdiff
path: root/src/social/test_social.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/social/test_social.c')
-rw-r--r--src/social/test_social.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/src/social/test_social.c b/src/social/test_social.c
new file mode 100644
index 000000000..8851ba0df
--- /dev/null
+++ b/src/social/test_social.c
@@ -0,0 +1,158 @@
1/*
2 * This file is part of GNUnet
3 * (C) 2013 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 3, 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/**
22 * @file social/test_social.c
23 * @brief Test for the SOCIAL service.
24 * @author Gabor X Toth
25 * @author Christian Grothoff
26 */
27
28#include <inttypes.h>
29
30#include "platform.h"
31#include "gnunet_crypto_lib.h"
32#include "gnunet_common.h"
33#include "gnunet_util_lib.h"
34#include "gnunet_testing_lib.h"
35#include "gnunet_env_lib.h"
36#include "gnunet_social_service.h"
37
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
39
40#define DEBUG_SERVICE 0
41
42/**
43 * Return value from 'main'.
44 */
45static int res;
46
47static const struct GNUNET_CONFIGURATION_Handle *cfg;
48
49/**
50 * Handle for task for timeout termination.
51 */
52static GNUNET_SCHEDULER_TaskIdentifier end_badly_task;
53
54
55/**
56 * Clean up all resources used.
57 */
58static void
59cleanup ()
60{
61
62}
63
64
65/**
66 * Terminate the test case (failure).
67 *
68 * @param cls NULL
69 * @param tc scheduler context
70 */
71static void
72end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
73{
74 res = 1;
75 cleanup ();
76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Test FAILED.\n");
77}
78
79
80/**
81 * Terminate the test case (success).
82 *
83 * @param cls NULL
84 * @param tc scheduler context
85 */
86static void
87end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
88{
89 res = 0;
90 cleanup ();
91 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test PASSED.\n");
92}
93
94
95/**
96 * Finish the test case (successfully).
97 */
98static void
99end ()
100{
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ending tests.\n");
102
103 if (end_badly_task != GNUNET_SCHEDULER_NO_TASK)
104 {
105 GNUNET_SCHEDULER_cancel (end_badly_task);
106 end_badly_task = GNUNET_SCHEDULER_NO_TASK;
107 }
108 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS,
109 &end_normally, NULL);
110}
111
112
113/**
114 * Main function of the test, run from scheduler.
115 *
116 * @param cls NULL
117 * @param cfg configuration we use (also to connect to SOCIAL service)
118 * @param peer handle to access more of the peer (not used)
119 */
120static void
121#if DEBUG_SERVICE
122run (void *cls, char *const *args, const char *cfgfile,
123 const struct GNUNET_CONFIGURATION_Handle *c)
124#else
125run (void *cls,
126 const struct GNUNET_CONFIGURATION_Handle *c,
127 struct GNUNET_TESTING_Peer *peer)
128#endif
129{
130 cfg = c;
131 end_badly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
132
133 /* FIXME: add tests */
134
135 end ();
136}
137
138
139int
140main (int argc, char *argv[])
141{
142 res = 1;
143#if DEBUG_SERVICE
144 const struct GNUNET_GETOPT_CommandLineOption opts[] = {
145 GNUNET_GETOPT_OPTION_END
146 };
147 if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "test-social",
148 "test-social [options]",
149 opts, &run, NULL))
150 return 1;
151#else
152 if (0 != GNUNET_TESTING_peer_run ("test-social", "test_social.conf", &run, NULL))
153 return 1;
154#endif
155 return res;
156}
157
158/* end of test_social.c */