Exemple #1
0
        def DoTest(size):
            allocator = HGlobalAllocator()
            ptr1 = allocator.Alloc(REASONABLE_SIZE)
            ptr2 = allocator.Realloc(ptr1, REASONABLE_SIZE * (2**size))
            if (ptr1 == ptr2):
                return False

            self.assertEquals(allocator.Contains(ptr1), False)
            self.assertEquals(allocator.Contains(ptr2), True)
            self.assertRaises(KeyError, allocator.Free, ptr1)
            allocator.FreeAll()
            self.assertEquals(allocator.Contains(ptr2), False)
            self.assertRaises(KeyError, allocator.Free, ptr2)
            return True
Exemple #2
0
    def testAllocFreeAll(self):
        allocator = HGlobalAllocator()
        ptr1 = allocator.Alloc(REASONABLE_SIZE)
        self.assertEquals(allocator.Contains(ptr1), True)
        ptr2 = allocator.Alloc(REASONABLE_SIZE)
        self.assertEquals(allocator.Contains(ptr2), True)
        ptr3 = allocator.Alloc(REASONABLE_SIZE)
        self.assertEquals(allocator.Contains(ptr3), True)

        allocator.Free(ptr1)
        self.assertEquals(allocator.Contains(ptr1), False)
        self.assertRaises(KeyError, allocator.Free, ptr1)

        allocator.FreeAll()
        self.assertEquals(allocator.Contains(ptr2), False)
        self.assertEquals(allocator.Contains(ptr3), False)
        self.assertRaises(KeyError, allocator.Free, ptr2)
        self.assertRaises(KeyError, allocator.Free, ptr3)