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