| // Copyright 2023 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include <string> |
| |
| #include "base/functional/bind.h" |
| #include "base/run_loop.h" |
| #include "base/test/task_environment.h" |
| #include "media/muxers/output_position_tracker.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| |
| namespace media { |
| |
| TEST(OutputPositionTrackerTest, OutputPositionTracker) { |
| base::test::SingleThreadTaskEnvironment task_environment; |
| std::string written_data; |
| base::RunLoop run_loop; |
| |
| OutputPositionTracker buffer(base::BindRepeating( |
| [](std::string* written_data, base::OnceClosure run_loop_quit, |
| base::StringPiece data) { |
| written_data->append(data.data(), data.size()); |
| static int called_count = 0; |
| if (++called_count == 3) { |
| std::move(run_loop_quit).Run(); |
| } |
| }, |
| &written_data, run_loop.QuitClosure())); |
| |
| std::string str1 = "abc"; |
| buffer.WriteString(str1); |
| EXPECT_EQ(buffer.GetCurrentPos(), 3u); |
| |
| str1.resize(5); |
| buffer.WriteString(str1); |
| EXPECT_EQ(buffer.GetCurrentPos(), 8u); |
| |
| buffer.WriteString(str1); |
| EXPECT_EQ(buffer.GetCurrentPos(), 13u); |
| |
| run_loop.Run(); |
| |
| constexpr char kExpectedResult[] = {'a', 'b', 'c', 'a', 'b', 'c', '\0', |
| '\0', 'a', 'b', 'c', '\0', '\0'}; |
| ASSERT_EQ(std::size(kExpectedResult), written_data.size()); |
| EXPECT_EQ(memcmp(kExpectedResult, written_data.data(), written_data.size()), |
| 0); |
| } |
| |
| } // namespace media |