aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorJi Lu <jilu@140774ce-b5e7-0310-ab8b-a85725594a96>2009-11-20 23:01:02 +0000
committerJi Lu <jilu@140774ce-b5e7-0310-ab8b-a85725594a96>2009-11-20 23:01:02 +0000
commit82d72e196f7cc87ef2902ac42c54f868baf775de (patch)
tree9d32df0d0ee634dda54961d738e7922148b29705 /src/util
parent2c55f8e2c193cf09883291c254f42f95ecc5e99a (diff)
downloadgnunet-82d72e196f7cc87ef2902ac42c54f868baf775de.tar.gz
gnunet-82d72e196f7cc87ef2902ac42c54f868baf775de.zip
some log problem and 55bytes mem lack not fixed
Diffstat (limited to 'src/util')
-rw-r--r--src/util/test_pseudonym.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/util/test_pseudonym.c b/src/util/test_pseudonym.c
index 62157cede..a8b4575e3 100644
--- a/src/util/test_pseudonym.c
+++ b/src/util/test_pseudonym.c
@@ -66,7 +66,25 @@ noti_callback (void *cls,
66 return GNUNET_OK; 66 return GNUNET_OK;
67} 67}
68 68
69static int
70fake_noti_callback (void *cls,
71 const GNUNET_HashCode *
72 pseudonym,
73 const struct GNUNET_CONTAINER_MetaData *md, int rating)
74{
75 int *ret = cls;
76 (*ret)++;
77 return GNUNET_OK;
78}
69 79
80static int
81false_callback (void *cls,
82 const GNUNET_HashCode *
83 pseudonym,
84 const struct GNUNET_CONTAINER_MetaData *md, int rating)
85{
86 return GNUNET_OK;
87}
70int 88int
71main (int argc, char *argv[]) 89main (int argc, char *argv[])
72{ 90{
@@ -74,12 +92,22 @@ main (int argc, char *argv[])
74 GNUNET_HashCode rid1; 92 GNUNET_HashCode rid1;
75 GNUNET_HashCode id2; 93 GNUNET_HashCode id2;
76 GNUNET_HashCode rid2; 94 GNUNET_HashCode rid2;
95 GNUNET_HashCode fid;
96 GNUNET_HashCode id3;
97 GNUNET_HashCode rid3;
98
77 int old; 99 int old;
78 int newVal; 100 int newVal;
79 struct GNUNET_CONFIGURATION_Handle *cfg; 101 struct GNUNET_CONFIGURATION_Handle *cfg;
80 char *name1; 102 char *name1;
81 char *name2; 103 char *name2;
82 int notiCount; 104 char *name3;
105 char *noname;
106 int notiCount,fakenotiCount;
107 int count;
108 static char m[1024 * 1024 * 10];
109 memset (m, 'b', sizeof (m));
110 m[sizeof (m) - 1] = '\0';
83 111
84 GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); 112 GNUNET_log_setup ("test-pseudonym", "WARNING", NULL);
85 ok = GNUNET_YES; 113 ok = GNUNET_YES;
@@ -93,8 +121,15 @@ main (int argc, char *argv[])
93 return -1; 121 return -1;
94 } 122 }
95 notiCount = 0; 123 notiCount = 0;
124 fakenotiCount = 0;
125 count = 0;
126 GNUNET_PSEUDONYM_discovery_callback_register (cfg,
127 &fake_noti_callback, &fakenotiCount);
96 GNUNET_PSEUDONYM_discovery_callback_register (cfg, 128 GNUNET_PSEUDONYM_discovery_callback_register (cfg,
97 &noti_callback, &notiCount); 129 &noti_callback, &notiCount);
130 GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count);
131 GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, &fakenotiCount);
132
98 /* ACTUAL TEST CODE */ 133 /* ACTUAL TEST CODE */
99 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); 134 old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL);
100 meta = GNUNET_CONTAINER_meta_data_create (); 135 meta = GNUNET_CONTAINER_meta_data_create ();
@@ -112,21 +147,35 @@ main (int argc, char *argv[])
112 CHECK (notiCount == 3); 147 CHECK (notiCount == 3);
113 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); 148 newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok);
114 CHECK (old < newVal); 149 CHECK (old < newVal);
150 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, EXTRACTOR_COMMENT, m));
151 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3);
152 GNUNET_PSEUDONYM_add (cfg, &id3, meta);
153 GNUNET_log_skip (1, GNUNET_NO);
154 name3 = GNUNET_PSEUDONYM_id_to_name (cfg, &id3);
155 GNUNET_log_skip (0, GNUNET_YES);
115 name2 = GNUNET_PSEUDONYM_id_to_name (cfg, &id2); 156 name2 = GNUNET_PSEUDONYM_id_to_name (cfg, &id2);
116 CHECK (name2 != NULL); 157 CHECK (name2 != NULL);
117 name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1); 158 name1 = GNUNET_PSEUDONYM_id_to_name (cfg, &id1);
118 CHECK (name1 != NULL); 159 CHECK (name1 != NULL);
119 CHECK (0 != strcmp (name1, name2)); 160 CHECK (0 != strcmp (name1, name2));
161 CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2))
120 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); 162 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2));
121 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); 163 CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1));
122 CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode))); 164 CHECK (0 == memcmp (&id1, &rid1, sizeof (GNUNET_HashCode)));
123 CHECK (0 == memcmp (&id2, &rid2, sizeof (GNUNET_HashCode))); 165 CHECK (0 == memcmp (&id2, &rid2, sizeof (GNUNET_HashCode)));
166
167 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid);
168 CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0));
169 noname = GNUNET_PSEUDONYM_id_to_name (cfg, &fid);
170 CHECK (noname != NULL);
124 CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 0)); 171 CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 0));
125 CHECK (5 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); 172 CHECK (5 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5));
126 CHECK (-5 == GNUNET_PSEUDONYM_rank (cfg, &id1, -10)); 173 CHECK (-5 == GNUNET_PSEUDONYM_rank (cfg, &id1, -10));
127 CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); 174 CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5));
128 GNUNET_free (name1); 175 GNUNET_free (name1);
129 GNUNET_free (name2); 176 GNUNET_free (name2);
177 GNUNET_free (name3);
178 GNUNET_free (noname);
130 /* END OF TEST CODE */ 179 /* END OF TEST CODE */
131FAILURE: 180FAILURE:
132 GNUNET_PSEUDONYM_discovery_callback_unregister (&noti_callback, &notiCount); 181 GNUNET_PSEUDONYM_discovery_callback_unregister (&noti_callback, &notiCount);