From 6259bcd51f057a7389bf41a1c653c1e5387c6999 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 28 Jan 2010 04:58:03 +0000 Subject: Chris Conroy provided first RTSP tests --- tests/libtest/Makefile.inc | 14 ++++- tests/libtest/lib567.c | 54 ++++++++++++++++++ tests/libtest/lib568.c | 135 +++++++++++++++++++++++++++++++++++++++++++ tests/libtest/lib569.c | 107 ++++++++++++++++++++++++++++++++++ tests/libtest/lib570.c | 87 ++++++++++++++++++++++++++++ tests/libtest/lib571.c | 139 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 535 insertions(+), 1 deletion(-) create mode 100644 tests/libtest/lib567.c create mode 100644 tests/libtest/lib568.c create mode 100644 tests/libtest/lib569.c create mode 100644 tests/libtest/lib570.c create mode 100644 tests/libtest/lib571.c (limited to 'tests/libtest') diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 087758d73..5a5a0ea8e 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -10,7 +10,8 @@ noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506 \ lib517 lib518 lib519 lib520 lib521 lib523 lib524 lib525 lib526 lib527 \ lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \ lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 \ - lib539 lib557 lib558 lib559 lib560 lib562 lib564 lib565 lib566 + lib539 lib557 lib558 lib559 lib560 lib562 lib564 lib565 lib566 lib567 \ + lib568 lib569 lib570 lib571 lib500_SOURCES = lib500.c $(SUPPORTFILES) @@ -131,3 +132,14 @@ lib565_SOURCES = lib510.c $(SUPPORTFILES) lib565_CFLAGS = -DLIB565 lib566_SOURCES = lib566.c $(SUPPORTFILES) + +lib567_SOURCES = lib567.c $(SUPPORTFILES) + +lib568_SOURCES = lib568.c $(SUPPORTFILES) + +lib569_SOURCES = lib569.c $(SUPPORTFILES) + +lib570_SOURCES = lib570.c $(SUPPORTFILES) + +lib571_SOURCES = lib571.c $(SUPPORTFILES) + diff --git a/tests/libtest/lib567.c b/tests/libtest/lib567.c new file mode 100644 index 000000000..e04873b11 --- /dev/null +++ b/tests/libtest/lib567.c @@ -0,0 +1,54 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include "test.h" +#include "memdebug.h" + +/* + * Test a simple OPTIONS request with a custom header + */ +int test(char *URL) +{ + CURLcode res; + CURL *curl; + struct curl_slist *custom_headers=NULL; + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + /* Dump data to stdout for protocol verification */ + curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + + curl_easy_setopt(curl, CURLOPT_URL, URL); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI, URL); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "test567"); + + custom_headers = curl_slist_append(custom_headers, "Test-Number: 567"); + curl_easy_setopt(curl, CURLOPT_RTSPHEADER, custom_headers); + + res = curl_easy_perform(curl); + + curl_slist_free_all(custom_headers); + curl_easy_cleanup(curl); + curl_global_cleanup(); + + return (int)res; +} + diff --git a/tests/libtest/lib568.c b/tests/libtest/lib568.c new file mode 100644 index 000000000..5e59a9cae --- /dev/null +++ b/tests/libtest/lib568.c @@ -0,0 +1,135 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include "test.h" + +#include +#include +#include +#include + +#include + +#include "memdebug.h" + +/* build request url */ +static char *suburl(const char *base, int i) +{ + return curl_maprintf("%s%.4d", base, i); +} + +/* + * Test the Client->Server ANNOUNCE functionality (PUT style) + */ +int test(char *URL) +{ + CURLcode res; + CURL *curl; + int sdp; + FILE *sdpf; + struct stat file_info; + char *stream_uri; + int request=1; + struct curl_slist *custom_headers=NULL; + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + + curl_easy_setopt(curl, CURLOPT_URL, URL); + + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + sdp = open("log/file568.txt", O_RDONLY); + fstat(sdp, &file_info); + sdpf = fdopen(sdp, "rb"); + if(sdpf == NULL) { + close(sdp); + fprintf(stderr, "can't open log/file568.txt\n"); + return TEST_ERR_MAJOR_BAD; + } + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE); + + curl_easy_setopt(curl, CURLOPT_READDATA, sdpf); + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t) file_info.st_size); + + /* Do the ANNOUNCE */ + res = curl_easy_perform(curl); + if(res) { + fclose(sdpf); + close(sdp); + return res; + } + + curl_easy_setopt(curl, CURLOPT_UPLOAD, 0L); + fclose(sdpf); + close(sdp); + + /* Make sure we can do a normal request now */ + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); + res = curl_easy_perform(curl); + if(res) + return res; + + /* Now do a POST style one */ + + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + custom_headers = curl_slist_append(custom_headers, + "Content-Type: posty goodness"); + + curl_easy_setopt(curl, CURLOPT_RTSPHEADER, custom_headers); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_ANNOUNCE); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, + "postyfield=postystuff&project=curl\n"); + + res = curl_easy_perform(curl); + if(res) + return res; + + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, NULL); + curl_easy_setopt(curl, CURLOPT_RTSPHEADER, NULL); + curl_slist_free_all(custom_headers); + + /* Make sure we can do a normal request now */ + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); + res = curl_easy_perform(curl); + if(res) + return res; + + curl_easy_cleanup(curl); + curl_global_cleanup(); + + return res; +} + diff --git a/tests/libtest/lib569.c b/tests/libtest/lib569.c new file mode 100644 index 000000000..6f276d350 --- /dev/null +++ b/tests/libtest/lib569.c @@ -0,0 +1,107 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include "test.h" + +#include + +#include "memdebug.h" + +/* build request url */ +static char *suburl(const char *base, int i) +{ + return curl_maprintf("%s%.4d", base, i); +} + +/* + * Test Session ID capture + */ +int test(char *URL) +{ + CURLcode res; + CURL *curl; + char *stream_uri; + char *rtsp_session_id; + int request=1; + int i; + FILE *idfile; + + idfile = fopen(libtest_arg2, "w"); + if(idfile == NULL) { + fprintf(stderr, "couldn't open the Session ID File\n"); + return TEST_ERR_MAJOR_BAD; + } + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + fclose(idfile); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + fclose(idfile); + return TEST_ERR_MAJOR_BAD; + } + + curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + + curl_easy_setopt(curl, CURLOPT_URL, URL); + + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); + res = curl_easy_perform(curl); + if(res != CURLE_BAD_FUNCTION_ARGUMENT) { + fprintf(stderr, "This should have failed. " + "Cannot setup without a Transport: header"); + fclose(idfile); + return TEST_ERR_MAJOR_BAD; + } + + /* Go through the various Session IDs */ + for(i = 0; i < 3; i++) { + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); + curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, + "Fake/NotReal/JustATest;foo=baz"); + res = curl_easy_perform(curl); + if(res) { + fclose(idfile); + return res; + } + + curl_easy_getinfo(curl, CURLINFO_RTSP_SESSION_ID, &rtsp_session_id); + fprintf(idfile, "Got Session ID: [%s]\n", rtsp_session_id); + rtsp_session_id = NULL; + + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); + curl_easy_perform(curl); + + /* Clear for the next go-round */ + curl_easy_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL); + } + + fclose(idfile); + + curl_easy_cleanup(curl); + curl_global_cleanup(); + + return (int)res; +} + diff --git a/tests/libtest/lib570.c b/tests/libtest/lib570.c new file mode 100644 index 000000000..69a0168e0 --- /dev/null +++ b/tests/libtest/lib570.c @@ -0,0 +1,87 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include "test.h" + +#include + +#include "memdebug.h" + +/* build request url */ +static char *suburl(const char *base, int i) +{ + return curl_maprintf("%s%.4d", base, i); +} + +int test(char *URL) +{ + CURLcode res; + CURL *curl; + int request=1; + char *stream_uri; + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + curl_easy_setopt(curl, CURLOPT_HEADERDATA, stdout); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, stdout); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + + curl_easy_setopt(curl, CURLOPT_URL, URL); + + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_OPTIONS); + + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + res = curl_easy_perform(curl); + if(res != CURLE_RTSP_CSEQ_ERROR) { + fprintf(stderr, "Failed to detect CSeq mismatch"); + return res; + } + + curl_easy_setopt(curl, CURLOPT_RTSP_CLIENT_CSEQ, 999); + curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, + "RAW/RAW/UDP;unicast;client_port=3056-3057"); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); + + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + res = curl_easy_perform(curl); + if(res) + return res; + + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY); + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + res = curl_easy_perform(curl); + if(res != CURLE_RTSP_SESSION_ERROR) { + fprintf(stderr, "Failed to detect a Session ID mismatch"); + } + + curl_easy_cleanup(curl); + curl_global_cleanup(); + + return (int)res; +} + diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c new file mode 100644 index 000000000..f530deadc --- /dev/null +++ b/tests/libtest/lib571.c @@ -0,0 +1,139 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + */ + +#include "test.h" + +#include +#include +#include +#include + +#include + +#include "memdebug.h" + +#define RTP_DATA_SIZE 12 +static const char *RTP_DATA = "$_1234\n\0asdf"; + +static int rtp_packet_count = 0; + +static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) { + char *data = (char *)ptr; + int channel = (int)data[0]; + int message_size = (int)(size * nmemb - 3); + int i; + (void)stream; + + printf("RTP: message size %d, channel %d\n", message_size, channel); + + data += 3; + for(i = 0; i < message_size; i+= RTP_DATA_SIZE) { + if(message_size - i > RTP_DATA_SIZE) { + if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) { + printf("RTP PAYLOAD CORRUPTED [%s]\n", data + i); + } + } else { + if (memcmp(RTP_DATA, data + i, message_size - i) != 0) { + printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n", + message_size - i, data + i); + } + } + } + + rtp_packet_count++; + fprintf(stderr, "packet count is %d\n", rtp_packet_count); + + return size * nmemb; +} + +/* build request url */ +static char *suburl(const char *base, int i) +{ + return curl_maprintf("%s%.4d", base, i); +} + +int test(char *URL) +{ + CURLcode res; + CURL *curl; + char *stream_uri; + int request=1; + FILE *protofile; + + protofile = fopen(libtest_arg2, "w"); + if(protofile == NULL) { + fprintf(stderr, "Couldn't open the protocol dump file\n"); + return TEST_ERR_MAJOR_BAD; + } + + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + fclose(protofile); + return TEST_ERR_MAJOR_BAD; + } + + if ((curl = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + fclose(protofile); + return TEST_ERR_MAJOR_BAD; + } + curl_easy_setopt(curl, CURLOPT_URL, URL); + + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + + curl_easy_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write); + curl_easy_setopt(curl, CURLOPT_TIMEOUT, 3); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, protofile); + + curl_easy_setopt(curl, CURLOPT_RTSP_TRANSPORT, "RTP/AVP/TCP;interleaved=0-1"); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP); + res = curl_easy_perform(curl); + + /* This PLAY starts the interleave */ + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY); + res = curl_easy_perform(curl); + + /* The DESCRIBE request will try to consume data after the Content */ + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE); + + res = curl_easy_perform(curl); + + stream_uri = suburl(URL, request++); + curl_easy_setopt(curl, CURLOPT_RTSP_STREAM_URI,stream_uri); + free(stream_uri); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY); + res = curl_easy_perform(curl); + + fprintf(stderr, "PLAY COMPLETE\n"); + + /* Use Receive to get the rest of the data */ + while(!res && rtp_packet_count < 13) { + fprintf(stderr, "LOOPY LOOP!\n"); + curl_easy_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE); + res = curl_easy_perform(curl); + } + + curl_easy_cleanup(curl); + curl_global_cleanup(); + fclose(protofile); + + return (int)res; +} + -- cgit v1.2.3