1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
---|---|
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #include "Testing/BsTestSuite.h" |
4 | #include "Utility/BsTextureRowAllocator.h" |
5 | |
6 | namespace bs |
7 | { |
8 | /** Runs unit tests for systems specific to the RenderBeast plugin. */ |
9 | class RenderBeastTestSuite : public TestSuite |
10 | { |
11 | public: |
12 | RenderBeastTestSuite(); |
13 | |
14 | private: |
15 | void testTextureRowAllocator(); |
16 | }; |
17 | |
18 | RenderBeastTestSuite::RenderBeastTestSuite() |
19 | { |
20 | BS_ADD_TEST(RenderBeastTestSuite::testTextureRowAllocator); |
21 | } |
22 | |
23 | void RenderBeastTestSuite::testTextureRowAllocator() |
24 | { |
25 | ct::TextureRowAllocator<128, 128> alloc; |
26 | |
27 | auto a0 = alloc.alloc(16); |
28 | BS_TEST_ASSERT(a0.x == 0 && a0.y == 0 && a0.length == 16); |
29 | |
30 | auto a1 = alloc.alloc(16); |
31 | BS_TEST_ASSERT(a1.x == (a0.x + a0.length)); |
32 | |
33 | auto a2 = alloc.alloc(8); |
34 | auto a3 = alloc.alloc(8); |
35 | auto a4 = alloc.alloc(16); |
36 | auto a5 = alloc.alloc(16); |
37 | auto a6 = alloc.alloc(8); |
38 | auto a7 = alloc.alloc(8); |
39 | alloc.alloc(32); |
40 | |
41 | // Test if free space can get re-allocated |
42 | alloc.free(a1); |
43 | |
44 | auto a8 = alloc.alloc(16); |
45 | BS_TEST_ASSERT(a8.x == a1.x); |
46 | |
47 | // Test if free space gets merged and can be reallocated |
48 | alloc.free(a4); |
49 | alloc.free(a2); |
50 | alloc.free(a3); |
51 | alloc.free(a6); |
52 | alloc.free(a7); |
53 | alloc.free(a5); |
54 | |
55 | auto a9 = alloc.alloc(64); |
56 | BS_TEST_ASSERT(a9.x == a2.x && a9.y == 0 && a9.length == 64); |
57 | |
58 | // Test if allocation to another row works |
59 | auto a10 = alloc.alloc(64); |
60 | BS_TEST_ASSERT(a10.x == 0 && a10.y == 1 && a10.length == 64); |
61 | |
62 | // Test if allocation that doesn't fit goes to a new row |
63 | auto a11 = alloc.alloc(128); |
64 | BS_TEST_ASSERT(a11.x == 0 && a11.y == 2 && a11.length == 128); |
65 | |
66 | // Test if too large allocation fails |
67 | auto a12 = alloc.alloc(256); |
68 | BS_TEST_ASSERT(a12.length == 0); |
69 | |
70 | // Test if zero allocation is handled gracefully |
71 | auto a13 = alloc.alloc(0); |
72 | BS_TEST_ASSERT(a13.length == 0); |
73 | } |
74 | } |
75 |