Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
Ezstream
Commits
9cb757f1
Commit
9cb757f1
authored
Sep 25, 2017
by
Moritz Grimm
Browse files
Add util_* tests
parent
ddc30688
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/Makefile.am
View file @
9cb757f1
...
...
@@ -8,6 +8,7 @@ TESTS = \
check_mdata
\
check_playlist
\
check_stream
\
check_util
\
check_xalloc
check_PROGRAMS
=
$(TESTS)
...
...
@@ -46,6 +47,11 @@ check_stream_SOURCES = \
check_stream_DEPENDENCIES
=
$(top_builddir)
/src/libezstream.la
check_stream_LDADD
=
$(check_stream_DEPENDENCIES)
@CHECK_LIBS@
check_util_SOURCES
=
\
check_util.c
check_util_DEPENDENCIES
=
$(top_builddir)
/src/libezstream.la
check_util_LDADD
=
$(check_util_DEPENDENCIES)
@CHECK_LIBS@
check_xalloc_SOURCES
=
\
check_xalloc.c
check_xalloc_DEPENDENCIES
=
$(top_builddir)
/src/libezstream.la
...
...
@@ -57,6 +63,7 @@ AM_CPPFLAGS = @EZ_CPPFLAGS@ \
-I
$(top_builddir)
/src
AM_CFLAGS
=
@EZ_CFLAGS@ @CHECK_CFLAGS@
\
-DSRCDIR
=
"
\"
$(srcdir)
\"
"
\
-DBUILDDIR
=
"
\"
$(builddir)
\"
"
\
-DEXAMPLESDIR
=
"
\"
$(top_srcdir)
/examples
\"
"
AM_LDFLAGS
=
@EZ_LDFLAGS@
...
...
tests/check_util.c
0 → 100644
View file @
9cb757f1
#include
<sys/file.h>
#include
<stdio.h>
#include
<unistd.h>
#include
<check.h>
#include
"util.h"
#include
"xalloc.h"
Suite
*
util_suite
(
void
);
START_TEST
(
test_util_write_pid_file
)
{
FILE
*
pidfile_2
;
ck_assert_int_eq
(
util_write_pid_file
(
NULL
),
0
);
ck_assert_int_ne
(
util_write_pid_file
(
"/nonexistent/path/check_util-write_pid_file.pid"
),
0
);
pidfile_2
=
fopen
(
BUILDDIR
"/check_util-write_pid_file2.pid"
,
"w"
);
ck_assert_ptr_ne
(
pidfile_2
,
NULL
);
ck_assert_int_eq
(
flock
(
fileno
(
pidfile_2
),
LOCK_EX
),
0
);
ck_assert_int_ne
(
util_write_pid_file
(
BUILDDIR
"/check_util-write_pid_file2.pid"
),
0
);
ck_assert_int_eq
(
flock
(
fileno
(
pidfile_2
),
LOCK_UN
),
0
);
ck_assert_int_eq
(
fclose
(
pidfile_2
),
0
);
unlink
(
BUILDDIR
"/check_util-write_pid_file.pid"
);
ck_assert_int_ne
(
access
(
BUILDDIR
"/check_util-write_pid_file.pid"
,
F_OK
),
0
);
ck_assert_int_eq
(
util_write_pid_file
(
BUILDDIR
"/check_util-write_pid_file.pid"
),
0
);
ck_assert_int_eq
(
access
(
BUILDDIR
"/check_util-write_pid_file.pid"
,
F_OK
),
0
);
ck_assert_int_eq
(
util_write_pid_file
(
BUILDDIR
"/check_util-write_pid_file.pid"
),
0
);
ck_assert_int_eq
(
access
(
BUILDDIR
"/check_util-write_pid_file.pid"
,
F_OK
),
0
);
ck_assert_int_eq
(
unlink
(
BUILDDIR
"/check_util-write_pid_file.pid"
),
0
);
ck_assert_int_ne
(
access
(
BUILDDIR
"/check_util-write_pid_file.pid"
,
F_OK
),
0
);
}
END_TEST
START_TEST
(
test_util_strrcmp
)
{
ck_assert_int_ne
(
util_strrcmp
(
".m3u"
,
"playlist.m3u"
),
0
);
ck_assert_int_ne
(
util_strrcasecmp
(
".m3u"
,
"playlist.m3u"
),
0
);
ck_assert_int_ne
(
util_strrcmp
(
"playlist.m3u"
,
".MEU"
),
0
);
ck_assert_int_ne
(
util_strrcasecmp
(
"playlist.m3u"
,
".MEU"
),
0
);
ck_assert_int_ne
(
util_strrcmp
(
"playlist.m3u"
,
".M3u"
),
0
);
ck_assert_int_eq
(
util_strrcasecmp
(
"playlist.m3u"
,
".M3u"
),
0
);
ck_assert_int_eq
(
util_strrcmp
(
"playlist.m3u"
,
".m3u"
),
0
);
ck_assert_int_eq
(
util_strrcasecmp
(
"playlist.m3u"
,
".m3u"
),
0
);
}
END_TEST
START_TEST
(
test_util_utf8sanity
)
{
const
char
*
test_str
=
"TESTing
\t
1234 !@#{}
\n
"
;
char
*
str
;
str
=
util_char2utf8
(
test_str
);
ck_assert_str_eq
(
str
,
test_str
);
xfree
(
str
);
str
=
util_utf82char
(
test_str
);
ck_assert_str_eq
(
str
,
test_str
);
xfree
(
str
);
}
END_TEST
START_TEST
(
test_util_expand_words
)
{
ck_assert_ptr_eq
(
util_expand_words
(
""
,
NULL
),
NULL
);
}
END_TEST
START_TEST
(
test_util_shellquote
)
{
char
*
str
;
str
=
util_shellquote
(
"testing 1 2 3"
,
0
);
ck_assert_str_eq
(
str
,
"'testing 1 2 3'"
);
xfree
(
str
);
str
=
util_shellquote
(
"testing 1 2 3"
,
9
);
ck_assert_str_eq
(
str
,
"'testing'"
);
xfree
(
str
);
str
=
util_shellquote
(
"testing'1 2 3"
,
11
);
ck_assert_str_eq
(
str
,
"'testing'"
);
xfree
(
str
);
str
=
util_shellquote
(
"foo'bar"
,
0
);
ck_assert_str_eq
(
str
,
"'foo'
\\
''bar'"
);
xfree
(
str
);
str
=
util_shellquote
(
"foo
\\
bar"
,
0
);
ck_assert_str_eq
(
str
,
"'foo
\\
bar'"
);
xfree
(
str
);
str
=
util_shellquote
(
"''''"
,
0
);
ck_assert_str_eq
(
str
,
"''
\\
'''
\\
'''
\\
'''
\\
'''"
);
xfree
(
str
);
str
=
util_shellquote
(
"$(echo TEST)"
,
0
);
ck_assert_str_eq
(
str
,
"'$(echo TEST)'"
);
xfree
(
str
);
str
=
util_shellquote
(
"`echo TEST`"
,
1000000
);
ck_assert_str_eq
(
str
,
"'`echo TEST`'"
);
xfree
(
str
);
}
END_TEST
Suite
*
util_suite
(
void
)
{
Suite
*
s
;
TCase
*
tc_util
;
s
=
suite_create
(
"Util"
);
tc_util
=
tcase_create
(
"Util"
);
tcase_add_test
(
tc_util
,
test_util_write_pid_file
);
tcase_add_test
(
tc_util
,
test_util_strrcmp
);
tcase_add_test
(
tc_util
,
test_util_utf8sanity
);
tcase_add_test
(
tc_util
,
test_util_expand_words
);
tcase_add_test
(
tc_util
,
test_util_shellquote
);
suite_add_tcase
(
s
,
tc_util
);
return
(
s
);
}
int
main
(
void
)
{
unsigned
int
num_failed
;
Suite
*
s
;
SRunner
*
sr
;
s
=
util_suite
();
sr
=
srunner_create
(
s
);
srunner_run_all
(
sr
,
CK_NORMAL
);
num_failed
=
srunner_ntests_failed
(
sr
);
srunner_free
(
sr
);
if
(
num_failed
)
return
(
1
);
return
(
0
);
}
Write
Preview
Supports
Markdown
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