| 1287 | } |
| 1288 | |
| 1289 | void VerifyDecodingLevels(Encoding::type encoding, int16_t max_level, |
| 1290 | const std::vector<int16_t>& input_levels, |
| 1291 | std::vector<uint8_t>& bytes) { |
| 1292 | LevelDecoder decoder; |
| 1293 | int levels_count = 0; |
| 1294 | std::vector<int16_t> output_levels; |
| 1295 | int num_levels = static_cast<int>(input_levels.size()); |
| 1296 | |
| 1297 | output_levels.resize(num_levels); |
| 1298 | ASSERT_EQ(num_levels, static_cast<int>(output_levels.size())); |
| 1299 | |
| 1300 | // Decode levels and test with multiple decode calls |
| 1301 | decoder.SetData(encoding, max_level, num_levels, bytes.data(), |
| 1302 | static_cast<int32_t>(bytes.size())); |
| 1303 | int decode_count = 4; |
| 1304 | int num_inner_levels = num_levels / decode_count; |
| 1305 | // Try multiple decoding on a single SetData call |
| 1306 | for (int ct = 0; ct < decode_count; ct++) { |
| 1307 | int offset = ct * num_inner_levels; |
| 1308 | levels_count = decoder.Decode(num_inner_levels, output_levels.data()); |
| 1309 | ASSERT_EQ(num_inner_levels, levels_count); |
| 1310 | for (int i = 0; i < num_inner_levels; i++) { |
| 1311 | EXPECT_EQ(input_levels[i + offset], output_levels[i]); |
| 1312 | } |
| 1313 | } |
| 1314 | // check the remaining levels |
| 1315 | int num_levels_completed = decode_count * (num_levels / decode_count); |
| 1316 | int num_remaining_levels = num_levels - num_levels_completed; |
| 1317 | if (num_remaining_levels > 0) { |
| 1318 | levels_count = decoder.Decode(num_remaining_levels, output_levels.data()); |
| 1319 | ASSERT_EQ(num_remaining_levels, levels_count); |
| 1320 | for (int i = 0; i < num_remaining_levels; i++) { |
| 1321 | EXPECT_EQ(input_levels[i + num_levels_completed], output_levels[i]); |
| 1322 | } |
| 1323 | } |
| 1324 | // Test zero Decode values |
| 1325 | ASSERT_EQ(0, decoder.Decode(1, output_levels.data())); |
| 1326 | } |
| 1327 | |
| 1328 | void VerifyDecodingMultipleSetData(Encoding::type encoding, int16_t max_level, |
| 1329 | const std::vector<int16_t>& input_levels, |