rps: add test for gnunet-service-rps_peers
authorJulius Bünger <buenger@mytum.de>
Fri, 8 Apr 2016 18:27:52 +0000 (18:27 +0000)
committerJulius Bünger <buenger@mytum.de>
Fri, 8 Apr 2016 18:27:52 +0000 (18:27 +0000)
src/rps/Makefile.am
src/rps/test_service_rps_peers.c [new file with mode: 0644]

index f08ded57aae3bf18440a627e3ed0116f88b799ff..91efc3a5521b422f83616d5c1389eb28a56b2bd8 100644 (file)
@@ -73,6 +73,7 @@ if HAVE_TESTING
 check_PROGRAMS = \
  test_service_rps_view \
  test_service_rps_custommap \
+ test_service_rps_peers \
  test_rps_malicious_1 \
  test_rps_malicious_2 \
  test_rps_malicious_3 \
@@ -102,6 +103,11 @@ test_service_rps_view_SOURCES = gnunet-service-rps_view.h gnunet-service-rps_vie
                                                                                                                                test_service_rps_view.c
 test_service_rps_view_LDADD = $(top_builddir)/src/util/libgnunetutil.la
 
+test_service_rps_peers_SOURCES = gnunet-service-rps_peers.h gnunet-service-rps_peers.c \
+                                                                                                                                test_service_rps_peers.c
+test_service_rps_peers_LDADD = $(top_builddir)/src/util/libgnunetutil.la \
+                                                                                                                        $(top_builddir)/src/cadet/libgnunetcadet.la
+
 test_service_rps_custommap_SOURCES = gnunet-service-rps_custommap.h gnunet-service-rps_custommap.c \
                                                                                                                                 test_service_rps_custommap.c
 test_service_rps_custommap_LDADD = $(top_builddir)/src/util/libgnunetutil.la
diff --git a/src/rps/test_service_rps_peers.c b/src/rps/test_service_rps_peers.c
new file mode 100644 (file)
index 0000000..f5191fa
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+     This file is part of GNUnet.
+     Copyright (C)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+/**
+ * @file rps/test_service_rps_peers.c
+ * @brief testcase for gnunet-service-rps_peers.c
+ */
+#include <platform.h>
+#include "gnunet-service-rps_peers.h"
+
+#define ABORT() { fprintf(stderr, "Error at %s:%d\n", __FILE__, __LINE__); Peers_terminate (); return 1; }
+#define CHECK(c) { if (! (c)) ABORT(); }
+
+
+/**
+ * @brief Dummy implementation of #PeerOp (Operation on peer)
+ *
+ * @param cls closure
+ * @param peer peer
+ */
+void peer_op (void *cls, const struct GNUNET_PeerIdentity *peer)
+{
+  GNUNET_assert (NULL != peer);
+}
+
+/**
+ * @brief Function that is called on a peer for later execution
+ *
+ * @param cls closure
+ * @param peer peer to execute function upon
+ */
+void
+peer_op (void *cls, const struct GNUNET_PeerIdentity *peer);
+
+
+static int
+check ()
+{
+  struct GNUNET_PeerIdentity k1;
+  struct GNUNET_PeerIdentity own_id;
+  
+  memset (&k1, 0, sizeof (k1));
+  memset (&own_id, 1, sizeof (own_id));
+
+  /* Do nothing */
+  Peers_initialise (NULL, &own_id);
+  Peers_terminate ();
+
+
+  /* Create peer */
+  Peers_initialise (NULL, &own_id);
+  CHECK (GNUNET_YES == Peers_insert_peer (&k1));
+  Peers_terminate ();
+
+
+  /* Create peer */
+  Peers_initialise (NULL, &own_id);
+  CHECK (GNUNET_YES == Peers_insert_peer (&k1));
+  CHECK (GNUNET_YES == Peers_remove_peer (&k1));
+  Peers_terminate ();
+
+
+  /* Insertion and Removal */
+  Peers_initialise (NULL, &own_id);
+  CHECK (GNUNET_NO  == Peers_check_peer_known (&k1));
+
+  CHECK (GNUNET_YES == Peers_insert_peer (&k1));
+  CHECK (GNUNET_NO  == Peers_insert_peer (&k1));
+  CHECK (GNUNET_YES == Peers_check_peer_known (&k1));
+
+  CHECK (GNUNET_YES == Peers_remove_peer (&k1));
+  CHECK (GNUNET_NO  == Peers_remove_peer (&k1));
+  CHECK (GNUNET_NO  == Peers_check_peer_known (&k1));
+
+
+  /* Flags */
+  Peers_insert_peer (&k1);
+
+  CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_PULL_REPLY_PENDING));
+  CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_VALID));
+  CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_ONLINE));
+  CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
+
+  Peers_set_peer_flag (&k1, Peers_VALID);
+  CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_VALID));
+  CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1, Peers_ONLINE));
+  Peers_unset_peer_flag (&k1, Peers_VALID);
+  CHECK (GNUNET_NO == Peers_check_peer_flag (&k1, Peers_VALID));
+
+  Peers_set_peer_flag (&k1, Peers_VALID);
+  Peers_set_peer_flag (&k1, Peers_ONLINE);
+  CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_VALID));
+  CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_ONLINE));
+  CHECK (GNUNET_YES == Peers_check_peer_flag (&k1,
+                                              Peers_ONLINE | Peers_VALID));
+  CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
+  Peers_unset_peer_flag (&k1, Peers_VALID);
+  CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1, Peers_VALID));
+  CHECK (GNUNET_YES == Peers_check_peer_flag (&k1, Peers_ONLINE));
+  CHECK (GNUNET_YES == Peers_check_peer_flag (&k1,
+                                              Peers_ONLINE | Peers_VALID));
+  CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1,
+                                              Peers_ONLINE & Peers_VALID));
+  CHECK (GNUNET_NO  == Peers_check_peer_flag (&k1, Peers_TO_DESTROY));
+
+  /* Check send intention */
+  CHECK (GNUNET_NO == Peers_check_peer_send_intention (&k1));
+
+  /* Check existence of sending channel */
+  CHECK (GNUNET_NO == Peers_check_sending_channel_exists (&k1));
+
+  /* Check role of channels */
+  CHECK (GNUNET_YES == Peers_check_channel_role (&k1,
+                                                 NULL,
+                                                 Peers_CHANNEL_ROLE_SENDING));
+  CHECK (GNUNET_YES == Peers_check_channel_role (&k1,
+                                                 NULL,
+                                                 Peers_CHANNEL_ROLE_RECEIVING));
+
+  CHECK (GNUNET_YES == Peers_schedule_operation (&k1, peer_op));
+
+  Peers_terminate ();
+  return 0;
+}
+
+
+int
+main (int argc, char *argv[])
+{
+  GNUNET_log_setup ("test_service_rps_peers", 
+                   "WARNING",
+                   NULL);
+  return check ();
+}
+
+/* end of test_service_rps_peers.c */