Commit cde6c46d authored by Max Kellermann's avatar Max Kellermann

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

parent d305f187
......@@ -36,7 +36,6 @@
#include "fs/Traits.hxx"
#include "fs/FileSystem.hxx"
#include "fs/StandardDirectory.hxx"
#include "util/Macros.hxx"
#include "util/Domain.hxx"
#include "util/OptionDef.hxx"
#include "util/OptionParser.hxx"
......@@ -385,7 +384,7 @@ ParseCommandLine(int argc, char **argv, struct options &options,
#ifdef _UNICODE
wchar_t buffer[MAX_PATH];
auto result = MultiByteToWideChar(CP_ACP, 0, config_file, -1,
buffer, ARRAY_SIZE(buffer));
buffer, std::size(buffer));
if (result <= 0)
throw MakeLastError("MultiByteToWideChar() failed");
......
......@@ -24,7 +24,8 @@
#include "plugins/Bzip2ArchivePlugin.hxx"
#include "plugins/Iso9660ArchivePlugin.hxx"
#include "plugins/ZzipArchivePlugin.hxx"
#include "util/Macros.hxx"
#include <iterator>
#include <assert.h>
#include <string.h>
......@@ -43,7 +44,7 @@ const ArchivePlugin *const archive_plugins[] = {
};
/** which plugins have been initialized successfully? */
static bool archive_plugins_enabled[ARRAY_SIZE(archive_plugins) - 1];
static bool archive_plugins_enabled[std::size(archive_plugins) - 1];
#define archive_plugins_for_each_enabled(plugin) \
archive_plugins_for_each(plugin) \
......
......@@ -41,7 +41,6 @@
#include "Instance.hxx"
#include "client/Client.hxx"
#include "client/Response.hxx"
#include "util/Macros.hxx"
#include "util/Tokenizer.hxx"
#include "util/StringAPI.hxx"
......@@ -49,6 +48,8 @@
#include "StickerCommands.hxx"
#endif
#include <iterator>
#include <assert.h>
#include <string.h>
......@@ -208,7 +209,7 @@ static constexpr struct command commands[] = {
{ "volume", PERMISSION_CONTROL, 1, 1, handle_volume },
};
static constexpr unsigned num_commands = ARRAY_SIZE(commands);
static constexpr unsigned num_commands = std::size(commands);
static bool
command_available(gcc_unused const Partition &partition,
......
......@@ -19,7 +19,8 @@
#include "Templates.hxx"
#include "Option.hxx"
#include "util/Macros.hxx"
#include <iterator>
#include <string.h>
......@@ -77,7 +78,7 @@ const ConfigTemplate config_param_templates[] = {
};
static constexpr unsigned n_config_param_templates =
ARRAY_SIZE(config_param_templates);
std::size(config_param_templates);
static_assert(n_config_param_templates == unsigned(ConfigOption::MAX),
"Wrong number of config_param_templates");
......@@ -95,7 +96,7 @@ const ConfigTemplate config_block_templates[] = {
};
static constexpr unsigned n_config_block_templates =
ARRAY_SIZE(config_block_templates);
std::size(config_block_templates);
static_assert(n_config_block_templates == unsigned(ConfigBlockOption::MAX),
"Wrong number of config_block_templates");
......
......@@ -46,9 +46,10 @@
#include "plugins/MpcdecDecoderPlugin.hxx"
#include "plugins/FluidsynthDecoderPlugin.hxx"
#include "plugins/SidplayDecoderPlugin.hxx"
#include "util/Macros.hxx"
#include "util/RuntimeError.hxx"
#include <iterator>
#include <string.h>
const struct DecoderPlugin *const decoder_plugins[] = {
......@@ -117,7 +118,7 @@ const struct DecoderPlugin *const decoder_plugins[] = {
};
static constexpr unsigned num_decoder_plugins =
ARRAY_SIZE(decoder_plugins) - 1;
std::size(decoder_plugins) - 1;
/** which plugins have been initialized successfully? */
bool decoder_plugins_enabled[num_decoder_plugins];
......
......@@ -23,7 +23,6 @@
#include "CheckAudioFormat.hxx"
#include "fs/Path.hxx"
#include "util/Domain.hxx"
#include "util/Macros.hxx"
#include "util/StringView.hxx"
#include "Log.hxx"
......@@ -71,7 +70,7 @@ adplug_file_decode(DecoderClient &client, Path path_fs)
break;
int16_t buffer[2048];
constexpr unsigned frames_per_buffer = ARRAY_SIZE(buffer) / 2;
constexpr unsigned frames_per_buffer = std::size(buffer) / 2;
opl.update(buffer, frames_per_buffer);
cmd = client.SubmitData(nullptr,
buffer, sizeof(buffer),
......
......@@ -22,7 +22,6 @@
#include "CheckAudioFormat.hxx"
#include "fs/Path.hxx"
#include "util/Domain.hxx"
#include "util/Macros.hxx"
#include "Log.hxx"
#include <fluidsynth.h>
......@@ -169,7 +168,7 @@ fluidsynth_file_decode(DecoderClient &client, Path path_fs)
DecoderCommand cmd;
while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING) {
int16_t buffer[2048];
const unsigned max_frames = ARRAY_SIZE(buffer) / 2;
const unsigned max_frames = std::size(buffer) / 2;
/* read samples from fluidsynth and send them to the
MPD core */
......
......@@ -24,13 +24,14 @@
#include "pcm/Traits.hxx"
#include "tag/Handler.hxx"
#include "util/Domain.hxx"
#include "util/Macros.hxx"
#include "util/Clamp.hxx"
#include "util/ScopeExit.hxx"
#include "Log.hxx"
#include <mpc/mpcdec.h>
#include <iterator>
#include <math.h>
struct mpc_decoder_data {
......@@ -216,7 +217,7 @@ mpcdec_decode(DecoderClient &client, InputStream &is)
mpc_uint32_t ret = frame.samples;
ret *= info.channels;
MpcdecSampleTraits::value_type chunk[ARRAY_SIZE(sample_buffer)];
MpcdecSampleTraits::value_type chunk[std::size(sample_buffer)];
mpc_to_mpd_buffer(chunk, sample_buffer, ret);
long bit_rate = unsigned(frame.bits) * audio_format.sample_rate
......
......@@ -29,7 +29,6 @@
#include "fs/io/FileReader.hxx"
#include "util/RuntimeError.hxx"
#endif
#include "util/Macros.hxx"
#include "util/StringFormat.hxx"
#include "util/StringView.hxx"
#include "util/Domain.hxx"
......@@ -52,6 +51,8 @@
#include <sidplay/utils/SidDatabase.h>
#endif
#include <iterator>
#include <string.h>
#include <stdio.h>
......@@ -392,7 +393,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
do {
short buffer[4096];
const auto result = player.play(buffer, ARRAY_SIZE(buffer));
const auto result = player.play(buffer, std::size(buffer));
if (result <= 0)
break;
......@@ -421,7 +422,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
/* ignore data until target time is reached */
while (data_time < target_time &&
player.play(buffer, ARRAY_SIZE(buffer)) > 0)
player.play(buffer, std::size(buffer)) > 0)
data_time = player.time();
client.CommandFinished();
......
......@@ -29,7 +29,6 @@
#include "input/Reader.hxx"
#include "OggCodec.hxx"
#include "pcm/Interleave.hxx"
#include "util/Macros.hxx"
#include "util/ScopeExit.hxx"
#include "CheckAudioFormat.hxx"
#include "tag/Handler.hxx"
......@@ -41,6 +40,7 @@
#include <tremor/ivorbiscodec.h>
#endif /* HAVE_TREMOR */
#include <iterator>
#include <stdexcept>
class VorbisDecoder final : public OggDecoder {
......@@ -209,7 +209,7 @@ VorbisDecoder::SubmitSomePcm()
out_sample_t buffer[4096];
const unsigned channels = audio_format.channels;
size_t max_frames = ARRAY_SIZE(buffer) / channels;
size_t max_frames = std::size(buffer) / channels;
size_t n_frames = std::min(size_t(result), max_frames);
#ifdef HAVE_TREMOR
......
......@@ -24,7 +24,6 @@
#include "CheckAudioFormat.hxx"
#include "tag/Handler.hxx"
#include "fs/Path.hxx"
#include "util/Macros.hxx"
#include "util/Alloc.hxx"
#include "util/ScopeExit.hxx"
#include "util/RuntimeError.hxx"
......@@ -32,6 +31,7 @@
#include <wavpack/wavpack.h>
#include <algorithm>
#include <iterator>
#include <memory>
#include <cstdlib>
......@@ -235,7 +235,7 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek)
/* wavpack gives us all kind of samples in a 32-bit space */
int32_t chunk[1024];
const uint32_t samples_requested = ARRAY_SIZE(chunk) /
const uint32_t samples_requested = std::size(chunk) /
audio_format.channels;
DecoderCommand cmd = client.GetCommand();
......
......@@ -21,7 +21,6 @@
#define MPD_FS_NARROW_PATH_HXX
#include "Path.hxx"
#include "util/Macros.hxx"
#ifdef _UNICODE
#include "lib/icu/Win32.hxx"
......
......@@ -19,7 +19,6 @@
#include "Registry.hxx"
#include "InputPlugin.hxx"
#include "util/Macros.hxx"
#include "plugins/TidalInputPlugin.hxx"
#include "plugins/QobuzInputPlugin.hxx"
#include "config.h"
......@@ -83,7 +82,7 @@ const InputPlugin *const input_plugins[] = {
nullptr
};
bool input_plugins_enabled[ARRAY_SIZE(input_plugins) - 1];
bool input_plugins_enabled[std::size(input_plugins) - 1];
bool
HasRemoteTagScanner(const char *uri) noexcept
......
......@@ -18,13 +18,13 @@
*/
#include "Converter.hxx"
#include "util/Macros.hxx"
#include "util/AllocatedString.hxx"
#include "util/AllocatedArray.hxx"
#include "util/ConstBuffer.hxx"
#include "util/FormatString.hxx"
#include "config.h"
#include <iterator>
#include <stdexcept>
#include <string.h>
......@@ -115,7 +115,7 @@ IcuConverter::ToUTF8(const char *s) const
UErrorCode code = U_ZERO_ERROR;
ucnv_toUnicode(converter, &target, buffer + ARRAY_SIZE(buffer),
ucnv_toUnicode(converter, &target, buffer + std::size(buffer),
&source, source + strlen(source),
nullptr, true, &code);
if (code != U_ZERO_ERROR)
......@@ -144,7 +144,7 @@ IcuConverter::FromUTF8(const char *s) const
const UChar *source = u.begin();
UErrorCode code = U_ZERO_ERROR;
ucnv_fromUnicode(converter, &target, buffer + ARRAY_SIZE(buffer),
ucnv_fromUnicode(converter, &target, buffer + std::size(buffer),
&source, u.end(),
nullptr, true, &code);
......
......@@ -18,7 +18,8 @@
*/
#include "SocketError.hxx"
#include "util/Macros.hxx"
#include <iterator>
#include <string.h>
......@@ -27,7 +28,7 @@
SocketErrorMessage::SocketErrorMessage(socket_error_t code) noexcept
{
#ifdef _UNICODE
wchar_t buffer[ARRAY_SIZE(msg)];
wchar_t buffer[std::size(msg)];
#else
auto *buffer = msg;
#endif
......@@ -36,7 +37,7 @@ SocketErrorMessage::SocketErrorMessage(socket_error_t code) noexcept
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_MAX_WIDTH_MASK,
nullptr, code, 0,
buffer, ARRAY_SIZE(msg), nullptr);
buffer, std::size(msg), nullptr);
if (nbytes == 0) {
strcpy(msg, "Unknown error");
return;
......@@ -44,7 +45,7 @@ SocketErrorMessage::SocketErrorMessage(socket_error_t code) noexcept
#ifdef _UNICODE
auto length = WideCharToMultiByte(CP_UTF8, 0, buffer, -1,
msg, ARRAY_SIZE(msg),
msg, std::size(msg),
nullptr, nullptr);
if (length <= 0) {
strcpy(msg, "WideCharToMultiByte() error");
......
......@@ -24,10 +24,10 @@
#include "system/Error.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Domain.hxx"
#include "util/Macros.hxx"
#include "util/ByteOrder.hxx"
#include "Log.hxx"
#include <iterator>
#include <stdexcept>
#include <sys/stat.h>
......@@ -168,7 +168,7 @@ static const char *const default_devices[] = { "/dev/sound/dsp", "/dev/dsp" };
static bool
oss_output_test_default_device() noexcept
{
for (int i = ARRAY_SIZE(default_devices); --i >= 0; ) {
for (int i = std::size(default_devices); --i >= 0; ) {
UniqueFileDescriptor fd;
if (fd.Open(default_devices[i], O_WRONLY, 0))
return true;
......@@ -184,16 +184,16 @@ oss_output_test_default_device() noexcept
static OssOutput *
oss_open_default()
{
int err[ARRAY_SIZE(default_devices)];
enum oss_stat ret[ARRAY_SIZE(default_devices)];
int err[std::size(default_devices)];
enum oss_stat ret[std::size(default_devices)];
for (int i = ARRAY_SIZE(default_devices); --i >= 0; ) {
for (int i = std::size(default_devices); --i >= 0; ) {
ret[i] = oss_stat_device(default_devices[i], &err[i]);
if (ret[i] == OSS_STAT_NO_ERROR)
return new OssOutput(default_devices[i]);
}
for (int i = ARRAY_SIZE(default_devices); --i >= 0; ) {
for (int i = std::size(default_devices); --i >= 0; ) {
const char *dev = default_devices[i];
switch(ret[i]) {
case OSS_STAT_NO_ERROR:
......
......@@ -23,10 +23,10 @@
#include "mixer/MixerList.hxx"
#include "fs/AllocatedPath.hxx"
#include "util/RuntimeError.hxx"
#include "util/Macros.hxx"
#include "util/StringCompare.hxx"
#include <array>
#include <iterator>
#include <stdlib.h>
#include <string.h>
......@@ -86,7 +86,7 @@ MakeWaveOutError(MMRESULT result, const char *prefix)
{
char buffer[256];
if (waveOutGetErrorTextA(result, buffer,
ARRAY_SIZE(buffer)) == MMSYSERR_NOERROR)
std::size(buffer)) == MMSYSERR_NOERROR)
return FormatRuntimeError("%s: %s", prefix, buffer);
else
return std::runtime_error(prefix);
......
......@@ -22,7 +22,8 @@
#include "util/FormatString.hxx"
#include "util/AllocatedString.hxx"
#include "util/TruncateString.hxx"
#include "util/Macros.hxx"
#include <iterator>
#include <string.h>
......@@ -97,7 +98,7 @@ icy_server_metadata_page(const Tag &tag, const TagType *types) noexcept
// Length + Metadata - "StreamTitle='';StreamUrl='';" = 4081 - 28
char stream_title[(1 + 255 - 28) * 16];
char *p = stream_title, *const end = stream_title + ARRAY_SIZE(stream_title);
char *p = stream_title, *const end = stream_title + std::size(stream_title);
stream_title[0] = '\0';
while (p < end && item <= last_item) {
......
......@@ -25,7 +25,6 @@
#include "../../OutputAPI.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "util/Macros.hxx"
#include "util/Domain.hxx"
#include "util/ByteOrder.hxx"
#include "Log.hxx"
......@@ -33,6 +32,7 @@
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
#include <iterator>
#include <stdexcept>
class SlesOutput final : AudioOutput {
......@@ -212,7 +212,7 @@ SlesOutput::Open(AudioFormat &audio_format)
};
result = engine.CreateAudioPlayer(&_object, &audioSrc, &audioSnk,
ARRAY_SIZE(ids2), ids2, req2);
std::size(ids2), ids2, req2);
if (result != SL_RESULT_SUCCESS) {
mix_object.Destroy();
engine_object.Destroy();
......
......@@ -36,10 +36,11 @@
#include "util/UriUtil.hxx"
#include "util/StringUtil.hxx"
#include "util/StringView.hxx"
#include "util/Macros.hxx"
#include "config/Data.hxx"
#include "config/Block.hxx"
#include <iterator>
#include <assert.h>
const struct playlist_plugin *const playlist_plugins[] = {
......@@ -65,7 +66,7 @@ const struct playlist_plugin *const playlist_plugins[] = {
};
static constexpr unsigned n_playlist_plugins =
ARRAY_SIZE(playlist_plugins) - 1;
std::size(playlist_plugins) - 1;
/** which plugins have been initialized successfully? */
static bool playlist_plugins_enabled[n_playlist_plugins];
......
......@@ -22,10 +22,11 @@
#include "lib/sqlite/Util.hxx"
#include "fs/Path.hxx"
#include "Idle.hxx"
#include "util/Macros.hxx"
#include "util/StringCompare.hxx"
#include "util/ScopeExit.hxx"
#include <iterator>
#include <assert.h>
using namespace Sqlite;
......@@ -98,7 +99,7 @@ StickerDatabase::StickerDatabase(Path path)
/* prepare the statements we're going to use */
for (unsigned i = 0; i < ARRAY_SIZE(sticker_sql); ++i) {
for (unsigned i = 0; i < std::size(sticker_sql); ++i) {
assert(sticker_sql[i] != nullptr);
stmt[i] = Prepare(db, sticker_sql[i]);
......@@ -109,7 +110,7 @@ StickerDatabase::~StickerDatabase() noexcept
{
assert(db != nullptr);
for (unsigned i = 0; i < ARRAY_SIZE(stmt); ++i) {
for (unsigned i = 0; i < std::size(stmt); ++i) {
assert(stmt[i] != nullptr);
sqlite3_finalize(stmt[i]);
......
/*
* Copyright (C) 2010-2013 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MACROS_HPP
#define MACROS_HPP
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
......@@ -30,15 +30,15 @@
#include "NumberParser.hxx"
#include "StringView.hxx"
#include "Macros.hxx"
#include <algorithm>
#include <iterator>
int64_t
ParseInt64(StringView s, const char **endptr_r, int base) noexcept
{
char buffer[32];
*std::copy_n(s.data, std::min(s.size, ARRAY_SIZE(buffer) - 1),
*std::copy_n(s.data, std::min(s.size, std::size(buffer) - 1),
buffer) = 0;
char *endptr;
......
......@@ -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)
......
......@@ -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);
}
......@@ -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);
......
#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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment