RegressionTests__UninterpretedBytesTest.st
changeset 1362 9810c48bb498
parent 1361 82462e2d93ae
child 1447 2351db93aa5b
--- a/RegressionTests__UninterpretedBytesTest.st	Tue Mar 15 22:49:23 2016 +0100
+++ b/RegressionTests__UninterpretedBytesTest.st	Wed Mar 23 14:38:08 2016 +0100
@@ -65,13 +65,49 @@
     self assert:(bytes byteAt:1) == 16rFF.
     self assert:(bytes signedByteAt:1) == -1.
 
+    "/ check immutablility checks
+    bytes :=  #[ 16rFF 16r00 ] beImmutable.
+    self 
+        should:[        
+            bytes byteAt:1 put:0
+        ]
+        raise:NoModificationError.
+    self assert:(bytes at:1) == 16rFF.
+
+    "/ check bounds checks
+    #(3 0 -1 -2) do:[:badIndex |
+        self 
+            should:[        
+                #[ 16rFF 16r00 ] byteAt:badIndex
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r00 ] signedByteAt:badIndex
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r00 ] byteAt:badIndex put:0
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r00 ] signedByteAt:badIndex put:0
+            ]
+            raise:SubscriptOutOfBoundsError.
+    ]
+
     "
      self run:#test00_byteAccess
     "
 !
 
 test01_int16Access
-    |check|
+    |check bytes|
 
     check := 
         [:bytes1 :bytes2 |
@@ -150,6 +186,30 @@
         value: (IntegerArray with:16r40302010)
         value: (IntegerArray with:16r81807FFF).
 
+    "/ check immutablility checks
+    bytes :=  #[ 1 2 ] beImmutable.
+    self 
+        should:[        
+            bytes unsignedInt16At:1 put:0
+        ]
+        raise:NoModificationError.
+    self assert:(bytes at:1) == 1.
+    self assert:(bytes at:2) == 2.
+
+    "/ check bounds checks
+    #(2 0 -1 -2) do:[:badIndex |
+        self 
+            should:[        
+                #[ 16rFF 16r00 ] unsignedInt16At:badIndex MSB:true
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r00 ] unsignedInt16At:badIndex MSB:false
+            ]
+            raise:SubscriptOutOfBoundsError.
+    ]
 
     "
      self run:#test01_int16Access
@@ -210,6 +270,33 @@
     self assert:(bytes unsignedInt32At:1 MSB:false) = 16rFFFFFFFD.
     self assert:(bytes signedInt32At:1 MSB:false) = -3.
 
+    "/ check immutablility checks
+    bytes :=  #[ 1 2 3 4 ] beImmutable.
+    self 
+        should:[        
+            bytes unsignedInt32At:1 put:0
+        ]
+        raise:NoModificationError.
+    self assert:(bytes at:1) == 1.
+    self assert:(bytes at:2) == 2.
+    self assert:(bytes at:3) == 3.
+    self assert:(bytes at:4) == 4.
+
+    "/ check bounds checks
+    #(2 0 -1 -2) do:[:badIndex |
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 ] unsignedInt32At:badIndex MSB:true
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 ] unsignedInt32At:badIndex MSB:false
+            ]
+            raise:SubscriptOutOfBoundsError.
+    ]
+
     "
      self run:#test02_int32Access
     "
@@ -251,6 +338,37 @@
     self assert:(bytes signedInt64At:1 MSB:true)  = -6876855410854182864. "/ 16rA090807060504030 signExtendedLongLongValue.
     self assert:(bytes signedInt64At:1 MSB:false)   = 16r30405060708090A0.
 
+    "/ check immutablility checks
+    bytes :=  #[ 1 2 3 4 5 6 7 8 ] beImmutable.
+    self 
+        should:[        
+            bytes unsignedInt64At:1 put:0
+        ]
+        raise:NoModificationError.
+    self assert:(bytes at:1) == 1.
+    self assert:(bytes at:2) == 2.
+    self assert:(bytes at:3) == 3.
+    self assert:(bytes at:4) == 4.
+    self assert:(bytes at:5) == 5.
+    self assert:(bytes at:6) == 6.
+    self assert:(bytes at:7) == 7.
+    self assert:(bytes at:8) == 8.
+
+    "/ check bounds checks
+    #(2 0 -1 -2) do:[:badIndex |
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 16r04 16r05 16r06 16r07 ] unsignedInt64At:badIndex MSB:true
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 16r04 16r05 16r06 16r07 ] unsignedInt64At:badIndex MSB:false
+            ]
+            raise:SubscriptOutOfBoundsError.
+    ]
+
     "
      self run:#test03_int64Access
     "
@@ -280,6 +398,33 @@
     bytes doubleAt:1 put:345.
     self assert:(bytes = #[0 0 0 0 0 144 117 64]).
 
+    "/ check bounds checks
+    #(2 0 -1 -2) do:[:badIndex |
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 ] floatAt:badIndex MSB:true
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 ] floatAt:badIndex MSB:false
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 16rFF 16r01 16r02 16r03 ] doubleAt:badIndex MSB:true
+            ]
+            raise:SubscriptOutOfBoundsError.
+
+        self 
+            should:[        
+                #[ 16rFF 16r01 16r02 16r03 16rFF 16r01 16r02 16r03 ] doubleAt:badIndex MSB:false
+            ]
+            raise:SubscriptOutOfBoundsError.
+    ]
+
     "
      self run:#test10_floatAccess
     "
@@ -305,35 +450,6 @@
     "
      self run:#test90_backwardCompatibility
     "
-!
-
-testFloatAccess
-    |bytes|
-
-    bytes := ByteArray new:4.
-    bytes floatAt:1 put:1.234.
-    self assert:(bytes = #[182 243 157 63]).
-
-    bytes floatAt:1 put:2.345 asShortFloat.
-    self assert:(bytes = #[123 20 22 64]).
-
-    bytes floatAt:1 put:345.
-    self assert:(bytes = #[0 128 172 67]).
-
-
-    bytes := ByteArray new:8.
-    bytes doubleAt:1 put:1.234.
-    self assert:(bytes = #[88 57 180 200 118 190 243 63]).
-
-    bytes doubleAt:1 put:2.345 asShortFloat.
-    self assert:(bytes = #[0 0 0 96 143 194 2 64]).
-
-    bytes doubleAt:1 put:345.
-    self assert:(bytes = #[0 0 0 0 0 144 117 64]).
-
-    "
-     self run:#testFloatAccess
-    "
 ! !
 
 !UninterpretedBytesTest class methodsFor:'documentation'!