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