Merge jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Wed, 13 Apr 2016 23:15:27 +0100
branchjv
changeset 1486 27e6519ac900
parent 1485 5a1aadddbc7f
child 1487 c737fa75ba5a
Merge
RegressionTests__BinaryIOTests.st
RegressionTests__FloatTest.st
RegressionTests__StreamTests.st
RegressionTests__StringTests.st
--- a/RegressionTests__BinaryIOTests.st	Tue Apr 05 19:13:28 2016 +0100
+++ b/RegressionTests__BinaryIOTests.st	Wed Apr 13 23:15:27 2016 +0100
@@ -31,6 +31,12 @@
     "Created: / 09-09-2004 / 13:13:39 / cg"
 ! !
 
+!BinaryIOTests class methodsFor:'queries'!
+
+coveredPackageNames
+    ^ #( 'stx:libboss' )
+! !
+
 !BinaryIOTests methodsFor:'initialize / release'!
 
 setUp
@@ -113,6 +119,42 @@
     "
 !
 
+testBehavior
+    |clsOut clsIn outStream boss inStream|
+
+    Class withoutUpdatingChangesDo:[
+        clsOut := Object
+                subclass:#BinarioTestClass
+                instanceVariableNames:'a b c'
+                classVariableNames:''
+                poolDictionaries:''
+                category:'tests'
+                inEnvironment:nil.
+    ].
+    
+    outStream := ByteArray new writeStream.
+    boss := BinaryOutputManager new.
+    clsOut storeBinaryClassOn:outStream manager:boss.
+
+    inStream := BinaryInputManager on:(outStream contents readStream).
+    BinaryIOManager nonexistingClassSignal handle:[:ex |
+        ex proceedWith:ex parameter
+    ] do:[    
+        clsIn := inStream nextObject.
+    ].
+    self assert:( clsIn name = clsOut name ).
+    self assert:( clsIn superclass == clsOut superclass ).
+    self assert:( clsIn instVarNames = clsOut instVarNames ).
+    self assert:( clsIn category = clsOut category ).
+    self assert:( clsIn poolDictionaries = clsOut poolDictionaries ).
+    self assert:( clsIn methodDictionary sameContentsAs: clsOut methodDictionary ).
+
+    "
+     self run:#testBehavior
+     self new testBehavior
+    "
+!
+
 testByteArrays1
     |objs outStream inStream|
 
@@ -186,6 +228,40 @@
     "
 !
 
+testCharacters
+    |objs outStream inStream|
+
+    outStream := ByteArray new writeStream.
+
+    objs := 
+        {
+            $a .
+            (Character value:0) .
+            (Character value:255) .
+            (Character value:256) .
+            (Character value:16rFFFF) .
+            (Character value:16r10000) .
+            (Character value:16rFFFFFF) .
+        }.
+
+    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:#testCharacters
+     self new testCharacters
+    "
+!
+
 testIntegers1
     |nums outStream bytes inStream verbose|
 
@@ -196,6 +272,14 @@
     nums := #(
         0
         1
+        15
+        16
+        30
+        31
+        32
+        62
+        63
+        64
         127
         128
         129
@@ -354,6 +438,81 @@
     "Modified: / 10-01-2012 / 19:23:44 / cg"
 !
 
+testNumbers1
+    |floats fractions nums outStream bytes inStream verbose|
+
+    verbose := false.
+
+    outStream := ByteArray new writeStream.
+
+    floats := #(
+        0.0
+        1.0
+        2.0
+        1.23456
+        1e17
+    ).
+    fractions := {
+        (1/2) .
+        (3/17) .
+        (1234567890123456789/17) .
+        (12345678901234567890123456789/17) .
+        (17/1234567890123456789) .
+        (17/12345678901234567890123456789) .
+        (1234567890123456788/1234567890123456789) .
+        (12345678901234567890123456788/12345678901234567890123456789) .
+    }.
+    nums := floats , fractions.
+    
+    nums do:[:written |
+        |bytes read|
+
+        bytes := written binaryStoreBytes.
+        verbose ifTrue:[
+            Transcript show:written.
+            Transcript show:' -> '.
+            Transcript showCR:bytes.
+        ].
+        read := Object fromBinaryStoreBytes:bytes.
+        self assert:(read = written).
+    ].
+
+    nums do:[:written |
+        |bytes read|
+
+        bytes := written negated binaryStoreBytes.
+        verbose ifTrue:[
+            Transcript show:written.
+            Transcript show:' -> '.
+            Transcript showCR:bytes.
+        ].
+        read := Object fromBinaryStoreBytes:bytes.
+        self assert:(read = written negated).
+    ].
+
+    nums do:[:written |
+        written storeBinaryOn:outStream.
+        written negated storeBinaryOn:outStream.
+    ].
+
+    bytes := outStream contents.
+    inStream := BinaryInputManager on:(bytes readStream).
+
+    nums do:[:expected | |read|
+        read := inStream nextObject.
+        self assert:( read = expected).
+
+        read := inStream nextObject.
+        self assert:( read = expected negated).
+
+    ].
+
+    "
+     self run:#testNumbers1
+     self new testNumbers1
+    "
+!
+
 testOrderedCollection1
     |o rw|
 
@@ -543,6 +702,16 @@
         self assert:( read = written).
     ].
 
+    test value:(String new:14).
+    test value:(String new:15).
+    test value:(String new:16).
+    test value:(String new:30).
+    test value:(String new:31).
+    test value:(String new:32).
+    test value:(String new:62).
+    test value:(String new:63).
+    test value:(String new:64).
+    test value:(String new:65).
     test value:(String new:100).
     test value:(String new:127).
     test value:(String new:128).
--- a/RegressionTests__FloatTest.st	Tue Apr 05 19:13:28 2016 +0100
+++ b/RegressionTests__FloatTest.st	Wed Apr 13 23:15:27 2016 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "{ Package: 'exept:regression' }"
 
 "{ NameSpace: RegressionTests }"
@@ -18,14 +16,15 @@
     "get the actual number of valid bits in the mantissa.
      This does a real test (i.e. does not believe the compiled-in ifdefs)"
 
-    |one x count|
+    |one x count two|
 
     one := aFloatClass unity.  "/ 1.0 in this class
+    two := one coerce:2.0.
     x := one.    
     count := 0.
-
+    
     [one + x > one] whileTrue:[
-        x := x / 2.
+        x := x / two.
         count := count + 1.
     ].
     ^ count
@@ -44,25 +43,12 @@
 
     |a b|
 
-    self assert: (Float unity class == Float).
-    self assert: (ShortFloat unity class == ShortFloat).
-    self assert: (LongFloat unity class == LongFloat).
-
-    self assert: (Float unity = 1.0).
-    self assert: (ShortFloat unity = 1.0).
-    self assert: (LongFloat unity = 1.0).
-
-    self assert: (Float zero class == Float).
-    self assert: (ShortFloat zero class == ShortFloat).
-    self assert: (LongFloat zero class == LongFloat).
-
-    self assert: (Float zero = 0.0).
-    self assert: (ShortFloat zero = 0.0).
-    self assert: (LongFloat zero = 0.0).
-
-    self assert:( (a := Float precision) = (b := self actualPrecisionOf:Float)).
-    self assert:( (a := ShortFloat precision) = (b := self actualPrecisionOf:ShortFloat)).
-    self assert:( (a := LongFloat precision) = (b := self actualPrecisionOf:LongFloat)).
+    self assert:( (a := Float precision) = (b := self actualPrecisionOf:Float))
+                description:('Float precision: %1 ~~ actual: %2' bindWith:a with:b).
+    self assert:( (a := ShortFloat precision) = (b := self actualPrecisionOf:ShortFloat))
+                description:('ShortFloat precision: %1 ~~ actual: %2' bindWith:a with:b).
+    self assert:( (a := LongFloat precision) = (b := self actualPrecisionOf:LongFloat))
+                description:('LongFloat precision: %1 ~~ actual: %2' bindWith:a with:b).
 
     "
      self basicNew test00_Precision
@@ -346,6 +332,21 @@
     self assert:( 1.0 asLongFloat / 1.0 asFloat ) class == LongFloat.
     self assert:( 1.0 asLongFloat / 1 ) class == LongFloat.
 
+    self assert:( 1.0 / 2.0 ) class == Float.
+    self assert:( 1.0 / 2.0 asShortFloat) class == Float.
+    self assert:( 1.0 / 2.0 asLongFloat) class == LongFloat.
+    self assert:( 1.0 / 2) class == Float.
+
+    self assert:( 1.0 asShortFloat / 2.0 ) class == Float.
+    self assert:( 1.0 asShortFloat / 2.0 asShortFloat) class == ShortFloat.
+    self assert:( 1.0 asShortFloat / 2.0 asLongFloat) class == LongFloat.
+    self assert:( 1.0 asShortFloat / 2) class == ShortFloat.
+
+    self assert:( 1.0 asLongFloat / 2.0 ) class == LongFloat.
+    self assert:( 1.0 asLongFloat / 2.0 asShortFloat ) class == LongFloat.
+    self assert:( 1.0 asLongFloat / 2.0 asFloat ) class == LongFloat.
+    self assert:( 1.0 asLongFloat / 2 ) class == LongFloat.
+
     self assert:( 5.0 rem: 2.0 ) class == Float.
     self assert:( 5.0 rem: 2.0 asShortFloat) class == Float.
     self assert:( 5.0 rem: 2.0 asLongFloat) class == LongFloat.
@@ -748,6 +749,26 @@
 !
 
 test08_Representation
+    self assert: (Float unity class == Float).
+    self assert: (ShortFloat unity class == ShortFloat).
+    self assert: (LongFloat unity class == LongFloat).
+
+    self assert: (Float unity = 1.0).
+    self assert: (ShortFloat unity = 1.0).
+    self assert: (LongFloat unity = 1.0).
+
+    self assert: (Float zero class == Float).
+    self assert: (ShortFloat zero class == ShortFloat).
+    self assert: (LongFloat zero class == LongFloat).
+
+    self assert: (Float zero = 0.0).
+    self assert: (ShortFloat zero = 0.0).
+    self assert: (LongFloat zero = 0.0).
+
+    self assert:( LongFloat unity = 1 asLongFloat ).
+    self assert:( ShortFloat unity = 1 asShortFloat ).
+    self assert:( Float unity = 1 asFloat ).
+
     self assert:( 0.0 exponent = 0 ).
     self assert:( 1.0 exponent = 1 ).
     self assert:( 2.0 exponent = 2 ).
@@ -781,10 +802,6 @@
     self assert:( 0.125 asLongFloat exponent = -2 ).
     self assert:( 0.00000011111 asLongFloat exponent = -23 ).
 
-    self assert:( LongFloat unity = 1 asLongFloat ).
-    self assert:( ShortFloat unity = 1 asShortFloat ).
-    self assert:( Float unity = 1 asFloat ).
-
     "
      self basicNew test08_Representation
     "
--- a/RegressionTests__StreamTests.st	Tue Apr 05 19:13:28 2016 +0100
+++ b/RegressionTests__StreamTests.st	Wed Apr 13 23:15:27 2016 +0100
@@ -516,6 +516,69 @@
      self run:#test30_readWriteBinary
      self new test30_readWriteBinary
     "
+!
+
+test31_readWriteBinaryIntegers
+    |s|
+
+    #(
+        0       1 #[ 0 ]
+        0       2 #[ 0 0 ]
+        0       3 #[ 0 0 0 ]
+        0       4 #[ 0 0 0 0]
+        0       6 #[ 0 0 0 0 0 0]
+
+        1       1 #[ 1 ]
+        1       2 #[ 0 1 ]
+        1       3 #[ 0 0 1 ]
+        1       4 #[ 0 0 0 1 ]
+        1       6 #[ 0 0 0 0 0 1 ]
+
+       16r8000  2 #[ 16r80 16r00 ]
+       16r8000  3 #[ 16r00 16r80 16r00 ]
+       16r8000  4 #[ 16r00 16r00 16r80 16r00 ]
+       16r8000  5 #[ 16r00 16r00 16r00 16r80 16r00 ]
+       16r8000  6 #[ 16r00 16r00 16r00 16r00 16r80 16r00 ]
+
+       16r12345678  4 #[ 16r12 16r34 16r56 16r78 ]
+       16r12345678  5 #[ 16r00 16r12 16r34 16r56 16r78 ]
+       16r12345678  6 #[ 16r00 16r00 16r12 16r34 16r56 16r78 ]
+
+       16r87654321  4 #[ 16r87 16r65 16r43 16r21 ]
+       16r87654321  5 #[ 16r00 16r87 16r65 16r43 16r21 ]
+       16r87654321  6 #[ 16r00 16r00 16r87 16r65 16r43 16r21 ]
+
+    ) inGroupsOf:3 do:[:val :nBytes :expected |    
+        s := WriteStream on:(ByteArray new).
+        s nextNumber:nBytes put:val MSB:true.
+        self assert:(s contents = expected).
+
+        s := WriteStream on:(ByteArray new).
+        s nextNumber:nBytes put:val MSB:false.
+        self assert:(s contents reversed = expected).
+
+        "/ because external streams may have specially tuned output methods,
+        "/ test them also
+        [    
+            s := 'testData' asFilename writeStream.
+            s nextNumber:nBytes put:val MSB:true.
+            s close.
+            self assert:('testData' asFilename binaryContentsOfEntireFile = expected).
+
+            s := 'testData' asFilename writeStream.
+            s nextNumber:nBytes put:val MSB:false.
+            s close.
+            self assert:('testData' asFilename binaryContentsOfEntireFile reversed = expected).
+        ] ensure:[
+            'testData' asFilename delete
+        ].    
+    ].
+    
+    
+    "
+     self run:#test31_readWriteBinaryIntegers
+     self new test31_readWriteBinaryIntegers
+    "
 ! !
 
 !StreamTests class methodsFor:'documentation'!
--- a/RegressionTests__StringTests.st	Tue Apr 05 19:13:28 2016 +0100
+++ b/RegressionTests__StringTests.st	Wed Apr 13 23:15:27 2016 +0100
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "{ Package: 'exept:regression' }"
 
 "{ NameSpace: RegressionTests }"
@@ -387,12 +385,11 @@
         u32Hash := s asUnicode32String hash.
 
         self assert: sHash == u16Hash
-             description: 'String and Unicode16String hashes differ!!'.
+             description: ('String and Unicode16String hashes differ on "%1" (%2)'
+                                bindWith:s with:s class name).
         self assert: sHash == u32Hash
-             description: 'String and Unicode32String hashes differ!!'.
-"/ rubbish...
-"/        self assert: u16Hash == u32Hash
-"/             description: 'Unicode16String and Unicode32String hashes differ!!'.
+             description: ('String and Unicode32String hashes differ on "%1" (%2)'
+                                bindWith:s with:s class name)
     ].
 
     tester value:'a'.