util/Macros: replace with std::size() (C++17)

This commit is contained in:
Max Kellermann
2019-08-03 13:10:49 +02:00
parent d305f187d5
commit cde6c46d2f
27 changed files with 84 additions and 115 deletions

View File

@@ -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)

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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);
}