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