author | joe |
Fri, 15 Mar 2013 19:39:10 -0400 | |
changeset 112 | b6b3d8435bb7 |
parent 71 | b5baf23694f3 |
permissions | -rw-r--r-- |
9 | 1 |
"{ Package: 'stx:goodies/xtreams/terminals/tests' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
FiniteReadingWritingTests subclass:#CollectionReadingWritingTest |
|
6 |
instanceVariableNames:'' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
26
d740fff525d4
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
9
diff
changeset
|
9 |
category:'Xtreams-Terminals-Tests' |
9 | 10 |
! |
11 |
||
12 |
||
13 |
!CollectionReadingWritingTest methodsFor:'initialize-release'! |
|
14 |
||
15 |
input |
|
16 |
||
17 |
^input ifNil: [ input := (self output close; terminal) reading ] |
|
18 |
! |
|
19 |
||
20 |
output |
|
21 |
||
22 |
^output ifNil: [ output := ByteArray new writing ] |
|
23 |
! ! |
|
24 |
||
25 |
!CollectionReadingWritingTest methodsFor:'tests - core'! |
|
26 |
||
27 |
testInsert |
|
28 |
self output write: #[ 1 2 3 4 7 8 9 0 ]. |
|
29 |
self output -- 4. |
|
30 |
self output insert: #[ 5 6 ]. |
|
31 |
self output -= 0. "Have to seek to the end otherwise output gets truncated when we close it" |
|
32 |
self assert: (self input read: 10) = #[ 1 2 3 4 5 6 7 8 9 0 ] |
|
33 |
! |
|
34 |
||
35 |
testReadWriteLargeAmount |
|
36 |
| data | |
|
37 |
1 to: 10 do: [:each | |
|
38 |
output := input := nil. |
|
39 |
self output put: 1. self assert: self input get = 1]. |
|
40 |
#( 64 1024 2048 4096 8192 ) do: [:dataSize | |
|
41 |
output := input := nil. |
|
42 |
data := ByteArray new: dataSize. |
|
43 |
1 to: data size do: [:i | data at: i put: (i - 1) \\ 256]. |
|
44 |
self timeout: 1000 milliseconds |
|
45 |
server: [1 to: 10 do: [:each | self output write: data]. true] |
|
46 |
client: [(1 to: 10) inject: true into: [:pass :each | pass and: [(self input read: data size) = data]]]] |
|
47 |
! |
|
48 |
||
49 |
testWriteFromCollectionAt |
|
50 |
||
51 |
| data | |
|
52 |
data := #[1 2 3 4 5 6 7]. |
|
53 |
self assert: (self output write: 4 from: data at: 1) = 4. |
|
54 |
self assert: (self output write: 3 from: data at: 5) = 3. |
|
55 |
self assert: (self input read: 4) = (data first: 4). |
|
56 |
self assert: (self input read: 3) = (data last: 3) |
|
57 |
! |
|
58 |
||
59 |
testWriteFromStream |
|
60 |
| data | |
|
61 |
data := #[ 1 2 3 4 ] reading. |
|
62 |
self assert: (self output write: 3 from: data) = 3. |
|
63 |
self assert: (self output write: 1 from: data) = 1. |
|
64 |
self assert: (self input read: 3) = #[ 1 2 3 ]. |
|
65 |
self assert: self input get = 4. |
|
66 |
self assert: ( |
|
67 |
[ self output write: 2 from: data. false |
|
68 |
] on: Incomplete do: [ :eos | |
|
69 |
eos count = 0 ]) |
|
70 |
! ! |
|
71 |
||
72 |
||
73 |
!CollectionReadingWritingTest class methodsFor:'documentation'! |
|
74 |
||
112 | 75 |
version_HG |
76 |
||
77 |
^ '$Changeset: <not expanded> $' |
|
78 |
! |
|
79 |
||
9 | 80 |
version_SVN |
81 |
^ '$Id$' |
|
82 |
! ! |
|
112 | 83 |