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