Untitled diff

Créé Le diff n'expire jamais
Les deux textes sont identiques
Il n'y a aucune différence entre ces deux textes
0 suppressions
348 lignes
0 ajouts
348 lignes
"
"
SUnit tests for MultiByteFileStream
SUnit tests for MultiByteFileStream


"
"
Class {
Class {
#name : #MultiByteFileStreamTest,
#name : #MultiByteFileStreamTest,
#superclass : #TestCase,
#superclass : #TestCase,
#category : #Deprecated70
#category : #Deprecated70
}
}


{ #category : #support }
{ #category : #support }
MultiByteFileStreamTest >> chunkString [
MultiByteFileStreamTest >> chunkString [
"A chunk larger than buffer (currently 2048), but not long enough to fill it completely again. Therefore, buffer should contain some elements at end that are not part of the real buffer"
"A chunk larger than buffer (currently 2048), but not long enough to fill it completely again. Therefore, buffer should contain some elements at end that are not part of the real buffer"
| smallChunk chunkString |
| smallChunk chunkString |
chunkString :=
chunkString :=
String new: (MultiByteFileStream new ascii enableReadBuffering braceArray size * 1.3) floor.
String new: (MultiByteFileStream new ascii enableReadBuffering braceArray size * 1.3) floor.
smallChunk := 'ASDFASDFASDFASDFasdfasdfasdfasdfQWERQWERQWERqwerqwerqwer! !'.
smallChunk := 'ASDFASDFASDFASDFasdfasdfasdfasdfQWERQWERQWERqwerqwerqwer! !'.
1 to: chunkString size by: smallChunk size do: [:ix |
1 to: chunkString size by: smallChunk size do: [:ix |
chunkString replaceFrom: ix to: (ix + smallChunk size -1 min: chunkString size) with: smallChunk startingAt: 1].
chunkString replaceFrom: ix to: (ix + smallChunk size -1 min: chunkString size) with: smallChunk startingAt: 1].
^chunkString
^chunkString
]
]


{ #category : #accessing }
{ #category : #accessing }
MultiByteFileStreamTest >> fileOutTestClass [
MultiByteFileStreamTest >> fileOutTestClass [
^ MultiByteFileStreamFileOutTestClass
^ MultiByteFileStreamFileOutTestClass
]
]


{ #category : #support }
{ #category : #support }
MultiByteFileStreamTest >> lineEndTestFile [
MultiByteFileStreamTest >> lineEndTestFile [
^'lineEndTesting.txt'
^'lineEndTesting.txt'
]
]


{ #category : #running }
{ #category : #running }
MultiByteFileStreamTest >> tearDown [
MultiByteFileStreamTest >> tearDown [
'foobug6933' asFileReference ensureDelete.
'foobug6933' asFileReference ensureDelete.
self lineEndTestFile asFileReference ensureDelete.
self lineEndTestFile asFileReference ensureDelete.
super tearDown
super tearDown
]
]


{ #category : #testing }
{ #category : #testing }
MultiByteFileStreamTest >> testBasicChunk [
MultiByteFileStreamTest >> testBasicChunk [
| internalStream chunkKey |
| internalStream chunkKey |
internalStream := ChunkReadStream on: self chunkString readStream.
internalStream := ChunkReadStream on: self chunkString readStream.
chunkKey := OrderedCollection new.
chunkKey := OrderedCollection new.
[internalStream atEnd] whileFalse:
[internalStream atEnd] whileFalse:
[ | chunk |
[ | chunk |
chunk := internalStream next.
chunk := internalStream next.
chunkKey add: {internalStream position. chunk size. chunk}].
chunkKey add: {internalStream position. chunk size. chunk}].
[self writeChunkToFile.
[self writeChunkToFile.
(File named: 'chunkTest.txt') readStreamDo: [:fileStream | | stream |
(File named: 'chunkTest.txt') readStreamDo: [:fileStream | | stream |
stream := ChunkReadStream on: (ZnCharacterReadStream on: fileStream).
stream := ChunkReadStream on: (ZnCharacterReadStream on: fileStream).
1 to: chunkKey size do: [:ix | |chunk|
1 to: chunkKey size do: [:ix | |chunk|
chunk := stream next.
chunk := stream next.
self assert: (chunkKey at: ix) second equals: chunk size.
self assert: (chunkKey at: ix) second equals: chunk size.
self assert: (chunkKey at: ix) last equals: chunk.]].
self assert: (chunkKey at: ix) last equals: chunk.]].
] ensure: [ | f |
] ensure: [ | f |
f := File named: 'chunkTest.txt'.
f := File named: 'chunkTest.txt'.
f exists ifTrue: [ f delete ]]
f exists ifTrue: [ f delete ]]
]
]


{ #category : #testing }
{ #category : #testing }
MultiByteFileStreamTest >> testBinaryUpTo [
MultiByteFileStreamTest >> testBinaryUpTo [
"This is a non regression test for bug http://bugs.squeak.org/view.php?id=6933"
"This is a non regression test for bug http://bugs.squeak.org/view.php?id=6933"
| foo fileName |
| foo fileName |
fileName := 'foobug6933'.
fileName := 'foobug6933'.
MultiByteFileStream
MultiByteFileStream
forceNewFileNamed: fileName
forceNewFileNamed: fileName
do: [ :stream | stream binary.
do: [ :stream | stream binary.
stream nextPutAll: #[1 2 3 4] ].
stream nextPutAll: #[1 2 3 4] ].


foo := MultiByteFileStream oldFileNamed: fileName.
foo := MultiByteFileStream oldFileNamed: fileName.
[foo binary.
[foo binary.
self assert: (foo upTo: 3) = #[1 2]
self assert: (foo upTo: 3) = #[1 2]
] ensure: [
] ensure: [
foo close.
foo close.
fileName asFileReference delete].
fileName asFileReference delete].
]
]


{ #category : #testing }
{ #category : #testing }
MultiByteFileStreamTest >> testFileOutNonAscii [
MultiByteFileStreamTest >> testFileOutNonAscii [
"My test class, class side, contains a method with non-ascii characters,
"My test class, class side, contains a method with non-ascii characters,
fileOut used to fail due to #backChunk problems"
fileOut used to fail due to #backChunk problems"
(self fileOutTestClass name asString, '.st') asFileReference ensureDelete.
(self fileOutTestClass name asString, '.st') asFileReference ensureDelete.
self fileOutTestClass fileOut
self fileOutTestClass fileOut
]
]


{ #category : #testing }
{ #category : #testing }
MultiByteFileStreamTest >> testLineEndingsWith: anEncodingName [
MultiByteFileStreamTest >> testLineEndingsWith: anEncodingName [
| byteMap |
| byteMap |
"Make a map of different endings, and the expected byte pattern when three cr's are added using it"
"Make a map of different endings, and the expected byte pattern when three cr's are added using it"
byteMap := Dictionary new.
byteMap := Dictionary new.
byteMap at: #cr put: #[13 13 13];
byteMap at: #cr put: #[13 13 13];
at: #lf put: #[10 10 10];
at: #lf put: #[10 10 10];
at: #crlf put: #[13 10 13 10 13 10].
at: #crlf put: #[13 10 13 10 13 10].
byteMap keysDo: [:lineEnding |
byteMap keysDo: [:lineEnding |
FileStream forceNewFileNamed: self lineEndTestFile do: [:stream |
FileStream forceNewFileNamed: self lineEndTestFile do: [:stream |