Example #1
0
 def test_finalize(self):
     heap = _S.SpeadHeap()
     heap.add_packet(self.pkts[0])
     heap.finalize()
     self.assertFalse(heap.is_valid)
     heap = _S.SpeadHeap()
     heap.add_packet(self.pkts[0])
     heap.add_packet(self.pkts[1])
     heap.finalize()
     self.assertTrue(heap.is_valid)
Example #2
0
 def test_get_items(self):
     heap = _S.SpeadHeap()
     self.assertRaises(RuntimeError, heap.get_items)
     heap.add_packet(self.pkts[0])
     heap.finalize()
     items = heap.get_items()
     self.assertEqual(len(items), 1)
     self.assertEqual(items[S.DESCRIPTOR_ID], [])
     heap = _S.SpeadHeap()
     heap.add_packet(self.pkts[0])
     heap.add_packet(self.pkts[1])
     heap.finalize()
     items = heap.get_items()
     self.assertEqual(len(items), 3)
     self.assertEqual(items[S.DESCRIPTOR_ID], [])
     self.assertEqual(items[0x3333],
                      struct.pack('>d', 3.1415) + struct.pack('>d', 2.7182))
     self.assertEqual(items[0x3334], struct.pack('>d', 1.4))
Example #3
0
 def test_add_packet(self):
     heap = _S.SpeadHeap()
     self.assertRaises(TypeError, lambda: heap.add_packet('test'))
     self.assertRaises(ValueError, lambda: heap.add_packet(_S.SpeadPacket()))
     heap.add_packet(self.pkts[0])
     self.assertEqual(heap.heap_cnt, 3)
     heap.add_packet(self.pkts[1])
     self.assertEqual(heap.heap_cnt, 3)
     self.assertRaises(ValueError, lambda: heap.add_packet(self.pkts[2]))
Example #4
0
 def test_zero_len_items_at_front_and_back(self):
     pkt = _S.SpeadPacket()
     pkt.unpack(ex_pkts['0-len-items-at-front-and-back'])
     heap = _S.SpeadHeap()
     heap.add_packet(pkt)
     heap.finalize()
     self.assertTrue(heap.is_valid)
     items = heap.get_items()
     self.assertEqual(len(items), 4)
     self.assertEqual(items[S.DESCRIPTOR_ID], [])
     self.assertEqual(items[0x3333], '')
     self.assertEqual(items[0x3334], struct.pack('>d', 3.1415))
     self.assertEqual(items[0x3335], '')
Example #5
0
 def test_update(self):
     ig2 = S.ItemGroup()
     ig2.add_item('var1', id=0x3333, fmt='f\x00\x00\x40')
     ig2.add_item('var2', id=0x3334)
     ig2['var1'] = 10
     ig2['var2'] = 10
     heap = _S.SpeadHeap()
     p = _S.SpeadPacket()
     p.unpack(example_pkt)
     heap.add_packet(p)
     heap.finalize()
     #heap = {
     #    S.HEAP_CNT_ID: (S.IMMEDIATEADDR, '\x00\x00\x00\x00\x0f'),
     #    S.DESCRIPTOR_ID: [self.ig.get_item(name).to_descriptor_string() for name in self.ig.keys()],
     #    self.id1: (S.IMMEDIATEADDR, '\x00\x00\x00\x00\x0f'),
     #    self.id2: (S.IMMEDIATEADDR, '\x00\x00\x00\x00\x0f'),
     #    self.id3: (S.DIRECTADDR, struct.pack('>d', 15.15)),
     #}
     ig2.update(heap)
     self.assertEqual(ig2.heap_cnt, 3)
     #self.assertEqual(len(ig2.keys()), 3)
     self.assertEqual(ig2['var1'], 3.1415)
     self.assertEqual(ig2['var2'], 10)
Example #6
0
 def test_attributes(self):
     heap = _S.SpeadHeap()
     self.assertEqual(heap.heap_cnt, -1)
     self.assertFalse(heap.is_valid)