Ocean
Loading...
Searching...
No Matches
TestFrame.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTBASE_TEST_FRAME_H
9#define META_OCEAN_TEST_TESTBASE_TEST_FRAME_H
10
13
14#include "ocean/base/Frame.h"
16
17namespace Ocean
18{
19
20namespace Test
21{
22
23namespace TestBase
24{
25
26/**
27 * This class implements tests for the Frame class.
28 * @ingroup testbase
29 */
30class OCEAN_TEST_BASE_EXPORT TestFrame
31{
32 public:
33
34 /**
35 * Invokes all tests.
36 * @param testDuration Number of seconds for each test, with range (0, infinity)
37 * @param selector The test selector
38 * @return True, if succeeded
39 */
40 static bool test(const double testDuration, const TestSelector& selector = TestSelector());
41
42 /**
43 * Test ensuring that the function returning all data types is correct.
44 * @return True, if so
45 */
46 static bool testDefinedDataTypes();
47
48 /**
49 * Test ensuring that the function returning all defined pixel formats is correct.
50 * @return True, if so
51 */
53
54 /**
55 * Sets the is sum inside value range functions.
56 * @param testDuration Number of seconds for each test, with range (0, infinity)
57 * @return True, if succeeded
58 */
59 static bool testIsSumInsideValueRange(const double testDuration);
60
61 /**
62 * Sets the is product inside value range functions.
63 * @param testDuration Number of seconds for each test, with range (0, infinity)
64 * @return True, if succeeded
65 */
66 static bool testIsProductInsideValueRange(const double testDuration);
67
68 /**
69 * Tests the Plane constructors.
70 * @param testDuration Number of seconds for each test, with range (0, infinity)
71 * @return True, if succeeded
72 */
73 static bool testPlaneContructors(const double testDuration);
74
75 /**
76 * Tests the Plane copy constructors.
77 * @param testDuration Number of seconds for each test, with range (0, infinity)
78 * @return True, if succeeded
79 */
80 static bool testPlaneCopyContructors(const double testDuration);
81
82 /**
83 * Tests the whether the frame specifications for generic pixel formats are correct.
84 * @param testDuration Number of seconds for each test, with range (0, infinity)
85 * @return True, if succeeded
86 */
87 static bool testFrameSpecificationGenericPixelFormats(const double testDuration);
88
89 /**
90 * Tests the whether the frame specifications for non-generic pixel formats are correct.
91 * @param testDuration Number of seconds for each test, with range (0, infinity)
92 * @return True, if succeeded
93 */
94 static bool testFrameSpecificationNonGenericPixelFormats(const double testDuration);
95
96 /**
97 * Tests all constructors.
98 * @param testDuration Number of seconds for each test, with range (0, infinity)
99 * @return True, if succeeded
100 */
101 static bool testConstructor(const double testDuration);
102
103 /**
104 * Tests all copy constructors.
105 * @param testDuration Number of seconds for each test, with range (0, infinity)
106 * @return True, if succeeded
107 */
108 static bool testCopyConstructor(const double testDuration);
109
110 /**
111 * Tests all move constructors.
112 * @param testDuration Number of seconds for each test, with range (0, infinity)
113 * @return True, if succeeded
114 */
115 static bool testMoveConstructor(const double testDuration);
116
117 /**
118 * Tests all copy operators.
119 * @param testDuration Number of seconds for each test, with range (0, infinity)
120 * @return True, if succeeded
121 */
122 static bool testCopyOperator(const double testDuration);
123
124 /**
125 * Tests the initializer for planes.
126 * @param testDuration Number of seconds for each test, with range (0, infinity)
127 * @return True, if succeeded
128 */
129 static bool testPlaneInitializer(const double testDuration);
130
131 /**
132 * Tests the plane layout function.
133 * @param testDuration Number of seconds for each test, with range (0, infinity)
134 * @return True, if succeeded
135 */
136 static bool testPlaneLayout(const double testDuration);
137
138 /**
139 * Tests the release function.
140 * @param testDuration Number of seconds for each test, with range (0, infinity)
141 * @return True, if succeeded
142 */
143 static bool testRelease(const double testDuration);
144
145 /**
146 * Tests the extraction of a sub-frame.
147 * @param testDuration Number of seconds for each test, with range (0, infinity)
148 * @return True, if succeeded
149 */
150 static bool testSubFrame(const double testDuration);
151
152 /**
153 * Tests timestamps.
154 * @param testDuration Number of seconds for each test, with range (0, infinity)
155 * @return True, if succeeded
156 */
157 static bool testTimestamp(const double testDuration);
158
159 /**
160 * Tests the row and pixel accessor function based on data types.
161 * @param testDuration Number of seconds for each test, with range (0, infinity)
162 * @return True, if succeeded
163 */
164 static bool testAccessorsDataTypes(const double testDuration);
165
166 /**
167 * Tests the row and pixel accessor function based on pixel formats.
168 * @param testDuration Number of seconds for each test, with range (0, infinity)
169 * @return True, if succeeded
170 */
171 static bool testAccessorsPixelFormats(const double testDuration);
172
173 /**
174 * Tests the set function for frame types.
175 * @param testDuration Number of seconds for each test, with range (0, infinity)
176 * @return True, if succeeded
177 */
178 static bool testSetFrameType(const double testDuration);
179
180 /**
181 * Tests the legacy copy function of the entire image.
182 * @param testDuration Number of seconds for each test, with range (0, infinity)
183 * @return True, if succeeded
184 */
185 static bool testLegacyCopy(const double testDuration);
186
187 /**
188 * Tests the copy function.
189 * @param testDuration Number of seconds for each test, with range (0, infinity)
190 * @return True, if succeeded
191 */
192 static bool testCopy(const double testDuration);
193
194 /**
195 * Tests the make continuous function.
196 * @param testDuration Number of seconds for each test, with range (0, infinity)
197 * @return True, if succeeded
198 */
199 static bool testMakeContinuous(const double testDuration);
200
201 /**
202 * Tests the plane bits per pixel function.
203 * @return True, if succeeded
204 */
206
207 /**
208 * Tests the setValue functions.
209 * @param testDuration Number of seconds for each test, with range (0, infinity)
210 * @return True, if succeeded
211 */
212 static bool testSetValue(const double testDuration);
213
214 /**
215 * Tests the containsValue functions.
216 * @param testDuration Number of seconds for each test, with range (0, infinity)
217 * @return True, if succeeded
218 */
219 static bool testContainsValue(const double testDuration);
220
221 /**
222 * Tests the hasTransparentPixel function.
223 * @param testDuration Number of seconds for each test, with range (0, infinity)
224 * @return True, if succeeded
225 */
226 static bool testHasTransparentPixel(const double testDuration);
227
228 /**
229 * Tests the function calculating padding elements based on stride bytes.
230 * @param testDuration Number of seconds for each test, with range (0, infinity)
231 * @return True, if succeeded
232 */
233 static bool testStrideBytes2paddingElements(const double testDuration);
234
235 /**
236 * Tests several generic pixel format functions.
237 * @param testDuration Number of seconds for each test, with range (0, infinity)
238 * @return True, if succeeded
239 */
240 static bool testHaveIntersectingMemory(const double testDuration);
241
242 /**
243 * Tests the update memory functions.
244 * @param testDuration Number of seconds for each test, with range (0, infinity)
245 * @return True, if succeeded
246 */
247 static bool testUpdateMemory(const double testDuration);
248
249 /**
250 * Tests the formatIsPacked() function.
251 * @return True, if succeeded
252 */
253 static bool testFormatIsPacked();
254
255 /**
256 * Tests the formatIsLimitedRange() function.
257 * @return True, if succeeded
258 */
260
261 /**
262 * Tests the translate data type functions.
263 * @return True, if succeeded
264 */
266
267 /**
268 * Tests the translate pixel format functions.
269 * @return True, if succeeded
270 */
272
273 /**
274 * Tests the arePixelFormatsCompatible() function.
275 * @param testDuration Number of seconds for each test, with range (0, infinity)
276 * @return True, if succeeded
277 */
278 static bool testArePixelFormatsCompatible(const double testDuration);
279
280 /**
281 * Tests the areFrameTypesCompatible() function.
282 * @param testDuration Number of seconds for each test, with range (0, infinity)
283 * @return True, if succeeded
284 */
285 static bool testAreFrameTypesCompatible(const double testDuration);
286
287 /**
288 * Tests the isDataLayoutCompatible() function.
289 * @param testDuration Number of seconds for each test, with range (0, infinity)
290 * @return True, if succeeded
291 */
292 static bool testIsDataLayoutCompatible(const double testDuration);
293
294 /**
295 * Tests the areFrameTypesDataLayoutCompatible() function.
296 * @param testDuration Number of seconds for each test, with range (0, infinity)
297 * @return True, if succeeded
298 */
299 static bool testAreFrameTypesDataLayoutCompatible(const double testDuration);
300
301 /**
302 * Tests the creation of a frame with extreme resolutions or padding.
303 * @param testDuration Number of seconds for each test, with range (0, infinity)
304 * @return True, if succeeded
305 */
306 static bool testExtremeResolutions(const double testDuration);
307
308 protected:
309
310 /**
311 * Tests the copy function.
312 * @param pixelFormat The pixel format to be tested, must be valid
313 * @param randomGenerator The random generator to be used
314 * @return True, if succeeded
315 * @tparam T The data type of each pixel element
316 */
317 template <typename T>
318 static bool testCopy(const FrameType::PixelFormat pixelFormat, RandomGenerator& randomGenerator);
319
320 /**
321 * Tests the Plane constructors for a specified resolution, channel number and element type.
322 * @param width The width of the plane in pixels, with range [1, infinity)
323 * @param height The height of the plane in pixels, with range [1, infinity)
324 * @param channels The of channels the plane has, with range [1, infinity)
325 * @param paddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
326 * @return True, if succeeded
327 * @tparam T The element data type
328 */
329 template <typename T>
330 static bool testPlaneContructors(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int paddingElements);
331
332 /**
333 * Tests the Plane copy constructors for a specified resolution, channel number and element type.
334 * @param width The width of the plane in pixels, with range [1, infinity)
335 * @param height The height of the plane in pixels, with range [1, infinity)
336 * @param channels The of channels the plane has, with range [1, infinity)
337 * @param paddingElements The number of padding elements at the end of each row, in elements, with range [0, infinity)
338 * @return True, if succeeded
339 * @tparam T The element data type
340 */
341 template <typename T>
342 static bool testPlaneCopyContructors(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int paddingElements);
343
344 /**
345 * Validates the initializer for one plane.
346 * @param frameType The frame type of the image to be used, must be valid
347 * @param randomGenerator The random generator object to be used
348 * @return True, if succeeded
349 * @tparam T The element data type
350 */
351 template <typename T>
352 static bool validatePlaneInitializer(const FrameType& frameType, RandomGenerator& randomGenerator);
353
354 /**
355 * Validates whether a given frame with multiple planes has the correct specification.
356 * @param frame The frame to be checked, must be valid
357 * @param frameType The type of the frame to check, must be valid
358 * @param paddingElementsPerPlane The number of padding elements for each individual plane, with ranges [0, infinity)
359 * @param bytesPerElement The number of bytes per elements, with range [1, infinity)
360 * @param isOwner True, if the frame should be the owner of the memory; False, otherwise
361 * @param isReadOnly True, if the frame should have access to read-only memory; False, if the frame has should have access to writable memory
362 * @return True, if the frame matches the given specification
363 */
364 static bool validateFrameSpecification(const Frame& frame, const FrameType& frameType, const Indices32& paddingElementsPerPlane, const unsigned int bytesPerElement, const bool isOwner, const bool isReadOnly);
365
366 /**
367 * Validates whether a given frame with one plane has the correct specification.
368 * @param frame The frame to be checked, must be valid
369 * @param frameType The type of the frame to check, must be valid
370 * @param paddingElements The number of padding elements for the one and only plane, with range [0, infinity)
371 * @param bytesPerElement The number of bytes per elements, with range [1, infinity)
372 * @param isOwner True, if the frame should be the owner of the memory; False, otherwise
373 * @param isReadOnly True, if the frame should have access to read-only memory; False, if the frame has should have access to writable memory
374 * @return True, if the frame matches the given specification
375 */
376 static inline bool validateFrameSpecification(const Frame& frame, const FrameType& frameType, const unsigned int paddingElements, const unsigned int bytesPerElement, const bool isOwner, const bool isReadOnly);
377
378 /**
379 * Tests the setValue functions.
380 * @param frame The frame to be used for testing, must be valid
381 * @param randomGenerator The random generator to be used
382 * @return True, if succeeded
383 * @tparam T The data type of the frame's elements
384 */
385 template <typename T>
386 static bool testSetValue(const Frame& frame, RandomGenerator& randomGenerator);
387
388 /**
389 * Returns all defined pixel formats.
390 * @param genericPixelFormats Optional custom generic pixel formats which will be added to the resulting pixel formats
391 * @return Ocean's defined pixel formats
392 */
394
395 /**
396 * Returns a random frame type.
397 * @param pixelFormats The pixel formats which can be used for the frame type, at least one
398 * @param randomGenerator Optional random generator object to be used
399 */
400 static FrameType randomizedFrameType(const FrameType::PixelFormats& pixelFormats, RandomGenerator* randomGenerator = nullptr);
401};
402
403inline bool TestFrame::validateFrameSpecification(const Frame& frame, const FrameType& frameType, const unsigned int paddingElements, const unsigned int bytesPerElement, const bool isOwner, const bool isReadOnly)
404{
405 ocean_assert(frame.numberPlanes() == 1u);
406
407 return validateFrameSpecification(frame, frameType, Indices32(1u, paddingElements), bytesPerElement, isOwner, isReadOnly);
408}
409
410}
411
412}
413
414}
415
416#endif // META_OCEAN_TEST_TESTBASE_TEST_FRAME_H
This class implements Ocean's image class.
Definition Frame.h:1879
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition Frame.h:30
PixelFormat
Definition of all pixel formats available in the Ocean framework.
Definition Frame.h:183
std::vector< PixelFormat > PixelFormats
Definition of a vector holding pixel formats.
Definition Frame.h:1040
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition Frame.h:3281
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements tests for the Frame class.
Definition TestFrame.h:31
static bool testFrameSpecificationNonGenericPixelFormats(const double testDuration)
Tests the whether the frame specifications for non-generic pixel formats are correct.
static bool testMoveConstructor(const double testDuration)
Tests all move constructors.
static bool testPlaneContructors(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int paddingElements)
Tests the Plane constructors for a specified resolution, channel number and element type.
static bool testHaveIntersectingMemory(const double testDuration)
Tests several generic pixel format functions.
static bool validatePlaneInitializer(const FrameType &frameType, RandomGenerator &randomGenerator)
Validates the initializer for one plane.
static bool testStrideBytes2paddingElements(const double testDuration)
Tests the function calculating padding elements based on stride bytes.
static bool testSetFrameType(const double testDuration)
Tests the set function for frame types.
static bool test(const double testDuration, const TestSelector &selector=TestSelector())
Invokes all tests.
static bool testLegacyCopy(const double testDuration)
Tests the legacy copy function of the entire image.
static bool testPlaneCopyContructors(const double testDuration)
Tests the Plane copy constructors.
static bool testDefinedDataTypes()
Test ensuring that the function returning all data types is correct.
static bool testSubFrame(const double testDuration)
Tests the extraction of a sub-frame.
static bool testFrameSpecificationGenericPixelFormats(const double testDuration)
Tests the whether the frame specifications for generic pixel formats are correct.
static bool testCopyConstructor(const double testDuration)
Tests all copy constructors.
static bool testPlaneCopyContructors(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int paddingElements)
Tests the Plane copy constructors for a specified resolution, channel number and element type.
static bool testConstructor(const double testDuration)
Tests all constructors.
static bool testTranslateDataType()
Tests the translate data type functions.
static bool testAccessorsDataTypes(const double testDuration)
Tests the row and pixel accessor function based on data types.
static FrameType randomizedFrameType(const FrameType::PixelFormats &pixelFormats, RandomGenerator *randomGenerator=nullptr)
Returns a random frame type.
static bool testMakeContinuous(const double testDuration)
Tests the make continuous function.
static bool testFormatIsLimitedRange()
Tests the formatIsLimitedRange() function.
static bool testAreFrameTypesDataLayoutCompatible(const double testDuration)
Tests the areFrameTypesDataLayoutCompatible() function.
static bool testPlaneContructors(const double testDuration)
Tests the Plane constructors.
static bool testPlaneBytesPerPixel()
Tests the plane bits per pixel function.
static bool testTranslatePixelFormat()
Tests the translate pixel format functions.
static bool testAccessorsPixelFormats(const double testDuration)
Tests the row and pixel accessor function based on pixel formats.
static bool testIsDataLayoutCompatible(const double testDuration)
Tests the isDataLayoutCompatible() function.
static bool testAreFrameTypesCompatible(const double testDuration)
Tests the areFrameTypesCompatible() function.
static bool testExtremeResolutions(const double testDuration)
Tests the creation of a frame with extreme resolutions or padding.
static bool testCopy(const FrameType::PixelFormat pixelFormat, RandomGenerator &randomGenerator)
Tests the copy function.
static bool testSetValue(const double testDuration)
Tests the setValue functions.
static FrameType::PixelFormats definedPixelFormats(const FrameType::PixelFormats &genericPixelFormats=FrameType::PixelFormats())
Returns all defined pixel formats.
static bool testIsSumInsideValueRange(const double testDuration)
Sets the is sum inside value range functions.
static bool testTimestamp(const double testDuration)
Tests timestamps.
static bool testArePixelFormatsCompatible(const double testDuration)
Tests the arePixelFormatsCompatible() function.
static bool testRelease(const double testDuration)
Tests the release function.
static bool testPlaneLayout(const double testDuration)
Tests the plane layout function.
static bool testContainsValue(const double testDuration)
Tests the containsValue functions.
static bool testDefinedPixelFormats()
Test ensuring that the function returning all defined pixel formats is correct.
static bool testHasTransparentPixel(const double testDuration)
Tests the hasTransparentPixel function.
static bool testUpdateMemory(const double testDuration)
Tests the update memory functions.
static bool testPlaneInitializer(const double testDuration)
Tests the initializer for planes.
static bool validateFrameSpecification(const Frame &frame, const FrameType &frameType, const Indices32 &paddingElementsPerPlane, const unsigned int bytesPerElement, const bool isOwner, const bool isReadOnly)
Validates whether a given frame with multiple planes has the correct specification.
static bool testCopy(const double testDuration)
Tests the copy function.
static bool testIsProductInsideValueRange(const double testDuration)
Sets the is product inside value range functions.
static bool testCopyOperator(const double testDuration)
Tests all copy operators.
static bool testFormatIsPacked()
Tests the formatIsPacked() function.
static bool testSetValue(const Frame &frame, RandomGenerator &randomGenerator)
Tests the setValue functions.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
The namespace covering the entire Ocean framework.
Definition Accessor.h:15