-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathtestdisplayheapwindow.cpp
211 lines (172 loc) · 7.09 KB
/
testdisplayheapwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <QtTest/QtTest>
#include "displayheapwindow.h"
#include "glsl_simulation_functions.h"
#include "heapwindow.h"
#include "testdisplayheapwindow.h"
#include "testactiveregioncache.h"
void TestDisplayHeapWindow::TestLongDoubleTo96Bits() {
long double test(2);
ivec3 result = LongDoubleTo96Bits(test);
QCOMPARE(result.x , 2);
QCOMPARE(result.y, 0);
QCOMPARE(result.z, 0);
test = 0x100000000;
result = LongDoubleTo96Bits(test);
QCOMPARE(result.x, 0);
QCOMPARE(result.y, 1);
QCOMPARE(result.z, 0);
}
void TestDisplayHeapWindow::Test96ToAndFromConversion() {
uint64_t testvalue = 0xFEDCBA9876543210;
ivec3 vec = Load64BitLeftShiftedBy4Into96Bit(
testvalue & 0xFFFFFFFF, testvalue >> 32);
uint64_t result = Convert96BitTo64BitRightShift(vec);
QCOMPARE(result, testvalue);
}
void TestDisplayHeapWindow::Test96BitFlipBits() {
ivec3 result;
result.flipBit(0);
QCOMPARE(result.x, 1);
result.flipBit(31);
QCOMPARE(result.x, static_cast<int32_t>(0x80000001));
result.flipBit(32);
QCOMPARE(result.y, 1);
result.flipBit(63);
QCOMPARE(result.y, static_cast<int32_t>(0x80000001));
result.flipBit(64);
QCOMPARE(result.z, 1);
}
void TestDisplayHeapWindow::Test96BitSubtraction() {
ivec3 base(0, 0, 0);
ivec3 subtrahend(0xFFFFFFF8, 0xFFFFFFFF, 0x7);
ivec3 result = Sub96(base, subtrahend);
QCOMPARE(static_cast<uint32_t>(result.z), 0xFFFFFFF8);
QCOMPARE(static_cast<uint32_t>(result.y), 0x00000000U);
QCOMPARE(static_cast<uint32_t>(result.x), 0x00000008U);
ivec3 subtrahend2(0x43232151, 0x7FFFF, 0);
ivec3 value(0x631C4000, 0x7FFFF, 0);
result = Sub96(value, subtrahend2);
QCOMPARE(static_cast<uint32_t>(result.x), 0x1FF91EAFU);
QCOMPARE(static_cast<uint32_t>(result.y), 0U);
//ivec3 subtrahend3(0xe5e0fe38, 0, 0);
//ivec3 value
}
void TestDisplayHeapWindow::Test96BitAddition() {
ivec3 base(0, 0, 0);
ivec3 addend(0xFFFFFFF8, 0xFFFFFFFF, 0x7);
ivec3 result = Add96(base, addend);
QCOMPARE(static_cast<uint32_t>(result.z), 0x7U);
QCOMPARE(static_cast<uint32_t>(result.y), 0xFFFFFFFFU);
QCOMPARE(static_cast<uint32_t>(result.x), 0xFFFFFFF8U);
ivec3 base2(0xFFFFFFF0, 0xFFFFFFFF, 0xF);
ivec3 result2 = Add96(base2, addend);
QCOMPARE(static_cast<uint32_t>(result2.z), 0x17U);
QCOMPARE(static_cast<uint32_t>(result2.y), 0xFFFFFFFFU);
QCOMPARE(static_cast<uint32_t>(result2.x), 0xFFFFFFE8U);
}
void TestDisplayHeapWindow::MapFromHeapToScreenMaximumPositiveSizes() {
DisplayHeapWindow display_heap_window;
ivec3 minimum_address(0, 0, 0);
// Entire 64-bit address space, left-shifted by 4 bits.
ivec3 maximum_address(0xFFFFFFF0, 0xFFFFFFFF, 0xF);
ivec2 minimum_tick(0, 0);
// 32-bit tick space, left-shifted by 4 bits.
ivec2 maximum_tick(0xFFFFFFF0, 0xF);
display_heap_window.setMinAndMaxAddress(minimum_address, maximum_address);
display_heap_window.setMinAndMaxTick(minimum_tick, maximum_tick);
auto result = display_heap_window.mapHeapCoordinateToDisplay(
0xFFFFFFFF, 0xFFFFFFFFFFFFFFFFUL);
QCOMPARE(result.first, 1.0);
QCOMPARE(result.second, 1.0);
auto result2 = display_heap_window.mapHeapCoordinateToDisplay(0, 0);
QCOMPARE(result2.first, -1.0);
QCOMPARE(result2.second, -1.0);
auto result3 = display_heap_window.mapHeapCoordinateToDisplay(
0xFFFFFFFF >> 1, 0xFFFFFFFFFFFFFFFFUL >> 1);
QCOMPARE(result3.first, 0.0);
QCOMPARE(result3.second, 0.0);
}
// Sets up a DisplayHeapWindow of maximum size so that only the upper-right
// quarter of the screen falls into the screen space. This involves both
// negative tick and address coordinates.
void TestDisplayHeapWindow::MapFromHeapToScreenBottomLeftWindow() {
DisplayHeapWindow display_heap_window;
ivec3 minimum_address(0, 0, 0);
// Entire 64-bit address space, left-shifted by 4 bits.
ivec3 maximum_address(0xFFFFFFF0, 0xFFFFFFFF, 0xF);
ivec2 minimum_tick(0, 0);
// 32-bit tick space, left-shifted by 4 bits.
ivec2 maximum_tick(0xFFFFFFF0, 0xF);
// Now shift the coordinates left and down.
ivec3 half_window_height(0xFFFFFFF8, 0xFFFFFFFF, 0x7);
ivec2 half_window_width(0xFFFFFFF8, 0x7);
minimum_address = Sub96(minimum_address, half_window_height);
maximum_address = Sub96(maximum_address, half_window_height);
minimum_tick = Sub64(minimum_tick, half_window_width);
maximum_tick = Sub64(maximum_tick, half_window_width);
display_heap_window.setMinAndMaxAddress(minimum_address, maximum_address);
display_heap_window.setMinAndMaxTick(minimum_tick, maximum_tick);
// The origin of the heap coordinate system should now map to the center
// of the screen.
auto result2 = display_heap_window.mapHeapCoordinateToDisplay(0, 0);
// Should now map to the center of the screen.
QCOMPARE(result2.first, 0.0);
QCOMPARE(result2.second, 0.0);
// The middle of the current window should now map to the upper right
// corner of the screen.
auto result3 = display_heap_window.mapHeapCoordinateToDisplay(
0xFFFFFFFF >> 1, 0xFFFFFFFFFFFFFFFFUL >> 1);
// Shoud now map to the top-right corner.
QCOMPARE(result3.first, 1.0);
QCOMPARE(result3.second, 1.0);
}
// Sets up a DisplayHeapWindow of maximum size so that only the lower-left
// quarter of the screen falls into the screen space. This involves very
// large tick and address coordinates.
void TestDisplayHeapWindow::MapFromHeapToScreenTopRightWindow() {
DisplayHeapWindow display_heap_window;
ivec3 minimum_address(0, 0, 0);
// Entire 64-bit address space, left-shifted by 4 bits.
ivec3 maximum_address(0xFFFFFFF0, 0xFFFFFFFF, 0xF);
ivec2 minimum_tick(0, 0);
// 32-bit tick space, left-shifted by 4 bits.
ivec2 maximum_tick(0xFFFFFFF0, 0xF);
// Now shift the coordinates right and up.
ivec3 half_window_height(0xFFFFFFF0, 0xFFFFFFFF, 0x7);
ivec2 half_window_width(0xFFFFFFF0, 0x7);
minimum_address = Add96(minimum_address, half_window_height);
maximum_address = Add96(maximum_address, half_window_height);
minimum_tick = Add64(minimum_tick, half_window_width);
maximum_tick = Add64(maximum_tick, half_window_width);
display_heap_window.setMinAndMaxAddress(minimum_address, maximum_address);
display_heap_window.setMinAndMaxTick(minimum_tick, maximum_tick);
// The origin of the heap coordinate system should now map to the center
// of the screen.
auto result2 = display_heap_window.mapHeapCoordinateToDisplay(
0xFFFFFFFF, 0xFFFFFFFFFFFFFFFF);
// Should now map to the center of the screen.
QCOMPARE(result2.first, 0.0);
QCOMPARE(result2.second, 0.0);
// The middle of the current window should now map to the lower left
// corner of the screen.
auto result3 = display_heap_window.mapHeapCoordinateToDisplay(
0xFFFFFFFF >> 1, 0xFFFFFFFFFFFFFFFFUL >> 1);
// Shoud now map to the top-right corner.
QCOMPARE(result3.first, -1.0);
QCOMPARE(result3.second, -1.0);
}
//QTEST_MAIN(TestDisplayHeapWindow)
int main(int argc, char** argv)
{
int status = 0;
auto ASSERT_TEST = [&status, argc, argv](QObject* obj) {
status |= QTest::qExec(obj, argc, argv);
delete obj;
};
printf("WHo?\n");
ASSERT_TEST(new TestActiveRegionCache());
printf("What??\n");
ASSERT_TEST(new TestDisplayHeapWindow());
return status;
}
//#include "testdisplayheapwindow.moc"