3 * Copyright (C)2007-2008 Versabanq Innovations Inc. and contributors.
4 * See the included file named LICENSE for license information.
8 using System
.Collections
.Generic
;
14 public class WvStreamTests
16 [Test
] public void basics()
18 using (WvStream s
= new WvStream())
25 using (WvStream s
= new WvStream())
27 int closed_called
= 0, closed_called2
= 0;
28 s
.onclose
+= delegate() { closed_called++; }
;
29 s
.onclose
+= delegate() { closed_called2++; }
;
30 Exception e1
= new Exception("e1");
31 Exception e2
= new Exception("e2");
33 WVPASSEQ(closed_called
, 0);
34 WVPASSEQ(closed_called2
, 0);
38 WVPASS(s
.err
!= null);
40 WVPASS(s
.err
.Message
== "e1");
41 WVPASSEQ(closed_called
, 1);
42 WVPASSEQ(closed_called2
, 1);
46 [Test
] public void loopback()
48 using (WvLoopback l
= new WvLoopback())
50 l
.print("bonk\nwonk\nblonk");
51 WVPASSEQ(l
.read(5).FromUTF8(), "bonk\n");
52 WVPASSEQ(l
.read(2).FromUTF8(), "wo");
53 string got
= null, got2
= null;
54 Action d
= delegate() {
55 Console
.WriteLine("onreadable!");
56 got
= l
.read(4096).FromUTF8();
57 got2
= l
.read(4096).FromUTF8();
64 WVPASSEQ(got
, "nk\nblonkbah");
67 WVPASSEQ(got
, "nk\nblonkbah");
69 WVPASSEQ(got
, "nk\nblonkbah");
73 l
.onwritable
+= delegate() {
85 [Test
] public void inbufstream()
87 using (WvLoopback l
= new WvLoopback())
88 using (WvInBufStream b
= new WvInBufStream(l
))
91 int wcount
= 0, rcount
= 0;
94 b
.onwritable
+= delegate() {
95 Console
.WriteLine("writing");
98 Console
.WriteLine("done writing");
101 b
.onreadable
+= delegate() {
102 Console
.WriteLine("reading");
104 s
= b
.getline(0, '\n');
105 Console
.WriteLine("done reading");
120 wv
.print("putstring\n");
121 b
.print("string!\n");
122 WvStream
.runonce(10000);
127 WVPASSEQ(s
, "XXstring!\n");
131 IEnumerable
<int> checker(WvFile f
)
133 Console
.WriteLine("checker!");
134 WVPASSEQ(f
.getline(-1, '\n'), "Line 1\n");
136 WVPASSEQ(f
.getline(-1, '\n'), "Line 2!!\n");
138 WVPASSEQ(f
.getline(-1, '\n'), "Line 3\rwith CR\n");
140 WVPASSEQ(f
.getline(-1, '\n'), null);
142 WVPASS(false); // should never reach here
145 [Test
] public void filestream()
147 using (WvFile f
= new WvFile("testfile.txt", "r"))
149 f
.onreadable
+= checker(f
).ToAction();
152 Console
.WriteLine("iter");
153 WvStream
.runonce(1000);
158 Console
.WriteLine(f
.err
);
163 using (WvFile f
= new WvFile("testfile.txt", "r"))
166 f
.onreadable
+= delegate() {
170 WvStream
.runonce(10000);
172 WVPASSEQ(f
.read(1).FromUTF8(), "L");
173 WVPASSEQ(f
.getline(-1, '\r'), "ine 1\nLine 2!!\nLine 3\r");
174 WvStream
.runonce(10000);
175 WVPASSEQ(f
.read(1024).FromUTF8(), "with CR\n");