示例#1
0
    def test_correct_number_of_fields(self):
        b = Builder()

        b.set_template(TMPL_TWO_FIELDS)
        b.prepare()

        self.assertEqual(2, b.count())
示例#2
0
    def test_get_raw(self):
        b = Builder()
        b.set_template("foo[1] = 1, foe[2] = 2")
        b.prepare()

        self.assertTrue(b.is_correct())

        target = "\x01\x00\x02"
        self.assertEqual(target, b.get_raw())
示例#3
0
    def test_correct_sizes_of_fields(self):
        b = Builder()

        b.set_template(TMPL_TWO_FIELDS)
        b.prepare()

        fields = b.get_fields()

        self.assertEqual(1, fields["foo"].size)
        self.assertEqual(2, fields["foe"].size)
示例#4
0
    def test_correct_names_of_fields(self):
        b = Builder()

        b.set_template(TMPL_TWO_FIELDS)
        b.prepare()

        fields = b.get_fields()

        self.assertEqual(2, len(fields))
        self.assertTrue("foo" in fields)
        self.assertTrue("foe" in fields)
示例#5
0
    def test_is_correct(self):
        b = Builder()
        b.set_template(TMPL_TWO_FIELDS)
        b.prepare()
        self.assertFalse(b.is_correct())

        b = Builder()
        b.set_template("foo[1] = 128")
        b.prepare()
        self.assertTrue(b.is_correct())

        b = Builder()
        b.set_template("foo[1] = 0, foe[2], bar[1] = 2")
        b.prepare()
        self.assertFalse(b.is_correct())

        b.fields["foe"].value = 3
        self.assertTrue(b.is_correct())
示例#6
0
    def test_set_template(self):
        b = Builder()

        b.set_template(TMPL_TWO_FIELDS)

        self.assertEqual(TMPL_TWO_FIELDS, b.template)