Ocean
TestMicroQRCodeEncoder.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 #pragma once
9 
11 
14 
17 
18 namespace Ocean
19 {
20 
21 namespace Test
22 {
23 
24 namespace TestCV
25 {
26 
27 namespace TestDetector
28 {
29 
30 namespace TestQRCodes
31 {
32 
33 /**
34  * This class implements tests for the Micro QR code features
35  * @ingroup testcvdetectorqrcodes
36  */
37 class OCEAN_TEST_CV_DETECTOR_QRCODES_EXPORT TestMicroQRCodeEncoder
38 {
39  friend class TestMicroQRCodeDecoder;
40 
41  protected:
42 
43  /**
44  * Helper data structure for Micro QR Code symbol numbers
45  */
46  struct SymbolNumber
47  {
48  /// The version number of the Micro QR code symbol number
49  unsigned int version_;
50 
51  /// The level of the error correction capacity of the Micro QR code symbol number
53  };
54 
55  public:
56 
57  /**
58  * This class implements a test data collection based on a local file.
59  */
61  {
62  public:
63 
64  /**
65  * Creates a new test data collection object.
66  * @param filename The filename of the file containing the test data
67  */
68  explicit FileDataCollection(const std::string& filename);
69 
70  /**
71  * Returns the test data object associated with a specified index.
72  * @see TestDataCollection::data().
73  */
74  SharedTestData data(const size_t index) override;
75 
76  /**
77  * Returns the number of data object objects this collection holds.
78  * @see TestDataCollection::size().
79  */
80  size_t size() override;
81 
82  protected:
83 
84  /// The filename of the test data belonging to this test collection.
85  std::string filename_;
86  };
87 
88  protected:
89 
90  /**
91  * Definition of a helper data structure that's used to verify the Micro QR code encoding functionality
92  * This will contain the raw message and the values of corresponding Micro QR code that were generated with a reference Micro QR code generator and which are assumed to be correct.
93  */
95  {
96  public:
97 
98  /**
99  * Constructor - creates an invalid instance
100  */
102 
103  /**
104  * Constructor
105  * @param version The version of the Micro QR code
106  * @param errorCorrectionCapacity The level of error correction that the Micro QR code has
107  * @param maskingPattern The masking pattern that was used to generate the Micro QR code
108  * @param message The raw input message that was used to generate the Micro QR code
109  * @param modules The modules of a Micro QR code as a string ("1", "0" only), must have `(2 * version + 9)^2` elements
110  * @sa loadCSVTestMicroQRCodeEncoding()
111  */
112  inline MicroQRCodeVerificationItem(const unsigned int version, const CV::Detector::QRCodes::QRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const CV::Detector::QRCodes::MicroQRCodeEncoder::MaskingPattern maskingPattern, const std::string& message, const std::string& modules);
113 
114  public:
115 
116  /// Version number
117  unsigned int version_ = 0u;
118 
119  /// Error correction capacity
121 
122  /// Masking pattern
124 
125  /// The raw message
126  std::string message_;
127 
128  /// The modules (bit matrix)
129  std::string modules_;
130  };
131 
132  /// Vector of verification items
133  typedef std::vector<MicroQRCodeVerificationItem> MicroQRCodeVerificationItems;
134 
135  public:
136 
137  /**
138  * Tests the Micro QR code functions.
139  * @param testDuration Number of seconds for each test, with range (0, infinity)
140  * @return True, if succeeded
141  */
142  static bool test(const double testDuration);
143 
144  /**
145  * Tests encoding (generation) of Micro QR codes
146  * @param testDuration The duration in seconds for which this test will be run, must be > 0.0
147  * @return True, if succeeded
148  */
149  static bool testMicroQRCodeEncoding(const double testDuration);
150 
151  /**
152  * Tests the encoding/decoding of the format information
153  * @return True, if succeeded
154  */
156 
157  protected:
158 
159  /**
160  * Provides verification data for the Micro QR code encoding test.
161  * The source is either a test data collection, or a minimal dataset
162  * @return The verification data, empty if the data could not be loaded
163  */
165 
166  /**
167  * Loads the verification data for the Micro QR code encoding test from a buffer containing a CSV file.
168  * @param buffer The pointer to the buffer, must be valid
169  * @param size The size of the buffer, in bytes, with range [1, infinity)
170  * @return The verification data
171  */
172  static MicroQRCodeVerificationItems loadCSVTestMicroQRCodeEncoding(const void* buffer, const size_t size);
173 
174  /**
175  * Converts a line from a CSV file into a helper data structure that is subsequently used for testing
176  * @param lineCSV A line for a CSV file, cf. `loadDataTestMicroQRCodeEncoding()`
177  * @param qrcodeVerificationItem The converted line from a CSV that will be stored here
178  * @return True on success, otherwise false
179  */
180  static bool convertCSVToMicroQRCodeVerificationItem(const std::string& lineCSV, MicroQRCodeVerificationItem& qrcodeVerificationItem);
181 };
182 
183 #ifdef OCEAN_USE_LOCAL_TEST_DATA_COLLECTION
184 
185 /**
186  * Registers the data collections for the MicroQRCodeEncoder test.
187  * @return The scoped subscription for the registered data collection
188  */
190 
191 #endif // OCEAN_USE_LOCAL_TEST_DATA_COLLECTION
192 
193 inline TestMicroQRCodeEncoder::MicroQRCodeVerificationItem::MicroQRCodeVerificationItem(const unsigned int version, const CV::Detector::QRCodes::QRCode::ErrorCorrectionCapacity errorCorrectionCapacity, const CV::Detector::QRCodes::MicroQRCodeEncoder::MaskingPattern maskingPattern, const std::string& message, const std::string& modules) :
194  version_(version),
195  errorCorrectionCapacity_(errorCorrectionCapacity),
196  maskingPattern_(maskingPattern),
197  message_(message),
198  modules_(modules)
199 {
200  // Nothing else to do.
201 }
202 
203 } // namespace TestQRCodes
204 
205 } // namespace TestDetector
206 
207 } // namespace TestCV
208 
209 } // namespace Test
210 
211 } // namespace Ocean
MaskingPattern
Enum for the mask patterns used to shuffle modules of a Micro QR code.
Definition: MicroQRCodeEncoder.h:45
@ MP_PATTERN_UNKNOWN
Denotes unknown masking patterns (not part of the standard)
Definition: MicroQRCodeEncoder.h:59
ErrorCorrectionCapacity
Enumeration of the levels of error correction The value of the enums correspond to the standard-defin...
Definition: QRCodeBase.h:53
@ ECC_INVALID
Indicator for an invalid error correction capacity.
Definition: QRCodeBase.h:65
This class implements a subscription object which can be used unique subscriptions to e....
Definition: ScopedSubscription.h:28
Definition of a helper data structure that's used to verify the Micro QR code encoding functionality ...
Definition: TestMicroQRCodeEncoder.h:95
std::string modules_
The modules (bit matrix)
Definition: TestMicroQRCodeEncoder.h:129
std::string message_
The raw message.
Definition: TestMicroQRCodeEncoder.h:126
This class implements a test data collection based on a local file.
Definition: TestMicroQRCodeEncoder.h:61
SharedTestData data(const size_t index) override
Returns the test data object associated with a specified index.
FileDataCollection(const std::string &filename)
Creates a new test data collection object.
std::string filename_
The filename of the test data belonging to this test collection.
Definition: TestMicroQRCodeEncoder.h:85
size_t size() override
Returns the number of data object objects this collection holds.
This class implements tests for the Micro QR code features.
Definition: TestMicroQRCodeEncoder.h:38
static bool convertCSVToMicroQRCodeVerificationItem(const std::string &lineCSV, MicroQRCodeVerificationItem &qrcodeVerificationItem)
Converts a line from a CSV file into a helper data structure that is subsequently used for testing.
static bool testMicroQRCodeEncoding(const double testDuration)
Tests encoding (generation) of Micro QR codes.
std::vector< MicroQRCodeVerificationItem > MicroQRCodeVerificationItems
Vector of verification items.
Definition: TestMicroQRCodeEncoder.h:133
static MicroQRCodeVerificationItems loadDataTestMicroQRCodeEncoding()
Provides verification data for the Micro QR code encoding test.
static bool testMicroQRCodeFormatEncodingDecoding()
Tests the encoding/decoding of the format information.
static bool test(const double testDuration)
Tests the Micro QR code functions.
static MicroQRCodeVerificationItems loadCSVTestMicroQRCodeEncoding(const void *buffer, const size_t size)
Loads the verification data for the Micro QR code encoding test from a buffer containing a CSV file.
This class is the base class for all TestDataCollection objects.
Definition: TestDataCollection.h:35
std::shared_ptr< TestData > SharedTestData
Definition of a shared pointer holding a TestData object.
Definition: TestData.h:29
TestDataManager::ScopedSubscription TestMicroQRCodeEncoder_registerTestDataCollection()
Registers the data collections for the MicroQRCodeEncoder test.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
Helper data structure for Micro QR Code symbol numbers.
Definition: TestMicroQRCodeEncoder.h:47
CV::Detector::QRCodes::MicroQRCode::ErrorCorrectionCapacity errorCorrectionCapacity_
The level of the error correction capacity of the Micro QR code symbol number.
Definition: TestMicroQRCodeEncoder.h:52
unsigned int version_
The version number of the Micro QR code symbol number.
Definition: TestMicroQRCodeEncoder.h:49