diff options
author | Gabor X Toth <*@tg-x.net> | 2013-08-27 07:29:59 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2013-08-27 07:29:59 +0000 |
commit | 0f87ae3787762ea32fb3d9580d13782cb2aacdd2 (patch) | |
tree | d56c234e6e33be730ca02bb79da65caae28efd23 /src/psycstore/test_psycstore.c | |
parent | dff71f18889ee5ca515ab096c8f925858968f1fc (diff) | |
download | gnunet-0f87ae3787762ea32fb3d9580d13782cb2aacdd2.tar.gz gnunet-0f87ae3787762ea32fb3d9580d13782cb2aacdd2.zip |
psycstore service skeleton
Diffstat (limited to 'src/psycstore/test_psycstore.c')
-rw-r--r-- | src/psycstore/test_psycstore.c | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/src/psycstore/test_psycstore.c b/src/psycstore/test_psycstore.c new file mode 100644 index 000000000..405d1622c --- /dev/null +++ b/src/psycstore/test_psycstore.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 psycstore/test_psycstore.c | ||
23 | * @brief Testcase for the PSYCstore service | ||
24 | * @author Gabor X Toth | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_common.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_psycstore_service.h" | ||
32 | #include "gnunet_testing_lib.h" | ||
33 | |||
34 | |||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
36 | |||
37 | |||
38 | /** | ||
39 | * Return value from 'main'. | ||
40 | */ | ||
41 | static int res; | ||
42 | |||
43 | /** | ||
44 | * Handle to PSYCstore service. | ||
45 | */ | ||
46 | static struct GNUNET_PSYCSTORE_Handle *h; | ||
47 | |||
48 | /** | ||
49 | * Handle to PSYCstore operation. | ||
50 | */ | ||
51 | static struct GNUNET_PSYCSTORE_Operation *op; | ||
52 | |||
53 | /** | ||
54 | * Handle for task for timeout termination. | ||
55 | */ | ||
56 | static GNUNET_SCHEDULER_TaskIdentifier endbadly_task; | ||
57 | |||
58 | |||
59 | /** | ||
60 | * Clean up all resources used. | ||
61 | */ | ||
62 | static void | ||
63 | cleanup () | ||
64 | { | ||
65 | if (NULL != op) | ||
66 | { | ||
67 | GNUNET_PSYCSTORE_operation_cancel (op); | ||
68 | op = NULL; | ||
69 | } | ||
70 | if (NULL != h) | ||
71 | { | ||
72 | GNUNET_PSYCSTORE_disconnect (h); | ||
73 | h = NULL; | ||
74 | } | ||
75 | GNUNET_SCHEDULER_shutdown (); | ||
76 | } | ||
77 | |||
78 | |||
79 | /** | ||
80 | * Termiante the testcase (failure). | ||
81 | * | ||
82 | * @param cls NULL | ||
83 | * @param tc scheduler context | ||
84 | */ | ||
85 | static void | ||
86 | endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
87 | { | ||
88 | cleanup (); | ||
89 | res = 1; | ||
90 | } | ||
91 | |||
92 | |||
93 | /** | ||
94 | * Termiante the testcase (success). | ||
95 | * | ||
96 | * @param cls NULL | ||
97 | * @param tc scheduler context | ||
98 | */ | ||
99 | static void | ||
100 | end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
101 | { | ||
102 | cleanup (); | ||
103 | res = 0; | ||
104 | } | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Finish the testcase (successfully). | ||
109 | */ | ||
110 | static void | ||
111 | end () | ||
112 | { | ||
113 | if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) | ||
114 | { | ||
115 | GNUNET_SCHEDULER_cancel (endbadly_task); | ||
116 | endbadly_task = GNUNET_SCHEDULER_NO_TASK; | ||
117 | } | ||
118 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | ||
119 | &end_normally, NULL); | ||
120 | } | ||
121 | |||
122 | |||
123 | /** | ||
124 | * Main function of the test, run from scheduler. | ||
125 | * | ||
126 | * @param cls NULL | ||
127 | * @param cfg configuration we use (also to connect to PSYCstore service) | ||
128 | * @param peer handle to access more of the peer (not used) | ||
129 | */ | ||
130 | static void | ||
131 | run (void *cls, | ||
132 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
133 | struct GNUNET_TESTING_Peer *peer) | ||
134 | { | ||
135 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
136 | &endbadly, NULL); | ||
137 | h = GNUNET_PSYCSTORE_connect (cfg); | ||
138 | GNUNET_assert (NULL != h); | ||
139 | end (); | ||
140 | } | ||
141 | |||
142 | |||
143 | int | ||
144 | main (int argc, char *argv[]) | ||
145 | { | ||
146 | res = 1; | ||
147 | if (0 != | ||
148 | GNUNET_TESTING_service_run ("test-psycstore", | ||
149 | "psycstore", | ||
150 | "test_psycstore.conf", | ||
151 | &run, | ||
152 | NULL)) | ||
153 | return 1; | ||
154 | return res; | ||
155 | } | ||
156 | |||
157 | |||
158 | /* end of test_psycstore.c */ | ||