| 121 | } |
| 122 | |
| 123 | int test_reset() |
| 124 | { |
| 125 | std::cout << "\n*** Test reset ***\n"; |
| 126 | |
| 127 | const int size_buffer = 20; |
| 128 | |
| 129 | DataBuffer::init(size_buffer); |
| 130 | |
| 131 | const int size_write = 3; |
| 132 | const int size_read = size_write; |
| 133 | |
| 134 | const int b = 1; |
| 135 | const int e = size_write + 1; |
| 136 | std::string data = create_range(b, e); |
| 137 | |
| 138 | // test writing and reading data: |
| 139 | { |
| 140 | std::vector<uint8_t> bytes(size_read, to_char(99)); |
| 141 | |
| 142 | const uint32_t Nw = DataBuffer::write(data); |
| 143 | |
| 144 | #if 0 |
| 145 | if ( Nw != DataBuffer::size() ) |
| 146 | { |
| 147 | std::cout << "*** Test reset: expecting '" << Nw << "' items in buffer, got '" << DataBuffer::size() << "'\n"; |
| 148 | return EXIT_FAILURE; |
| 149 | } |
| 150 | #endif |
| 151 | const uint32_t Nr = DataBuffer::read(size_read, bytes.data()); |
| 152 | |
| 153 | if ( Nr != Nw || create_data(bytes) != data) |
| 154 | { |
| 155 | std::cout << "*** Test reset: expected to read '" << size_read << "', got '" << Nr << "'\n"; |
| 156 | return EXIT_FAILURE; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // test reading data after reset: |
| 161 | { |
| 162 | std::vector<uint8_t> bytes(size_read, to_char(99)); |
| 163 | |
| 164 | const uint32_t Nw = DataBuffer::write(data); |
| 165 | |
| 166 | // clear buffer, keep allocated memory: |
| 167 | std::cout << "*** Test reset: Reset buffer\n"; |
| 168 | DataBuffer::reset(); |
| 169 | |
| 170 | const uint32_t Nr = DataBuffer::read(size_read, bytes.data()); |
| 171 | |
| 172 | if ( Nr != 0 || bytes[0] != to_char(99)) |
| 173 | { |
| 174 | std::cout << "*** Test reset: Failed with Nr is '" << Nr << "', bytes[0] is '" << to_int(bytes[0]) << "', expected Nr of 0.\n"; |
| 175 | print("*** ", data, "\n"); |
| 176 | print("*** ", bytes, "\n"); |
| 177 | return EXIT_FAILURE; |
| 178 | } |
| 179 | } |
| 180 |
no test coverage detected