diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-11-10 08:54:05 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-11-10 08:54:05 +0000 |
commit | 1351e32fa8ffcd56fc6329f4a68ccc83d0cf0cc5 (patch) | |
tree | 31bc30c6b78bc76f7e77b3aa1cf73dd5633c52f1 /src/util/test_peer.c | |
parent | b4a9784abd12ddb0d038bae71bc3a0e74cbeaf78 (diff) | |
download | gnunet-1351e32fa8ffcd56fc6329f4a68ccc83d0cf0cc5.tar.gz gnunet-1351e32fa8ffcd56fc6329f4a68ccc83d0cf0cc5.zip |
update
Diffstat (limited to 'src/util/test_peer.c')
-rw-r--r-- | src/util/test_peer.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/util/test_peer.c b/src/util/test_peer.c index e2fd100fd..695e2549b 100644 --- a/src/util/test_peer.c +++ b/src/util/test_peer.c | |||
@@ -28,7 +28,8 @@ | |||
28 | #include "gnunet_peer_lib.h" | 28 | #include "gnunet_peer_lib.h" |
29 | 29 | ||
30 | #define NUMBER_OF_PEERS 10 | 30 | #define NUMBER_OF_PEERS 10 |
31 | /*#define DEBUG*/ | 31 | |
32 | #define DEBUG GNUNET_NO | ||
32 | 33 | ||
33 | /** | 34 | /** |
34 | * A list of Peer ID's to play with | 35 | * A list of Peer ID's to play with |
@@ -45,7 +46,7 @@ generatePeerIdList () | |||
45 | { | 46 | { |
46 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, | 47 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, |
47 | &pidArr[i].hashPubKey); | 48 | &pidArr[i].hashPubKey); |
48 | #ifdef DEBUG | 49 | #if DEBUG |
49 | printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); | 50 | printf ("Peer %d: %s\n", i, GNUNET_i2s (&pidArr[i])); |
50 | #endif | 51 | #endif |
51 | } | 52 | } |
@@ -57,7 +58,10 @@ check () | |||
57 | { | 58 | { |
58 | int i; | 59 | int i; |
59 | GNUNET_PEER_Id pid; | 60 | GNUNET_PEER_Id pid; |
61 | struct GNUNET_PeerIdentity res; | ||
62 | GNUNET_PEER_Id ids[] = { 1, 2, 3 }; | ||
60 | 63 | ||
64 | GNUNET_assert (0 == GNUNET_PEER_intern (NULL)); | ||
61 | /* Insert Peers into PeerEntry table and hashmap */ | 65 | /* Insert Peers into PeerEntry table and hashmap */ |
62 | for (i = 0; i < NUMBER_OF_PEERS; i++) | 66 | for (i = 0; i < NUMBER_OF_PEERS; i++) |
63 | { | 67 | { |
@@ -77,28 +81,24 @@ check () | |||
77 | if (pid != (i + 1)) | 81 | if (pid != (i + 1)) |
78 | { | 82 | { |
79 | fprintf (stderr, | 83 | fprintf (stderr, |
80 | "Unexpcted Peer ID returned by intern function \n"); | 84 | "Unexpected Peer ID returned by intern function \n"); |
81 | return 1; | 85 | return 1; |
82 | } | 86 | } |
83 | } | 87 | } |
84 | 88 | ||
85 | /* Dereferencing the first 3 peers once [decrementing their reference count] */ | 89 | /* Dereferencing the first 3 peers once [decrementing their reference count] */ |
86 | { | 90 | GNUNET_PEER_decrement_rcs (ids, 3); |
87 | GNUNET_PEER_Id ids[] = { 1, 2, 3 }; | ||
88 | GNUNET_PEER_decrement_rcs (ids, 3); | ||
89 | } | ||
90 | 91 | ||
91 | /* re-referencing the first 3 peers using the change_rc function */ | 92 | /* re-referencing the first 3 peers using the change_rc function */ |
92 | for (i = 0; i < 3; i++) | 93 | for (i = 0; i < 3; i++) |
93 | { | 94 | GNUNET_PEER_change_rc (i, 1); |
94 | GNUNET_PEER_change_rc (i, 1); | ||
95 | } | ||
96 | 95 | ||
97 | /* Removing the second Peer from the PeerEntry hash map */ | 96 | /* Removing the second Peer from the PeerEntry hash map */ |
98 | GNUNET_PEER_change_rc (2, -2); | 97 | GNUNET_PEER_change_rc (2, -2); |
99 | 98 | ||
100 | /* convert the pid of the first PeerEntry into that of the third */ | 99 | /* convert the pid of the first PeerEntry into that of the third */ |
101 | GNUNET_PEER_resolve (1, &pidArr[3]); | 100 | GNUNET_PEER_resolve (1, &res); |
101 | GNUNET_assert (0 == memcmp (&res, &pidArr[0], sizeof(res))); | ||
102 | 102 | ||
103 | return 0; | 103 | return 0; |
104 | } | 104 | } |
@@ -107,9 +107,15 @@ check () | |||
107 | int | 107 | int |
108 | main () | 108 | main () |
109 | { | 109 | { |
110 | int i; | ||
110 | GNUNET_log_setup ("test-peer", "ERROR", NULL); | 111 | GNUNET_log_setup ("test-peer", "ERROR", NULL); |
111 | generatePeerIdList (); | 112 | for (i=0;i<1;i++) |
112 | return check (); | 113 | { |
114 | generatePeerIdList (); | ||
115 | if (0 != check ()) | ||
116 | return 1; | ||
117 | } | ||
118 | return 0; | ||
113 | } | 119 | } |
114 | 120 | ||
115 | /* end of test_peer.c */ | 121 | /* end of test_peer.c */ |