Mercurial > hg > svcore
comparison data/model/test/TestZoomConstraints.h @ 1531:2f3a77472c8c zoom
Refactor tests. Still testing frames-per-pixel only.
author | Chris Cannam |
---|---|
date | Tue, 18 Sep 2018 16:28:56 +0100 |
parents | bf32b26d1dad |
children | 05c3fbaec8ea |
comparison
equal
deleted
inserted
replaced
1530:bf32b26d1dad | 1531:2f3a77472c8c |
---|---|
28 | 28 |
29 class TestZoomConstraints : public QObject | 29 class TestZoomConstraints : public QObject |
30 { | 30 { |
31 Q_OBJECT | 31 Q_OBJECT |
32 | 32 |
33 void checkFpp(const ZoomConstraint &c, | |
34 ZoomConstraint::RoundingDirection dir, | |
35 int n, | |
36 int expected) { | |
37 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, n), | |
38 dir), | |
39 ZoomLevel(ZoomLevel::FramesPerPixel, expected)); | |
40 } | |
41 | |
33 private slots: | 42 private slots: |
34 void unconstrainedNearest() { | 43 void unconstrainedNearest() { |
35 // well, this shows how horrible this api is | |
36 ZoomConstraint c; | 44 ZoomConstraint c; |
37 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1)), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 45 checkFpp(c, ZoomConstraint::RoundNearest, 1, 1); |
38 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2)), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 46 checkFpp(c, ZoomConstraint::RoundNearest, 2, 2); |
39 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3)), ZoomLevel(ZoomLevel::FramesPerPixel, 3)); | 47 checkFpp(c, ZoomConstraint::RoundNearest, 3, 3); |
40 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4)), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 48 checkFpp(c, ZoomConstraint::RoundNearest, 4, 4); |
41 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20)), ZoomLevel(ZoomLevel::FramesPerPixel, 20)); | 49 checkFpp(c, ZoomConstraint::RoundNearest, 20, 20); |
42 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23)), ZoomLevel(ZoomLevel::FramesPerPixel, 23)); | 50 checkFpp(c, ZoomConstraint::RoundNearest, 32, 32); |
43 auto max = c.getMaxZoomLevel(); | 51 auto max = c.getMaxZoomLevel(); |
44 QCOMPARE(c.getNearestZoomLevel(max), max); | 52 QCOMPARE(c.getNearestZoomLevel(max), max); |
45 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1)), max); | 53 QCOMPARE(c.getNearestZoomLevel(max.incremented()), max); |
46 } | 54 } |
47 | 55 |
48 void unconstrainedUp() { | 56 void unconstrainedUp() { |
49 ZoomConstraint c; | 57 ZoomConstraint c; |
50 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 58 checkFpp(c, ZoomConstraint::RoundUp, 1, 1); |
51 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 59 checkFpp(c, ZoomConstraint::RoundUp, 2, 2); |
52 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 3)); | 60 checkFpp(c, ZoomConstraint::RoundUp, 3, 3); |
53 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 61 checkFpp(c, ZoomConstraint::RoundUp, 4, 4); |
54 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 20)); | 62 checkFpp(c, ZoomConstraint::RoundUp, 20, 20); |
55 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 63 checkFpp(c, ZoomConstraint::RoundUp, 32, 32); |
56 auto max = c.getMaxZoomLevel(); | 64 auto max = c.getMaxZoomLevel(); |
57 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundUp), max); | 65 QCOMPARE(c.getNearestZoomLevel(max, |
58 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundUp), max); | 66 ZoomConstraint::RoundUp), max); |
67 QCOMPARE(c.getNearestZoomLevel(max.incremented(), | |
68 ZoomConstraint::RoundUp), max); | |
59 } | 69 } |
60 | 70 |
61 void unconstrainedDown() { | 71 void unconstrainedDown() { |
62 ZoomConstraint c; | 72 ZoomConstraint c; |
63 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 73 checkFpp(c, ZoomConstraint::RoundDown, 1, 1); |
64 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 74 checkFpp(c, ZoomConstraint::RoundDown, 2, 2); |
65 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 3)); | 75 checkFpp(c, ZoomConstraint::RoundDown, 3, 3); |
66 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 76 checkFpp(c, ZoomConstraint::RoundDown, 4, 4); |
67 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 20)); | 77 checkFpp(c, ZoomConstraint::RoundDown, 20, 20); |
68 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 78 checkFpp(c, ZoomConstraint::RoundDown, 32, 32); |
69 auto max = c.getMaxZoomLevel(); | 79 auto max = c.getMaxZoomLevel(); |
70 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundDown), max); | 80 QCOMPARE(c.getNearestZoomLevel(max, |
71 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundDown), max); | 81 ZoomConstraint::RoundDown), max); |
82 QCOMPARE(c.getNearestZoomLevel(max.incremented(), | |
83 ZoomConstraint::RoundDown), max); | |
72 } | 84 } |
73 | 85 |
74 void powerOfTwoNearest() { | 86 void powerOfTwoNearest() { |
75 PowerOfTwoZoomConstraint c; | 87 PowerOfTwoZoomConstraint c; |
76 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1)), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 88 checkFpp(c, ZoomConstraint::RoundNearest, 1, 1); |
77 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2)), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 89 checkFpp(c, ZoomConstraint::RoundNearest, 2, 2); |
78 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3)), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 90 checkFpp(c, ZoomConstraint::RoundNearest, 3, 2); |
79 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4)), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 91 checkFpp(c, ZoomConstraint::RoundNearest, 4, 4); |
80 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20)), ZoomLevel(ZoomLevel::FramesPerPixel, 16)); | 92 checkFpp(c, ZoomConstraint::RoundNearest, 20, 16); |
81 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23)), ZoomLevel(ZoomLevel::FramesPerPixel, 16)); | 93 checkFpp(c, ZoomConstraint::RoundNearest, 23, 16); |
82 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 24)), ZoomLevel(ZoomLevel::FramesPerPixel, 16)); | 94 checkFpp(c, ZoomConstraint::RoundNearest, 24, 16); |
83 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 25)), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 95 checkFpp(c, ZoomConstraint::RoundNearest, 25, 32); |
84 auto max = c.getMaxZoomLevel(); | 96 auto max = c.getMaxZoomLevel(); |
85 QCOMPARE(c.getNearestZoomLevel(max), max); | 97 QCOMPARE(c.getNearestZoomLevel(max), max); |
86 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1)), max); | 98 QCOMPARE(c.getNearestZoomLevel(max.incremented()), max); |
87 } | 99 } |
88 | 100 |
89 void powerOfTwoUp() { | 101 void powerOfTwoUp() { |
90 PowerOfTwoZoomConstraint c; | 102 PowerOfTwoZoomConstraint c; |
91 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 103 checkFpp(c, ZoomConstraint::RoundUp, 1, 1); |
92 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 104 checkFpp(c, ZoomConstraint::RoundUp, 2, 2); |
93 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 105 checkFpp(c, ZoomConstraint::RoundUp, 3, 4); |
94 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 106 checkFpp(c, ZoomConstraint::RoundUp, 4, 4); |
95 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 107 checkFpp(c, ZoomConstraint::RoundUp, 20, 32); |
96 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 108 checkFpp(c, ZoomConstraint::RoundUp, 32, 32); |
97 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 33), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 64)); | 109 checkFpp(c, ZoomConstraint::RoundUp, 33, 64); |
98 auto max = c.getMaxZoomLevel(); | 110 auto max = c.getMaxZoomLevel(); |
99 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundUp), max); | 111 QCOMPARE(c.getNearestZoomLevel(max, |
100 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundUp), max); | 112 ZoomConstraint::RoundUp), max); |
113 QCOMPARE(c.getNearestZoomLevel(max.incremented(), | |
114 ZoomConstraint::RoundUp), max); | |
101 } | 115 } |
102 | 116 |
103 void powerOfTwoDown() { | 117 void powerOfTwoDown() { |
104 PowerOfTwoZoomConstraint c; | 118 PowerOfTwoZoomConstraint c; |
105 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 119 checkFpp(c, ZoomConstraint::RoundDown, 1, 1); |
106 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 120 checkFpp(c, ZoomConstraint::RoundDown, 2, 2); |
107 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 121 checkFpp(c, ZoomConstraint::RoundDown, 3, 2); |
108 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 122 checkFpp(c, ZoomConstraint::RoundDown, 4, 4); |
109 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 16)); | 123 checkFpp(c, ZoomConstraint::RoundDown, 20, 16); |
110 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 32), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 124 checkFpp(c, ZoomConstraint::RoundDown, 32, 32); |
111 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 33), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 125 checkFpp(c, ZoomConstraint::RoundDown, 33, 32); |
112 auto max = c.getMaxZoomLevel(); | 126 auto max = c.getMaxZoomLevel(); |
113 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundDown), max); | 127 QCOMPARE(c.getNearestZoomLevel(max, |
114 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundDown), max); | 128 ZoomConstraint::RoundDown), max); |
129 QCOMPARE(c.getNearestZoomLevel(max.incremented(), | |
130 ZoomConstraint::RoundDown), max); | |
115 } | 131 } |
116 | 132 |
117 void powerOfSqrtTwoNearest() { | 133 void powerOfSqrtTwoNearest() { |
118 PowerOfSqrtTwoZoomConstraint c; | 134 PowerOfSqrtTwoZoomConstraint c; |
119 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1)), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 135 checkFpp(c, ZoomConstraint::RoundNearest, 1, 1); |
120 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2)), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 136 checkFpp(c, ZoomConstraint::RoundNearest, 2, 2); |
121 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3)), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 137 checkFpp(c, ZoomConstraint::RoundNearest, 3, 2); |
122 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4)), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 138 checkFpp(c, ZoomConstraint::RoundNearest, 4, 4); |
123 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 18)), ZoomLevel(ZoomLevel::FramesPerPixel, 16)); | 139 checkFpp(c, ZoomConstraint::RoundNearest, 18, 16); |
124 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 19)), ZoomLevel(ZoomLevel::FramesPerPixel, 16)); | 140 checkFpp(c, ZoomConstraint::RoundNearest, 19, 16); |
125 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 20)), ZoomLevel(ZoomLevel::FramesPerPixel, 22)); | 141 checkFpp(c, ZoomConstraint::RoundNearest, 20, 22); |
126 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23)), ZoomLevel(ZoomLevel::FramesPerPixel, 22)); | 142 checkFpp(c, ZoomConstraint::RoundNearest, 23, 22); |
127 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 28)), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 143 checkFpp(c, ZoomConstraint::RoundNearest, 28, 32); |
128 // PowerOfSqrtTwoZoomConstraint makes an effort to ensure | 144 // PowerOfSqrtTwoZoomConstraint makes an effort to ensure |
129 // bigger numbers get rounded to a multiple of something | 145 // bigger numbers get rounded to a multiple of something |
130 // simple (64 or 90 depending on whether they are power-of-two | 146 // simple (64 or 90 depending on whether they are power-of-two |
131 // or power-of-sqrt-two types) | 147 // or power-of-sqrt-two types) |
132 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 800)), ZoomLevel(ZoomLevel::FramesPerPixel, 720)); | 148 checkFpp(c, ZoomConstraint::RoundNearest, 800, 720); |
133 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1023)), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 149 checkFpp(c, ZoomConstraint::RoundNearest, 1023, 1024); |
134 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1024)), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 150 checkFpp(c, ZoomConstraint::RoundNearest, 1024, 1024); |
135 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1025)), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 151 checkFpp(c, ZoomConstraint::RoundNearest, 1024, 1024); |
152 checkFpp(c, ZoomConstraint::RoundNearest, 1025, 1024); | |
136 auto max = c.getMaxZoomLevel(); | 153 auto max = c.getMaxZoomLevel(); |
137 QCOMPARE(c.getNearestZoomLevel(max), max); | 154 QCOMPARE(c.getNearestZoomLevel(max), max); |
138 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1)), max); | 155 QCOMPARE(c.getNearestZoomLevel(max.incremented()), max); |
139 } | 156 } |
140 | 157 |
141 void powerOfSqrtTwoUp() { | 158 void powerOfSqrtTwoUp() { |
142 PowerOfSqrtTwoZoomConstraint c; | 159 PowerOfSqrtTwoZoomConstraint c; |
143 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 160 checkFpp(c, ZoomConstraint::RoundUp, 1, 1); |
144 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 161 checkFpp(c, ZoomConstraint::RoundUp, 2, 2); |
145 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 162 checkFpp(c, ZoomConstraint::RoundUp, 3, 4); |
146 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 163 checkFpp(c, ZoomConstraint::RoundUp, 4, 4); |
147 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 18), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 22)); | 164 checkFpp(c, ZoomConstraint::RoundUp, 18, 22); |
148 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 22), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 22)); | 165 checkFpp(c, ZoomConstraint::RoundUp, 22, 22); |
149 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 32)); | 166 checkFpp(c, ZoomConstraint::RoundUp, 23, 32); |
150 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 800), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 167 checkFpp(c, ZoomConstraint::RoundUp, 800, 1024); |
151 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1023), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 168 checkFpp(c, ZoomConstraint::RoundUp, 1023, 1024); |
152 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1024), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 169 checkFpp(c, ZoomConstraint::RoundUp, 1024, 1024); |
153 // see comment above | 170 // see comment above |
154 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1025), ZoomConstraint::RoundUp), ZoomLevel(ZoomLevel::FramesPerPixel, 1440)); | 171 checkFpp(c, ZoomConstraint::RoundUp, 1025, 1440); |
155 auto max = c.getMaxZoomLevel(); | 172 auto max = c.getMaxZoomLevel(); |
156 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundUp), max); | 173 QCOMPARE(c.getNearestZoomLevel(max, |
157 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundUp), max); | 174 ZoomConstraint::RoundUp), max); |
175 QCOMPARE(c.getNearestZoomLevel(max.incremented(), | |
176 ZoomConstraint::RoundUp), max); | |
158 } | 177 } |
159 | 178 |
160 void powerOfSqrtTwoDown() { | 179 void powerOfSqrtTwoDown() { |
161 PowerOfSqrtTwoZoomConstraint c; | 180 PowerOfSqrtTwoZoomConstraint c; |
162 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1)); | 181 checkFpp(c, ZoomConstraint::RoundDown, 1, 1); |
163 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 2), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 182 checkFpp(c, ZoomConstraint::RoundDown, 2, 2); |
164 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 3), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 2)); | 183 checkFpp(c, ZoomConstraint::RoundDown, 3, 2); |
165 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 4), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 4)); | 184 checkFpp(c, ZoomConstraint::RoundDown, 4, 4); |
166 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 18), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 16)); | 185 checkFpp(c, ZoomConstraint::RoundDown, 18, 16); |
167 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 22), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 22)); | 186 checkFpp(c, ZoomConstraint::RoundDown, 22, 22); |
168 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 23), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 22)); | 187 checkFpp(c, ZoomConstraint::RoundDown, 23, 22); |
169 // see comment above | 188 // see comment above |
170 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 800), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 720)); | 189 checkFpp(c, ZoomConstraint::RoundDown, 800, 720); |
171 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1023), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 720)); | 190 checkFpp(c, ZoomConstraint::RoundDown, 1023, 720); |
172 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1024), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 191 checkFpp(c, ZoomConstraint::RoundDown, 1024, 1024); |
173 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, 1025), ZoomConstraint::RoundDown), ZoomLevel(ZoomLevel::FramesPerPixel, 1024)); | 192 checkFpp(c, ZoomConstraint::RoundDown, 1025, 1024); |
174 auto max = c.getMaxZoomLevel(); | 193 auto max = c.getMaxZoomLevel(); |
175 QCOMPARE(c.getNearestZoomLevel(max, ZoomConstraint::RoundDown), max); | 194 QCOMPARE(c.getNearestZoomLevel(max, |
176 QCOMPARE(c.getNearestZoomLevel(ZoomLevel(ZoomLevel::FramesPerPixel, max.level + 1), ZoomConstraint::RoundDown), max); | 195 ZoomConstraint::RoundDown), max); |
196 QCOMPARE(c.getNearestZoomLevel(max.incremented(), | |
197 ZoomConstraint::RoundDown), max); | |
177 } | 198 } |
178 }; | 199 }; |
179 | 200 |
180 #endif | 201 #endif |
181 | 202 |