aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_peer.c')
-rw-r--r--src/util/test_peer.c98
1 files changed, 50 insertions, 48 deletions
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index 46a803e39..5a7203507 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -36,102 +36,104 @@ static struct GNUNET_PeerIdentity pidArr[NUMBER_OF_PEERS];
36 36
37 37
38static void 38static void
39generatePeerIdList() 39generatePeerIdList ()
40{ 40{
41 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++) 41 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
42 { 42 {
43 gcry_randomize(&pidArr[i], 43 gcry_randomize (&pidArr[i],
44 sizeof(struct GNUNET_PeerIdentity), 44 sizeof(struct GNUNET_PeerIdentity),
45 GCRY_STRONG_RANDOM); 45 GCRY_STRONG_RANDOM);
46 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
47 "Peer %u: %s\n", 47 "Peer %u: %s\n",
48 i, 48 i,
49 GNUNET_i2s(&pidArr[i])); 49 GNUNET_i2s (&pidArr[i]));
50 } 50 }
51} 51}
52 52
53 53
54static int 54static int
55check() 55check ()
56{ 56{
57 GNUNET_PEER_Id pid; 57 GNUNET_PEER_Id pid;
58 struct GNUNET_PeerIdentity res; 58 struct GNUNET_PeerIdentity res;
59 GNUNET_PEER_Id ids[] = { 1, 2, 3 }; 59 GNUNET_PEER_Id ids[] = { 1, 2, 3 };
60 60
61 GNUNET_assert(0 == GNUNET_PEER_intern(NULL)); 61 GNUNET_assert (0 == GNUNET_PEER_intern (NULL));
62 /* Insert Peers into PeerEntry table and hashmap */ 62 /* Insert Peers into PeerEntry table and hashmap */
63 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++) 63 for (unsigned int i = 0; i < NUMBER_OF_PEERS; i++)
64 {
65 pid = GNUNET_PEER_intern (&pidArr[i]);
66 if (pid != (i + 1))
64 { 67 {
65 pid = GNUNET_PEER_intern(&pidArr[i]); 68 fprintf (stderr, "%s",
66 if (pid != (i + 1)) 69 "Unexpected Peer ID returned by intern function\n");
67 { 70 return 1;
68 fprintf(stderr, "%s", "Unexpected Peer ID returned by intern function\n");
69 return 1;
70 }
71 } 71 }
72 }
72 73
73 /* Referencing the first 3 peers once again */ 74 /* Referencing the first 3 peers once again */
74 for (unsigned int i = 0; i < 3; i++) 75 for (unsigned int i = 0; i < 3; i++)
76 {
77 pid = GNUNET_PEER_intern (&pidArr[i]);
78 if (pid != (i + 1))
75 { 79 {
76 pid = GNUNET_PEER_intern(&pidArr[i]); 80 fprintf (stderr, "%s",
77 if (pid != (i + 1)) 81 "Unexpected Peer ID returned by intern function\n");
78 { 82 return 1;
79 fprintf(stderr, "%s", "Unexpected Peer ID returned by intern function\n");
80 return 1;
81 }
82 } 83 }
84 }
83 85
84 /* Dereferencing the first 3 peers once [decrementing their reference count] */ 86 /* Dereferencing the first 3 peers once [decrementing their reference count] */
85 GNUNET_PEER_decrement_rcs(ids, 3); 87 GNUNET_PEER_decrement_rcs (ids, 3);
86 88
87 /* re-referencing the first 3 peers using the change_rc function */ 89 /* re-referencing the first 3 peers using the change_rc function */
88 for (unsigned int i = 1; i <= 3; i++) 90 for (unsigned int i = 1; i <= 3; i++)
89 GNUNET_PEER_change_rc(i, 1); 91 GNUNET_PEER_change_rc (i, 1);
90 92
91 /* Removing the second Peer from the PeerEntry hash map */ 93 /* Removing the second Peer from the PeerEntry hash map */
92 GNUNET_PEER_change_rc(2, -2); 94 GNUNET_PEER_change_rc (2, -2);
93 95
94 /* convert the pid of the first PeerEntry into that of the third */ 96 /* convert the pid of the first PeerEntry into that of the third */
95 GNUNET_PEER_resolve(1, 97 GNUNET_PEER_resolve (1,
96 &res); 98 &res);
97 GNUNET_assert(0 == 99 GNUNET_assert (0 ==
98 GNUNET_memcmp(&res, 100 GNUNET_memcmp (&res,
99 &pidArr[0])); 101 &pidArr[0]));
100 102
101 /* 103 /*
102 * Attempt to convert pid = 0 (which is reserved) 104 * Attempt to convert pid = 0 (which is reserved)
103 * into a peer identity object, the peer identity memory 105 * into a peer identity object, the peer identity memory
104 * is expected to be set to zero 106 * is expected to be set to zero
105 */ 107 */
106 GNUNET_log_skip(1, GNUNET_YES); 108 GNUNET_log_skip (1, GNUNET_YES);
107 GNUNET_PEER_resolve(0, &res); 109 GNUNET_PEER_resolve (0, &res);
108 GNUNET_assert(0 == 110 GNUNET_assert (0 ==
109 GNUNET_is_zero(&res)); 111 GNUNET_is_zero (&res));
110 112
111 /* Removing peer entries 1 and 3 from table using the list decrement function */ 113 /* Removing peer entries 1 and 3 from table using the list decrement function */
112 /* If count = 0, nothing should be done whatsoever */ 114 /* If count = 0, nothing should be done whatsoever */
113 GNUNET_PEER_decrement_rcs(ids, 0); 115 GNUNET_PEER_decrement_rcs (ids, 0);
114 116
115 ids[1] = 3; 117 ids[1] = 3;
116 GNUNET_PEER_decrement_rcs(ids, 2); 118 GNUNET_PEER_decrement_rcs (ids, 2);
117 GNUNET_PEER_decrement_rcs(ids, 2); 119 GNUNET_PEER_decrement_rcs (ids, 2);
118 120
119 return 0; 121 return 0;
120} 122}
121 123
122 124
123int 125int
124main() 126main ()
125{ 127{
126 GNUNET_log_setup("test-peer", 128 GNUNET_log_setup ("test-peer",
127 "ERROR", 129 "ERROR",
128 NULL); 130 NULL);
129 for (unsigned int i = 0; i < 1; i++) 131 for (unsigned int i = 0; i < 1; i++)
130 { 132 {
131 generatePeerIdList(); 133 generatePeerIdList ();
132 if (0 != check()) 134 if (0 != check ())
133 return 1; 135 return 1;
134 } 136 }
135 return 0; 137 return 0;
136} 138}
137 139