diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/cubeb-sys/libcubeb/test/test_utils.cpp | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/cubeb-sys/libcubeb/test/test_utils.cpp')
-rw-r--r-- | third_party/rust/cubeb-sys/libcubeb/test/test_utils.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/third_party/rust/cubeb-sys/libcubeb/test/test_utils.cpp b/third_party/rust/cubeb-sys/libcubeb/test/test_utils.cpp new file mode 100644 index 0000000000..cbdb960984 --- /dev/null +++ b/third_party/rust/cubeb-sys/libcubeb/test/test_utils.cpp @@ -0,0 +1,72 @@ +#include "gtest/gtest.h" +#include "cubeb_utils.h" + +TEST(cubeb, auto_array) +{ + auto_array<uint32_t> array; + auto_array<uint32_t> array2(10); + uint32_t a[10]; + + ASSERT_EQ(array2.length(), 0u); + ASSERT_EQ(array2.capacity(), 10u); + + + for (uint32_t i = 0; i < 10; i++) { + a[i] = i; + } + + ASSERT_EQ(array.capacity(), 0u); + ASSERT_EQ(array.length(), 0u); + + array.push(a, 10); + + ASSERT_TRUE(!array.reserve(9)); + + for (uint32_t i = 0; i < 10; i++) { + ASSERT_EQ(array.data()[i], i); + } + + ASSERT_EQ(array.capacity(), 10u); + ASSERT_EQ(array.length(), 10u); + + uint32_t b[10]; + + array.pop(b, 5); + + ASSERT_EQ(array.capacity(), 10u); + ASSERT_EQ(array.length(), 5u); + for (uint32_t i = 0; i < 5; i++) { + ASSERT_EQ(b[i], i); + ASSERT_EQ(array.data()[i], 5 + i); + } + uint32_t* bb = b + 5; + array.pop(bb, 5); + + ASSERT_EQ(array.capacity(), 10u); + ASSERT_EQ(array.length(), 0u); + for (uint32_t i = 0; i < 5; i++) { + ASSERT_EQ(bb[i], 5 + i); + } + + ASSERT_TRUE(!array.pop(nullptr, 1)); + + array.push(a, 10); + array.push(a, 10); + + for (uint32_t j = 0; j < 2; j++) { + for (uint32_t i = 0; i < 10; i++) { + ASSERT_EQ(array.data()[10 * j + i], i); + } + } + ASSERT_EQ(array.length(), 20u); + ASSERT_EQ(array.capacity(), 20u); + array.pop(nullptr, 5); + + for (uint32_t i = 0; i < 5; i++) { + ASSERT_EQ(array.data()[i], 5 + i); + } + + ASSERT_EQ(array.length(), 15u); + ASSERT_EQ(array.capacity(), 20u); +} + |