Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
afe53997
Commit
afe53997
authored
May 21, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/test_rewind: unit test for class RewindInputStream
parent
c42e412c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
177 additions
and
0 deletions
+177
-0
Makefile.am
Makefile.am
+13
-0
test_rewind.cxx
test/test_rewind.cxx
+164
-0
No files found.
Makefile.am
View file @
afe53997
...
...
@@ -1388,6 +1388,7 @@ if ENABLE_TEST
C_TESTS
=
\
test
/test_util
\
test
/test_byte_reverse
\
test
/test_rewind
\
test
/test_mixramp
\
test
/test_pcm
\
test
/test_queue_priority
...
...
@@ -1857,6 +1858,18 @@ test_test_byte_reverse_LDADD = \
libutil.a
\
$(CPPUNIT_LIBS)
test_test_rewind_SOURCES
=
\
src/Log.cxx src/LogBackend.cxx
\
test
/test_rewind.cxx
test_test_rewind_CPPFLAGS
=
$(AM_CPPFLAGS)
$(CPPUNIT_CFLAGS)
-DCPPUNIT_HAVE_RTTI
=
0
test_test_rewind_CXXFLAGS
=
$(AM_CXXFLAGS)
-Wno-error
=
deprecated-declarations
test_test_rewind_LDADD
=
\
$(INPUT_LIBS)
\
libthread.a
\
libtag.a
\
libutil.a
\
$(CPPUNIT_LIBS)
test_test_mixramp_SOURCES
=
\
src/Log.cxx src/LogBackend.cxx
\
test
/test_mixramp.cxx
...
...
test/test_rewind.cxx
0 → 100644
View file @
afe53997
/*
* Unit tests for class RewindInputStream.
*/
#include "config.h"
#include "input/plugins/RewindInputPlugin.hxx"
#include "input/InputStream.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.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>
#include <string.h>
class
StringInputStream
final
:
public
InputStream
{
const
char
*
data
;
size_t
remaining
;
public
:
StringInputStream
(
const
char
*
_uri
,
Mutex
&
_mutex
,
Cond
&
_cond
,
const
char
*
_data
)
:
InputStream
(
_uri
,
_mutex
,
_cond
),
data
(
_data
),
remaining
(
strlen
(
data
))
{
SetReady
();
}
/* virtual methods from InputStream */
bool
IsEOF
()
override
{
return
remaining
==
0
;
}
size_t
Read
(
void
*
ptr
,
size_t
read_size
,
gcc_unused
Error
&
error
)
override
{
size_t
nbytes
=
std
::
min
(
remaining
,
read_size
);
memcpy
(
ptr
,
data
,
nbytes
);
data
+=
nbytes
;
remaining
-=
nbytes
;
offset
+=
nbytes
;
return
nbytes
;
}
};
class
RewindTest
:
public
CppUnit
::
TestFixture
{
CPPUNIT_TEST_SUITE
(
RewindTest
);
CPPUNIT_TEST
(
TestRewind
);
CPPUNIT_TEST_SUITE_END
();
public
:
void
TestRewind
()
{
Mutex
mutex
;
Cond
cond
;
StringInputStream
*
sis
=
new
StringInputStream
(
"foo://"
,
mutex
,
cond
,
"foo bar"
);
CPPUNIT_ASSERT
(
sis
->
IsReady
());
InputStream
*
ris
=
input_rewind_open
(
sis
);
CPPUNIT_ASSERT
(
ris
!=
sis
);
CPPUNIT_ASSERT
(
ris
!=
nullptr
);
const
ScopeLock
protect
(
mutex
);
ris
->
Update
();
CPPUNIT_ASSERT
(
ris
->
IsReady
());
CPPUNIT_ASSERT
(
!
ris
->
KnownSize
());
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
0
),
ris
->
GetOffset
());
Error
error
;
char
buffer
[
16
];
size_t
nbytes
=
ris
->
Read
(
buffer
,
2
,
error
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
2
),
nbytes
);
CPPUNIT_ASSERT_EQUAL
(
'f'
,
buffer
[
0
]);
CPPUNIT_ASSERT_EQUAL
(
'o'
,
buffer
[
1
]);
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
2
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
nbytes
=
ris
->
Read
(
buffer
,
2
,
error
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
2
),
nbytes
);
CPPUNIT_ASSERT_EQUAL
(
'o'
,
buffer
[
0
]);
CPPUNIT_ASSERT_EQUAL
(
' '
,
buffer
[
1
]);
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
4
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
CPPUNIT_ASSERT
(
ris
->
Seek
(
1
,
SEEK_SET
,
error
));
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
1
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
nbytes
=
ris
->
Read
(
buffer
,
2
,
error
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
2
),
nbytes
);
CPPUNIT_ASSERT_EQUAL
(
'o'
,
buffer
[
0
]);
CPPUNIT_ASSERT_EQUAL
(
'o'
,
buffer
[
1
]);
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
3
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
CPPUNIT_ASSERT
(
ris
->
Seek
(
0
,
SEEK_SET
,
error
));
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
0
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
nbytes
=
ris
->
Read
(
buffer
,
2
,
error
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
2
),
nbytes
);
CPPUNIT_ASSERT_EQUAL
(
'f'
,
buffer
[
0
]);
CPPUNIT_ASSERT_EQUAL
(
'o'
,
buffer
[
1
]);
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
2
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
nbytes
=
ris
->
Read
(
buffer
,
sizeof
(
buffer
),
error
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
2
),
nbytes
);
CPPUNIT_ASSERT_EQUAL
(
'o'
,
buffer
[
0
]);
CPPUNIT_ASSERT_EQUAL
(
' '
,
buffer
[
1
]);
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
4
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
nbytes
=
ris
->
Read
(
buffer
,
sizeof
(
buffer
),
error
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
3
),
nbytes
);
CPPUNIT_ASSERT_EQUAL
(
'b'
,
buffer
[
0
]);
CPPUNIT_ASSERT_EQUAL
(
'a'
,
buffer
[
1
]);
CPPUNIT_ASSERT_EQUAL
(
'r'
,
buffer
[
2
]);
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
7
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
ris
->
IsEOF
());
CPPUNIT_ASSERT
(
ris
->
Seek
(
3
,
SEEK_SET
,
error
));
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
3
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
!
ris
->
IsEOF
());
nbytes
=
ris
->
Read
(
buffer
,
sizeof
(
buffer
),
error
);
CPPUNIT_ASSERT_EQUAL
(
size_t
(
4
),
nbytes
);
CPPUNIT_ASSERT_EQUAL
(
' '
,
buffer
[
0
]);
CPPUNIT_ASSERT_EQUAL
(
'b'
,
buffer
[
1
]);
CPPUNIT_ASSERT_EQUAL
(
'a'
,
buffer
[
2
]);
CPPUNIT_ASSERT_EQUAL
(
'r'
,
buffer
[
3
]);
CPPUNIT_ASSERT_EQUAL
(
InputStream
::
offset_type
(
7
),
ris
->
GetOffset
());
CPPUNIT_ASSERT
(
ris
->
IsEOF
());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION
(
RewindTest
);
int
main
(
gcc_unused
int
argc
,
gcc_unused
char
**
argv
)
{
CppUnit
::
TextUi
::
TestRunner
runner
;
auto
&
registry
=
CppUnit
::
TestFactoryRegistry
::
getRegistry
();
runner
.
addTest
(
registry
.
makeTest
());
return
runner
.
run
()
?
EXIT_SUCCESS
:
EXIT_FAILURE
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment