Ejemplo n.º 1
0
    def setUp(self):
        #print " "
        pass

        mt1 = Type("one")
        mt2 = Type("two")

        mf1 = Field("f1")
        mf2 = Field("f2")
        mf3 = Field("f3")
        mf4 = Field("f4")
        mf5 = Field("f5")
        mf6 = Field("f6")

        mt1.putValidator(mf1, Validator_boolean.get(0))
        mt1.putValidator(mf2, Validator_boolean.get(1))
        mt1.putValidator(mf3, Validator_int.get(0))
        mt1.putValidator(mf4, Validator_int.get(1))
        mt1.putValidator(mf5, Validator_string.get(0))
        mt1.putValidator(mf6, Validator_string.get(1))

        self._mt1 = mt1
        self._mt2 = mt2
        self._mf1 = mf1
        self._mf2 = mf2
        self._mf3 = mf3
        self._mf4 = mf4
        self._mf5 = mf5
        self._mf6 = mf6
Ejemplo n.º 2
0
    def test_runValidators(self):
        b = Type.getRunValidators()
        Type.setRunValidators(True)
        self.assertEqual(Type.getRunValidators(), True)

        Type.setRunValidators(False)
        self.assertEqual(Type.getRunValidators(), False)

        Type.setRunValidators(b)
Ejemplo n.º 3
0
    def setUp(self):
        self.__vf = MyValueFactory()
        self.__mt1 = Type(1, "mt")
        self.__rmt = Type(2, "rmt")
        self.__mf1 = Field(3, "x")
        self.__mf2 = Field(4, "y")

        self.__mt1.putValidator(self.__mf1, Validator_int.get(0))
        self.__mt1.putValidator(self.__mf2, Validator_int.get(0))
        self.__mt1.putValidator(self.__vf.mf_messageId, Validator_long.get(0))

        self.__rmt.putValidator(self.__vf.mf_messageId, Validator_long.get(0))
        self.__rmt.putValidator(self.__vf.mf_inReplyTo, Validator_long.get(0))
Ejemplo n.º 4
0
    def test_putValidatorNull(self):
        t = Type("t")
        f = Field("f")
        v = Validator_int.get(0)

        Type.setRunValidators(True)
        self.assertEqual(t.getValidator(f), None)

        t.putValidator(f, None)
        self.assertEqual(t.getValidator(f), None)

        t.putValidator(f, v)
        self.assertEqual(v, t.getValidator(f))

        t.putValidator(f, v)
        self.assertEqual(ComboValidator, t.getValidator(f).__class__)

        t.clearValidator(f)
        self.assertEqual(t.getValidator(f), None)
Ejemplo n.º 5
0
    def test_getValidator(self):
        t = Type("t")
        f = Field("f")
        g = Field("g")
        v = Validator_int.get(0)

        t.putValidator(f, v)
        Type.setRunValidators(False)
        self.assertEqual(t.getValidator(f), None)

        Type.setRunValidators(True)
        self.assertEqual(v, t.getValidator(f))

        Type.setRunValidators(False)
        self.assertEqual(t.getValidator(g), None)

        Type.setRunValidators(True)
        self.assertEqual(t.getValidator(g), None)
Ejemplo n.º 6
0
    def _testMt(self, *args):
        if len(args) == 1:
            n = args[0]
            i = IdName.hash(n)
        elif len(args) == 2:
            i = args[0]
            n = args[1]
        else:
            raise Exception, "Bad number of arguments"

        mt = Type(i, n)
        self.assertEquals(i, mt.getId())
        self.assertEquals(n, mt.getName())
Ejemplo n.º 7
0
    def test_check_value(self):
        btdo = BinaryTaggedDataOutput(None, None)

        # positive small bytes
        self.assertEquals(0, btdo.checkValue(Byte(0)))
        self.assertEquals(1, btdo.checkValue(Byte(1)))
        self.assertEquals(31, btdo.checkValue(Byte(31)))

        # positive small shorts
        self.assertEquals(32, btdo.checkValue(Short(0)))
        self.assertEquals(33, btdo.checkValue(Short(1)))
        self.assertEquals(63, btdo.checkValue(Short(31)))

        # positive small ints
        self.assertEquals(64, btdo.checkValue(0))
        self.assertEquals(65, btdo.checkValue(1))
        self.assertEquals(95, btdo.checkValue(31))

        # positive small longs
        self.assertEquals(96, btdo.checkValue(0L))
        self.assertEquals(97, btdo.checkValue(1L))
        self.assertEquals(127, btdo.checkValue(31L))

        # negative small bytes
        self.assertEquals(-128, btdo.checkValue(Byte(-1)))
        self.assertEquals(-127, btdo.checkValue(Byte(-2)))
        self.assertEquals(-113, btdo.checkValue(Byte(-16)))

        # negative small shorts
        self.assertEquals(-112, btdo.checkValue(Short(-1)))
        self.assertEquals(-111, btdo.checkValue(Short(-2)))
        self.assertEquals(-97, btdo.checkValue(Short(-16)))

        # negative small ints
        self.assertEquals(-96, btdo.checkValue(-1))
        self.assertEquals(-79, btdo.checkValue(-2))
        self.assertEquals(-65, btdo.checkValue(-16))

        # negative small longs
        self.assertEquals(-80, btdo.checkValue(-1L))
        self.assertEquals(-79, btdo.checkValue(-2L))
        self.assertEquals(-65, btdo.checkValue(-16L))

        # null value
        self.assertEquals(-1, btdo.checkValue(None))

        # boolean values
        self.assertEquals(-2, btdo.checkValues(False))
        self.assertEquals(-3, btdo.checkValues(True))

        # normal bytes
        self.assertEquals(-4, btdo.checkValue(Byte(-45)))
        self.assertEquals(-4, btdo.checkValue(Byte(45)))

        # normal shorts
        self.assertEquals(-5, btdo.checkValue(Short(-45)))
        self.assertEquals(-5, btdo.checkValue(Short(45)))

        self.assertEquals(-6, btdo.checkValue(Short(-4545)))
        self.assertEquals(-6, btdo.checkValue(Short(4545)))

        # normal ints
        self.assertEquals(-7, btdo.checkValues(-45))
        self.assertEquals(-7, btdo.checkValue(45))

        self.assertEquals(-8, btdo.checkValue(-4545))
        self.assertEquals(-8, btdo.checkValue(4545))

        self.assertEquals(-9, btdo.checkValue(-45454545))
        self.assertEquals(-9, btdo.checkValue(45454545))

        # normal longs
        self.assertEquals(-10, btdo.checkValues(-45L))
        self.assertEquals(-10, btdo.checkValue(45L))

        self.assertEquals(-11, btdo.checkValue(-4545L))
        self.assertEquals(-11, btdo.checkValue(4545L))

        self.assertEquals(-12, btdo.checkValue(-45454545L))
        self.assertEquals(-12, btdo.checkValue(45454545L))

        self.assertEquals(-12, btdo.checkValue(-4545454545454545L))
        self.assertEquals(-12, btdo.checkValue(4545454545454545L))

        # float
        self.assertEquals(-14, btdo.checkValue(Float(3.14159)))

        # double
        self.assertEquals(-15, btdo.checkValue(3.14159))

        # byte array
        self.assertEquals(-16, btdo.checkValue(ByteArray(0)))
        self.assertEquals(-16, btdo.checkValue(ByteArray(1)))

        # empty string
        self.assertEquals(-17, btdo.checkValue(""))
        self.assertEquals(-17, btdo.checkValue(''))
        self.assertEquals(-17, btdo.checkValue(u''))
        self.assertEquals(-17, btdo.checkValue(""""""))

        # short string
        self.assertEquals(-18, btdo.checkValue("a"))
        self.assertEquals(-18, btdo.checkValue('a'))

        # non-empty string
        self.assertEquals(-18, btdo.checkValue("abc"))
        self.assertEquals(-18, btdo.checkValue('abc'))
        self.assertEquals(-18, btdo.checkValue(u"abc"))

        # struct
        self.assertEquals(-19, btdo.checkValue(StructValue(Type("foo"))))

        # custom
        self.assertEquals(-21, btdo.checkValue(Date()))

        # none
        self.assertEquals(-22, btdo.checkValue(BinaryTaggedData.NONE))