'Tests the AFF4MemoryStream.'

def testAFF4MemoryStream(self):

    path = '/C.12345/memorystreamtest'
    fd = aff4.FACTORY.Create(path, aff4.AFF4MemoryStream, token=self.token)
    self.assertEqual(fd.size, 0)
    self.assertEqual(fd.Tell(), 0)
    size = 0
    for i in range(100):
        data = ('Test%08X\n' % i)
        fd.Write(data)
        size += len(data)
        self.assertEqual(fd.size, size)
        self.assertEqual(fd.Tell(), size)
    fd.Close()
    fd = aff4.FACTORY.Open(path, mode='rw', token=self.token)
    self.assertEqual(fd.size, size)
    self.assertEqual(fd.Tell(), 0)
    fd.Seek(size)
    self.assertEqual(fd.Tell(), size)
    fd.Seek(100)
    fd.Write('Hello    World!')
    self.assertEqual(fd.size, size)
    fd.Close()
    fd = aff4.FACTORY.Open(path, mode='rw', token=self.token)
    self.assertEqual(fd.size, size)
    data = fd.Read(size)
    self.assertEqual(len(data), size)
    self.assertTrue(('Hello    World!' in data))
    fd.Close()
