[vlc-commits] tests: check dash uri token replacements

Francois Cartegnie git at videolan.org
Tue Jul 31 18:31:59 CEST 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Jul 31 18:14:00 2018 +0200| [d5fd1c8ca283dbe0dd05f9dc735bea4294c06d17] | committer: Francois Cartegnie

tests: check dash uri token replacements

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d5fd1c8ca283dbe0dd05f9dc735bea4294c06d17
---

 test/Makefile.am               |   6 +-
 test/modules/demux/dashuri.cpp | 164 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 169 insertions(+), 1 deletion(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index e6c511adff..db8e8b1786 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -32,7 +32,8 @@ check_PROGRAMS = \
 	test_src_misc_keystore \
 	test_modules_packetizer_helpers \
 	test_modules_packetizer_hxxx \
-	test_modules_keystore
+	test_modules_keystore \
+        test_modules_demux_dashuri
 if ENABLE_SOUT
 check_PROGRAMS += test_modules_tls
 endif
@@ -132,6 +133,9 @@ test_modules_keystore_SOURCES = modules/keystore/test.c
 test_modules_keystore_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_tls_SOURCES = modules/misc/tls.c
 test_modules_tls_LDADD = $(LIBVLCCORE) $(LIBVLC)
+test_modules_demux_dashuri_SOURCES = modules/demux/dashuri.cpp \
+                                  ../modules/demux/dash/mpd/TemplatedUri.cpp \
+                                  ../modules/demux/dash/mpd/TemplatedUri.hpp
 
 checkall:
 	$(MAKE) check_PROGRAMS="$(check_PROGRAMS) $(EXTRA_PROGRAMS)" check
diff --git a/test/modules/demux/dashuri.cpp b/test/modules/demux/dashuri.cpp
new file mode 100644
index 0000000000..64ff9c401c
--- /dev/null
+++ b/test/modules/demux/dashuri.cpp
@@ -0,0 +1,164 @@
+/*****************************************************************************
+ * dashuri.cpp
+ *****************************************************************************
+ * Copyright (C) 2018 VideoLabs, VideoLAN and VLC Authors
+ *
+ * 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
+
+#include "../modules/demux/dash/mpd/TemplatedUri.hpp"
+
+#include <iostream>
+#include <cstring>
+
+using namespace dash::mpd;
+
+static const struct
+{
+    const char *src;
+    const char *dst;
+    const char *str;
+    const unsigned val;
+} dataset[] = {
+    {
+        "",
+        "",
+        NULL,
+        0,
+    },
+    {
+        "$",
+        "$",
+        NULL,
+        0,
+    },
+    {
+        "/Num$$ber.m4v",
+        "/Num$ber.m4v",
+        NULL,
+        0,
+    },
+    {
+        "/$Number$.m4v",
+        "/123.m4v",
+        NULL,
+        123,
+    },
+    {
+        "/$$$Number$.m4v",
+        "/$456789123.m4v",
+        NULL,
+        456789123,
+    },
+    {
+        "$Number%d$",
+        "123",
+        NULL,
+        123,
+    },
+    {
+        "/$Number%5d$.m4v",
+        "/00001.m4v",
+        NULL,
+        1,
+    },
+    {
+        "/$Number%2d$.m4v",
+        "/123456.m4v",
+        NULL,
+        123456, /* Must not truncate */
+    },
+    {
+        "/$RepresentationID$.m4v",
+        "/foobar.m4v",
+        "foobar",
+        0,
+    },
+    {
+        "/$RepresentationID$.m4v",
+        "/$Time$.m4v",
+        "$Time$",
+        0,
+    },
+    {
+        "$RepresentationID$/$Number$$Time$$$",
+        "id/123123$",
+        "id",
+        123, /* Must not truncate */
+    },
+};
+
+int main(int, char **)
+{
+    for(size_t i=0; i<sizeof(dataset)/sizeof(dataset[0]); i++)
+    {
+        std::string str = std::string(dataset[i].src);
+
+        std::cout << str << std::endl;
+
+        std::string::size_type pos = 0;
+        while(pos < str.length())
+        {
+            TemplatedUri::Token token;
+
+            if(str[pos] == '$' && TemplatedUri::IsDASHToken(str, pos, token))
+            {
+                std::cout << " * token " << str.substr(pos, token.fulllength)
+                          << " " << token.width << std::endl;
+
+                TemplatedUri::TokenReplacement replparam;
+
+                switch(token.type)
+                {
+                    case TemplatedUri::Token::TOKEN_TIME:
+                    case TemplatedUri::Token::TOKEN_BANDWIDTH:
+                    case TemplatedUri::Token::TOKEN_NUMBER:
+                        replparam.value = dataset[i].val;
+                        break;
+                    case TemplatedUri::Token::TOKEN_REPRESENTATION:
+                    {
+                        if(!dataset[i].str)
+                            return -1;
+                        replparam.str = std::string(dataset[i].str);
+                        break;
+                    }
+                    case TemplatedUri::Token::TOKEN_ESCAPE:
+                        break;
+
+                    default:
+                        pos += token.fulllength;
+                        continue;
+                }
+
+                std::string::size_type newlen =
+                    TemplatedUri::ReplaceDASHToken(str, pos, token, replparam);
+                if(newlen == std::string::npos)
+                    return -1;
+                pos += newlen;
+            }
+            else pos++;
+        }
+
+        std::cout << " -> " << str << std::endl;
+
+        if(std::strcmp(dataset[i].dst, str.c_str()))
+            return 1;
+    }
+
+    return 0;
+}



More information about the vlc-commits mailing list