aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/.gitignore1
-rw-r--r--test/DivideStringTest.hxx54
-rw-r--r--test/DumpDatabase.cxx27
-rw-r--r--test/FakeDecoderAPI.cxx9
-rw-r--r--test/FakeDecoderAPI.hxx2
-rw-r--r--test/FakeReplayGainConfig.cxx2
-rw-r--r--test/ReadApeTags.cxx64
-rw-r--r--test/ScopeIOThread.hxx2
-rw-r--r--test/ShutdownHandler.cxx2
-rw-r--r--test/ShutdownHandler.hxx2
-rw-r--r--test/SplitStringTest.hxx65
-rw-r--r--test/TestCircularBuffer.hxx7
-rw-r--r--test/TestFs.cxx107
-rw-r--r--test/TestIcu.cxx86
-rw-r--r--test/UriUtilTest.hxx66
-rw-r--r--test/WriteFile.cxx78
-rw-r--r--test/dump_playlist.cxx14
-rw-r--r--test/dump_rva2.cxx2
-rw-r--r--test/dump_text_file.cxx15
-rw-r--r--test/read_conf.cxx6
-rw-r--r--test/read_mixer.cxx16
-rw-r--r--test/read_tags.cxx12
-rw-r--r--test/run_avahi.cxx2
-rw-r--r--test/run_convert.cxx11
-rw-r--r--test/run_decoder.cxx13
-rw-r--r--test/run_encoder.cxx48
-rw-r--r--test/run_filter.cxx21
-rw-r--r--test/run_gunzip.cxx2
-rw-r--r--test/run_gzip.cxx2
-rw-r--r--test/run_inotify.cxx2
-rw-r--r--test/run_input.cxx15
-rw-r--r--test/run_neighbor_explorer.cxx2
-rw-r--r--test/run_normalize.cxx3
-rw-r--r--test/run_output.cxx21
-rw-r--r--test/run_resolver.cxx8
-rw-r--r--test/run_storage.cxx22
-rw-r--r--test/software_volume.cxx3
-rw-r--r--test/stdbin.h29
-rw-r--r--test/test_byte_reverse.cxx2
-rw-r--r--test/test_mixramp.cxx2
-rw-r--r--test/test_pcm_all.hxx19
-rw-r--r--test/test_pcm_channels.cxx2
-rw-r--r--test/test_pcm_dither.cxx2
-rw-r--r--test/test_pcm_export.cxx2
-rw-r--r--test/test_pcm_format.cxx2
-rw-r--r--test/test_pcm_interleave.cxx126
-rw-r--r--test/test_pcm_main.cxx3
-rw-r--r--test/test_pcm_mix.cxx2
-rw-r--r--test/test_pcm_pack.cxx2
-rw-r--r--test/test_pcm_util.hxx4
-rw-r--r--test/test_pcm_volume.cxx2
-rw-r--r--test/test_protocol.cxx37
-rw-r--r--test/test_translate_song.cxx6
-rw-r--r--test/test_util.cxx62
-rw-r--r--test/test_vorbis_encoder.cxx62
-rw-r--r--test/visit_archive.cxx15
56 files changed, 830 insertions, 365 deletions
diff --git a/test/.gitignore b/test/.gitignore
index 132ce5fcf..a411aa32e 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1 +1,2 @@
/run_neighbor_explorer
+/ReadApeTags
diff --git a/test/DivideStringTest.hxx b/test/DivideStringTest.hxx
new file mode 100644
index 000000000..f6c01bdde
--- /dev/null
+++ b/test/DivideStringTest.hxx
@@ -0,0 +1,54 @@
+/*
+ * Unit tests for src/util/
+ */
+
+#include "check.h"
+#include "util/DivideString.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+
+class DivideStringTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(DivideStringTest);
+ CPPUNIT_TEST(TestBasic);
+ CPPUNIT_TEST(TestEmpty);
+ CPPUNIT_TEST(TestFail);
+ CPPUNIT_TEST(TestStrip);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestBasic() {
+ constexpr char input[] = "foo.bar";
+ const DivideString ds(input, '.');
+ CPPUNIT_ASSERT(ds.IsDefined());
+ CPPUNIT_ASSERT(!ds.IsEmpty());
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo"));
+ CPPUNIT_ASSERT_EQUAL(input + 4, ds.GetSecond());
+ }
+
+ void TestEmpty() {
+ constexpr char input[] = ".bar";
+ const DivideString ds(input, '.');
+ CPPUNIT_ASSERT(ds.IsDefined());
+ CPPUNIT_ASSERT(ds.IsEmpty());
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), ""));
+ CPPUNIT_ASSERT_EQUAL(input + 1, ds.GetSecond());
+ }
+
+ void TestFail() {
+ constexpr char input[] = "foo!bar";
+ const DivideString ds(input, '.');
+ CPPUNIT_ASSERT(!ds.IsDefined());
+ }
+
+ void TestStrip() {
+ constexpr char input[] = " foo\t.\nbar\r";
+ const DivideString ds(input, '.', true);
+ CPPUNIT_ASSERT(ds.IsDefined());
+ CPPUNIT_ASSERT(!ds.IsEmpty());
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo"));
+ CPPUNIT_ASSERT_EQUAL(input + 7, ds.GetSecond());
+ }
+};
diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx
index 07f342319..4f00006c7 100644
--- a/test/DumpDatabase.cxx
+++ b/test/DumpDatabase.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -27,16 +27,13 @@
#include "db/LightSong.hxx"
#include "db/PlaylistVector.hxx"
#include "config/ConfigGlobal.hxx"
-#include "config/ConfigData.hxx"
+#include "config/Param.hxx"
+#include "config/Block.hxx"
#include "tag/TagConfig.hxx"
#include "fs/Path.hxx"
#include "event/Loop.hxx"
#include "util/Error.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <iostream>
using std::cout;
using std::cerr;
@@ -44,7 +41,7 @@ using std::endl;
#include <stdlib.h>
-#ifdef HAVE_LIBUPNP
+#ifdef ENABLE_UPNP
#include "input/InputStream.hxx"
size_t
InputStream::LockRead(void *, size_t, Error &)
@@ -107,14 +104,6 @@ main(int argc, char **argv)
return EXIT_FAILURE;
}
- /* initialize GLib */
-
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(nullptr);
-#endif
-#endif
-
/* initialize MPD */
config_global_init();
@@ -132,13 +121,13 @@ main(int argc, char **argv)
/* do it */
- const struct config_param *path = config_get_param(CONF_DB_FILE);
- config_param param("database", path != nullptr ? path->line : -1);
+ const auto *path = config_get_param(ConfigOption::DB_FILE);
+ ConfigBlock block(path != nullptr ? path->line : -1);
if (path != nullptr)
- param.AddBlockParam("path", path->value.c_str(), path->line);
+ block.AddBlockParam("path", path->value.c_str(), path->line);
Database *db = plugin->create(event_loop, database_listener,
- param, error);
+ block, error);
if (db == nullptr) {
cerr << error.GetMessage() << endl;
diff --git a/test/FakeDecoderAPI.cxx b/test/FakeDecoderAPI.cxx
index 3c7453a4f..49f7a7a5e 100644
--- a/test/FakeDecoderAPI.cxx
+++ b/test/FakeDecoderAPI.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -145,8 +145,13 @@ decoder_data(gcc_unused Decoder &decoder,
DecoderCommand
decoder_tag(gcc_unused Decoder &decoder,
gcc_unused InputStream *is,
- gcc_unused Tag &&tag)
+ Tag &&tag)
{
+ fprintf(stderr, "TAG: duration=%f\n", tag.duration.ToDoubleS());
+
+ for (const auto &i : tag)
+ fprintf(stderr, " %s=%s\n", tag_item_names[i.type], i.value);
+
return DecoderCommand::NONE;
}
diff --git a/test/FakeDecoderAPI.hxx b/test/FakeDecoderAPI.hxx
index 6f1933977..20bdee799 100644
--- a/test/FakeDecoderAPI.hxx
+++ b/test/FakeDecoderAPI.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/FakeReplayGainConfig.cxx b/test/FakeReplayGainConfig.cxx
index 0cb282050..a95f3e888 100644
--- a/test/FakeReplayGainConfig.cxx
+++ b/test/FakeReplayGainConfig.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/ReadApeTags.cxx b/test/ReadApeTags.cxx
new file mode 100644
index 000000000..a0a0e652e
--- /dev/null
+++ b/test/ReadApeTags.cxx
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2003-2015 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 "config.h"
+#include "tag/ApeLoader.hxx"
+#include "fs/Path.hxx"
+#include "util/StringView.hxx"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+static bool
+MyApeTagCallback(gcc_unused unsigned long flags,
+ const char *key, StringView value)
+{
+ if ((flags & (0x3 << 1)) == 0)
+ // UTF-8
+ printf("\"%s\"=\"%.*s\"\n", key, (int)value.size, value.data);
+ else
+ printf("\"%s\"=0x%lx\n", key, flags);
+ return true;
+}
+
+int
+main(int argc, char **argv)
+{
+#ifdef HAVE_LOCALE_H
+ /* initialize locale */
+ setlocale(LC_CTYPE,"");
+#endif
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: ReadApeTags FILE\n");
+ return EXIT_FAILURE;
+ }
+
+ const Path path = Path::FromFS(argv[1]);
+ if (!tag_ape_scan(path, MyApeTagCallback)) {
+ fprintf(stderr, "error\n");
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/test/ScopeIOThread.hxx b/test/ScopeIOThread.hxx
index 06d27a4b8..1eb16912f 100644
--- a/test/ScopeIOThread.hxx
+++ b/test/ScopeIOThread.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/ShutdownHandler.cxx b/test/ShutdownHandler.cxx
index c04834444..b55b9ff6a 100644
--- a/test/ShutdownHandler.cxx
+++ b/test/ShutdownHandler.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/ShutdownHandler.hxx b/test/ShutdownHandler.hxx
index 9db88a1b4..e808bbeb1 100644
--- a/test/ShutdownHandler.hxx
+++ b/test/ShutdownHandler.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/SplitStringTest.hxx b/test/SplitStringTest.hxx
new file mode 100644
index 000000000..87ed385ea
--- /dev/null
+++ b/test/SplitStringTest.hxx
@@ -0,0 +1,65 @@
+/*
+ * Unit tests for src/util/
+ */
+
+#include "check.h"
+#include "util/SplitString.hxx"
+#include "util/Macros.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+
+class SplitStringTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(SplitStringTest);
+ CPPUNIT_TEST(TestBasic);
+ CPPUNIT_TEST(TestStrip);
+ CPPUNIT_TEST(TestNoStrip);
+ CPPUNIT_TEST(TestEmpty);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestBasic() {
+ constexpr char input[] = "foo.bar";
+ const char *const output[] = { "foo", "bar" };
+ size_t i = 0;
+ for (auto p : SplitString(input, '.')) {
+ CPPUNIT_ASSERT(i < ARRAY_SIZE(output));
+ CPPUNIT_ASSERT(p == output[i]);
+ ++i;
+ }
+
+ CPPUNIT_ASSERT_EQUAL(ARRAY_SIZE(output), i);
+ }
+
+ void TestStrip() {
+ constexpr char input[] = " foo\t.\r\nbar\r\n2";
+ const char *const output[] = { "foo", "bar\r\n2" };
+ size_t i = 0;
+ for (auto p : SplitString(input, '.')) {
+ CPPUNIT_ASSERT(i < ARRAY_SIZE(output));
+ CPPUNIT_ASSERT(p == output[i]);
+ ++i;
+ }
+
+ CPPUNIT_ASSERT_EQUAL(ARRAY_SIZE(output), i);
+ }
+
+ void TestNoStrip() {
+ constexpr char input[] = " foo\t.\r\nbar\r\n2";
+ const char *const output[] = { " foo\t", "\r\nbar\r\n2" };
+ size_t i = 0;
+ for (auto p : SplitString(input, '.', false)) {
+ CPPUNIT_ASSERT(i < ARRAY_SIZE(output));
+ CPPUNIT_ASSERT(p == output[i]);
+ ++i;
+ }
+
+ CPPUNIT_ASSERT_EQUAL(ARRAY_SIZE(output), i);
+ }
+
+ void TestEmpty() {
+ CPPUNIT_ASSERT(SplitString("", '.').empty());
+ }
+};
diff --git a/test/TestCircularBuffer.hxx b/test/TestCircularBuffer.hxx
index c808d85dc..4283be45b 100644
--- a/test/TestCircularBuffer.hxx
+++ b/test/TestCircularBuffer.hxx
@@ -2,17 +2,12 @@
* Unit tests for class CircularBuffer.
*/
-#include "config.h"
+#include "check.h"
#include "util/CircularBuffer.hxx"
#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
-#include <string.h>
-#include <stdlib.h>
-
class TestCircularBuffer : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(TestCircularBuffer);
CPPUNIT_TEST(TestIt);
diff --git a/test/TestFs.cxx b/test/TestFs.cxx
new file mode 100644
index 000000000..aa840f848
--- /dev/null
+++ b/test/TestFs.cxx
@@ -0,0 +1,107 @@
+/*
+ * Unit tests for src/fs/
+ */
+
+#include "config.h"
+#include "fs/Glob.hxx"
+#include "util/Error.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef HAVE_CLASS_GLOB
+
+class TestGlob : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(TestGlob);
+ CPPUNIT_TEST(Basic);
+ CPPUNIT_TEST(Asterisk);
+ CPPUNIT_TEST(QuestionMark);
+ CPPUNIT_TEST(Wildcard);
+ CPPUNIT_TEST(PrefixWildcard);
+ CPPUNIT_TEST(SuffixWildcard);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void Basic() {
+ const Glob glob("foo");
+ CPPUNIT_ASSERT(glob.Check("foo"));
+ CPPUNIT_ASSERT(!glob.Check("fooo"));
+ CPPUNIT_ASSERT(!glob.Check("_foo"));
+ CPPUNIT_ASSERT(!glob.Check("a/foo"));
+ CPPUNIT_ASSERT(!glob.Check(""));
+ CPPUNIT_ASSERT(!glob.Check("*"));
+ }
+
+ void Asterisk() {
+ const Glob glob("*");
+ CPPUNIT_ASSERT(glob.Check("foo"));
+ CPPUNIT_ASSERT(glob.Check("bar"));
+ CPPUNIT_ASSERT(glob.Check("*"));
+ CPPUNIT_ASSERT(glob.Check("?"));
+ }
+
+ void QuestionMark() {
+ const Glob glob("foo?bar");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(!glob.Check("foobar"));
+ CPPUNIT_ASSERT(!glob.Check("foo__bar"));
+ }
+
+ void Wildcard() {
+ const Glob glob("foo*bar");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar"));
+ CPPUNIT_ASSERT(glob.Check("foo__bar"));
+ CPPUNIT_ASSERT(!glob.Check("_foobar"));
+ CPPUNIT_ASSERT(!glob.Check("foobar_"));
+ }
+
+ void PrefixWildcard() {
+ const Glob glob("*bar");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar"));
+ CPPUNIT_ASSERT(glob.Check("foo__bar"));
+ CPPUNIT_ASSERT(glob.Check("_foobar"));
+ CPPUNIT_ASSERT(glob.Check("bar"));
+ CPPUNIT_ASSERT(!glob.Check("foobar_"));
+ }
+
+ void SuffixWildcard() {
+ const Glob glob("foo*");
+ CPPUNIT_ASSERT(glob.Check("foo_bar"));
+ CPPUNIT_ASSERT(glob.Check("foo?bar"));
+ CPPUNIT_ASSERT(glob.Check("foo bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar"));
+ CPPUNIT_ASSERT(glob.Check("foo__bar"));
+ CPPUNIT_ASSERT(glob.Check("foobar_"));
+ CPPUNIT_ASSERT(glob.Check("foo"));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestGlob);
+
+#endif
+
+int
+main(gcc_unused int argc, gcc_unused char **argv)
+{
+#ifdef HAVE_CLASS_GLOB
+ CppUnit::TextUi::TestRunner runner;
+ auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
+#else
+ return EXIT_SUCCESS;
+#endif
+}
diff --git a/test/TestIcu.cxx b/test/TestIcu.cxx
new file mode 100644
index 000000000..484af4f22
--- /dev/null
+++ b/test/TestIcu.cxx
@@ -0,0 +1,86 @@
+/*
+ * Unit tests for src/util/
+ */
+
+#include "config.h"
+#include "lib/icu/Converter.hxx"
+#include "util/AllocatedString.hxx"
+#include "util/StringAPI.hxx"
+#include "util/Error.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef HAVE_ICU_CONVERTER
+
+static const char *const invalid_utf8[] = {
+ "\xfc",
+};
+
+struct StringPair {
+ const char *utf8, *other;
+};
+
+static constexpr StringPair latin1_tests[] = {
+ { "foo", "foo" },
+ { "\xc3\xbc", "\xfc" },
+};
+
+class TestIcuConverter : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(TestIcuConverter);
+ CPPUNIT_TEST(TestInvalidCharset);
+ CPPUNIT_TEST(TestLatin1);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestInvalidCharset() {
+ CPPUNIT_ASSERT_EQUAL((IcuConverter *)nullptr,
+ IcuConverter::Create("doesntexist",
+ IgnoreError()));
+ }
+
+ void TestLatin1() {
+ IcuConverter *const converter =
+ IcuConverter::Create("iso-8859-1", IgnoreError());
+ CPPUNIT_ASSERT(converter != nullptr);
+
+ for (const auto i : invalid_utf8) {
+ auto f = converter->FromUTF8(i);
+ CPPUNIT_ASSERT_EQUAL(true, f.IsNull());
+ }
+
+ for (const auto i : latin1_tests) {
+ auto f = converter->FromUTF8(i.utf8);
+ CPPUNIT_ASSERT_EQUAL(true, StringIsEqual(f.c_str(),
+ i.other));
+
+ auto t = converter->ToUTF8(i.other);
+ CPPUNIT_ASSERT_EQUAL(true, StringIsEqual(t.c_str(),
+ i.utf8));
+ }
+
+ delete converter;
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestIcuConverter);
+
+#endif
+
+int
+main(gcc_unused int argc, gcc_unused char **argv)
+{
+#ifdef HAVE_ICU_CONVERTER
+ CppUnit::TextUi::TestRunner runner;
+ auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
+#else
+ return EXIT_SUCCESS;
+#endif
+}
diff --git a/test/UriUtilTest.hxx b/test/UriUtilTest.hxx
new file mode 100644
index 000000000..07f52a475
--- /dev/null
+++ b/test/UriUtilTest.hxx
@@ -0,0 +1,66 @@
+/*
+ * Unit tests for src/util/
+ */
+
+#include "check.h"
+#include "util/UriUtil.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+
+class UriUtilTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(UriUtilTest);
+ CPPUNIT_TEST(TestSuffix);
+ CPPUNIT_TEST(TestRemoveAuth);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestSuffix() {
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix("/foo/bar"));
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix("/foo.jpg/bar"));
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg"),
+ "jpg"));
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo.png/bar.jpg"),
+ "jpg"));
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix(".jpg"));
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix("/foo/.jpg"));
+
+ /* the first overload does not eliminate the query
+ string */
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string"),
+ "jpg?query_string"));
+
+ /* ... but the second one does */
+ UriSuffixBuffer buffer;
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string",
+ buffer),
+ "jpg"));
+
+ /* repeat some of the above tests with the second overload */
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix("/foo/bar", buffer));
+ CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
+ uri_get_suffix("/foo.jpg/bar", buffer));
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg", buffer),
+ "jpg"));
+ }
+
+ void TestRemoveAuth() {
+ CPPUNIT_ASSERT_EQUAL(std::string(),
+ uri_remove_auth("http://www.example.com/"));
+ CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"),
+ uri_remove_auth("http://foo:bar@www.example.com/"));
+ CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"),
+ uri_remove_auth("http://foo@www.example.com/"));
+ CPPUNIT_ASSERT_EQUAL(std::string(),
+ uri_remove_auth("http://www.example.com/f:oo@bar"));
+ CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftp.example.com/"),
+ uri_remove_auth("ftp://foo:bar@ftp.example.com/"));
+ }
+};
diff --git a/test/WriteFile.cxx b/test/WriteFile.cxx
new file mode 100644
index 000000000..706ca65eb
--- /dev/null
+++ b/test/WriteFile.cxx
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2003-2015 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 "config.h"
+#include "fs/io/FileOutputStream.hxx"
+#include "util/Error.hxx"
+
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+static bool
+Copy(OutputStream &dest, int src)
+{
+ Error error;
+
+ while (true) {
+ uint8_t buffer[8192];
+ ssize_t nbytes = read(src, buffer, sizeof(buffer));
+ if (nbytes < 0) {
+ fprintf(stderr, "Failed to read from stdin: %s\n",
+ strerror(errno));
+ return false;
+ }
+
+ if (nbytes == 0)
+ return true;
+
+ if (!dest.Write(buffer, nbytes, error)) {
+ fprintf(stderr, "%s\n", error.GetMessage());
+ return false;
+ }
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ if (argc != 2) {
+ fprintf(stderr, "Usage: WriteFile PATH\n");
+ return EXIT_FAILURE;
+ }
+
+ const Path path = Path::FromFS(argv[1]);
+
+ Error error;
+ FileOutputStream fos(path, error);
+ if (!fos.IsDefined()) {
+ fprintf(stderr, "%s\n", error.GetMessage());
+ return EXIT_FAILURE;
+ }
+
+ if (!Copy(fos, STDIN_FILENO))
+ return EXIT_FAILURE;
+
+ if (!fos.Commit(error)) {
+ fprintf(stderr, "%s\n", error.GetMessage());
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index 0047ef427..4a21e2df5 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -35,10 +35,6 @@
#include "thread/Cond.hxx"
#include "Log.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <unistd.h>
#include <stdlib.h>
@@ -64,14 +60,6 @@ int main(int argc, char **argv)
const Path config_path = Path::FromFS(argv[1]);
uri = argv[2];
- /* initialize GLib */
-
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
/* initialize MPD */
config_global_init();
diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx
index fd46ee36c..fff0aa044 100644
--- a/test/dump_rva2.cxx
+++ b/test/dump_rva2.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/dump_text_file.cxx b/test/dump_text_file.cxx
index 5bfd316a5..a207b3400 100644
--- a/test/dump_text_file.cxx
+++ b/test/dump_text_file.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -23,7 +23,6 @@
#include "input/InputStream.hxx"
#include "input/TextInputStream.hxx"
#include "config/ConfigGlobal.hxx"
-#include "stdbin.h"
#include "util/Error.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
@@ -32,10 +31,6 @@
#include "archive/ArchiveList.hxx"
#endif
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
@@ -79,14 +74,6 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- /* initialize GLib */
-
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
/* initialize MPD */
config_global_init();
diff --git a/test/read_conf.cxx b/test/read_conf.cxx
index 42afdfb4b..fdf93a40d 100644
--- a/test/read_conf.cxx
+++ b/test/read_conf.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -46,8 +46,8 @@ int main(int argc, char **argv)
}
ConfigOption option = ParseConfigOptionName(name);
- const char *value = option != CONF_MAX
- ? config_get_string(option, nullptr)
+ const char *value = option != ConfigOption::MAX
+ ? config_get_string(option)
: nullptr;
int ret;
if (value != NULL) {
diff --git a/test/read_mixer.cxx b/test/read_mixer.cxx
index 83a1d26b4..2d68aab09 100644
--- a/test/read_mixer.cxx
+++ b/test/read_mixer.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -24,14 +24,10 @@
#include "pcm/Volume.hxx"
#include "Main.hxx"
#include "event/Loop.hxx"
-#include "config/ConfigData.hxx"
+#include "config/Block.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <assert.h>
#include <string.h>
#include <unistd.h>
@@ -53,19 +49,13 @@ int main(int argc, gcc_unused char **argv)
return EXIT_FAILURE;
}
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
EventLoop event_loop;
Error error;
Mixer *mixer = mixer_new(event_loop, alsa_mixer_plugin,
*(AudioOutput *)nullptr,
*(MixerListener *)nullptr,
- config_param(), error);
+ ConfigBlock(), error);
if (mixer == NULL) {
LogError(error, "mixer_new() failed");
return EXIT_FAILURE;
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index 91ac9c674..a00e87529 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -32,10 +32,6 @@
#include "thread/Cond.hxx"
#include "Log.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
@@ -90,12 +86,6 @@ int main(int argc, char **argv)
decoder_name = argv[1];
const Path path = Path::FromFS(argv[2]);
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
const ScopeIOThread io_thread;
Error error;
diff --git a/test/run_avahi.cxx b/test/run_avahi.cxx
index b3b20365c..5c1c77d27 100644
--- a/test/run_avahi.cxx
+++ b/test/run_avahi.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_convert.cxx b/test/run_convert.cxx
index 8b9b15cf0..01cace0c3 100644
--- a/test/run_convert.cxx
+++ b/test/run_convert.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -27,25 +27,16 @@
#include "AudioParser.hxx"
#include "AudioFormat.hxx"
#include "pcm/PcmConvert.hxx"
-#include "config/ConfigGlobal.hxx"
#include "util/ConstBuffer.hxx"
#include "util/StaticFifoBuffer.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
-#include "stdbin.h"
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
-const char *
-config_get_string(gcc_unused enum ConfigOption option,
- const char *default_value)
-{
- return default_value;
-}
-
int main(int argc, char **argv)
{
AudioFormat in_audio_format, out_audio_format;
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index 0e9af6a1a..35d55cedf 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -28,11 +28,6 @@
#include "AudioFormat.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
-#include "stdbin.h"
-
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
#include <assert.h>
#include <unistd.h>
@@ -50,12 +45,6 @@ int main(int argc, char **argv)
const char *const decoder_name = argv[1];
const char *const uri = argv[2];
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
const ScopeIOThread io_thread;
Error error;
diff --git a/test/run_encoder.cxx b/test/run_encoder.cxx
index f16d8cb0a..307d1b73d 100644
--- a/test/run_encoder.cxx
+++ b/test/run_encoder.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,29 +20,20 @@
#include "config.h"
#include "encoder/EncoderList.hxx"
#include "encoder/EncoderPlugin.hxx"
+#include "encoder/EncoderInterface.hxx"
+#include "encoder/ToOutputStream.hxx"
#include "AudioFormat.hxx"
#include "AudioParser.hxx"
-#include "config/ConfigData.hxx"
+#include "config/Block.hxx"
+#include "fs/io/StdioOutputStream.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
-#include "stdbin.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
-static void
-encoder_to_stdout(Encoder &encoder)
-{
- size_t length;
- static char buffer[32768];
-
- while ((length = encoder_read(&encoder, buffer, sizeof(buffer))) > 0) {
- gcc_unused ssize_t ignored = write(1, buffer, length);
- }
-}
-
int main(int argc, char **argv)
{
const char *encoder_name;
@@ -69,11 +60,11 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- config_param param;
- param.AddBlockParam("quality", "5.0", -1);
+ ConfigBlock block;
+ block.AddBlockParam("quality", "5.0", -1);
Error error;
- const auto encoder = encoder_init(*plugin, param, error);
+ const auto encoder = encoder_init(*plugin, block, error);
if (encoder == NULL) {
LogError(error, "Failed to initialize encoder");
return EXIT_FAILURE;
@@ -89,12 +80,17 @@ int main(int argc, char **argv)
}
}
- if (!encoder_open(encoder, audio_format, error)) {
+ if (!encoder->Open(audio_format, error)) {
LogError(error, "Failed to open encoder");
return EXIT_FAILURE;
}
- encoder_to_stdout(*encoder);
+ StdioOutputStream os(stdout);
+
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
/* do it */
@@ -105,7 +101,10 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- encoder_to_stdout(*encoder);
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
}
if (!encoder_end(encoder, error)) {
@@ -113,8 +112,11 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- encoder_to_stdout(*encoder);
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
- encoder_close(encoder);
- encoder_finish(encoder);
+ encoder->Close();
+ encoder->Dispose();
}
diff --git a/test/run_filter.cxx b/test/run_filter.cxx
index ab99c9a1e..6499b9631 100644
--- a/test/run_filter.cxx
+++ b/test/run_filter.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,7 @@
*/
#include "config.h"
-#include "config/ConfigData.hxx"
+#include "config/Param.hxx"
#include "config/ConfigGlobal.hxx"
#include "fs/Path.hxx"
#include "AudioParser.hxx"
@@ -27,16 +27,11 @@
#include "filter/FilterInternal.hxx"
#include "pcm/Volume.hxx"
#include "mixer/MixerControl.hxx"
-#include "stdbin.h"
#include "util/Error.hxx"
#include "util/ConstBuffer.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <assert.h>
#include <string.h>
#include <stdlib.h>
@@ -54,8 +49,8 @@ mixer_set_volume(gcc_unused Mixer *mixer,
static Filter *
load_filter(const char *name)
{
- const config_param *param =
- config_find_block(CONF_AUDIO_FILTER, "name", name);
+ const auto *param = config_find_block(ConfigBlockOption::AUDIO_FILTER,
+ "name", name);
if (param == NULL) {
fprintf(stderr, "No such configured filter: %s\n", name);
return nullptr;
@@ -86,14 +81,6 @@ int main(int argc, char **argv)
AudioFormat audio_format(44100, SampleFormat::S16, 2);
- /* initialize GLib */
-
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
/* read configuration file (mpd.conf) */
config_global_init();
diff --git a/test/run_gunzip.cxx b/test/run_gunzip.cxx
index 51bdb532e..7ea70678a 100644
--- a/test/run_gunzip.cxx
+++ b/test/run_gunzip.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_gzip.cxx b/test/run_gzip.cxx
index c52b32ac7..15b769f0a 100644
--- a/test/run_gzip.cxx
+++ b/test/run_gzip.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_inotify.cxx b/test/run_inotify.cxx
index df4046356..ae4f196f8 100644
--- a/test/run_inotify.cxx
+++ b/test/run_inotify.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_input.cxx b/test/run_input.cxx
index 6864a5d64..6d51b3749 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -19,7 +19,6 @@
#include "config.h"
#include "TagSave.hxx"
-#include "stdbin.h"
#include "tag/Tag.hxx"
#include "config/ConfigGlobal.hxx"
#include "input/InputStream.hxx"
@@ -35,10 +34,6 @@
#include "archive/ArchiveList.hxx"
#endif
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <unistd.h>
#include <stdlib.h>
@@ -105,14 +100,6 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- /* initialize GLib */
-
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
/* initialize MPD */
config_global_init();
diff --git a/test/run_neighbor_explorer.cxx b/test/run_neighbor_explorer.cxx
index c79948d6e..29582fc55 100644
--- a/test/run_neighbor_explorer.cxx
+++ b/test/run_neighbor_explorer.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/run_normalize.cxx b/test/run_normalize.cxx
index 9a361b790..092deab59 100644
--- a/test/run_normalize.cxx
+++ b/test/run_normalize.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -28,7 +28,6 @@
#include "AudioParser.hxx"
#include "AudioFormat.hxx"
#include "util/Error.hxx"
-#include "stdbin.h"
#include <stddef.h>
#include <stdio.h>
diff --git a/test/run_output.cxx b/test/run_output.cxx
index 345127556..5100e8b44 100644
--- a/test/run_output.cxx
+++ b/test/run_output.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,7 @@
#include "config.h"
#include "output/Internal.hxx"
#include "output/OutputPlugin.hxx"
-#include "config/ConfigData.hxx"
+#include "config/Param.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
#include "Idle.hxx"
@@ -31,15 +31,10 @@
#include "AudioParser.hxx"
#include "pcm/PcmConvert.hxx"
#include "filter/FilterRegistry.hxx"
-#include "PlayerControl.hxx"
-#include "stdbin.h"
+#include "player/Control.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <assert.h>
#include <string.h>
#include <unistd.h>
@@ -65,8 +60,8 @@ PlayerControl::~PlayerControl() {}
static AudioOutput *
load_audio_output(EventLoop &event_loop, const char *name)
{
- const config_param *param =
- config_find_block(CONF_AUDIO_OUTPUT, "name", name);
+ const auto *param = config_find_block(ConfigBlockOption::AUDIO_OUTPUT,
+ "name", name);
if (param == NULL) {
fprintf(stderr, "No such configured audio output: %s\n", name);
return nullptr;
@@ -163,12 +158,6 @@ int main(int argc, char **argv)
AudioFormat audio_format(44100, SampleFormat::S16, 2);
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
/* read configuration file (mpd.conf) */
config_global_init();
diff --git a/test/run_resolver.cxx b/test/run_resolver.cxx
index 71cadbeec..1fe458cfc 100644
--- a/test/run_resolver.cxx
+++ b/test/run_resolver.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,9 @@
*/
#include "config.h"
-#include "system/Resolver.hxx"
+#include "net/Resolver.hxx"
+#include "net/ToString.hxx"
+#include "net/SocketAddress.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
@@ -50,7 +52,7 @@ int main(int argc, char **argv)
}
for (const struct addrinfo *i = ai; i != NULL; i = i->ai_next) {
- const auto s = sockaddr_to_string(i->ai_addr, i->ai_addrlen);
+ const auto s = ToString({i->ai_addr, i->ai_addrlen});
printf("%s\n", s.c_str());
}
diff --git a/test/run_storage.cxx b/test/run_storage.cxx
index 9fc6e6e76..0d99676d5 100644
--- a/test/run_storage.cxx
+++ b/test/run_storage.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -24,10 +24,6 @@
#include "storage/FileInfo.hxx"
#include "util/Error.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <memory>
#include <unistd.h>
@@ -60,7 +56,7 @@ Ls(Storage &storage, const char *path)
const char *name;
while ((name = dir->Read()) != nullptr) {
- FileInfo info;
+ StorageFileInfo info;
if (!dir->GetInfo(false, info, error)) {
printf("Error on %s: %s\n", name, error.GetMessage());
error.Clear();
@@ -69,15 +65,15 @@ Ls(Storage &storage, const char *path)
const char *type = "unk";
switch (info.type) {
- case FileInfo::Type::OTHER:
+ case StorageFileInfo::Type::OTHER:
type = "oth";
break;
- case FileInfo::Type::REGULAR:
+ case StorageFileInfo::Type::REGULAR:
type = "reg";
break;
- case FileInfo::Type::DIRECTORY:
+ case StorageFileInfo::Type::DIRECTORY:
type = "dir";
break;
}
@@ -102,14 +98,6 @@ main(int argc, char **argv)
return EXIT_FAILURE;
}
- /* initialize GLib */
-
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
const char *const command = argv[1];
const char *const storage_uri = argv[2];
diff --git a/test/software_volume.cxx b/test/software_volume.cxx
index 1e41f95fd..a0dd207a7 100644
--- a/test/software_volume.cxx
+++ b/test/software_volume.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -29,7 +29,6 @@
#include "AudioFormat.hxx"
#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
-#include "stdbin.h"
#include "Log.hxx"
#include <stdio.h>
diff --git a/test/stdbin.h b/test/stdbin.h
deleted file mode 100644
index 8b5502e6f..000000000
--- a/test/stdbin.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2003-2014 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.
- */
-
-#ifndef MPD_STDBIN_H
-#define MPD_STDBIN_H
-
-#ifdef WIN32
-#include <fcntl.h>
-/** set binary mode on stdin/stdout */
-int _CRT_fmode = _O_BINARY;
-#endif
-
-#endif
diff --git a/test/test_byte_reverse.cxx b/test/test_byte_reverse.cxx
index 0ab97e4d1..a57753e38 100644
--- a/test/test_byte_reverse.cxx
+++ b/test/test_byte_reverse.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_mixramp.cxx b/test/test_mixramp.cxx
index 954aade87..ea245f72f 100644
--- a/test/test_mixramp.cxx
+++ b/test/test_mixramp.cxx
@@ -3,7 +3,7 @@
*/
#include "config.h"
-#include "CrossFade.cxx"
+#include "player/CrossFade.cxx"
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
diff --git a/test/test_pcm_all.hxx b/test/test_pcm_all.hxx
index 7cdd8b63f..fd08ec451 100644
--- a/test/test_pcm_all.hxx
+++ b/test/test_pcm_all.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -103,6 +103,23 @@ public:
void TestMix32();
};
+class PcmInterleaveTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(PcmInterleaveTest);
+ CPPUNIT_TEST(TestInterleave8);
+ CPPUNIT_TEST(TestInterleave16);
+ CPPUNIT_TEST(TestInterleave24);
+ CPPUNIT_TEST(TestInterleave32);
+ CPPUNIT_TEST(TestInterleave64);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestInterleave8();
+ void TestInterleave16();
+ void TestInterleave24();
+ void TestInterleave32();
+ void TestInterleave64();
+};
+
class PcmExportTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(PcmExportTest);
CPPUNIT_TEST(TestShift8);
diff --git a/test/test_pcm_channels.cxx b/test/test_pcm_channels.cxx
index 748a76351..fa6aa32da 100644
--- a/test/test_pcm_channels.cxx
+++ b/test/test_pcm_channels.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_pcm_dither.cxx b/test/test_pcm_dither.cxx
index 09a2b5cf9..f1a375f6c 100644
--- a/test/test_pcm_dither.cxx
+++ b/test/test_pcm_dither.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_pcm_export.cxx b/test/test_pcm_export.cxx
index 410e64e4d..347e2394a 100644
--- a/test/test_pcm_export.cxx
+++ b/test/test_pcm_export.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_pcm_format.cxx b/test/test_pcm_format.cxx
index 825a8bd84..ac9e47240 100644
--- a/test/test_pcm_format.cxx
+++ b/test/test_pcm_format.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_pcm_interleave.cxx b/test/test_pcm_interleave.cxx
new file mode 100644
index 000000000..e7be38813
--- /dev/null
+++ b/test/test_pcm_interleave.cxx
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2003-2015 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 "config.h"
+#include "test_pcm_all.hxx"
+#include "pcm/Interleave.hxx"
+#include "util/Macros.hxx"
+
+#include <algorithm>
+
+template<typename T>
+static void
+TestInterleaveN()
+{
+ static constexpr T src1[] = { 1, 4, 7 };
+ static constexpr T src2[] = { 2, 5, 8 };
+ 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 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);
+
+ PcmInterleave(dest, src, n_frames, sizeof(T));
+
+ CPPUNIT_ASSERT_EQUAL(T(1), dest[0]);
+ CPPUNIT_ASSERT_EQUAL(T(2), dest[1]);
+ CPPUNIT_ASSERT_EQUAL(T(3), dest[2]);
+ CPPUNIT_ASSERT_EQUAL(T(4), dest[3]);
+ CPPUNIT_ASSERT_EQUAL(T(5), dest[4]);
+ CPPUNIT_ASSERT_EQUAL(T(6), dest[5]);
+ CPPUNIT_ASSERT_EQUAL(T(7), dest[6]);
+ CPPUNIT_ASSERT_EQUAL(T(8), dest[7]);
+ CPPUNIT_ASSERT_EQUAL(T(9), dest[8]);
+ CPPUNIT_ASSERT_EQUAL(poison, dest[9]);
+}
+
+void
+PcmInterleaveTest::TestInterleave8()
+{
+ TestInterleaveN<uint8_t>();
+}
+
+void
+PcmInterleaveTest::TestInterleave16()
+{
+ TestInterleaveN<uint16_t>();
+}
+
+void
+PcmInterleaveTest::TestInterleave24()
+{
+ typedef uint8_t T;
+ static constexpr T src1[] = { 1, 2, 3, 4, 5, 6 };
+ static constexpr T src2[] = { 7, 8, 9, 10, 11, 12 };
+ 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 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);
+
+ PcmInterleave(dest, src, n_frames, 3);
+
+ CPPUNIT_ASSERT_EQUAL(T(1), dest[0]);
+ CPPUNIT_ASSERT_EQUAL(T(2), dest[1]);
+ CPPUNIT_ASSERT_EQUAL(T(3), dest[2]);
+ CPPUNIT_ASSERT_EQUAL(T(7), dest[3]);
+ CPPUNIT_ASSERT_EQUAL(T(8), dest[4]);
+ CPPUNIT_ASSERT_EQUAL(T(9), dest[5]);
+ CPPUNIT_ASSERT_EQUAL(T(13), dest[6]);
+ CPPUNIT_ASSERT_EQUAL(T(14), dest[7]);
+ CPPUNIT_ASSERT_EQUAL(T(15), dest[8]);
+ CPPUNIT_ASSERT_EQUAL(T(4), dest[9]);
+ CPPUNIT_ASSERT_EQUAL(T(5), dest[10]);
+ CPPUNIT_ASSERT_EQUAL(T(6), dest[11]);
+ CPPUNIT_ASSERT_EQUAL(T(10), dest[12]);
+ CPPUNIT_ASSERT_EQUAL(T(11), dest[13]);
+ CPPUNIT_ASSERT_EQUAL(T(12), dest[14]);
+ CPPUNIT_ASSERT_EQUAL(T(16), dest[15]);
+ CPPUNIT_ASSERT_EQUAL(T(17), dest[16]);
+ CPPUNIT_ASSERT_EQUAL(T(18), dest[17]);
+ CPPUNIT_ASSERT_EQUAL(poison, dest[18]);
+
+ TestInterleaveN<uint16_t>();
+}
+
+void
+PcmInterleaveTest::TestInterleave32()
+{
+ TestInterleaveN<uint8_t>();
+}
+
+void
+PcmInterleaveTest::TestInterleave64()
+{
+ TestInterleaveN<uint64_t>();
+}
diff --git a/test/test_pcm_main.cxx b/test/test_pcm_main.cxx
index 0e397a15c..8d478cd05 100644
--- a/test/test_pcm_main.cxx
+++ b/test/test_pcm_main.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -31,6 +31,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(PcmChannelsTest);
CPPUNIT_TEST_SUITE_REGISTRATION(PcmVolumeTest);
CPPUNIT_TEST_SUITE_REGISTRATION(PcmFormatTest);
CPPUNIT_TEST_SUITE_REGISTRATION(PcmMixTest);
+CPPUNIT_TEST_SUITE_REGISTRATION(PcmInterleaveTest);
CPPUNIT_TEST_SUITE_REGISTRATION(PcmExportTest);
int
diff --git a/test/test_pcm_mix.cxx b/test/test_pcm_mix.cxx
index 973b58f4d..9abe476fa 100644
--- a/test/test_pcm_mix.cxx
+++ b/test/test_pcm_mix.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_pcm_pack.cxx b/test/test_pcm_pack.cxx
index fff3e10f0..20732f0b6 100644
--- a/test/test_pcm_pack.cxx
+++ b/test/test_pcm_pack.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_pcm_util.hxx b/test/test_pcm_util.hxx
index f1efbc666..3ac84c307 100644
--- a/test/test_pcm_util.hxx
+++ b/test/test_pcm_util.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -34,7 +34,7 @@ struct RandomInt {
"RNG result type too small");
T operator()() {
- return T(random());
+ return T(engine());
}
};
diff --git a/test/test_pcm_volume.cxx b/test/test_pcm_volume.cxx
index 2d908f6c1..55b54244c 100644
--- a/test/test_pcm_volume.cxx
+++ b/test/test_pcm_volume.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
diff --git a/test/test_protocol.cxx b/test/test_protocol.cxx
index fb35cbc66..e683fe2cb 100644
--- a/test/test_protocol.cxx
+++ b/test/test_protocol.cxx
@@ -1,6 +1,6 @@
#include "config.h"
#include "protocol/ArgParser.hxx"
-#include "protocol/Result.hxx"
+#include "client/Response.hxx"
#include "Compiler.h"
#include <cppunit/TestFixture.h>
@@ -13,10 +13,15 @@
static enum ack last_error = ack(-1);
void
-command_error(gcc_unused Client &client, enum ack error,
- gcc_unused const char *fmt, ...)
+Response::Error(enum ack code, gcc_unused const char *msg)
{
- last_error = error;
+ last_error = code;
+}
+
+void
+Response::FormatError(enum ack code, gcc_unused const char *fmt, ...)
+{
+ last_error = code;
}
class ArgParserTest : public CppUnit::TestFixture {
@@ -32,21 +37,23 @@ void
ArgParserTest::TestRange()
{
Client &client = *(Client *)nullptr;
- unsigned a, b;
+ Response r(client, 0);
+
+ RangeArg range;
- CPPUNIT_ASSERT(check_range(client, &a, &b, "1"));
- CPPUNIT_ASSERT_EQUAL(1u, a);
- CPPUNIT_ASSERT_EQUAL(2u, b);
+ CPPUNIT_ASSERT(ParseCommandArg(r, range, "1"));
+ CPPUNIT_ASSERT_EQUAL(1u, range.start);
+ CPPUNIT_ASSERT_EQUAL(2u, range.end);
- CPPUNIT_ASSERT(check_range(client, &a, &b, "1:5"));
- CPPUNIT_ASSERT_EQUAL(1u, a);
- CPPUNIT_ASSERT_EQUAL(5u, b);
+ CPPUNIT_ASSERT(ParseCommandArg(r, range, "1:5"));
+ CPPUNIT_ASSERT_EQUAL(1u, range.start);
+ CPPUNIT_ASSERT_EQUAL(5u, range.end);
- CPPUNIT_ASSERT(check_range(client, &a, &b, "1:"));
- CPPUNIT_ASSERT_EQUAL(1u, a);
- CPPUNIT_ASSERT(b >= 999999u);
+ CPPUNIT_ASSERT(ParseCommandArg(r, range, "1:"));
+ CPPUNIT_ASSERT_EQUAL(1u, range.start);
+ CPPUNIT_ASSERT(range.end >= 999999u);
- CPPUNIT_ASSERT(!check_range(client, &a, &b, "-2"));
+ CPPUNIT_ASSERT(!ParseCommandArg(r, range, "-2"));
CPPUNIT_ASSERT_EQUAL(ACK_ERROR_ARG, last_error);
}
diff --git a/test/test_translate_song.cxx b/test/test_translate_song.cxx
index e3c1bcb79..b6be581e4 100644
--- a/test/test_translate_song.cxx
+++ b/test/test_translate_song.cxx
@@ -38,7 +38,7 @@ uri_supported_scheme(const char *uri)
return memcmp(uri, "http://", 7) == 0;
}
-static const char *const music_directory = "/music";
+static constexpr auto music_directory = PATH_LITERAL("/music");
static Storage *storage;
static void
@@ -121,9 +121,9 @@ DatabaseDetachSong(gcc_unused const Database &db,
}
bool
-DetachedSong::Update()
+DetachedSong::LoadFile(Path path)
{
- if (strcmp(GetURI(), uri1) == 0) {
+ if (path.ToUTF8() == uri1) {
SetTag(MakeTag1a());
return true;
}
diff --git a/test/test_util.cxx b/test/test_util.cxx
index 3e79aeca0..c2d73d7d9 100644
--- a/test/test_util.cxx
+++ b/test/test_util.cxx
@@ -3,7 +3,9 @@
*/
#include "config.h"
-#include "util/UriUtil.hxx"
+#include "DivideStringTest.hxx"
+#include "SplitStringTest.hxx"
+#include "UriUtilTest.hxx"
#include "TestCircularBuffer.hxx"
#include <cppunit/TestFixture.h>
@@ -11,64 +13,10 @@
#include <cppunit/ui/text/TestRunner.h>
#include <cppunit/extensions/HelperMacros.h>
-#include <string.h>
#include <stdlib.h>
-class UriUtilTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(UriUtilTest);
- CPPUNIT_TEST(TestSuffix);
- CPPUNIT_TEST(TestRemoveAuth);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- void TestSuffix() {
- CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
- uri_get_suffix("/foo/bar"));
- CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
- uri_get_suffix("/foo.jpg/bar"));
- CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg"),
- "jpg"));
- CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo.png/bar.jpg"),
- "jpg"));
- CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
- uri_get_suffix(".jpg"));
- CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
- uri_get_suffix("/foo/.jpg"));
-
- /* the first overload does not eliminate the query
- string */
- CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string"),
- "jpg?query_string"));
-
- /* ... but the second one does */
- UriSuffixBuffer buffer;
- CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg?query_string",
- buffer),
- "jpg"));
-
- /* repeat some of the above tests with the second overload */
- CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
- uri_get_suffix("/foo/bar", buffer));
- CPPUNIT_ASSERT_EQUAL((const char *)nullptr,
- uri_get_suffix("/foo.jpg/bar", buffer));
- CPPUNIT_ASSERT_EQUAL(0, strcmp(uri_get_suffix("/foo/bar.jpg", buffer),
- "jpg"));
- }
-
- void TestRemoveAuth() {
- CPPUNIT_ASSERT_EQUAL(std::string(),
- uri_remove_auth("http://www.example.com/"));
- CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"),
- uri_remove_auth("http://foo:bar@www.example.com/"));
- CPPUNIT_ASSERT_EQUAL(std::string("http://www.example.com/"),
- uri_remove_auth("http://foo@www.example.com/"));
- CPPUNIT_ASSERT_EQUAL(std::string(),
- uri_remove_auth("http://www.example.com/f:oo@bar"));
- CPPUNIT_ASSERT_EQUAL(std::string("ftp://ftp.example.com/"),
- uri_remove_auth("ftp://foo:bar@ftp.example.com/"));
- }
-};
-
+CPPUNIT_TEST_SUITE_REGISTRATION(DivideStringTest);
+CPPUNIT_TEST_SUITE_REGISTRATION(SplitStringTest);
CPPUNIT_TEST_SUITE_REGISTRATION(UriUtilTest);
CPPUNIT_TEST_SUITE_REGISTRATION(TestCircularBuffer);
diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx
index 59b901da2..81b7b1cbe 100644
--- a/test/test_vorbis_encoder.cxx
+++ b/test/test_vorbis_encoder.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,29 +20,21 @@
#include "config.h"
#include "encoder/EncoderList.hxx"
#include "encoder/EncoderPlugin.hxx"
+#include "encoder/EncoderInterface.hxx"
+#include "encoder/ToOutputStream.hxx"
#include "AudioFormat.hxx"
-#include "config/ConfigData.hxx"
-#include "stdbin.h"
+#include "config/Block.hxx"
+#include "fs/io/StdioOutputStream.hxx"
#include "tag/Tag.hxx"
#include "tag/TagBuilder.hxx"
#include "util/Error.hxx"
+#include "Log.hxx"
#include <stddef.h>
#include <unistd.h>
static uint8_t zero[256];
-static void
-encoder_to_stdout(Encoder &encoder)
-{
- size_t length;
- static char buffer[32768];
-
- while ((length = encoder_read(&encoder, buffer, sizeof(buffer))) > 0) {
- gcc_unused ssize_t ignored = write(1, buffer, length);
- }
-}
-
int
main(gcc_unused int argc, gcc_unused char **argv)
{
@@ -53,33 +45,45 @@ main(gcc_unused int argc, gcc_unused char **argv)
const auto plugin = encoder_plugin_get("vorbis");
assert(plugin != NULL);
- config_param param;
- param.AddBlockParam("quality", "5.0", -1);
+ ConfigBlock block;
+ block.AddBlockParam("quality", "5.0", -1);
- const auto encoder = encoder_init(*plugin, param, IgnoreError());
+ const auto encoder = encoder_init(*plugin, block, IgnoreError());
assert(encoder != NULL);
/* open the encoder */
AudioFormat audio_format(44100, SampleFormat::S16, 2);
- success = encoder_open(encoder, audio_format, IgnoreError());
+ success = encoder->Open(audio_format, IgnoreError());
assert(success);
- encoder_to_stdout(*encoder);
+ StdioOutputStream os(stdout);
+
+ Error error;
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
/* write a block of data */
success = encoder_write(encoder, zero, sizeof(zero), IgnoreError());
assert(success);
- encoder_to_stdout(*encoder);
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
/* write a tag */
success = encoder_pre_tag(encoder, IgnoreError());
assert(success);
- encoder_to_stdout(*encoder);
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
Tag tag;
@@ -90,10 +94,13 @@ main(gcc_unused int argc, gcc_unused char **argv)
tag_builder.Commit(tag);
}
- success = encoder_tag(encoder, &tag, IgnoreError());
+ success = encoder_tag(encoder, tag, IgnoreError());
assert(success);
- encoder_to_stdout(*encoder);
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
/* write another block of data */
@@ -105,8 +112,11 @@ main(gcc_unused int argc, gcc_unused char **argv)
success = encoder_end(encoder, IgnoreError());
assert(success);
- encoder_to_stdout(*encoder);
+ if (!EncoderToOutputStream(os, *encoder, error)) {
+ LogError(error);
+ return EXIT_FAILURE;
+ }
- encoder_close(encoder);
- encoder_finish(encoder);
+ encoder->Close();
+ encoder->Dispose();
}
diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx
index 1ff3ba484..1e59746bd 100644
--- a/test/visit_archive.cxx
+++ b/test/visit_archive.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2014 The Music Player Daemon Project
+ * Copyright (C) 2003-2015 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,6 @@
*/
#include "config.h"
-#include "stdbin.h"
#include "tag/Tag.hxx"
#include "config/ConfigGlobal.hxx"
#include "ScopeIOThread.hxx"
@@ -30,10 +29,6 @@
#include "fs/Path.hxx"
#include "util/Error.hxx"
-#ifdef HAVE_GLIB
-#include <glib.h>
-#endif
-
#include <unistd.h>
#include <stdlib.h>
@@ -57,14 +52,6 @@ main(int argc, char **argv)
const char *plugin_name = argv[1];
const Path path = Path::FromFS(argv[2]);
- /* initialize GLib */
-
-#ifdef HAVE_GLIB
-#if !GLIB_CHECK_VERSION(2,32,0)
- g_thread_init(NULL);
-#endif
-#endif
-
/* initialize MPD */
config_global_init();