Exemplo n.º 1
0
 def _handleEventToken(self, token):
     currentEvent = self.decoder.currentEvent
     self.decoder.currentEvent = Trace.Event()
     self.decoder.currentEvent.name = self.stringCache.get(
         cstr(self.decoder.getPhrase(token.nameId)))
     self.decoder.currentEvent.seq = token.seq
     self.decoder.currentEvent.time = token.time
     self.decoder.currentEvent.apiId = self.decoder.apiId
     return currentEvent
Exemplo n.º 2
0
  def testSaving(self):
    trace = Trace.Trace()
    output = StringIO.StringIO()
    writer = BinaryCodec.Writer(trace, output)
    
    cls = Trace.Class("someClass")
    obj = Trace.Object(0xbadf00d, 0xdef, cls)
    obj.attrs["int"]       = Trace.IntegerValue(1234)
    obj.attrs["bytearray"] = Trace.ByteArrayValue(1001, [1,2,3,4])
    
    e1 = Trace.Event()
    e1.name     = "event1"
    e1.seq      = 0
    e1.time     = 0
    e1.apiId    = 0
    e1.duration = 0
    e1.values["void"] = Trace.VoidValue()
    e1.values["byte"] = Trace.ByteValue(1)
    e1.values["short"] = Trace.ShortValue(2)
    e1.values["int"] = Trace.IntegerValue(3)
    e1.values["long"] = Trace.LongValue(4)
    e1.values["float"] = Trace.FloatValue(5)
    e1.values["double"] = Trace.DoubleValue(6)
    e1.values["bytearray"] = Trace.ByteArrayValue(1002, [7,8])
    e1.values["shortarray"] = Trace.ShortArrayValue(1003, [9,10])
    e1.values["intarray"] = Trace.IntegerArrayValue(1004, [11,12])
    e1.values["longarray"] = Trace.LongArrayValue(1005, [13,14])
    e1.values["floatarray"] = Trace.FloatArrayValue(1006, [15,16])
    e1.values["doublearray"] = Trace.DoubleArrayValue(1007, [17,18])
    e1.values["object"] = obj
    e1.values[None] = Trace.IntegerValue(123)
    e2 = Trace.Event()
    e2.name     = "event2"
    e2.seq      = 1
    e2.time     = 2
    e2.apiId    = 3
    e2.duration = 4
    
    trace.events = [e1, e2]
    writer.save()
    
    output.seek(0)
    trace2 = Trace.Trace()
    reader = BinaryCodec.Reader(trace2, output)
    reader.load()
    
    f1, f2 = trace2.events
    
    self.assertEquals(e1.name,     f1.name)
    self.assertEquals(e1.seq,      f1.seq)
    self.assertEquals(e1.time,     f1.time)
    self.assertEquals(e1.apiId,    f1.apiId)
    self.assertEquals(e1.duration, f1.duration)
    self.assertEquals(len(e1.values),   len(f1.values))
    
    for v1, v2 in zip(e1.values, f1.values):
      self.assertEquals(v1, v2)

    for v1, v2 in zip(e1.values.values(), f1.values.values()):
      if isinstance(v1, Trace.VoidValue):
        continue
      elif isinstance(v1, Trace.Object):
        for a1, a2 in zip(v1.attrs.values(), v2.attrs.values()):
          self.assertEquals(a1, a2)
      else:
        self.assertEquals(v1, v2)

    self.assertEquals(e2.name,     f2.name)
    self.assertEquals(e2.seq,      f2.seq)
    self.assertEquals(e2.time,     f2.time)
    self.assertEquals(e2.apiId,    f2.apiId)
    self.assertEquals(e2.duration, f2.duration)