RegressionTests__XMLCoderTests.st
author Stefan Vogel <sv@exept.de>
Thu, 05 Sep 2002 15:54:40 +0200
changeset 165 b9dba6743d09
parent 164 fcc68d8814ad
child 166 79ff0709dccb
permissions -rw-r--r--
Test tabs in strings

"{ Package: 'exept:regression' }"

TestCase subclass:#XMLCoderTests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'XML-Presentation'
!

!XMLCoderTests class methodsFor:'documentation'!

documentation
"
    documentation to be added.

    [author:]
        Stefan Vogel (stefan@zwerg)

    [see also:]

    [instance variables:]

    [class variables:]
"
!

history
    "Created: / 26.6.2002 / 10:32:14 / stefan"
!

history
    "Created: / 26.6.2002 / 10:32:14 / stefan"
! !

!XMLCoderTests methodsFor:'helpers'!

encodeAndDecode:anObject
    "test, that encoding and decoding an Object results in anObject"

    |encodedString decodedObject|

    encodedString := XMLStandardCoder new encodingOf:anObject.
    decodedObject := (XMLStandardDecoder on:encodedString readStream) next.

    self should:anObject = decodedObject.

    encodedString := XMLStandardCoder new aspect:#encodeInstanceVariables; encodingOf:anObject.
    decodedObject := (XMLStandardDecoder on:encodedString readStream) useSend:true; next.

    self should:anObject = decodedObject.

    ^ decodedObject.
! !

!XMLCoderTests methodsFor:'initialize / release'!

setUp
    "common setup - invoked before testing"

    super setUp
!

tearDown
    "common cleanup - invoked after testing"

    super tearDown
! !

!XMLCoderTests methodsFor:'tests'!

testArray
    "test encoding an decoding of an integer"

    |arr|

    arr := Array new:10.
    arr at:1 put:true.
    arr at:2 put:'hallo'.
    arr at:3 put:#symbol.
    arr at:4 put:nil.
"/    arr at:6 put:arr.

    self encodeAndDecode:arr

    "
     self run:#testArray
    "
!

testBytes
    "test encoding an decoding of an ByteArray"

    self encodeAndDecode:#[1].
    self encodeAndDecode:#[1 2].
    self encodeAndDecode:#[1 2 3].
    self encodeAndDecode:#[1 2 3 4].
    self encodeAndDecode:#[1 2 3 4 5].
    self encodeAndDecode:#[1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 9 0 12 3 4 56 7 8 9 0].

    "
     self run:#testBytes
    "
!

testCharacter
    "test encoding an decoding of a Character"

    self encodeAndDecode:$a.
    self encodeAndDecode:$ä.

    "
     self run:#testCharacter
    "
!

testComplex
    "test encoding an decoding of an OrderedCollection"

    |coll r decodedObject|

    coll := OrderedCollection new.
    coll add:true.
    coll add:'hallo'.
    coll add:#symbol.
    coll add:(r:= #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]).
    coll add:#symbol.
    coll add:r.
    coll add:coll copy.

    decodedObject := self encodeAndDecode:coll.

    self should:(decodedObject at:4) == (decodedObject at:6).

    "
     self run:#testComplex
    "
!

testDictionary
    "test encoding an decoding of an integer"

    |dict|

    dict := Dictionary new.
    dict at:true put:1234.
    dict at:#murks put:'hallo'.
    dict at:5 put:#symbol.
        
    self encodeAndDecode:dict

    "
     self run:#testDictionary
    "
!

testEmptyCollection
    "test encoding an decoding of an OrderedCollection"

    |set|

    set := OrderedCollection new.

    self encodeAndDecode:set

    "
     self run:#testEmptyCollection
    "
!

        self encodeAndDecode:i
    "test encoding an decoding of an integer"

    -1.0 to: 1.0 by:0.5 do:[:i|
        self encodeAndDecode:i
    ].

    "
     self run:#testFloat
    "
!

        self encodeAndDecode:i
    "test encoding an decoding of an integer"

    (-3/4) to:(3/4) by:(1/4) do:[:i|
        self encodeAndDecode:i
    ].

    "
     self run:#testFraction
    "
!

testIdentityDictionary
    "test encoding an decoding of an integer"

    |dict|

    dict := IdentityDictionary new.
    dict at:true put:1234.
    dict at:#test put:'hallo'.
    dict at:5 put:#symbol.
        
    self encodeAndDecode:dict

    "
     self run:#testIdentityDictionary
    "
!
    -100 to: 100 do:[:i|
        self encodeAndDecode:i

    -100 to: 100 do:[:i|
        self encodeAndDecode:i
     self run:#test1

    "
     self run:#test1
    "
!

testOrderedCollection
    "test encoding an decoding of an OrderedCollection"

    |set|

    set := OrderedCollection new.
    set add:true.
    set add:'hallo'.
    set add:#symbol.

    self encodeAndDecode:set

    "
     self run:#testOrderedCollection
    "
!

testSet
    "test encoding an decoding of a set"

    |set|

    set := Set new.
    set add:true.
    set add:'hallo'.
    set add:#symbol.

    self encodeAndDecode:set

    "
     self run:#testSet
    "
!

testString
    "test encoding an decoding of a String"

                         Character tab asString, Character tab asString, 'tabs',
                         Character tab asString.
    self encodeAndDecode:Character tab asString , 'with', 
                         Character tab asString, Character tab asString, 'tabs',
                         Character tab asString.
    self encodeAndDecode:Character tab asString , '& with', 
                         Character tab asString, Character tab asString, 'tabs',
                         Character tab asString.

    "
     self run:#testUUID
    "
! !

    ^ '$Header$'

version
    ^ '$Header$'
! !