JavaUTF8Tests.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 03 Oct 2013 10:31:41 +0200
changeset 2760 818fa434937a
parent 2678 c865275e48a7
child 2731 13f5be2bf83b
permissions -rw-r--r--
initial checkin

"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010
"
"{ Package: 'stx:libjava' }"

TestCase subclass:#JavaUTF8Tests
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Tests'
!

!JavaUTF8Tests class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1996-2011 by Claus Gittinger

 New code and modifications done at SWING Research Group [1]:

 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
                            SWING Research Group, Czech Technical University in Prague

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.

 [1] Code written at SWING Research Group contains a signature
     of one of the above copright owners. For exact set of such code,
     see the differences between this version and version stx:libjava
     as of 1.9.2010

"
! !

!JavaUTF8Tests methodsFor:'loadingTests'!

testSingleByteCharacters
    |bytes|

    bytes := ByteArray new:1.
    bytes at:1 put:65.
    self assert:((CharacterArray decodeFromJavaUTF8:bytes) = 'A').

    "Created: / 04-02-2011 / 14:18:10 / Marcel Hlopko <hlopik@gmail.com>"
!

testSixByteCharacters
    | bytes  convertedString  expectedString |

    bytes := ByteArray new: 6.
    bytes at: 1 put: 2r11101101.
    bytes at: 2 put: 2r10101111.
    bytes at: 3 put: 2r10111111.
    bytes at: 4 put: 2r11101101.
    bytes at: 5 put: 2r10111111.
    bytes at: 6 put: 2r10101111.
    expectedString := Unicode32String new: 1.
    expectedString at: 1
        put: (Character codePoint: (((((2r11111111111111111111)))))).
    convertedString := CharacterArray decodeFromJavaUTF8: bytes.
    self assert: convertedString = expectedString.

    "Created: / 04-02-2011 / 15:25:27 / Marcel Hlopko <hlopik@gmail.com>"
    "Modified: / 13-03-2011 / 15:44:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!

testSixByteCharactersTrap
    |bytes convertedString expectedString|

    bytes := ByteArray new:6.
    bytes at:1 put:2r11101101.
    bytes at:2 put:2r10101111.
    bytes at:3 put:2r10111111.
    bytes at:4 put:2r11101101.
    bytes at:5 put:2r10101111.
    bytes at:6 put:2r10111111.
    expectedString := Unicode32String new:2.
    expectedString at:1
        put:(Character codePoint:2r1101101111111111).
    expectedString at:2
                    put:(Character codePoint:2r1101101111111111).
    convertedString := CharacterArray decodeFromJavaUTF8:bytes.
    self assert:convertedString = expectedString.

    "Created: / 04-02-2011 / 16:01:32 / Marcel Hlopko <hlopik@gmail.com>"
!

testThreeByteCharacters
    |bytes convertedString expectedString|

    bytes := ByteArray new:3.
    bytes at:1 put:2r11101111.
    bytes at:2 put:2r10001111.
    bytes at:3 put:2r10101111.
    expectedString := Unicode16String new:1.
    expectedString at:1 put:(Character codePoint:2r1111001111101111).
    convertedString := CharacterArray decodeFromJavaUTF8:bytes.    
    self assert:convertedString = expectedString.

    "Created: / 04-02-2011 / 15:06:03 / Marcel Hlopko <hlopik@gmail.com>"
!

testTwoByteCharacters
    |bytes convertedString expectedString|

    bytes := ByteArray new:2.
    bytes at:1 put:2r11011111.
    bytes at:2 put:2r10001111.
    expectedString := Unicode16String new:1.
    expectedString at:1 put:(Character codePoint:2r11111001111).
    convertedString := CharacterArray decodeFromJavaUTF8:bytes.    
    self assert:convertedString = expectedString.

    "Created: / 04-02-2011 / 14:31:26 / Marcel Hlopko <hlopik@gmail.com>"
    "Modified: / 04-02-2011 / 16:02:16 / Marcel Hlopko <hlopik@gmail.com>"
! !

!JavaUTF8Tests class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libjava/JavaUTF8Tests.st,v 1.4 2013-09-06 00:41:27 vrany Exp $'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '§Id§'
! !