from support import lib, ffi
from qcgc_test import QCGCTest

class BumpAllocatorTest(QCGCTest):
    def test_many_small_allocations(self):
        p = lib.qcgc_bump_allocate(16)
        self.assertNotEqual(p, ffi.NULL)
        arena = lib.qcgc_arena_addr(p)
        for i in range(1, 1000):
            q = lib.qcgc_bump_allocate(16)
            self.assertNotEqual(p, q)
            p = q
            self.assertEqual(arena, lib.qcgc_arena_addr(p))

    def test_large_alloc_overlap(self):
        p = lib.qcgc_bump_allocate(2**19)
        q = lib.qcgc_bump_allocate(2**19)
        self.assertNotEqual(lib.qcgc_arena_addr(p), lib.qcgc_arena_addr(q))

@@ -89,16 +89,1476 @@
 CTest):%0A
+    def test_bump_allocator_interface(self):%0A        arena = lib.qcgc_arena_create()%0A        first_cell = lib.arena_cells(arena)%5Blib.qcgc_arena_first_cell_index%5D%0A        size = lib.qcgc_arena_cells_count - lib.qcgc_arena_first_cell_index%0A        lib.qcgc_balloc_assign(ffi.addressof(first_cell), size)%0A%0A        self.assertEqual(ffi.addressof(first_cell), lib.qcgc_balloc_state.bump_ptr)%0A        self.assertEqual(size, lib.qcgc_balloc_state.remaining_cells)%0A%0A        self.assertTrue(lib.qcgc_balloc_can_allocate(size))%0A        self.assertFalse(lib.qcgc_balloc_can_allocate(size + 1))%0A%0A        p = lib.qcgc_balloc_allocate(1)%0A        self.assertEqual(ffi.addressof(first_cell), p)%0A        self.assertEqual(size - 1, lib.qcgc_balloc_state.remaining_cells)%0A%0A        q = lib.qcgc_balloc_allocate(size)%0A        self.assertEqual(q, ffi.NULL)%0A        self.assertEqual(size - 1, lib.qcgc_balloc_state.remaining_cells)%0A%0A        self.assertTrue(lib.qcgc_balloc_can_allocate(size - 1))%0A        self.assertFalse(lib.qcgc_balloc_can_allocate(size))%0A%0A        q = lib.qcgc_balloc_allocate(size - 1)%0A        self.assertEqual(ffi.addressof(lib.arena_cells(arena)%5Blib.qcgc_arena_first_cell_index + 1%5D), q)%0A        self.assertEqual(0, lib.qcgc_balloc_state.remaining_cells)%0A%0A        self.assertEqual(lib.qcgc_balloc_state.remaining_cells, 0)%0A        self.assertFalse(lib.qcgc_balloc_can_allocate(1))%0A%0A        r = lib.qcgc_balloc_allocate(1)%0A        self.assertEqual(r, ffi.NULL)%0A%0A
     def 

Test bump allocator interface