Exemple #1
0
    def test_lxor(self):
        """test lxor (long exclusive or)"""
        test_op_codes = ops.OpCodes()
        test_op_codes.stack.push_op(7)
        ops.i2l(test_op_codes)
        test_op_codes.stack.push_op(6)
        ops.i2l(test_op_codes)
        ops.lxor(test_op_codes)
        # assert isinstance(test_op_codes.stack.peek(), numpy.int64)
        self.assertEqual(test_op_codes.stack.pop_op
                         (ops.pop_twice), numpy.int64(1))

        test_op_codes.stack.push_op(-7)
        ops.i2l(test_op_codes)
        test_op_codes.stack.push_op(-6)
        ops.i2l(test_op_codes)
        ops.lxor(test_op_codes)
        # assert isinstance(test_op_codes.stack.peek(), numpy.int64)
        self.assertEqual(test_op_codes.stack.pop_op
                         (ops.pop_twice), numpy.int64(3))

        test_op_codes.stack.push_op(-7)
        ops.i2l(test_op_codes)
        test_op_codes.stack.push_op(6)
        ops.i2l(test_op_codes)
        ops.lxor(test_op_codes)
        # assert isinstance(test_op_codes.stack.peek(), numpy.int64)
        self.assertEqual(test_op_codes.stack.pop_op
                         (ops.pop_twice), numpy.int64(-1))
Exemple #2
0
 def test_iinc(self):
     """tests iinc method"""
     test = ops.OpCodes()
     for i in range(0, len(test.local_array)):
         ops.iinc(test, i, i)
         test.local_array[i] = i
         self.assertEqual(test.local_array[i], i)
Exemple #3
0
 def test_divide(self):
     """tests the idiv opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.int32(128))
     op_code.stack.push_op(numpy.int32(-3))
     ops.idiv(op_code)
     self.assertEqual(op_code.stack.peek(), -42)
Exemple #4
0
 def test_multiply(self):
     """tests the imul opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.int32(2000000000))
     op_code.stack.push_op(numpy.int32(1000000000))
     ops.imul(op_code)
     self.assertEqual(op_code.stack.peek(), 1321730048)
Exemple #5
0
 def test_fdiv(self):
     """tests the fdiv opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.float32(4.0))
     op_code.stack.push_op(numpy.float32(2.0))
     ops.fdiv(op_code)
     self.assertEqual(op_code.stack.peek(), 2.0)
Exemple #6
0
 def test_iload(self):
     """tests iload method"""
     test = ops.OpCodes()
     # tests every load index from 0 to length
     for i in range(0, len(test.local_array)):
         ops.iload(test, i)
         self.assertEqual(test.stack.peek(), test.local_array[i])
Exemple #7
0
 def test_mod(self):
     """tests the irem opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.int32(128))
     op_code.stack.push_op(numpy.int32(-3))
     ops.irem(op_code)
     self.assertEqual(op_code.stack.peek(), 2)
Exemple #8
0
    def test_ishr(self):
        """ Test the ishr (Integer Arithmetic Shift Right) opcode """
        test_op_codes = ops.OpCodes()
        test_op_codes.stack.push_op(0)
        test_op_codes.stack.push_op(0)
        ops.ishr(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 0)

        test_op_codes.stack.push_op(8)
        test_op_codes.stack.push_op(3)
        ops.ishr(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 1)

        test_op_codes.stack.push_op(256)
        test_op_codes.stack.push_op(6)
        ops.ishr(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 4)
        test_op_codes.stack.push_op(16)
        test_op_codes.stack.push_op(3)
        ops.ishr(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 2)

        test_op_codes.stack.push_op(32)
        test_op_codes.stack.push_op(2)
        ops.ishr(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 8)

        test_op_codes.stack.push_op(16)
        test_op_codes.stack.push_op(2)
        ops.ishr(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 4)
Exemple #9
0
 def test_l2f(self):
     """test l2d (long to float)"""
     test_op_codes = ops.OpCodes()
     ops.lconst_1(test_op_codes)
     ops.l2f(test_op_codes)
     assert isinstance(test_op_codes.stack.peek(), numpy.float32)
     self.assertEqual(numpy.float32(1), test_op_codes.stack.pop_op())
Exemple #10
0
 def test_f2i(self):
     """test f2i (float to integer)"""
     test_op_codes = ops.OpCodes()
     ops.fconst_1(test_op_codes)
     ops.f2i(test_op_codes)
     assert isinstance(test_op_codes.stack.peek(), numpy.int32)
     self.assertEqual(numpy.int(1), test_op_codes.stack.pop_op())
Exemple #11
0
    def test_fcmpl(self):
        """Test fcmpl (compare 2 floats)"""
        test_op_codes = ops.OpCodes()
        test_op_codes.stack.push_op(1/7)
        ops.i2f(test_op_codes)
        test_op_codes.stack.push_op(1/3)
        ops.i2f(test_op_codes)
        ops.fcmpl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), -1)

        test_op_codes.stack.push_op(1/3)
        ops.i2f(test_op_codes)
        test_op_codes.stack.push_op(1/7)
        ops.i2f(test_op_codes)
        ops.fcmpl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 1)

        test_op_codes.stack.push_op(1/7)
        ops.i2f(test_op_codes)
        test_op_codes.stack.push_op(1/7)
        ops.i2f(test_op_codes)
        ops.fcmpl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 0)

        test_op_codes.stack.push_op(numpy.nan)
        test_op_codes.stack.push_op(1/7)
        ops.i2f(test_op_codes)
        ops.fcmpl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), -1)

        test_op_codes.stack.push_op(1/7)
        test_op_codes.stack.push_op(numpy.nan)
        ops.i2f(test_op_codes)
        ops.fcmpl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), -1)
Exemple #12
0
    def test_fneg(self):
        """test fneg (negate a float)"""
        test_op_codes = ops.OpCodes()
        test_op_codes.stack.push_op(1/7)
        ops.i2f(test_op_codes)
        ops.fneg(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(),
                         numpy.float32(-1/7))

        test_op_codes.stack.push_op(float("inf"))
        ops.i2f(test_op_codes)
        ops.fneg(test_op_codes)
        numpy.isneginf(test_op_codes.stack.pop_op())

        test_op_codes.stack.push_op(float("-inf"))
        ops.i2f(test_op_codes)
        ops.fneg(test_op_codes)
        numpy.isposinf(test_op_codes.stack.pop_op())

        test_op_codes.stack.push_op(0)
        ops.i2f(test_op_codes)
        ops.fneg(test_op_codes)
        numpy.negative(test_op_codes.stack.pop_op())

        test_op_codes.stack.push_op(numpy.nan)
        ops.fneg(test_op_codes)
        numpy.isnan(test_op_codes.stack.pop_op())
Exemple #13
0
 def test_l2i(self):
     """test l2i (long to int)"""
     test_op_codes = ops.OpCodes()
     ops.lconst_1(test_op_codes)
     ops.l2i(test_op_codes)
     assert isinstance(test_op_codes.stack.peek(), numpy.int32)
     self.assertEqual(numpy.int(1), test_op_codes.stack.pop_op())
Exemple #14
0
    def test_ishl(self):
        """ Test the ishl (Integer Shift Left) opcode """
        test_op_codes = ops.OpCodes()
        test_op_codes.stack.push_op(0)
        test_op_codes.stack.push_op(0)
        ops.ishl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 0)

        test_op_codes.stack.push_op(1)
        test_op_codes.stack.push_op(1)
        ops.ishl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 2)

        test_op_codes.stack.push_op(1)
        test_op_codes.stack.push_op(3)
        ops.ishl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 8)

        test_op_codes.stack.push_op(1)
        test_op_codes.stack.push_op(8)
        ops.ishl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 256)

        test_op_codes.stack.push_op(8)
        test_op_codes.stack.push_op(4)
        ops.ishl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 128)

        test_op_codes.stack.push_op(16)
        test_op_codes.stack.push_op(2)
        ops.ishl(test_op_codes)
        self.assertEqual(test_op_codes.stack.pop_op(), 64)
Exemple #15
0
 def test_l2d(self):
     """test l2d (long to double)"""
     test_op_codes = ops.OpCodes()
     ops.lconst_1(test_op_codes)
     ops.l2d(test_op_codes)
     assert isinstance(test_op_codes.stack.peek(), numpy.float64)
     self.assertEqual(numpy.float64(1),
                      test_op_codes.stack.pop_op(ops.pop_twice))
Exemple #16
0
 def test_lload(self):
     """tests lload method"""
     test = ops.OpCodes()
     # tests every load index from 0 to length
     for i in range(0, len(test.local_array)):
         ops.lload(test, i)
         self.assertEqual(test.stack.pop_op
                          (ops.pop_twice), test.local_array[i])
Exemple #17
0
 def test_f2l(self):
     """test f2l (float to long)"""
     test_op_codes = ops.OpCodes()
     ops.fconst_1(test_op_codes)
     ops.f2l(test_op_codes)
     assert isinstance(test_op_codes.stack.peek(), numpy.int64)
     self.assertEqual(numpy.int64(1),
                      test_op_codes.stack.pop_op(ops.pop_twice))
Exemple #18
0
 def test_ixor(self):
     """ Test the ixor (Integer Exclusive Or) opcode """
     test_op_codes = ops.OpCodes()
     # ixor(255 ^ 129) should produce (126)
     test_op_codes.stack.push_op(255)
     test_op_codes.stack.push_op(129)
     ops.ixor(test_op_codes)
     self.assertEqual(test_op_codes.stack.peek(), 126)
Exemple #19
0
 def test_fstore(self):
     """tests the fstore method for 32 bit floats"""
     test = ops.OpCodes()
     test.stack.push_op(numpy.float32(3), ops.push_twice)
     test.stack.push_op(numpy.float32(2), ops.push_twice)
     test.stack.push_op(numpy.float32(1), ops.push_twice)
     test.stack.push_op(numpy.float32(0), ops.push_twice)
     for i in range(0, len(test.local_array)):
         ops.fstore(test, i)
         self.assertEqual(test.local_array[i], numpy.float32(i))
Exemple #20
0
 def test_istore(self):
     """tests istore method"""
     test = ops.OpCodes()
     test.stack.push_op(3)
     test.stack.push_op(2)
     test.stack.push_op(1)
     test.stack.push_op(0)
     for i in range(0, len(test.local_array)):
         ops.istore(test, i)
         self.assertEqual(test.local_array[i], i)
Exemple #21
0
 def test_lstore(self):
     """tests the lstore method for 64 bit longs"""
     test = ops.OpCodes()
     test.stack.push_op(numpy.int64(3), ops.push_twice)
     test.stack.push_op(numpy.int64(2), ops.push_twice)
     test.stack.push_op(numpy.int64(1), ops.push_twice)
     test.stack.push_op(numpy.int64(0), ops.push_twice)
     for i in range(0, len(test.local_array)):
         ops.lstore(test, i)
         self.assertEqual(test.local_array[i], numpy.int64(i))
Exemple #22
0
 def test_ldiv(self):
     """tests the ldiv opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.int64(4), ops.push_twice)
     op_code.stack.push_op(numpy.int64(2), ops.push_twice)
     ops.ldiv(op_code)
     self.assertEqual(op_code.stack.pop_op(ops.pop_twice), 2)
     op_code.stack.push_op(numpy.int64(-4), ops.push_twice)
     op_code.stack.push_op(numpy.int64(2), ops.push_twice)
     ops.ldiv(op_code)
     self.assertEqual(op_code.stack.pop_op(ops.pop_twice), -2)
Exemple #23
0
 def test_lrem(self):
     """tests the lrem opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.int64(0), ops.push_twice)
     op_code.stack.push_op(numpy.int64(0), ops.push_twice)
     ops.lrem(op_code)
     self.assertEqual(op_code.stack.pop_op(ops.pop_twice), 0)
     op_code.stack.push_op(numpy.int64(5), ops.push_twice)
     op_code.stack.push_op(numpy.int64(5), ops.push_twice)
     ops.lrem(op_code)
     self.assertEqual(op_code.stack.pop_op(ops.pop_twice), 0)
Exemple #24
0
 def test_frem(self):
     """tests the irem opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.float32(0.0))
     op_code.stack.push_op(numpy.float32(0.0))
     ops.frem(op_code)
     self.assertEqual(op_code.stack.peek(), 0.0)
     op_code.stack.push_op(numpy.float32(5.0))
     op_code.stack.push_op(numpy.float32(5.0))
     ops.frem(op_code)
     self.assertEqual(op_code.stack.peek(), 0.0)
Exemple #25
0
 def test_lmul(self):
     """tests the lmul opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.int64(2), ops.push_twice)
     op_code.stack.push_op(numpy.int64(3), ops.push_twice)
     ops.lmul(op_code)
     self.assertEqual(op_code.stack.pop_op(ops.pop_twice), 6)
     op_code.stack.push_op(numpy.int64(-2), ops.push_twice)
     op_code.stack.push_op(numpy.int64(-3), ops.push_twice)
     ops.lmul(op_code)
     self.assertEqual(op_code.stack.pop_op(ops.pop_twice), 6)
Exemple #26
0
 def test_add_subtract(self):
     """tests the iadd and isub opcodes"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.int32(2000000000))
     op_code.stack.push_op(numpy.int32(1000000000))
     ops.iadd(op_code)
     self.assertEqual(op_code.stack.peek(), -1294967296)
     op_code.stack.push_op(numpy.int32(10))
     op_code.stack.push_op(numpy.int32(3))
     ops.isub(op_code)
     self.assertEqual(op_code.stack.peek(), 7)
Exemple #27
0
 def test_fmul(self):
     """tests the fmul opcode"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.float32(2.0))
     op_code.stack.push_op(numpy.float32(3.0))
     ops.fmul(op_code)
     self.assertEqual(op_code.stack.peek(), 6.0)
     op_code.stack.push_op(numpy.float32(2.0))
     op_code.stack.push_op(numpy.float32(3.0))
     ops.fmul(op_code)
     self.assertEqual(op_code.stack.peek(), 6.0)
Exemple #28
0
 def test_fsub(self):
     """tests the fsub opcodes"""
     op_code = ops.OpCodes()
     op_code.stack.push_op(numpy.float32(0.0))
     op_code.stack.push_op(numpy.float32(0.0))
     ops.fsub(op_code)
     self.assertEqual(op_code.stack.peek(), 0.0)
     op_code.stack.push_op(numpy.float32(5.0))
     op_code.stack.push_op(numpy.float32(2.0))
     ops.fsub(op_code)
     self.assertEqual(op_code.stack.peek(), 3.0)
Exemple #29
0
 def test_land(self):
     """Test land (logical bitwise long AND)"""
     test_op_codes = ops.OpCodes()
     test_op_codes.stack.push_op(42)
     ops.i2l(test_op_codes)
     test_op_codes.stack.push_op(6)
     ops.i2l(test_op_codes)
     ops.land(test_op_codes)
     # assert isinstance(test_op_codes.stack.peek(), numpy.int64)
     self.assertEqual(test_op_codes.stack.pop_op
                      (ops.pop_twice), numpy.int64(2))
Exemple #30
0
 def test_iushr(self):
     """ Test the iushr (Logical Shift Right) opcode """
     test_op_codes = ops.OpCodes()
     # iushr(255 >>> 2) should produce (63)
     test_op_codes.stack.push_op(255)
     test_op_codes.stack.push_op(2)
     ops.iushr(test_op_codes)
     self.assertEqual(test_op_codes.stack.pop_op(), 63)
     # iushr(-1 >> 4) should produce (268,435,455)
     test_op_codes.stack.push_op(-1)
     test_op_codes.stack.push_op(4)
     ops.iushr(test_op_codes)
     self.assertEqual(test_op_codes.stack.pop_op(), 268435455)