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, 49 insertions, 49 deletions
diff --git a/src/util/test_peer.c b/src/util/test_peer.c
index b059f2cf3..46a803e39 100644
--- a/src/util/test_peer.c
+++ b/src/util/test_peer.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file util/test_peer.c 21 * @file util/test_peer.c
22 * @brief testcase for peer.c 22 * @brief testcase for peer.c
@@ -36,102 +36,102 @@ 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))
67 { 64 {
68 fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n"); 65 pid = GNUNET_PEER_intern(&pidArr[i]);
69 return 1; 66 if (pid != (i + 1))
67 {
68 fprintf(stderr, "%s", "Unexpected Peer ID returned by intern function\n");
69 return 1;
70 }
70 } 71 }
71 }
72 72
73 /* Referencing the first 3 peers once again */ 73 /* Referencing the first 3 peers once again */
74 for (unsigned int i = 0; i < 3; i++) 74 for (unsigned int i = 0; i < 3; i++)
75 {
76 pid = GNUNET_PEER_intern (&pidArr[i]);
77 if (pid != (i + 1))
78 { 75 {
79 fprintf (stderr, "%s", "Unexpected Peer ID returned by intern function\n"); 76 pid = GNUNET_PEER_intern(&pidArr[i]);
80 return 1; 77 if (pid != (i + 1))
78 {
79 fprintf(stderr, "%s", "Unexpected Peer ID returned by intern function\n");
80 return 1;
81 }
81 } 82 }
82 }
83 83
84 /* Dereferencing the first 3 peers once [decrementing their reference count] */ 84 /* Dereferencing the first 3 peers once [decrementing their reference count] */
85 GNUNET_PEER_decrement_rcs (ids, 3); 85 GNUNET_PEER_decrement_rcs(ids, 3);
86 86
87 /* re-referencing the first 3 peers using the change_rc function */ 87 /* re-referencing the first 3 peers using the change_rc function */
88 for (unsigned int i = 1; i <= 3; i++) 88 for (unsigned int i = 1; i <= 3; i++)
89 GNUNET_PEER_change_rc (i, 1); 89 GNUNET_PEER_change_rc(i, 1);
90 90
91 /* Removing the second Peer from the PeerEntry hash map */ 91 /* Removing the second Peer from the PeerEntry hash map */
92 GNUNET_PEER_change_rc (2, -2); 92 GNUNET_PEER_change_rc(2, -2);
93 93
94 /* convert the pid of the first PeerEntry into that of the third */ 94 /* convert the pid of the first PeerEntry into that of the third */
95 GNUNET_PEER_resolve (1, 95 GNUNET_PEER_resolve(1,
96 &res); 96 &res);
97 GNUNET_assert (0 == 97 GNUNET_assert(0 ==
98 GNUNET_memcmp (&res, 98 GNUNET_memcmp(&res,
99 &pidArr[0])); 99 &pidArr[0]));
100 100
101 /* 101 /*
102 * Attempt to convert pid = 0 (which is reserved) 102 * Attempt to convert pid = 0 (which is reserved)
103 * into a peer identity object, the peer identity memory 103 * into a peer identity object, the peer identity memory
104 * is expected to be set to zero 104 * is expected to be set to zero
105 */ 105 */
106 GNUNET_log_skip (1, GNUNET_YES); 106 GNUNET_log_skip(1, GNUNET_YES);
107 GNUNET_PEER_resolve (0, &res); 107 GNUNET_PEER_resolve(0, &res);
108 GNUNET_assert (0 == 108 GNUNET_assert(0 ==
109 GNUNET_is_zero (&res)); 109 GNUNET_is_zero(&res));
110 110
111 /* Removing peer entries 1 and 3 from table using the list decrement function */ 111 /* Removing peer entries 1 and 3 from table using the list decrement function */
112 /* If count = 0, nothing should be done whatsoever */ 112 /* If count = 0, nothing should be done whatsoever */
113 GNUNET_PEER_decrement_rcs (ids, 0); 113 GNUNET_PEER_decrement_rcs(ids, 0);
114 114
115 ids[1] = 3; 115 ids[1] = 3;
116 GNUNET_PEER_decrement_rcs (ids, 2); 116 GNUNET_PEER_decrement_rcs(ids, 2);
117 GNUNET_PEER_decrement_rcs (ids, 2); 117 GNUNET_PEER_decrement_rcs(ids, 2);
118 118
119 return 0; 119 return 0;
120} 120}
121 121
122 122
123int 123int
124main () 124main()
125{ 125{
126 GNUNET_log_setup ("test-peer", 126 GNUNET_log_setup("test-peer",
127 "ERROR", 127 "ERROR",
128 NULL); 128 NULL);
129 for (unsigned int i = 0; i < 1; i++) 129 for (unsigned int i = 0; i < 1; i++)
130 { 130 {
131 generatePeerIdList (); 131 generatePeerIdList();
132 if (0 != check ()) 132 if (0 != check())
133 return 1; 133 return 1;
134 } 134 }
135 return 0; 135 return 0;
136} 136}
137 137