Ocean
Loading...
Searching...
No Matches
TestStaticBuffer.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_STATIC_BUFFER_H
9#define META_OCEAN_TEST_TESTBASE_TEST_STATIC_BUFFER_H
10
13
15#include "ocean/base/RandomI.h"
16
17namespace Ocean
18{
19
20namespace Test
21{
22
23namespace TestBase
24{
25
26/**
27 * This class implements tests for StaticBuffer.
28 * @ingroup testbase
29 */
30class OCEAN_TEST_BASE_EXPORT TestStaticBuffer
31{
32 friend class TestStaticVector;
33
34 public:
35
36 /**
37 * Invokes all tests.
38 * @param testDuration Number of seconds for each test, with range (0, infinity)
39 * @param selector The test selector to filter specific tests
40 * @return True, if succeeded
41 */
42 static bool test(const double testDuration, const TestSelector& selector = TestSelector());
43
44 /**
45 * Tests the constructor functions.
46 * @return True, if succeeded
47 */
48 static bool testConstructor();
49
50 /**
51 * Tests the access functions.
52 * @return True, if succeeded
53 */
54 static bool testAccess();
55
56 /**
57 * Tests the clear function.
58 * @return True, if succeeded
59 */
60 static bool testClear();
61
62 /**
63 * Tests the comparison functions.
64 * @return True, if succeeded
65 */
66 static bool testComparison();
67
68 protected:
69
70 /**
71 * Tests the constructor functions.
72 * @param randomGenerator The random generator to be used
73 * @return True, if succeeded
74 * @tparam T The data type of the buffer
75 * @tparam tCapacity The capacity of the buffer, with range [1, infinity)
76 */
77 template <typename T, size_t tCapacity>
78 static bool testConstructor(RandomGenerator& randomGenerator);
79
80 /**
81 * Tests the access functions.
82 * @return True, if succeeded
83 * @tparam T The data type of the buffer
84 * @tparam tCapacity The capacity of the buffer, with range [1, infinity)
85 */
86 template <typename T, size_t tCapacity>
87 static bool testAccess();
88
89 /**
90 * Tests the clear function.
91 * @param randomGenerator The random generator to be used
92 * @return True, if succeeded
93 * @tparam T The data type of the buffer
94 * @tparam tCapacity The capacity of the buffer, with range [1, infinity)
95 */
96 template <typename T, size_t tCapacity>
97 static bool testClear(RandomGenerator& randomGenerator);
98
99 /**
100 * Tests the comparison functions.
101 * @param randomGenerator The random generator to be used
102 * @return True, if succeeded
103 * @tparam T The data type of the buffer
104 * @tparam tCapacity The capacity of the buffer, with range [1, infinity)
105 */
106 template <typename T, size_t tCapacity>
107 static bool testComparison(RandomGenerator& randomGenerator);
108
109 /**
110 * Returns a random value.
111 * @param randomGenerator The random generator to be used
112 * @return The random value
113 * @tparam T The data type of the value
114 */
115 template <typename T>
116 static inline T randomValue(RandomGenerator& randomGenerator);
117};
118
119template <>
120inline int32_t TestStaticBuffer::randomValue(RandomGenerator& randomGenerator)
121{
122 while (true)
123 {
124 const int32_t value = RandomI::random(randomGenerator, -1000, 1000);
125
126 if (value != 0)
127 {
128 return value;
129 }
130 }
131}
132
133template <>
134inline uint8_t TestStaticBuffer::randomValue(RandomGenerator& randomGenerator)
135{
136 return uint8_t(RandomI::random(randomGenerator, 1u, 255u));
137}
138
139template <>
140inline float TestStaticBuffer::randomValue(RandomGenerator& randomGenerator)
141{
142 while (true)
143 {
144 const float value = float(RandomI::random(randomGenerator, -1000, 1000));
145
146 if (value != 0.0f)
147 {
148 return value;
149 }
150 }
151}
152
153template <>
154inline std::string TestStaticBuffer::randomValue(RandomGenerator& randomGenerator)
155{
156 return String::toAString(RandomI::random(randomGenerator, 1000u));
157}
158
159}
160
161}
162
163}
164
165#endif // META_OCEAN_TEST_TESTBASE_TEST_STATIC_BUFFER_H
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
static unsigned int random(const unsigned int maxValue)
Returns one random integer value with specified maximum value.
static std::string toAString(const char value)
Converts a value to a string with 8bit character.
This class implements tests for StaticBuffer.
Definition TestStaticBuffer.h:31
static bool test(const double testDuration, const TestSelector &selector=TestSelector())
Invokes all tests.
static bool testConstructor(RandomGenerator &randomGenerator)
Tests the constructor functions.
static bool testConstructor()
Tests the constructor functions.
static bool testAccess()
Tests the access functions.
static bool testAccess()
Tests the access functions.
static T randomValue(RandomGenerator &randomGenerator)
Returns a random value.
static bool testClear()
Tests the clear function.
static bool testComparison(RandomGenerator &randomGenerator)
Tests the comparison functions.
static bool testClear(RandomGenerator &randomGenerator)
Tests the clear function.
static bool testComparison()
Tests the comparison functions.
This class implements tests for StaticVector.
Definition TestStaticVector.h:30
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
The namespace covering the entire Ocean framework.
Definition Accessor.h:15