Files
.github
android
build
doc
python
src
systemd
test
net
ConfigGlue.hxx
ContainerScan.cxx
DumpDatabase.cxx
DumpDecoderClient.cxx
DumpDecoderClient.hxx
MakeTag.hxx
NullMixerListener.hxx
ParseSongFilter.cxx
ReadApeTags.cxx
RunChromaprint.cxx
RunCurl.cxx
ShutdownHandler.cxx
ShutdownHandler.hxx
TestAudioFormat.cxx
TestCircularBuffer.cxx
TestDivideString.cxx
TestFs.cxx
TestISO8601.cxx
TestIcu.cxx
TestLookupFile.cxx
TestMimeType.cxx
TestRewindInputStream.cxx
TestSplitString.cxx
TestTagSongFilter.cxx
TestUriExtract.cxx
TestUriQueryParser.cxx
TestUriRelative.cxx
TestUriUtil.cxx
WriteFile.cxx
dump_playlist.cxx
dump_rva2.cxx
dump_text_file.cxx
meson.build
read_conf.cxx
read_mixer.cxx
read_tags.cxx
run_avahi.cxx
run_convert.cxx
run_decoder.cxx
run_encoder.cxx
run_filter.cxx
run_gunzip.cxx
run_gzip.cxx
run_inotify.cxx
run_input.cxx
run_neighbor_explorer.cxx
run_normalize.cxx
run_output.cxx
run_resolver.cxx
run_storage.cxx
software_volume.cxx
test_archive_bzip2.sh
test_archive_iso9660.sh
test_archive_zzip.sh
test_byte_reverse.cxx
test_icy_parser.cxx
test_mixramp.cxx
test_pcm_channels.cxx
test_pcm_dither.cxx
test_pcm_export.cxx
test_pcm_format.cxx
test_pcm_interleave.cxx
test_pcm_mix.cxx
test_pcm_pack.cxx
test_pcm_util.hxx
test_pcm_volume.cxx
test_protocol.cxx
test_queue_priority.cxx
test_translate_song.cxx
test_vorbis_encoder.cxx
visit_archive.cxx
win32
.gitignore
.travis.yml
AUTHORS
COPYING
NEWS
README.md
meson.build
meson_options.txt
mpd.svg
valgrind.suppressions
mpd/test/test_byte_reverse.cxx
2020-01-18 19:23:49 +01:00

71 lines
2.1 KiB
C++

/*
* Copyright 2003-2020 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "util/ByteReverse.hxx"
#include "util/Compiler.h"
#include <gtest/gtest.h>
#include <string.h>
#include <stdlib.h>
TEST(ByteReverse, A)
{
alignas(uint16_t) static const char src[] = "123456";
static const char result[] = "214365";
alignas(uint16_t)static uint8_t dest[std::size(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + std::size(src) - 1), 2);
EXPECT_STREQ(result, (const char *)dest);
}
TEST(ByteReverse, B)
{
static const char src[] = "123456";
static const char result[] = "321654";
static uint8_t dest[std::size(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + std::size(src) - 1), 3);
EXPECT_STREQ(result, (const char *)dest);
}
TEST(ByteReverse, C)
{
alignas(uint32_t) static const char src[] = "12345678";
static const char result[] = "43218765";
alignas(uint32_t) static uint8_t dest[std::size(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + std::size(src) - 1), 4);
EXPECT_STREQ(result, (const char *)dest);
}
TEST(ByteReverse, D)
{
static const char src[] = "1234567890";
static const char result[] = "5432109876";
static uint8_t dest[std::size(src)];
reverse_bytes(dest, (const uint8_t *)src,
(const uint8_t *)(src + std::size(src) - 1), 5);
EXPECT_STREQ(result, (const char *)dest);
}