summaryrefslogtreecommitdiff
path: root/xdelta1/libedsio/edsiotest.c
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta1/libedsio/edsiotest.c')
-rw-r--r--xdelta1/libedsio/edsiotest.c213
1 files changed, 0 insertions, 213 deletions
diff --git a/xdelta1/libedsio/edsiotest.c b/xdelta1/libedsio/edsiotest.c
deleted file mode 100644
index 1d30dc0..0000000
--- a/xdelta1/libedsio/edsiotest.c
+++ /dev/null
@@ -1,213 +0,0 @@
1/* -*-Mode: C;-*-
2 * $Id: edsiotest.c 1.1 Sun, 28 Jan 2007 10:02:26 -0800 jmacd $
3 *
4 * Copyright (C) 1998, 1999, Josh MacDonald.
5 * All Rights Reserved.
6 *
7 * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
8 */
9
10#include "edsio.h"
11
12void
13test1 ()
14{
15 guint32 x = 0;
16
17 PropTest *pt = g_new0 (PropTest, 1);
18
19 EdsioPropTestUintProperty prop;
20
21 g_assert (edsio_edsio_init ());
22
23 g_assert (edsio_new_proptest_uint_property ("Just testing (1)...", PF_Persistent, & prop));
24
25 g_assert (! proptest_isset_uint (pt, prop));
26
27 g_assert (proptest_set_uint (pt, prop, 42));
28
29 g_assert (proptest_isset_uint (pt, prop));
30
31 g_assert (proptest_get_uint (pt, prop, & x) && x == 42);
32
33 /* kill the cache, to test persistence. */
34 pt->_edsio_property_table = NULL;
35
36 g_assert (proptest_get_uint (pt, prop, & x) && x == 42);
37
38 g_assert (proptest_unset_uint (pt, prop));
39
40 g_assert (! proptest_isset_uint (pt, prop));
41
42 g_assert (! pt->_edsio_property_table);
43}
44
45void
46test2 ()
47{
48 const char* str = "hello there";
49 const char* str2;
50 guint32 str2_len;
51
52 PropTest *pt = g_new0 (PropTest, 1);
53
54 EdsioPropTestBytesProperty prop;
55
56 g_assert (edsio_edsio_init ());
57
58 g_assert (edsio_new_proptest_bytes_property ("Just testing (2)...", PF_Persistent, & prop));
59
60 g_assert (! proptest_isset_bytes (pt, prop));
61
62 g_assert (proptest_set_bytes (pt, prop, (guint8*) str, strlen (str) + 1));
63
64 g_assert (proptest_isset_bytes (pt, prop));
65
66 g_assert (proptest_get_bytes (pt, prop, (const guint8**) & str2, & str2_len) && str2_len == (strlen (str) + 1) && strcmp (str, str2) == 0);
67
68 /* kill the cache, to test persistence. */
69 pt->_edsio_property_table = NULL;
70
71 g_assert (proptest_get_bytes (pt, prop, (const guint8**) & str2, & str2_len) && str2_len == (strlen (str) + 1) && strcmp (str, str2) == 0);
72
73 g_assert (proptest_unset_bytes (pt, prop));
74
75 g_assert (! proptest_isset_bytes (pt, prop));
76
77 g_assert (! pt->_edsio_property_table);
78}
79
80void
81test3 ()
82{
83 SerialEdsioUint x;
84 SerialEdsioUint *p;
85 EdsioPropTestEdsioUintProperty prop;
86
87 PropTest *pt = g_new0 (PropTest, 1);
88
89 x.val = 42;
90
91 g_assert (edsio_edsio_init ());
92
93 g_assert (edsio_new_proptest_edsiouint_property ("Just testing (3)...", PF_Persistent, & prop));
94
95 g_assert (! proptest_isset_edsiouint (pt, prop));
96
97 g_assert (proptest_set_edsiouint (pt, prop, & x));
98
99 g_assert (proptest_isset_edsiouint (pt, prop));
100
101 g_assert (proptest_get_edsiouint (pt, prop, & p) && x.val == p->val);
102
103 /* kill the cache, to test persistence. */
104 pt->_edsio_property_table = NULL;
105
106 g_assert (proptest_get_edsiouint (pt, prop, & p) && x.val == p->val);
107
108 g_assert (proptest_unset_edsiouint (pt, prop));
109
110 g_assert (! proptest_isset_edsiouint (pt, prop));
111
112 g_assert (! pt->_edsio_property_table);
113}
114
115void
116test4 ()
117{
118 const char* str = "hello there";
119 const char* str2;
120
121 PropTest *pt = g_new0 (PropTest, 1);
122
123 EdsioPropTestStringProperty prop;
124
125 g_assert (edsio_edsio_init ());
126
127 g_assert (edsio_new_proptest_string_property ("Just testing (4)...", PF_Persistent, & prop));
128
129 g_assert (! proptest_isset_string (pt, prop));
130
131 g_assert (proptest_set_string (pt, prop, str));
132
133 g_assert (proptest_isset_string (pt, prop));
134
135 g_assert (proptest_get_string (pt, prop, & str2) && strcmp (str, str2) == 0);
136
137 /* kill the cache, to test persistence. */
138 pt->_edsio_property_table = NULL;
139
140 g_assert (proptest_get_string (pt, prop, & str2) && strcmp (str, str2) == 0);
141
142 g_assert (proptest_unset_string (pt, prop));
143
144 g_assert (! proptest_isset_string (pt, prop));
145
146 g_assert (! pt->_edsio_property_table);
147}
148
149void test5 ()
150{
151 GByteArray* sink_result;
152 SerialSink* sink = edsio_simple_sink (NULL, SBF_Checksum | SBF_Base64 | SBF_Compress, FALSE, NULL, & sink_result);
153 SerialSource* src;
154 const char* input = "hello there!!!!!!!!";
155 SerialEdsioString *output;
156 guint8 zero[1];
157 zero[0] = 0;
158
159 g_assert (serialize_edsiostring (sink, input));
160
161 g_assert (sink->sink_close (sink));
162
163 g_byte_array_append (sink_result, zero, 1);
164
165 g_print ("%s -> %s\n", input, sink_result->data);
166
167 src = edsio_simple_source (sink_result->data, sink_result->len - 1, SBF_Checksum | SBF_Base64 | SBF_Compress);
168
169 g_assert (unserialize_edsiostring (src, & output));
170
171 g_assert (src->source_close (src));
172
173 g_assert (strcmp (output->val, input) == 0);
174}
175
176void
177test6 ()
178{
179 const char* md5str = "aed3918c4ccb89f2dcf74d5dcab22989";
180 const char* md5strbad1 = "aed3918c4cXb89f2dcf74d5dcab22989";
181 const char* md5strbad2 = "aed3918c4cab89f2dcf74d5dcab22989X";
182 const char* md5strbad3 = "aed3918c4cab89f2dcf74d5dcab2298";
183 char md5str2[33];
184 guint8 md5[16];
185
186 g_assert (! edsio_md5_from_string (md5, md5strbad1));
187 g_assert (! edsio_md5_from_string (md5, md5strbad2));
188 g_assert (! edsio_md5_from_string (md5, md5strbad3));
189
190 g_assert (edsio_md5_from_string (md5, md5str));
191
192 edsio_md5_to_string (md5, md5str2);
193
194 g_assert (strcmp (md5str, md5str2) == 0);
195}
196
197int
198main ()
199{
200 test1 ();
201
202 test2 ();
203
204 test3 ();
205
206 test4 ();
207
208 test5 ();
209
210 test6 ();
211
212 return 0;
213}