Ocean
TestData.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_TEST_DATA_H
9 #define META_OCEAN_TEST_TEST_DATA_H
10 
11 #include "ocean/test/Test.h"
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Value.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Test
20 {
21 
22 // Forward declaration.
23 class TestData;
24 
25 /**
26  * Definition of a shared pointer holding a TestData object.
27  * @ingroup test
28  */
29 using SharedTestData = std::shared_ptr<TestData>;
30 
31 /**
32  * This class holds the test data necessary for one test iteration combining input data and potential expected test results.
33  * @ingroup test
34  */
35 class OCEAN_TEST_EXPORT TestData
36 {
37  public:
38 
39  /**
40  * Definition of individual data types.
41  */
42  enum DataType : uint32_t
43  {
44  /// Invalid data type
45  DT_INVALID = 0u,
46  /// The data is a value.
48  /// The data is an image.
49  DT_IMAGE
50  };
51 
52  public:
53 
54  /**
55  * Default constructor.
56  */
57  TestData() = default;
58 
59  /**
60  * Creates a new test data object holding a value.
61  * @param value The value of the new object, must be valid
62  * @param expectation The optional test expectation for the new object
63  */
64  explicit TestData(Value&& value, Value&& expectation = Value());
65 
66  /**
67  * Creates a new test data object holding an image.
68  * @param image The image of the new object, must be valid
69  * @param expectation The optional test expectation for the new object
70  */
71  explicit TestData(Frame&& image, Value&& expectation);
72 
73  /**
74  * Returns the data type of this test data object.
75  * @return The object's data type
76  */
77  inline DataType dataType() const;
78 
79  /**
80  * Returns the value of this object.
81  * Ensure that `dataType() == DT_VALUE` before calling this function.
82  * @return The object's value
83  */
84  inline const Value& value() const;
85 
86  /**
87  * Returns the image of this object.
88  * Ensure that `dataType() == DT_IMAGE` before calling this function.
89  * @return The object's image
90  */
91  inline const Frame& image() const;
92 
93  /**
94  * Returns the potential expectation of this test object.
95  * @return The object's expectation, invalid if no expectation is defined
96  */
97  inline const Value& expectation() const;
98 
99  /**
100  * Returns whether this object is valid and holds valid test data.
101  * @return True, if so
102  */
103  inline bool isValid() const;
104 
105  /**
106  * Returns whether this object is valid and holds valid test data.
107  * @return True, if so
108  */
109  inline explicit operator bool() const;
110 
111  protected:
112 
113  /// The data type of this test object.
114  DataType dataType_ = DT_INVALID;
115 
116  /// The object's value, invalid if not defined.
118 
119  //// The object's image, invalid if not defined.
121 
122  /// The object's expectation, invalid if not defined.
124 };
125 
127 {
128  return dataType_;
129 }
130 
131 inline const Value& TestData::value() const
132 {
133  ocean_assert(dataType_ == DT_VALUE);
134 
135  return value_;
136 }
137 
138 inline const Frame& TestData::image() const
139 {
140  ocean_assert(dataType_ == DT_IMAGE);
141 
142  return image_;
143 }
144 
145 inline const Value& TestData::expectation() const
146 {
147  ocean_assert(dataType_ != DT_INVALID);
148 
149  return expectation_;
150 }
151 
152 inline bool TestData::isValid() const
153 {
154  return dataType_ != DT_INVALID;
155 }
156 
157 inline TestData::operator bool() const
158 {
159  return isValid();
160 }
161 
162 }
163 
164 }
165 
166 #endif // META_OCEAN_TEST_TEST_DATA_H
This class implements Ocean's image class.
Definition: Frame.h:1760
This class holds the test data necessary for one test iteration combining input data and potential ex...
Definition: TestData.h:36
const Value & expectation() const
Returns the potential expectation of this test object.
Definition: TestData.h:145
Value value_
The object's value, invalid if not defined.
Definition: TestData.h:117
bool isValid() const
Returns whether this object is valid and holds valid test data.
Definition: TestData.h:152
TestData(Value &&value, Value &&expectation=Value())
Creates a new test data object holding a value.
TestData()=default
Default constructor.
const Value & value() const
Returns the value of this object.
Definition: TestData.h:131
Frame image_
Definition: TestData.h:120
DataType
Definition of individual data types.
Definition: TestData.h:43
@ DT_INVALID
Invalid data type.
Definition: TestData.h:45
@ DT_VALUE
The data is a value.
Definition: TestData.h:47
@ DT_IMAGE
The data is an image.
Definition: TestData.h:49
DataType dataType_
The data type of this test object.
Definition: TestData.h:114
Value expectation_
The object's expectation, invalid if not defined.
Definition: TestData.h:123
DataType dataType() const
Returns the data type of this test data object.
Definition: TestData.h:126
TestData(Frame &&image, Value &&expectation)
Creates a new test data object holding an image.
const Frame & image() const
Returns the image of this object.
Definition: TestData.h:138
This class implements a type independent value.
Definition: Value.h:23
std::shared_ptr< TestData > SharedTestData
Definition of a shared pointer holding a TestData object.
Definition: TestData.h:29
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15