2 * $Id: edsiotest.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
4 * Copyright (C) 1998, 1999, Josh MacDonald.
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
17 PropTest *pt = g_new0 (PropTest, 1);
19 EdsioPropTestUintProperty prop;
21 g_assert (edsio_edsio_init ());
23 g_assert (edsio_new_proptest_uint_property ("Just testing (1)...", PF_Persistent, & prop));
25 g_assert (! proptest_isset_uint (pt, prop));
27 g_assert (proptest_set_uint (pt, prop, 42));
29 g_assert (proptest_isset_uint (pt, prop));
31 g_assert (proptest_get_uint (pt, prop, & x) && x == 42);
33 /* kill the cache, to test persistence. */
34 pt->_edsio_property_table = NULL;
36 g_assert (proptest_get_uint (pt, prop, & x) && x == 42);
38 g_assert (proptest_unset_uint (pt, prop));
40 g_assert (! proptest_isset_uint (pt, prop));
42 g_assert (! pt->_edsio_property_table);
48 const char* str = "hello there";
51 const char ** str2_ptr = &str2;
53 PropTest *pt = g_new0 (PropTest, 1);
55 EdsioPropTestBytesProperty prop;
57 g_assert (edsio_edsio_init ());
59 g_assert (edsio_new_proptest_bytes_property ("Just testing (2)...", PF_Persistent, & prop));
61 g_assert (! proptest_isset_bytes (pt, prop));
63 g_assert (proptest_set_bytes (pt, prop, (guint8*) str, strlen (str) + 1));
65 g_assert (proptest_isset_bytes (pt, prop));
67 g_assert (proptest_get_bytes (pt, prop, (const guint8**) str2_ptr, & str2_len) && str2_len == (strlen (str) + 1) && strcmp (str, str2) == 0);
69 /* kill the cache, to test persistence. */
70 pt->_edsio_property_table = NULL;
72 g_assert (proptest_get_bytes (pt, prop, (const guint8**) str2_ptr, & str2_len) && str2_len == (strlen (str) + 1) && strcmp (str, str2) == 0);
74 g_assert (proptest_unset_bytes (pt, prop));
76 g_assert (! proptest_isset_bytes (pt, prop));
78 g_assert (! pt->_edsio_property_table);
86 EdsioPropTestEdsioUintProperty prop;
88 PropTest *pt = g_new0 (PropTest, 1);
92 g_assert (edsio_edsio_init ());
94 g_assert (edsio_new_proptest_edsiouint_property ("Just testing (3)...", PF_Persistent, & prop));
96 g_assert (! proptest_isset_edsiouint (pt, prop));
98 g_assert (proptest_set_edsiouint (pt, prop, & x));
100 g_assert (proptest_isset_edsiouint (pt, prop));
102 g_assert (proptest_get_edsiouint (pt, prop, & p) && x.val == p->val);
104 /* kill the cache, to test persistence. */
105 pt->_edsio_property_table = NULL;
107 g_assert (proptest_get_edsiouint (pt, prop, & p) && x.val == p->val);
109 g_assert (proptest_unset_edsiouint (pt, prop));
111 g_assert (! proptest_isset_edsiouint (pt, prop));
113 g_assert (! pt->_edsio_property_table);
119 const char* str = "hello there";
122 PropTest *pt = g_new0 (PropTest, 1);
124 EdsioPropTestStringProperty prop;
126 g_assert (edsio_edsio_init ());
128 g_assert (edsio_new_proptest_string_property ("Just testing (4)...", PF_Persistent, & prop));
130 g_assert (! proptest_isset_string (pt, prop));
132 g_assert (proptest_set_string (pt, prop, str));
134 g_assert (proptest_isset_string (pt, prop));
136 g_assert (proptest_get_string (pt, prop, & str2) && strcmp (str, str2) == 0);
138 /* kill the cache, to test persistence. */
139 pt->_edsio_property_table = NULL;
141 g_assert (proptest_get_string (pt, prop, & str2) && strcmp (str, str2) == 0);
143 g_assert (proptest_unset_string (pt, prop));
145 g_assert (! proptest_isset_string (pt, prop));
147 g_assert (! pt->_edsio_property_table);
152 GByteArray* sink_result;
153 SerialSink* sink = edsio_simple_sink (NULL, SBF_Checksum | SBF_Base64 | SBF_Compress, FALSE, NULL, & sink_result);
155 const char* input = "hello there!!!!!!!!";
156 SerialEdsioString *output;
160 g_assert (serialize_edsiostring (sink, input));
162 g_assert (sink->sink_close (sink));
164 g_byte_array_append (sink_result, zero, 1);
166 g_print ("%s -> %s\n", input, sink_result->data);
168 src = edsio_simple_source (sink_result->data, sink_result->len - 1, SBF_Checksum | SBF_Base64 | SBF_Compress);
170 g_assert (unserialize_edsiostring (src, & output));
172 g_assert (src->source_close (src));
174 g_assert (strcmp (output->val, input) == 0);
180 const char* md5str = "aed3918c4ccb89f2dcf74d5dcab22989";
181 const char* md5strbad1 = "aed3918c4cXb89f2dcf74d5dcab22989";
182 const char* md5strbad2 = "aed3918c4cab89f2dcf74d5dcab22989X";
183 const char* md5strbad3 = "aed3918c4cab89f2dcf74d5dcab2298";
187 g_assert (! edsio_md5_from_string (md5, md5strbad1));
188 g_assert (! edsio_md5_from_string (md5, md5strbad2));
189 g_assert (! edsio_md5_from_string (md5, md5strbad3));
191 g_assert (edsio_md5_from_string (md5, md5str));
193 edsio_md5_to_string (md5, md5str2);
195 g_assert (strcmp (md5str, md5str2) == 0);