diff options
author | Max Kellermann <max@musicpd.org> | 2019-08-03 13:10:49 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2019-08-03 13:10:49 +0200 |
commit | cde6c46d2fff083166c3aca7fbf07df737c07cdc (patch) | |
tree | 51c5706d03b6ea61fa6dad6566dfa67bc090efda /test | |
parent | d305f187d5268a040aca6df62849c33b05308963 (diff) |
util/Macros: replace with std::size() (C++17)
Diffstat (limited to 'test')
-rw-r--r-- | test/TestSplitString.cxx | 14 | ||||
-rw-r--r-- | test/test_byte_reverse.cxx | 17 | ||||
-rw-r--r-- | test/test_pcm_interleave.cxx | 13 | ||||
-rw-r--r-- | test/test_queue_priority.cxx | 9 |
4 files changed, 26 insertions, 27 deletions
diff --git a/test/TestSplitString.cxx b/test/TestSplitString.cxx index 6ba87ee1b..868aea573 100644 --- a/test/TestSplitString.cxx +++ b/test/TestSplitString.cxx @@ -3,10 +3,10 @@ */ #include "util/SplitString.hxx" -#include "util/Macros.hxx" #include <gtest/gtest.h> +#include <iterator> TEST(SplitString, Basic) { @@ -14,12 +14,12 @@ TEST(SplitString, Basic) const char *const output[] = { "foo", "bar" }; size_t i = 0; for (auto p : SplitString(input, '.')) { - EXPECT_LT(i, ARRAY_SIZE(output)); + EXPECT_LT(i, std::size(output)); EXPECT_EQ(p, output[i]); ++i; } - EXPECT_EQ(ARRAY_SIZE(output), i); + EXPECT_EQ(std::size(output), i); } TEST(SplitString, Strip) @@ -28,12 +28,12 @@ TEST(SplitString, Strip) const char *const output[] = { "foo", "bar\r\n2" }; size_t i = 0; for (auto p : SplitString(input, '.')) { - EXPECT_LT(i, ARRAY_SIZE(output)); + EXPECT_LT(i, std::size(output)); EXPECT_EQ(p, output[i]); ++i; } - EXPECT_EQ(ARRAY_SIZE(output), i); + EXPECT_EQ(std::size(output), i); } TEST(SplitString, NoStrip) @@ -42,12 +42,12 @@ TEST(SplitString, NoStrip) const char *const output[] = { " foo\t", "\r\nbar\r\n2" }; size_t i = 0; for (auto p : SplitString(input, '.', false)) { - EXPECT_LT(i, ARRAY_SIZE(output)); + EXPECT_LT(i, std::size(output)); EXPECT_EQ(p, output[i]); ++i; } - EXPECT_EQ(ARRAY_SIZE(output), i); + EXPECT_EQ(std::size(output), i); } TEST(SplitString, Empty) diff --git a/test/test_byte_reverse.cxx b/test/test_byte_reverse.cxx index 144ebde6c..8535a89df 100644 --- a/test/test_byte_reverse.cxx +++ b/test/test_byte_reverse.cxx @@ -18,7 +18,6 @@ */ #include "util/ByteReverse.hxx" -#include "util/Macros.hxx" #include "util/Compiler.h" #include <gtest/gtest.h> @@ -30,10 +29,10 @@ TEST(ByteReverse, A) { alignas(uint16_t) static const char src[] = "123456"; static const char result[] = "214365"; - alignas(uint16_t)static uint8_t dest[ARRAY_SIZE(src)]; + alignas(uint16_t)static uint8_t dest[std::size(src)]; reverse_bytes(dest, (const uint8_t *)src, - (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 2); + (const uint8_t *)(src + std::size(src) - 1), 2); EXPECT_STREQ(result, (const char *)dest); } @@ -41,10 +40,10 @@ TEST(ByteReverse, B) { static const char src[] = "123456"; static const char result[] = "321654"; - static uint8_t dest[ARRAY_SIZE(src)]; + static uint8_t dest[std::size(src)]; reverse_bytes(dest, (const uint8_t *)src, - (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 3); + (const uint8_t *)(src + std::size(src) - 1), 3); EXPECT_STREQ(result, (const char *)dest); } @@ -52,10 +51,10 @@ TEST(ByteReverse, C) { alignas(uint32_t) static const char src[] = "12345678"; static const char result[] = "43218765"; - alignas(uint32_t) static uint8_t dest[ARRAY_SIZE(src)]; + alignas(uint32_t) static uint8_t dest[std::size(src)]; reverse_bytes(dest, (const uint8_t *)src, - (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 4); + (const uint8_t *)(src + std::size(src) - 1), 4); EXPECT_STREQ(result, (const char *)dest); } @@ -63,9 +62,9 @@ TEST(ByteReverse, D) { static const char src[] = "1234567890"; static const char result[] = "5432109876"; - static uint8_t dest[ARRAY_SIZE(src)]; + static uint8_t dest[std::size(src)]; reverse_bytes(dest, (const uint8_t *)src, - (const uint8_t *)(src + ARRAY_SIZE(src) - 1), 5); + (const uint8_t *)(src + std::size(src) - 1), 5); EXPECT_STREQ(result, (const char *)dest); } diff --git a/test/test_pcm_interleave.cxx b/test/test_pcm_interleave.cxx index 8d52b884b..12f0ac4b2 100644 --- a/test/test_pcm_interleave.cxx +++ b/test/test_pcm_interleave.cxx @@ -18,7 +18,6 @@ */ #include "pcm/Interleave.hxx" -#include "util/Macros.hxx" #include <gtest/gtest.h> @@ -33,15 +32,15 @@ TestInterleaveN() static constexpr T src3[] = { 3, 6, 9 }; static constexpr const T *src_all[] = { src1, src2, src3 }; - static constexpr size_t n_frames = ARRAY_SIZE(src1); - static constexpr unsigned channels = ARRAY_SIZE(src_all); + static constexpr size_t n_frames = std::size(src1); + static constexpr unsigned channels = std::size(src_all); static const ConstBuffer<const void *> src((const void *const*)src_all, channels); static constexpr T poison = T(0xdeadbeef); T dest[n_frames * channels + 1]; - std::fill_n(dest, ARRAY_SIZE(dest), poison); + std::fill_n(dest, std::size(dest), poison); PcmInterleave(dest, src, n_frames, sizeof(T)); @@ -75,15 +74,15 @@ TEST(PcmTest, Interleave24) static constexpr T src3[] = { 13, 14, 15, 16, 17, 18 }; static constexpr const T *src_all[] = { src1, src2, src3 }; - static constexpr size_t n_frames = ARRAY_SIZE(src1) / 3; - static constexpr unsigned channels = ARRAY_SIZE(src_all); + static constexpr size_t n_frames = std::size(src1) / 3; + static constexpr unsigned channels = std::size(src_all); static const ConstBuffer<const void *> src((const void *const*)src_all, channels); static constexpr T poison = 0xff; T dest[n_frames * channels * 3 + 1]; - std::fill_n(dest, ARRAY_SIZE(dest), poison); + std::fill_n(dest, std::size(dest), poison); PcmInterleave(dest, src, n_frames, 3); diff --git a/test/test_queue_priority.cxx b/test/test_queue_priority.cxx index 1d65193b3..b6eaf800a 100644 --- a/test/test_queue_priority.cxx +++ b/test/test_queue_priority.cxx @@ -1,9 +1,10 @@ #include "queue/Queue.hxx" #include "song/DetachedSong.hxx" -#include "util/Macros.hxx" #include <gtest/gtest.h> +#include <iterator> + Tag::Tag(const Tag &) noexcept {} void Tag::Clear() noexcept {} @@ -46,10 +47,10 @@ TEST(QueuePriority, Priority) Queue queue(32); - for (unsigned i = 0; i < ARRAY_SIZE(songs); ++i) + for (unsigned i = 0; i < std::size(songs); ++i) queue.Append(DetachedSong(songs[i]), 0); - EXPECT_EQ(unsigned(ARRAY_SIZE(songs)), queue.GetLength()); + EXPECT_EQ(unsigned(std::size(songs)), queue.GetLength()); /* priority=10 for 4 items */ @@ -67,7 +68,7 @@ TEST(QueuePriority, Priority) assert(queue.PositionToOrder(i) < 4); } - for (unsigned i = 8; i < ARRAY_SIZE(songs); ++i) { + for (unsigned i = 8; i < std::size(songs); ++i) { assert(queue.PositionToOrder(i) >= 4); } |