Ocean
TestBitstream.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_TESTIO_TEST_BITSTREAM_H
9 #define META_OCEAN_TEST_TESTIO_TEST_BITSTREAM_H
10 
12 
13 #include "ocean/io/Bitstream.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Test
19 {
20 
21 namespace TestIO
22 {
23 
24 /**
25  * This class implements a test for the Bitstream class.
26  * @ingroup testio
27  */
28 class OCEAN_TEST_IO_EXPORT TestBitstream
29 {
30  public:
31 
32  /**
33  * Tests all functions of the Bitstream class.
34  * @param testDuration The number of seconds for each test
35  * @return True, if succeeded
36  */
37  static bool test(const double testDuration);
38 
39  /**
40  * Tests the input and output bitstream functions.
41  * @return True, if succeeded
42  */
43  static bool testInputOutputBitstream();
44 
45  /**
46  * Reads one value from an input stream and checks whether the value matches with a given value.
47  * @param inputStream The input stream
48  * @param expectedValue The expected value
49  * @return True, if succeeded
50  * @tparam T The data type of the value to be read
51  */
52  template <typename T>
53  static bool readValue(IO::InputBitstream& inputStream, const T& expectedValue);
54 };
55 
56 template <typename T>
57 bool TestBitstream::readValue(IO::InputBitstream& inputStream, const T& expectedValue)
58 {
59  ocean_assert(inputStream);
60 
61  T value;
62  if (!inputStream.read<T>(value))
63  {
64  return false;
65  }
66 
67  return value == expectedValue;
68 }
69 
70 }
71 
72 }
73 
74 }
75 
76 #endif // META_OCEAN_TEST_TESTIO_TEST_BITSTREAM_H
This class implements an input bitstream.
Definition: Bitstream.h:51
bool read(T &value)
Reads a value from the bitstream and moves the internal position inside the bitstream accordingly.
This class implements a test for the Bitstream class.
Definition: TestBitstream.h:29
static bool testInputOutputBitstream()
Tests the input and output bitstream functions.
static bool test(const double testDuration)
Tests all functions of the Bitstream class.
static bool readValue(IO::InputBitstream &inputStream, const T &expectedValue)
Reads one value from an input stream and checks whether the value matches with a given value.
Definition: TestBitstream.h:57
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15