aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_peer.c
diff options
context:
space:
mode:
authorSafey A.Halim <safey.allah@gmail.com>2009-12-21 10:48:36 +0000
committerSafey A.Halim <safey.allah@gmail.com>2009-12-21 10:48:36 +0000
commita139d4a98fcebc8b3047515a59d569a640269272 (patch)
treefba2a4d2372dc5040425d022361178e20bae925f /src/util/test_peer.c
parent71a89cc3ce47b813aa09655ac824677aa508259e (diff)
downloadgnunet-a139d4a98fcebc8b3047515a59d569a640269272.tar.gz
gnunet-a139d4a98fcebc8b3047515a59d569a640269272.zip
Coverage for functions:
peer.c/GNUNET_PEER_resolve() and peer.c/GNUNET_PEER_decrement_rcs()
Diffstat (limited to 'src/util/test_peer.c')
-rw-r--r--src/util/test_peer.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 695e2549b..45633119c 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -45,7 +45,7 @@ generatePeerIdList ()
45 for (i = 0; i < NUMBER_OF_PEERS; i++) 45 for (i = 0; i < NUMBER_OF_PEERS; i++)
46 { 46 {
47 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, 47 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
48 &pidArr[i].hashPubKey); 48 &pidArr[i].hashPubKey);
49#if DEBUG 49#if DEBUG
50 printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); 50 printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i]));
51#endif 51#endif
@@ -59,6 +59,7 @@ check ()
59 int i; 59 int i;
60 GNUNET_PEER_Id pid; 60 GNUNET_PEER_Id pid;
61 struct GNUNET_PeerIdentity res; 61 struct GNUNET_PeerIdentity res;
62 struct GNUNET_PeerIdentity zero;
62 GNUNET_PEER_Id ids[] = { 1, 2, 3 }; 63 GNUNET_PEER_Id ids[] = { 1, 2, 3 };
63 64
64 GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); 65 GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
@@ -67,11 +68,11 @@ check ()
67 { 68 {
68 pid = GNUNET_PEER_intern (&pidArr[i]); 69 pid = GNUNET_PEER_intern (&pidArr[i]);
69 if (pid != (i + 1)) 70 if (pid != (i + 1))
70 { 71 {
71 fprintf (stderr, 72 fprintf (stderr,
72 "Unexpected Peer ID returned by intern function \n"); 73 "Unexpected Peer ID returned by intern function \n");
73 return 1; 74 return 1;
74 } 75 }
75 } 76 }
76 77
77 /* Referencing the first 3 peers once again */ 78 /* Referencing the first 3 peers once again */
@@ -79,18 +80,18 @@ check ()
79 { 80 {
80 pid = GNUNET_PEER_intern (&pidArr[i]); 81 pid = GNUNET_PEER_intern (&pidArr[i]);
81 if (pid != (i + 1)) 82 if (pid != (i + 1))
82 { 83 {
83 fprintf (stderr, 84 fprintf (stderr,
84 "Unexpected Peer ID returned by intern function \n"); 85 "Unexpected Peer ID returned by intern function \n");
85 return 1; 86 return 1;
86 } 87 }
87 } 88 }
88 89
89 /* Dereferencing the first 3 peers once [decrementing their reference count] */ 90 /* Dereferencing the first 3 peers once [decrementing their reference count] */
90 GNUNET_PEER_decrement_rcs (ids, 3); 91 GNUNET_PEER_decrement_rcs (ids, 3);
91 92
92 /* re-referencing the first 3 peers using the change_rc function */ 93 /* re-referencing the first 3 peers using the change_rc function */
93 for (i = 0; i < 3; i++) 94 for (i = 1; i <= 3; i++)
94 GNUNET_PEER_change_rc (i, 1); 95 GNUNET_PEER_change_rc (i, 1);
95 96
96 /* Removing the second Peer from the PeerEntry hash map */ 97 /* Removing the second Peer from the PeerEntry hash map */
@@ -98,7 +99,25 @@ check ()
98 99
99 /* convert the pid of the first PeerEntry into that of the third */ 100 /* convert the pid of the first PeerEntry into that of the third */
100 GNUNET_PEER_resolve (1, &res); 101 GNUNET_PEER_resolve (1, &res);
101 GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof(res))); 102 GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof (res)));
103
104 /*
105 * Attempt to convert pid = 0 (which is reserved)
106 * into a peer identity object, the peer identity memory
107 * is expected to be set to zero
108 */
109 memset (&zero, 0, sizeof (struct GNUNET_PeerIdentity));
110 GNUNET_log_skip (1, GNUNET_YES);
111 GNUNET_PEER_resolve (0, &res);
112 GNUNET_assert (0 == memcmp (&res, &zero, sizeof (res)));
113
114 /* Removing peer entries 1 and 3 from table using the list decrement function */
115 /* If count = 0, nothing should be done whatsoever */
116 GNUNET_PEER_decrement_rcs (ids, 0);
117
118 ids[1] = 3;
119 GNUNET_PEER_decrement_rcs (ids, 2);
120 GNUNET_PEER_decrement_rcs (ids, 2);
102 121
103 return 0; 122 return 0;
104} 123}
@@ -109,7 +128,7 @@ main ()
109{ 128{
110 int i; 129 int i;
111 GNUNET_log_setup ("test-peer", "ERROR", NULL); 130 GNUNET_log_setup ("test-peer", "ERROR", NULL);
112 for (i=0;i<1;i++) 131 for (i = 0; i < 1; i++)
113 { 132 {
114 generatePeerIdList (); 133 generatePeerIdList ();
115 if (0 != check ()) 134 if (0 != check ())