diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-07-09 14:46:56 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-07-09 14:46:56 +0000 |
commit | e5d7c67c647e9620c5c1ae77e133a74698443ee1 (patch) | |
tree | 1f49323d5963cc4a77e2648b29744ad5cf6291bf /src/peerstore/test_peerstore_api_sync.c | |
parent | 696df0a02abec9683b34c3097cff4448ad154367 (diff) | |
download | gnunet-e5d7c67c647e9620c5c1ae77e133a74698443ee1.tar.gz gnunet-e5d7c67c647e9620c5c1ae77e133a74698443ee1.zip |
Added flag to API disconnect method to send pending store requests before disconnecting.
Added a test case for it.
Diffstat (limited to 'src/peerstore/test_peerstore_api_sync.c')
-rw-r--r-- | src/peerstore/test_peerstore_api_sync.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/peerstore/test_peerstore_api_sync.c b/src/peerstore/test_peerstore_api_sync.c new file mode 100644 index 000000000..634f62c26 --- /dev/null +++ b/src/peerstore/test_peerstore_api_sync.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) | ||
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 | * @file peerstore/test_peerstore_api_sync.c | ||
22 | * @brief testcase for peerstore sync before disconnect feature | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | #include "gnunet_peerstore_service.h" | ||
28 | |||
29 | int ok = 1; | ||
30 | |||
31 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
32 | |||
33 | static struct GNUNET_PEERSTORE_Handle *h; | ||
34 | |||
35 | static char *subsystem = "test_peerstore_api_sync"; | ||
36 | static struct GNUNET_PeerIdentity pid; | ||
37 | static char *key = "test_peerstore_api_store_key"; | ||
38 | static char *val = "test_peerstore_api_store_val"; | ||
39 | |||
40 | int iterate_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg) | ||
41 | { | ||
42 | const char *rec_val; | ||
43 | |||
44 | GNUNET_break (NULL == emsg); | ||
45 | if (NULL == record) | ||
46 | { | ||
47 | GNUNET_PEERSTORE_disconnect (h, GNUNET_NO); | ||
48 | GNUNET_SCHEDULER_shutdown(); | ||
49 | return GNUNET_YES; | ||
50 | } | ||
51 | rec_val = record->value; | ||
52 | GNUNET_break (0 == strcmp(rec_val, val)); | ||
53 | ok = 0; | ||
54 | return GNUNET_YES; | ||
55 | } | ||
56 | |||
57 | static void | ||
58 | test1() | ||
59 | { | ||
60 | GNUNET_PEERSTORE_store (h, subsystem, &pid, key, val, strlen(val) + 1, | ||
61 | GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
62 | NULL, NULL); | ||
63 | GNUNET_PEERSTORE_disconnect (h, GNUNET_YES); | ||
64 | h = GNUNET_PEERSTORE_connect (cfg); | ||
65 | GNUNET_PEERSTORE_iterate (h, subsystem, &pid, key, | ||
66 | GNUNET_TIME_UNIT_FOREVER_REL, &iterate_cb, NULL); | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | run (void *cls, | ||
71 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
72 | struct GNUNET_TESTING_Peer *peer) | ||
73 | { | ||
74 | cfg = c; | ||
75 | h = GNUNET_PEERSTORE_connect(cfg); | ||
76 | GNUNET_assert(NULL != h); | ||
77 | memset (&pid, 1, sizeof (pid)); | ||
78 | test1(); | ||
79 | } | ||
80 | |||
81 | int | ||
82 | main (int argc, char *argv[]) | ||
83 | { | ||
84 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | ||
85 | "peerstore", | ||
86 | "test_peerstore_api_data.conf", | ||
87 | &run, NULL)) | ||
88 | return 1; | ||
89 | return ok; | ||
90 | } | ||
91 | |||
92 | /* end of test_peerstore_api_store.c */ | ||