rps: store valid peer ids in file
[oweals/gnunet.git] / src / rps / test_service_rps_peers.c
1 /*
2      This file is part of GNUnet.
3      Copyright (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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20 /**
21  * @file rps/test_service_rps_peers.c
22  * @brief testcase for gnunet-service-rps_peers.c
23  */
24 #include <platform.h>
25 #include "gnunet-service-rps_peers.h"
26
27 #define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); Peers_terminate (); return 1; }
28 #define CHECK(c) { if (! (c)) ABORT(); }
29
30
31 /**
32  * @brief Dummy implementation of #PeerOp (Operation on peer)
33  *
34  * @param cls closure
35  * @param peer peer
36  */
37 void peer_op (void *cls, const struct GNUNET_PeerIdentity *peer)
38 {
39   GNUNET_assert (NULL != peer);
40 }
41
42 /**
43  * @brief Function that is called on a peer for later execution
44  *
45  * @param cls closure
46  * @param peer peer to execute function upon
47  */
48 void
49 peer_op (void *cls, const struct GNUNET_PeerIdentity *peer);
50
51
52 static int
53 check ()
54 {
55   struct GNUNET_PeerIdentity k1;
56   struct GNUNET_PeerIdentity own_id;
57   
58   memset (&k1, 0, sizeof (k1));
59   memset (&own_id, 1, sizeof (own_id));
60
61   /* Do nothing */
62   Peers_initialise ("", NULL, &own_id);
63   Peers_terminate ();
64
65
66   /* Create peer */
67   Peers_initialise ("", NULL, &own_id);
68   CHECK (GNUNET_YES == Peers_insert_peer (&k1));
69   Peers_terminate ();
70
71
72   /* Create peer */
73   Peers_initialise ("", NULL, &own_id);
74   CHECK (GNUNET_YES == Peers_insert_peer (&k1));
75   CHECK (GNUNET_YES == Peers_remove_peer (&k1));
76   Peers_terminate ();
77
78
79   /* Insertion and Removal */
80   Peers_initialise ("", NULL, &own_id);
81   CHECK (GNUNET_NO  == Peers_check_peer_known (&k1));
82
83   CHECK (GNUNET_YES == Peers_insert_peer (&k1));
84   CHECK (GNUNET_NO  == Peers_insert_peer (&k1));
85   CHECK (GNUNET_YES == Peers_check_peer_known (&k1));
86
87   CHECK (GNUNET_YES == Peers_remove_peer (&k1));
88   CHECK (GNUNET_NO  == Peers_remove_peer (&k1));
89   CHECK (GNUNET_NO  == Peers_check_peer_known (&k1));
90
91
92   /* Flags */
93   Peers_insert_peer (&k1);
94
95   CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_PULL_REPLY_PENDING));
96   CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_ONLINE));
97   CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
98
99   CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1, Peers_ONLINE));
100
101   Peers_set_peer_flag (&k1, Peers_ONLINE);
102   CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_ONLINE));
103   CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
104   CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_ONLINE));
105   CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
106
107   /* Check send intention */
108   CHECK (GNUNET_NO == Peers_check_peer_send_intention (&k1));
109
110   /* Check existence of sending channel */
111   CHECK (GNUNET_NO == Peers_check_sending_channel_exists (&k1));
112
113   /* Check role of channels */
114   CHECK (GNUNET_YES == Peers_check_channel_role (&k1,
115                                                  NULL,
116                                                  Peers_CHANNEL_ROLE_SENDING));
117   CHECK (GNUNET_YES == Peers_check_channel_role (&k1,
118                                                  NULL,
119                                                  Peers_CHANNEL_ROLE_RECEIVING));
120
121   CHECK (GNUNET_YES == Peers_schedule_operation (&k1, peer_op));
122
123   Peers_terminate ();
124   return 0;
125 }
126
127
128 int
129 main (int argc, char *argv[])
130 {
131   GNUNET_log_setup ("test_service_rps_peers", 
132                     "WARNING",
133                     NULL);
134   return check ();
135 }
136
137 /* end of test_service_rps_peers.c */