vfs: check userland buffers before reading them.
[haiku.git] / src / tests / bin / makeudfimage / AllocatorTest.cpp
blob013263fc017b787eb98a17fbd7df32357f591d6b
1 #include <ThreadedTestCaller.h>
2 #include <cppunit/Test.h>
3 #include <cppunit/TestCaller.h>
4 #include <cppunit/TestSuite.h>
5 #include <stdio.h>
6 #include <iostream>
7 #include <kernel/OS.h>
8 #include <TestUtils.h>
10 #include "AllocatorTest.h"
12 #include "Allocator.h"
13 #include "PhysicalPartitionAllocator.h"
15 AllocatorTest::AllocatorTest(std::string name)
16 : BTestCase(name)
20 CppUnit::Test*
21 AllocatorTest::Suite() {
22 CppUnit::TestSuite *suite = new CppUnit::TestSuite("Yo");
24 // And our tests
25 suite->addTest(new CppUnit::TestCaller<AllocatorTest>("Allocator::BlockSize Test", &AllocatorTest::BlockSizeTest));
26 suite->addTest(new CppUnit::TestCaller<AllocatorTest>("Allocator::Partition Full Test", &AllocatorTest::PartitionFullTest));
28 return suite;
31 void
32 AllocatorTest::BlockSizeTest() {
34 Allocator allocator(0);
35 CHK(allocator.InitCheck() != B_OK);
36 NextSubTest();
39 Allocator allocator(1);
40 CHK(allocator.InitCheck() == B_OK);
41 NextSubTest();
44 Allocator allocator(2);
45 CHK(allocator.InitCheck() == B_OK);
46 NextSubTest();
49 Allocator allocator(3);
50 CHK(allocator.InitCheck() != B_OK);
51 NextSubTest();
54 Allocator allocator(256);
55 CHK(allocator.InitCheck() == B_OK);
56 NextSubTest();
59 Allocator allocator(512);
60 CHK(allocator.InitCheck() == B_OK);
61 NextSubTest();
64 Allocator allocator(1024);
65 CHK(allocator.InitCheck() == B_OK);
66 NextSubTest();
69 Allocator allocator(1025);
70 CHK(allocator.InitCheck() != B_OK);
71 NextSubTest();
74 Allocator allocator(2048);
75 CHK(allocator.InitCheck() == B_OK);
76 NextSubTest();
79 Allocator allocator(4096);
80 CHK(allocator.InitCheck() == B_OK);
81 NextSubTest();
85 void
86 AllocatorTest::PartitionFullTest() {
88 extent_address extent;
89 const uint32 blockSize = 2048;
90 Allocator allocator(blockSize);
91 CHK(allocator.InitCheck() == B_OK);
92 CHK(allocator.GetNextExtent(blockSize*12, true, extent) == B_OK); // 0-11
93 extent.set_location(14);
94 extent.set_length(1);
95 CHK(allocator.GetExtent(extent) == B_OK); // 14
96 CHK(allocator.GetNextExtent(blockSize*3, true, extent) == B_OK); // 15-17
97 CHK(allocator.GetNextExtent(1, true, extent) == B_OK); // 12
98 CHK(allocator.GetBlock(12) != B_OK);
99 CHK(allocator.GetBlock(13) == B_OK);
101 NextSubTest();
103 extent_address extent;
104 Allocator allocator(2048);
105 CHK(allocator.InitCheck() == B_OK);
106 CHK(allocator.GetNextExtent(ULONG_MAX-1, true, extent) == B_OK);
107 CHK(allocator.GetNextExtent(1, true, extent) != B_OK);
108 extent.set_location(256);
109 extent.set_length(1);
110 CHK(allocator.GetExtent(extent) != B_OK);
111 CHK(allocator.GetBlock(13) != B_OK);
113 NextSubTest();
115 extent_address extent;
116 const uint32 blockSize = 2048;
117 Allocator allocator(blockSize);
118 CHK(allocator.InitCheck() == B_OK);
119 CHK(allocator.GetNextExtent(ULONG_MAX-blockSize*2, true, extent) == B_OK);
120 CHK(allocator.GetNextExtent(1, true, extent) == B_OK);
121 extent.set_location(256);
122 extent.set_length(1);
123 CHK(allocator.GetExtent(extent) != B_OK);
124 CHK(allocator.GetBlock(13) != B_OK);
125 PhysicalPartitionAllocator partition(0, 0, allocator);
126 std::list<long_address> extents;
127 std::list<extent_address> physicalExtents;
128 CHK(partition.GetNextExtents(1, extents, physicalExtents) == B_OK);
130 NextSubTest();
132 extent_address extent;
133 const uint32 blockSize = 2048;
134 Allocator allocator(blockSize);
135 CHK(allocator.InitCheck() == B_OK);
136 CHK(allocator.GetNextExtent(ULONG_MAX, true, extent) == B_OK);
137 PhysicalPartitionAllocator partition(0, 0, allocator);
138 std::list<long_address> extents;
139 std::list<extent_address> physicalExtents;
140 CHK(partition.GetNextExtents(1, extents, physicalExtents) != B_OK);
142 NextSubTest();