RegressionTests__BinaryIOTests.st
author Claus Gittinger <cg@exept.de>
Fri, 10 Sep 2004 13:04:48 +0200
changeset 243 a4d2af7147c7
child 244 cbabc6730fb7
permissions -rw-r--r--
initial checkin

"{ Package: 'exept:regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#BinaryIOTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'System-BinaryStorage'
!

!BinaryIOTests class methodsFor:'documentation'!

documentation
"
    documentation to be added.

    [author:]
        Claus Gittinger (cg@alan)

    [instance variables:]

    [class variables:]

    [see also:]

"
!

history
    "Created: / 09-09-2004 / 13:13:39 / cg"
! !

!BinaryIOTests methodsFor:'initialize / release'!

setUp
    "common setup - invoked before testing."

    super setUp
!

tearDown
    "common cleanup - invoked after testing."

    super tearDown
! !

!BinaryIOTests methodsFor:'tests'!

test1
    |test test2 loaders bytes outStream inStream|

    loaders := OrderedCollection new.

    outStream := ByteArray new writeStream.

    test := [:objWritten |
                objWritten storeBinaryOn:outStream.
                loaders add:[ 
                                    |objRead expected|

                                    expected := objWritten.
                                    objRead := inStream nextObject.
                                    self assert:( objRead = expected ) 
                                 ]
              ].

    test2 := [:val | test value:val. test value:  val negated].

    test value:(1 to:99).
    test value:(1 to:99) asArray.

    bytes := outStream contents.
    inStream := BinaryInputManager on:bytes readStream.

    loaders do:[:action | action value ].

    "
     self run:#test1
     self new test1
    "
!

testByteArrays1
    |objs outStream inStream|

    outStream := ByteArray new writeStream.

    objs := #(
        []
        [1]
        [1 2]
        [1 2 3]
    ).

    objs do:[:written |
        written storeBinaryOn:outStream.
    ].


    inStream := BinaryInputManager on:(outStream contents readStream).

    objs do:[:expected | |read|
        read := inStream nextObject.
        self assert:( read = expected).
    ].

    "
     self run:#testByteArrays1
     self new testByteArrays1
    "
!

testByteArrays2
    |outStream inStream test|

    test := [:obj |
        |written read|

        outStream := ByteArray new writeStream.
        written := obj.
        written storeBinaryOn:outStream.

        inStream := BinaryInputManager on:(outStream contents readStream).

        read := inStream nextObject.
        self assert:( read = written).
    ].

    test value:(1 to:254) asByteArray.
    test value:(1 to:255) asByteArray.
    test value:(0 to:255) asByteArray.

    test value:(ByteArray new:100).
    test value:(ByteArray new:127).
    test value:(ByteArray new:128).
    test value:(ByteArray new:129).
    test value:(ByteArray new:254).
    test value:(ByteArray new:255).
    test value:(ByteArray new:256).
    test value:(ByteArray new:257).
    test value:(ByteArray new:1000).
    test value:(ByteArray new:10000).
    test value:(ByteArray new:100000).
    test value:(ByteArray new:1000000).
    test value:(ByteArray new:10000000).

    "
     self run:#testByteArrays2
     self new testByteArrays2
    "
!

testIntegers1
    |nums outStream inStream|

    outStream := ByteArray new writeStream.

    nums := #(
        0
        1
        127
        128
        129
        254 
        255 
        256 
        16r3FFF 
        16r4000 
        16r4001 
        16r7FFF 
        16r8000 
        16r8001 
        16rFFFF 
        16r10000 
        16r10001 

        16r3FFFFF 
        16r400000 
        16r400001 
        16r7FFFFF 
        16r800000 
        16r800001 
        16rFFFFFF 
        16r1000000 
        16r1000001 

        16r3FFFFFFF 
        16r40000000 
        16r40000001 
        16r7FFFFFFF 
        16r80000000 
        16r80000001
        16rFFFFFFFF 
        16r100000000 
        16r100000001 

        16r3FFFFFFFFF 
        16r4000000000 
        16r4000000001 
        16r7FFFFFFFFF 
        16r8000000000 
        16r8000000001 
        16rFFFFFFFFFF 
        16r10000000000 
        16r10000000001 

        16r3FFFFFFFFFFF 
        16r400000000000 
        16r400000000001 
        16r7FFFFFFFFFFF 
        16r800000000000 
        16r800000000001 
        16rFFFFFFFFFFFF 
        16r1000000000000 
        16r1000000000001 

        16r3FFFFFFFFFFFFF 
        16r40000000000000 
        16r40000000000001 
        16r7FFFFFFFFFFFFF 
        16r80000000000000 
        16r80000000000001 
        16rFFFFFFFFFFFFFF 
        16r100000000000000 
        16r100000000000001 

        16r3FFFFFFFFFFFFFFF 
        16r4000000000000000 
        16r4000000000000001 
        16r7FFFFFFFFFFFFFFF 
        16r8000000000000000 
        16r8000000000000001 
        16rFFFFFFFFFFFFFFFF 
        16r10000000000000000 
        16r10000000000000001 

        16r3FFFFFFFFFFFFFFFFF 
        16r400000000000000000 
        16r400000000000000001 
        16r7FFFFFFFFFFFFFFFFF 
        16r800000000000000000 
        16r800000000000000001 
        16rFFFFFFFFFFFFFFFFFF 
        16r1000000000000000000 
        16r1000000000000000001 

        16r3FFFFFFFFFFFFFFFFFFF 
        16r40000000000000000000 
        16r40000000000000000001 
        16r7FFFFFFFFFFFFFFFFFFF 
        16r80000000000000000000 
        16r80000000000000000001 
        16rFFFFFFFFFFFFFFFFFFFF 
        16r100000000000000000000 
        16r100000000000000000001 

        16r7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
        16r80000000000000000000000000000000000000 
        16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 
    ).

    nums do:[:written |
        written storeBinaryOn:outStream.
        written negated storeBinaryOn:outStream.
    ].


    inStream := BinaryInputManager on:(outStream contents readStream).

    nums do:[:expected | |read|
        read := inStream nextObject.
        self assert:( read = expected).

        read := inStream nextObject.
        self assert:( read = expected negated).

    ].

    "
     self run:#testIntegers1
     self new testIntegers1
    "
!

testStrings1
    |objs outStream inStream|

    outStream := ByteArray new writeStream.

    objs := #(
        ''
        '1'
        '12'
        '123'
        "/        1         2         3         4         5         6         7         8         9         0         1         2
        '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678'

        "/        1         2         3         4         5         6         7         8         9         0         1         2         3         4         5         6         7         8         9         0         1         2         3         4         5
        '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345'

        "/        1         2         3         4         5         6         7         8         9         0         1         2         3         4         5         6         7         8         9         0         1         2         3         4         5
        '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456'

        "/        1         2         3         4         5         6         7         8         9         0         1         2         3         4         5         6         7         8         9         0         1         2         3         4         5
        '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567'
    ).

    objs do:[:written |
        written storeBinaryOn:outStream.
    ].


    inStream := BinaryInputManager on:(outStream contents readStream).

    objs do:[:expected | |read|
        read := inStream nextObject.
        self assert:( read = expected).
    ].

    "
     self run:#testStrings1
     self new testStrings1
    "
!

testStrings2
    |outStream inStream test|

    test := [:obj |
        |written read|

        outStream := ByteArray new writeStream.
        written := obj.
        written storeBinaryOn:outStream.

        inStream := BinaryInputManager on:(outStream contents readStream).

        read := inStream nextObject.
        self assert:( read = written).
    ].

    test value:(String new:100).
    test value:(String new:127).
    test value:(String new:128).
    test value:(String new:129).
    test value:(String new:254).
    test value:(String new:255).
    test value:(String new:256).
    test value:(String new:257).
    test value:(String new:1000).
    test value:(String new:10000).
    test value:(String new:100000).
    test value:(String new:1000000).
    test value:(String new:10000000).

    "
     self run:#testStrings2
     self new testStrings2
    "
! !

!BinaryIOTests class methodsFor:'documentation'!

version
    ^ '$Header$'
! !