Example #1
0
 def test_putDouble1(self):
     self.buf = FlexBuffer(ByteArray([]))
     self.buf.putDouble(Double.MAX_VALUE)
     self._checkBuf(8,8,0)
     self.buf.setIndex(0)
     self.assertEquals(Double.MAX_VALUE, self.buf.getDouble())
     self._checkBuf(8,8,0)
Example #2
0
 def test_compact(self):
     self.buf = FlexBuffer(ByteArray([1,2,3,4,5]), 1, 3)
     self.buf.compact()
     self._checkBuf(3, 0, 3)
     self.assertEquals(2, self.buf.get())
     self.assertEquals(3, self.buf.get())
     self.assertEquals(4, self.buf.get())
Example #3
0
 def test_getFloat1(self):
     
     self.buf = FlexBuffer(ByteArray([
            0, 0, 0, 0, 63, -128, 0, 0, 83, -113, 48, -37, 100, -98, -112, -120,
          117, -120, 20, 25, -65, -128, 0, 0, -45, -113, 48, -37, -28, -98, -112, -120,
          -11, -120, 20, 25, 50, 83, 79, -7, 34, 44, -87, 90, 17, -38, -85, 115,
          -78, 83, 79, -7, -94, 44, -87, 90, -111, -38, -85, 115]))
     
     self.assertEquals( 0.0,      self.buf.getFloat() )
     self.assertEquals( 1.0,      self.buf.getFloat() )
     self.assertEquals( 123e10,   self.buf.getFloat() )
     self.assertEquals( 234e20,   self.buf.getFloat() )
     self.assertEquals( 345e30,   self.buf.getFloat() )
     self.assertEquals( -1.0,     self.buf.getFloat() )
     self.assertEquals( -123e10,  self.buf.getFloat() )
     self.assertEquals( -234e20,  self.buf.getFloat() )
     self.assertEquals( -345e30,  self.buf.getFloat() )
     self.assertEquals( 123e-10,  self.buf.getFloat() )
     self.assertEquals( 234e-20,  self.buf.getFloat() )
     self.assertEquals( 345e-30,  self.buf.getFloat() )
     self.assertEquals( -123e-10, self.buf.getFloat() )
     self.assertEquals( -234e-20, self.buf.getFloat() )
     self.assertEquals( -345e-30, self.buf.getFloat() )
     
     self._checkBuf(15*4, 15*4, 0)
Example #4
0
 def test_putInt1(self):
     self.buf = FlexBuffer(ByteArray([]))
     self.buf.putInt(Integer.MAX_VALUE)
     self._checkBuf(4, 4, 0)
     self.buf.setIndex(0)
     self.assertEquals(Integer.MAX_VALUE, self.buf.getInt())
     self._checkBuf(4 ,4, 0)
Example #5
0
 def test_putLong1(self):
     self.buf = FlexBuffer(ByteArray([]))
     self.buf.putLong(Long.MAX_VALUE)
     self._checkBuf(8, 8, 0)
     self.buf.setIndex(0)
     self.assertEquals(Long.MAX_VALUE, self.buf.getLong())
     self._checkBuf(8, 8, 0)
Example #6
0
 def test_putShort1(self):
     self.buf = FlexBuffer(ByteArray([]))
     self.buf.putShort(Short.MAX_VALUE)
     self._checkBuf(2, 2, 0)
     self.buf.setIndex(0)
     self.assertEquals(Short.MAX_VALUE, self.buf.getShort())
     self._checkBuf(2, 2, 0)
Example #7
0
 def test_putFlexBuffer2(self):
     buf0 = FlexBuffer(ByteArray([1,2]))
     max  = 4*1024*1024
     self.buf = FlexBuffer(ByteArray(max))
     self.buf.setIndex(max)
     # TODO - Confirm this is the correct test
     self.assertRaises(IOException, self.buf.put, buf0)
Example #8
0
 def test_putByte1(self):
     self.buf = FlexBuffer(ByteArray())
     self.buf.putByte(0x01)
     self._checkBuf(1, 1, 0)
     self.buf.setIndex(0)
     self.assertEquals(0x01, self.buf.getByte())
     self._checkBuf(1, 1, 0)
Example #9
0
 def test_getByte1(self):
     self.buf = FlexBuffer(ByteArray([127, 1, 0, -1, -128]))
     self.assertEquals(127, self.buf.getByte())
     self.assertEquals(1, self.buf.getByte())
     self.assertEquals(0, self.buf.getByte())
     self.assertEquals(-1, self.buf.getByte())
     self.assertEquals(-128, self.buf.getByte())
     self._checkBuf(5, 5, 0)
Example #10
0
 def test_get6(self):
     self.buf = FlexBuffer(ByteArray([5,6,7,8]))
     buffer   = ByteArray([11,12,13,14,15])
     self.buf.get(buffer, 1, 3)
     
     self.assertEquals(11, buffer[0])
     self.assertEquals(5,  buffer[1])
     self.assertEquals(6,  buffer[2])
     self.assertEquals(7,  buffer[3])
     self.assertEquals(15, buffer[4])
Example #11
0
 def test_getFully1(self):
     self.buf = FlexBuffer(ByteArray([1,2,3,4,5,6]))
     b = ByteArray(3)
     self.buf.getFully(b)
     self.assertEquals(1, b[0])
     self.assertEquals(2, b[1])
     self.assertEquals(3, b[2])
     self.buf.getFully(b)
     self.assertEquals(4, b[0])
     self.assertEquals(5, b[1])
     self.assertEquals(6, b[2])
     self._checkBuf(6, 6, 0)
Example #12
0
    def test_getDouble1(self):
        # TODO - double conversions appear to be off compared to Java
        self.buf = FlexBuffer(ByteArray([
            0, 0, 0, 0, 0, 0, 0, 0
            , 63, -16, 0, 0, 0, 0, 0, 0
            , 66, 113, -26, 27, 104, -64, 0, 0
            , 85, 48, -73, 88, 68, 89, -6, -80
            , 105, -4, 43, 112, 122, -31, 67, -116
            , -65, -16, 0, 0, 0, 0, 0, 0
            , -62, 113, -26, 27, 104, -64, 0, 0
            , -43, 48, -73, 88, 68, 89, -6, -80
            , -23, -4, 43, 112, 122, -31, 67, -116
            , 62, 74, 105, -1, 27, 85, 80, 81
            , 43, -87, -105, 64, -36, -23, -48, -66
            , 22, -16, -127, 73, 111, 91, -75, -29
            , -66, 74, 105, -1, 27, 85, 80, 81
            , -85, -87, -105, 64, -36, -23, -48, -66
            , -106, -16, -127, 73, 111, 91, -75, -29
        ]))
                
        self.assertEquals( 0.0,              self.buf.getDouble())
        self.assertEquals( 1.0,              self.buf.getDouble())
        self.assertEquals( 123e10,           self.buf.getDouble())
        self.assertEquals( 234e100,          self.buf.getDouble())
        self.assertEquals( 345e200,          self.buf.getDouble())
        self.assertEquals( -1.0,             self.buf.getDouble())
        self.assertEquals( -123e10,          self.buf.getDouble())
        self.assertEquals( -234e100,         self.buf.getDouble())
        self.assertEquals( -345e200,         self.buf.getDouble())
        self.assertEquals( 123e-10,          self.buf.getDouble())
        self.assertEquals( 234e-100,         self.buf.getDouble())
        self.assertEquals( 345e-200,         self.buf.getDouble())
        self.assertEquals( -123e-10,          self.buf.getDouble())
        self.assertEquals( -234e-100,         self.buf.getDouble())
        self.assertEquals( -345e-200,         self.buf.getDouble())

        self._checkBuf(15*8, 15*8, 0)
Example #13
0
 def test_skip2(self):
     self.buf = FlexBuffer(ByteArray([]))
     self.assertRaises(EOFException, self.buf.skip, 2, False)
Example #14
0
 def test_skip1(self):
     self.buf = FlexBuffer(ByteArray([]))
     self.assertRaises(IllegalArgumentException, self.buf.skip, -1, False)
Example #15
0
 def test_putShort2(self):
     max = 4*1024*1024
     self.buf = FlexBuffer(ByteArray(max))
     self.buf.setIndex(max)
     # TODO - confirm this correct test
     self.assertRaises(IOException, self.buf.putShort, 1)
Example #16
0
 def test_getInt1(self):
     self.buf = FlexBuffer(ByteArray([1,2,3,4,-1,-2,-3,-4]))
     self.assertEquals(Integer(0x01020304), self.buf.getInt())
     self.assertEquals(Integer(0xfffefdfc), self.buf.getInt())
     self._checkBuf(8, 8, 0)
Example #17
0
 def test_putLong2(self):
     max = 4*1024*1024
     self.buf = FlexBuffer(ByteArray(max))
     self.buf.setIndex(max)
     # TODO - confirm this is the correct test
     self.assertRaises(IOException, self.buf.putLong, Long.MIN_VALUE)
Example #18
0
 def test_getLong1(self):
     self.buf = FlexBuffer(ByteArray([1,2,3,4,5,6,7,8,-1,-2,-3,-4,-5,-6,-7,-8]))
     self.assertEquals(Long(0x0102030405060708), self.buf.getLong())
     self.assertEquals(Long(0xfffefdfcfbfaf9f8), self.buf.getLong())
     self._checkBuf(16, 16, 0)
Example #19
0
 def test_putFlexBuffer3(self):
     buf0 = FlexBuffer(ByteArray([1,2]))
     self.buf = FlexBuffer(ByteArray([]))
     self.buf.setIndex(0)
     # TODO - confirm this is the correct test
     self.assertRaises(IllegalArgumentException, self.buf.put, buf0, 3)
Example #20
0
 def test_putDouble2(self):
     max = 4*1024*1024
     self.buf = FlexBuffer(ByteArray(max))
     self.buf.setIndex(max)
     self.assertRaises(IOException, self.buf.putDouble, Double.MIN_VALUE)
Example #21
0
 def test_getFully2(self):
     self.buf = FlexBuffer(ByteArray([1,2]))
     b = ByteArray(3)
     #self.buf = self.buf.getFully(b)
     self.assertRaises(EOFException, self.buf.getFully, b)
Example #22
0
 def test_skip7(self):
     self.buf = FlexBuffer(ByteArray([1,2]))
     self.buf.skip(5, True)
     self._checkBuf(5, 5, 0)
Example #23
0
 def test_putFlexBuffer5(self):
     buf0 = FlexBuffer(ByteArray([1,2]))
     max  = 4*1024*1024
     self.buf = FlexBuffer(ByteArray(max))
     self.buf.setIndex(max)
     self.assertRaises(IOException, self.buf.put, buf0, 1)
Example #24
0
 def test_putFlexBuffer4(self):
     buf0 = FlexBuffer(ByteArray([1,2]))
     self.buf = FlexBuffer(ByteArray([]))
     self.buf.put(buf0, 1)
     self._checkBuf(1,1,0)
Example #25
0
 def test_skip4(self):
     self.buf = FlexBuffer(ByteArray([1,2]))
     self.buf.skip(2, False)
     self._checkBuf(2, 2, 0)
Example #26
0
 def test_putInt2(self):
     max = 4*1024*1024
     self.buf = FlexBuffer(ByteArray(max))
     self.buf.setIndex(max)
     # TODO - validate test
     self.assertRaises(IOException, self.buf.putInt, Integer.MIN_VALUE)
Example #27
0
 def test_skip6(self):
     self.buf = FlexBuffer(ByteArray([1,2]))
     self.buf.skip(1, True)
     self._checkBuf(2, 1, 1)
Example #28
0
 def test_putFlexBuffer1(self):
     buf0     = FlexBuffer(ByteArray([1,2]))
     self.buf = FlexBuffer(ByteArray([]))
     self.buf.put(buf0)
     self._checkBuf(buf0.length(), buf0.length(), 0)
Example #29
0
 def test_skip8(self):
     self.buf = FlexBuffer(ByteArray([1,2]))
     max = 4*1024*1024
     # TODO - confirm this is the correct test
     self.assertRaises(IOException, self.buf.skip, max+1, True)
Example #30
0
 def test_putByte2(self):
     max = 4*1024*1024
     self.buf = FlexBuffer(ByteArray(max))
     self.buf.setIndex(max)
     self.assertRaises(IOException, self.buf.putByte, 0x01)