summaryrefslogtreecommitdiff
path: root/src/mt/test.cc
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
commit5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch)
tree1a81af141708b826e9c61e8a04019994fcca8298 /src/mt/test.cc
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/mt/test.cc')
-rw-r--r--src/mt/test.cc337
1 files changed, 337 insertions, 0 deletions
diff --git a/src/mt/test.cc b/src/mt/test.cc
new file mode 100644
index 0000000..5671a33
--- /dev/null
+++ b/src/mt/test.cc
@@ -0,0 +1,337 @@
1/*************************************************************************
2 *
3 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <mt/uniheap.h>
21#include <mt/stackque.h>
22#include <mt/random.h>
23#include <mt/lookup.h>
24#include <mt/mset.h>
25#include <mt/issue.h>
26#include <mt/mvec.h>
27#include <mt/msmap.h>
28#include <time.h>
29
30#define GENERAL 0
31#define STREAM 1
32#define HEAPS 0
33#define CHARSET 0
34#define RANDOM 0
35#define LOOKUP 0
36#define ISSUE 1
37#define MSET 0
38#define CVTS 0
39#define VECTOR 0
40#define MSMAP 0
41
42static fp_stream mout(stdout),merr(stderr);
43
44main(int argc,char* argv[])
45{
46 mstring s;
47#if GENERAL
48 s="asdfwerfindfindis?? asdf wert nnvnbn\n";
49
50 mout<<"["<<Trim(s,cset_para)<<"]\n";
51
52 sref find=sref("find");
53 sref rfind=sref("rfind");
54
55 mout<<s.find(find)<<"\n";
56 mout<<s.rfind(rfind)<<"\n";
57 mout<<s.find(find,cset_lcase)<<"\n";
58 mout<<s.rfind(rfind,cset_lcase)<<"\n";
59 mout<<s.find(find,cset_ucase)<<"\n";
60 mout<<s.rfind(rfind,cset_ucase)<<"\n";
61
62 mout<<"****\n";
63
64 mout<<"["<<s.leftand_last_not_of(cset_ws)<<"]\n";
65
66 mout<<"****\n";
67
68 s.tolower();
69 mout<<"["<<s<<"]\n";
70 s.toupper();
71 mout<<"["<<s<<"]\n";
72
73 mout<<"*****\n";
74
75 mstring st="abcdefghi2jklmn";
76 charset stset("123");
77 mout<<"["<<st.left_first_of(stset)<<"]\n";
78 mout<<"["<<st.right_first_of(stset)<<"]\n";
79 mout<<"["<<st.past_first_of(stset)<<"]\n";
80
81 mout<<"******\n";
82
83 mstring a=First(s);
84 mstring b=Rest(s);
85 mstring c=Last(s);
86 mout<<"["<<a<<"]\n";
87 mout<<"["<<b<<"]\n";
88 mout<<"["<<c<<"]\n";
89
90 mout<<"******\n";
91
92 sref first,rest=s;
93 while(Split(first,rest)) {
94 mout<<"["<<first<<"]["<<atoi(first)<<"]\n";
95 }
96
97 mout<<"*******\n";
98
99 mout<<"["<<mstring().convert("%d %02X",56,100)<<"]\n";
100
101 mout<<s.skip(cset_para)<<"\n";
102
103 mout<<"********\n";
104
105 //mstring buf; buf.load("tt.cc");
106 //mout<<"***\n"<<buf<<"***\n";
107#endif
108#if STREAM
109 s="more strange asdf\n";
110
111 swrite to;
112 mout<<s<<"\n";
113 to.hold(s)<<" Hello! this is appending "<<4<<" to string\n";
114 mout<<s<<"\n";
115
116 mout<<"********\n";
117
118 mstream mm; mm<<"Hejsan!\n";
119
120 mout<<"********\n";
121
122 try {
123 THROW("hello "<<4<<" once more");
124 }
125 catch(const merror_t& e) {
126 mout<<"Error test: "<<e.num<<"\n";
127 mout<<e.desc<<"\n";
128 }
129
130 mout<<"********\n";
131
132 sref sa=s;
133 sref sb=s;
134 mout<<(sa==sb)<<"\n";
135
136 mout<<"********\n";
137
138 mstring tt="(asdf)sdfsdf";
139 mout<<tt.skip(cset_para)<<"\n";
140 mout<<"["<<tt(1,tt.skip(cset_para)-2)<<"]\n";
141
142 mout<<"********\n";
143#endif
144
145#if HEAPS
146
147 uniheap<4> stack; stack.init();
148 for(int i=0;i<48;i++) {
149 //stack.pop(stack.push());
150 stack.push();
151 }
152 mout<<"--\n";
153 mout<<stack.chunksize()<<"\n";
154
155 mout<<"********\n";
156
157 stackque<int> que(8);
158 for(int i=0;i<8;i++) que.push(i);
159
160 try {
161 que.push(5);
162 }
163 catch(const merror_t& e) {
164 merr<<e.num<<"\n";
165 merr<<e.desc<<"\n";
166 }
167
168 int pop;
169 while(que.pop(pop)) merr<<pop<<"\n";
170
171#endif
172
173#if CHARSET
174
175 charset set("12345öd");
176 charset set2("12");
177 charset set3=set-set2;
178
179 merr<<"* \n";
180
181 for(int i=-127;i<127;i++) {
182 if(set.map[i]) mout<<i<<"("<<char(i)<<")\n";
183 }
184
185 merr<<"* \n";
186
187 for(int i=-127;i<127;i++) {
188 if(set3.map[i]) mout<<i<<"("<<char(i)<<")\n";
189 }
190
191 merr<<"**\n";
192
193 mout<<find_of_("ö",1,set.map)<<"\n";
194 mout<<s.find_of(set)<<"\n";
195
196 mout<<"***\n";
197
198 mout<<"[";
199 for(int i=-127;i<128;i++) if(cset_lcase[i]!=i) mout.put(i);
200 mout<<"]\n";
201 mout<<"[";
202 for(int i=-127;i<128;i++) if(cset_lcase[i]!=i) mout.put(cset_lcase[i]);
203 mout<<"]\n";
204
205 mout<<"\n";
206
207 mout<<"[";
208 for(int i=-127;i<128;i++) if(cset_ueqv1[i]!=i) mout.put(i);
209 mout<<"]\n";
210 mout<<"[";
211 for(int i=-127;i<128;i++) if(cset_ueqv1[i]!=i) mout.put(cset_ueqv1[i]);
212 mout<<"]\n";
213
214 mout<<"\n";
215
216 mout<<"[";
217 for(int i=-127;i<128;i++) if(cset_ueqv2[i]!=i) mout.put(i);
218 mout<<"]\n";
219 mout<<"[";
220 for(int i=-127;i<128;i++) if(cset_ueqv2[i]!=i) mout.put(cset_ueqv2[i]);
221 mout<<"]\n";
222
223 mout<<"\n";
224
225 mout<<"[";
226 for(int i=-127;i<128;i++) if(cset_sim[i]!=i) mout.put(i);
227 mout<<"]\n";
228 mout<<"[";
229 for(int i=-127;i<128;i++) if(cset_sim[i]!=i) mout.put(cset_sim[i]);
230 mout<<"]\n";
231#endif
232
233#if RANDOM
234 RandomInit(13);
235 for(int i=0;i<100;i++) mout<<Uniform()<<"\n";
236#endif
237
238#if LOOKUP
239
240 while(1) {
241 mstring ip;
242 merr<<"addr>";
243 getline(ip,stdin);
244 IPnode node;
245 for(int i=0;i<4;i++) {
246 if(Lookup(node,ip)) {
247 merr<<node.valid<<"\n";
248 merr<<node.ip<<"\n";
249 merr<<node.name<<"\n";
250 }
251 else {
252 merr<<"Not found\n";
253 break;
254 }
255 }
256 }
257
258#endif
259
260#if ISSUE
261
262 issue_t cmd(sref("/bin/cat"));
263 mswrite out;
264 mstring in="hello world!";
265 cmd.run(out,in);
266 mout<<"Got ["<<out.str()<<"]\n";
267
268 cmd.clear();
269 cmd.add(sref("sadfasfd"));
270 cmd.end();
271 out.clear();
272 cmd.run(out,in);
273 mout<<"Got ["<<out.str()<<"]\n";
274
275#endif
276
277#if MSET
278
279 mstring mm="hello world!\n how many items?\n";
280 mset a=mm;
281 for(int i=0;i<a.size();i++) {
282 mout<<a[i]<<"\n";
283 }
284
285 mout<<"OR ["<<a<<"]\n";
286
287#endif
288
289#if CVTS
290
291 merr<<"n: "<<itoa(5)<<"\n";
292 merr<<"f: "<<ftoa(5)<<"\n";
293 merr<<"f: "<<ftoa(5.7)<<"\n";
294 merr<<"f: "<<ftoa(-3)<<"\n";
295 merr<<"f: "<<ftoa(3.78678)<<"\n";
296 merr<<"f: "<<ftoa(exp(2.1))<<"\n";
297 merr<<"f: "<<ftoa(time(0))<<"\n";
298 merr<<"direct: "<<3.40000<<"\n";
299
300 pipe_stream tout(1);
301 tout<<"How does this one "<<-78.4<<" behave??\n";
302
303 mstring inp;
304 getline(inp,stdin);
305 merr<<ftoa(atof(inp))<<"\n";
306
307#endif
308
309#if VECTOR
310
311 mrvec<int> v(4);
312 for(int i=0;i<v.size();i++) v[i]=i;
313
314 for(int i=0;i<v.size();i++) merr<<v[i]<<"\n";
315
316#endif
317
318#if MSMAP
319
320 ssmap map;
321 //map.add("hello","world");
322 //map.add("one","world!");
323 map.push_back(sstring("one","world!"));
324 map.push_back(sstring("hello","world"));
325 map.sort();
326
327 for(ssmap::iterator p=map.begin();p!=map.end();p++) {
328 merr<<p->first<<" "<<p->second<<"\n";
329 }
330
331 const mstring* p=map.get("one");
332 if(p) merr<<"got "<<*p<<"\n";
333
334#endif
335
336 return 0;
337}