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