Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
55d00831
Commit
55d00831
authored
Dec 18, 2015
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
https: add chunked transfer encoding unit test
parent
547418a7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
155 additions
and
3 deletions
+155
-3
modules/access/http/Makefile.am
modules/access/http/Makefile.am
+4
-2
modules/access/http/chunked.c
modules/access/http/chunked.c
+0
-1
modules/access/http/chunked_test.c
modules/access/http/chunked_test.c
+151
-0
No files found.
modules/access/http/Makefile.am
View file @
55d00831
...
...
@@ -32,14 +32,16 @@ h2output_test_SOURCES = access/http/h2output_test.c
h2output_test_LDADD
=
libvlc_http.la
$(LIBPTHREAD)
h2conn_test_SOURCES
=
access/http/h2conn_test.c
h2conn_test_LDADD
=
libvlc_http.la
$(LIBPTHREAD)
h1chunked_test_SOURCES
=
access/http/chunked_test.c
h1chunked_test_LDADD
=
libvlc_http.la
http_msg_test_SOURCES
=
access/http/message_test.c
\
access/http/message.c access/http/message.h
http_file_test_SOURCES
=
access/http/file_test.c
\
access/http/message.c access/http/message.h
\
access/http/file.c access/http/file.h
check_PROGRAMS
+=
hpack_test hpackenc_test
\
h2frame_test h2output_test h2conn_test
\
h2frame_test h2output_test h2conn_test
h1chunked_test
\
http_msg_test http_file_test
TESTS
+=
hpack_test hpackenc_test
\
h2frame_test h2output_test h2conn_test
\
h2frame_test h2output_test h2conn_test
h1chunked_test
\
http_msg_test http_file_test
modules/access/http/chunked.c
View file @
55d00831
...
...
@@ -50,7 +50,6 @@ static_assert(offsetof(struct vlc_chunked_stream, stream) == 0, "Cast error");
static
void
*
vlc_chunked_fatal
(
struct
vlc_chunked_stream
*
s
)
{
assert
(
!
s
->
error
);
s
->
error
=
true
;
return
NULL
;
}
...
...
modules/access/http/chunked_test.c
0 → 100644
View file @
55d00831
/*****************************************************************************
* chunked_test.c: HTTP 1.1 chunked encoding decoder test
*****************************************************************************
* Copyright (C) 2015 Rémi Denis-Courmont
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#undef NDEBUG
#include <assert.h>
//#include <inttypes.h>
//#include <stdlib.h>
#include <string.h>
#include <vlc_common.h>
#include <vlc_tls.h>
#include <vlc_block.h>
#include "h1conn.h"
#include "message.h"
/* I/O callbacks */
static
const
char
*
stream_content
;
static
size_t
stream_length
;
static
bool
stream_bad
;
static
ssize_t
recv_callback
(
struct
vlc_tls
*
tls
,
void
*
buf
,
size_t
len
)
{
size_t
copy
=
len
;
if
(
copy
>
stream_length
)
copy
=
stream_length
;
if
(
copy
>
0
)
{
memcpy
(
buf
,
stream_content
,
copy
);
stream_content
+=
copy
;
stream_length
-=
copy
;
}
(
void
)
tls
;
return
copy
;
}
static
void
close_callback
(
struct
vlc_tls
*
tls
)
{
(
void
)
tls
;
}
static
struct
vlc_tls
chunked_tls
=
{
.
recv
=
recv_callback
,
.
close
=
close_callback
,
};
static
void
stream_close_callback
(
struct
vlc_http_stream
*
stream
,
bool
bad
)
{
(
void
)
stream
;
assert
(
bad
==
stream_bad
);
}
static
const
struct
vlc_http_stream_cbs
chunked_stream_cbs
=
{
.
close
=
stream_close_callback
,
};
static
struct
vlc_http_stream
chunked_stream
=
{
&
chunked_stream_cbs
,
};
/* Test cases */
static
void
test_good
(
void
)
{
struct
vlc_http_stream
*
s
;
block_t
*
b
;
/* Simple good payload */
stream_content
=
"A
\r\n
"
"1234567890
\r\n
"
"1A; ext-foo=1
\r\n
"
"abcdefghijklmnopqrstuvwxyz
\r\n
"
"0
\r\n
"
"
\r\n
"
;
stream_length
=
strlen
(
stream_content
);
stream_bad
=
false
;
s
=
vlc_chunked_open
(
&
chunked_stream
,
&
chunked_tls
);
assert
(
s
!=
NULL
);
assert
(
vlc_http_stream_read_headers
(
s
)
==
NULL
);
b
=
vlc_http_stream_read
(
s
);
assert
(
b
!=
NULL
);
assert
(
b
->
i_buffer
==
10
);
assert
(
!
memcmp
(
b
->
p_buffer
,
"1234567890"
,
10
));
block_Release
(
b
);
b
=
vlc_http_stream_read
(
s
);
assert
(
b
!=
NULL
);
assert
(
b
->
i_buffer
==
26
);
assert
(
!
memcmp
(
b
->
p_buffer
,
"abcdefghijklmnopqrstuvwxyz"
,
26
));
block_Release
(
b
);
b
=
vlc_http_stream_read
(
s
);
assert
(
b
==
NULL
);
b
=
vlc_http_stream_read
(
s
);
assert
(
b
==
NULL
);
vlc_http_stream_close
(
s
,
false
);
}
static
void
test_bad
(
const
char
*
payload
)
{
struct
vlc_http_stream
*
s
;
block_t
*
b
;
stream_content
=
payload
;
stream_length
=
strlen
(
payload
);
stream_bad
=
true
;
s
=
vlc_chunked_open
(
&
chunked_stream
,
&
chunked_tls
);
assert
(
s
!=
NULL
);
while
((
b
=
vlc_http_stream_read
(
s
))
!=
NULL
)
block_Release
(
b
);
vlc_http_stream_close
(
s
,
false
);
}
int
main
(
void
)
{
test_good
();
test_bad
(
""
);
test_bad
(
"A
\r\n
"
"123456789"
);
test_bad
(
"Z
\r\n
"
"123456789"
);
test_bad
(
"0
\r\n
"
);
return
0
;
}
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