summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2020-09-07 20:17:44 +0200
committerMax Kellermann <max@musicpd.org>2020-09-07 20:18:40 +0200
commit291be84704e9369f2cfc895c02bcceeace7b95d3 (patch)
tree020c4951e74e772dcca4a500300d9f13eef8c058 /test
parent67c7116f058666fbcc050d6d879778f41665b447 (diff)
parent962cf32ba7b956733cc1ddb6d9ab707cfc577c02 (diff)
Merge branch 'v0.21.x' into master
Diffstat (limited to 'test')
-rw-r--r--test/dump_playlist.cxx6
-rw-r--r--test/run_filter.cxx32
-rw-r--r--test/run_input.cxx28
3 files changed, 18 insertions, 48 deletions
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index 6f8dadabe..76961639b 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -41,9 +41,9 @@ static void
tag_save(FILE *file, const Tag &tag)
{
StdioOutputStream sos(file);
- BufferedOutputStream bos(sos);
- tag_save(bos, tag);
- bos.Flush();
+ WithBufferedOutputStream(sos, [&](auto &bos){
+ tag_save(bos, tag);
+ });
}
int main(int argc, char **argv)
diff --git a/test/run_filter.cxx b/test/run_filter.cxx
index 0ebedde72..b544a6ac9 100644
--- a/test/run_filter.cxx
+++ b/test/run_filter.cxx
@@ -71,34 +71,6 @@ ReadOrThrow(FileDescriptor fd, void *buffer, size_t size)
}
static size_t
-WriteOrThrow(FileDescriptor fd, const void *buffer, size_t size)
-{
- auto nbytes = fd.Write(buffer, size);
- if (nbytes < 0)
- throw MakeErrno("Write failed");
-
- return nbytes;
-}
-
-static void
-FullWrite(FileDescriptor fd, ConstBuffer<uint8_t> src)
-{
- while (!src.empty()) {
- size_t nbytes = WriteOrThrow(fd, src.data, src.size);
- if (nbytes == 0)
- throw std::runtime_error("Write failed");
-
- src.skip_front(nbytes);
- }
-}
-
-static void
-FullWrite(FileDescriptor fd, ConstBuffer<void> src)
-{
- FullWrite(fd, ConstBuffer<uint8_t>::FromVoid(src));
-}
-
-static size_t
ReadFrames(FileDescriptor fd, void *_buffer, size_t size, size_t frame_size)
{
auto buffer = (uint8_t *)_buffer;
@@ -166,14 +138,14 @@ try {
break;
auto dest = filter->FilterPCM({(const void *)buffer, (size_t)nbytes});
- FullWrite(output_fd, dest);
+ output_fd.FullWrite(dest.data, dest.size);
}
while (true) {
auto dest = filter->Flush();
if (dest.IsNull())
break;
- FullWrite(output_fd, dest);
+ output_fd.FullWrite(dest.data, dest.size);
}
/* cleanup and exit */
diff --git a/test/run_input.cxx b/test/run_input.cxx
index 20fe8c2d7..57300183a 100644
--- a/test/run_input.cxx
+++ b/test/run_input.cxx
@@ -124,26 +124,26 @@ static void
tag_save(FILE *file, const Tag &tag)
{
StdioOutputStream sos(file);
- BufferedOutputStream bos(sos);
- tag_save(bos, tag);
- bos.Flush();
+ WithBufferedOutputStream(sos, [&](auto &bos){
+ tag_save(bos, tag);
+ });
}
static int
-dump_input_stream(InputStream *is)
+dump_input_stream(InputStream &is, FileDescriptor out)
{
- std::unique_lock<Mutex> lock(is->mutex);
+ std::unique_lock<Mutex> lock(is.mutex);
/* print meta data */
- if (is->HasMimeType())
- fprintf(stderr, "MIME type: %s\n", is->GetMimeType());
+ if (is.HasMimeType())
+ fprintf(stderr, "MIME type: %s\n", is.GetMimeType());
/* read data and tags from the stream */
- while (!is->IsEOF()) {
+ while (!is.IsEOF()) {
{
- auto tag = is->ReadTag();
+ auto tag = is.ReadTag();
if (tag) {
fprintf(stderr, "Received a tag:\n");
tag_save(stderr, *tag);
@@ -151,16 +151,14 @@ dump_input_stream(InputStream *is)
}
char buffer[4096];
- size_t num_read = is->Read(lock, buffer, sizeof(buffer));
+ size_t num_read = is.Read(lock, buffer, sizeof(buffer));
if (num_read == 0)
break;
- ssize_t num_written = write(1, buffer, num_read);
- if (num_written <= 0)
- break;
+ out.FullWrite(buffer, num_read);
}
- is->Check();
+ is.Check();
return 0;
}
@@ -233,7 +231,7 @@ try {
Mutex mutex;
auto is = InputStream::OpenReady(c.uri, mutex);
- return dump_input_stream(is.get());
+ return dump_input_stream(*is, FileDescriptor(STDOUT_FILENO));
} catch (...) {
PrintException(std::current_exception());
return EXIT_FAILURE;