[vlc-commits] tests: adaptive: run tests against static lib

Francois Cartegnie git at videolan.org
Fri Jan 22 22:10:33 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Dec 17 11:17:55 2020 +0100| [b4c035ca978c3196c5fb6c4d7d9458747f303093] | committer: Francois Cartegnie

tests: adaptive: run tests against static lib

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

 modules/demux/Makefile.am                          |  8 ++
 .../demux/adaptive/test/playlist/TemplatedUri.cpp  | 96 +++++++++++-----------
 modules/demux/adaptive/test/test.cpp               | 35 ++++++++
 modules/demux/adaptive/test/test.hpp               | 41 +++++++++
 test/Makefile.am                                   |  2 -
 5 files changed, 134 insertions(+), 48 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index c13228bcba..ca641e6670 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -504,6 +504,14 @@ libadaptive_plugin_la_CXXFLAGS = $(libvlc_adaptive_la_CXXFLAGS)
 libadaptive_plugin_la_LIBADD = libvlc_adaptive.la
 demux_LTLIBRARIES += libadaptive_plugin.la
 
+adaptive_test_SOURCES = \
+    demux/adaptive/test/playlist/TemplatedUri.cpp \
+    demux/adaptive/test/test.cpp \
+    demux/adaptive/test/test.hpp
+adaptive_test_LDADD = libvlc_adaptive.la
+check_PROGRAMS += adaptive_test
+TESTS += adaptive_test
+
 libytdl_plugin_la_SOURCES = demux/ytdl.c
 libytdl_plugin_la_LIBADD = libvlc_json.la
 if !HAVE_WIN32
diff --git a/test/modules/demux/dashuri.cpp b/modules/demux/adaptive/test/playlist/TemplatedUri.cpp
similarity index 56%
rename from test/modules/demux/dashuri.cpp
rename to modules/demux/adaptive/test/playlist/TemplatedUri.cpp
index 0c3ea56ad9..3f0be13bf3 100644
--- a/test/modules/demux/dashuri.cpp
+++ b/modules/demux/adaptive/test/playlist/TemplatedUri.cpp
@@ -21,9 +21,10 @@
 # include "config.h"
 #endif
 
-#include "../modules/demux/dash/mpd/TemplatedUri.cpp"
+#include "../test.hpp"
+
+#include "../../../dash/mpd/TemplatedUri.hpp"
 
-#include <iostream>
 #include <cstring>
 #include <vlc_common.h>
 
@@ -104,62 +105,65 @@ static const struct
     },
 };
 
-int main(int, char **)
+int TemplatedUri_test()
 {
-    for(size_t i=0; i<ARRAY_SIZE(dataset); i++)
-    {
-        std::string str = std::string(dataset[i].src);
-
-        std::cout << str << std::endl;
-
-        std::string::size_type pos = 0;
-        while(pos < str.length())
+    try {
+        for(size_t i=0; i<ARRAY_SIZE(dataset); i++)
         {
-            TemplatedUri::Token token;
+            std::string str = std::string(dataset[i].src);
 
-            if(str[pos] == '$' && TemplatedUri::IsDASHToken(str, pos, token))
-            {
-                std::cout << " * token " << str.substr(pos, token.fulllength)
-                          << " " << token.width << std::endl;
+            std::cerr << str << std::endl;
 
-                TemplatedUri::TokenReplacement replparam;
+            std::string::size_type pos = 0;
+            while(pos < str.length())
+            {
+                TemplatedUri::Token token;
 
-                switch(token.type)
+                if(str[pos] == '$' && TemplatedUri::IsDASHToken(str, pos, token))
                 {
-                    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:
+                    std::cerr << " * token " << str.substr(pos, token.fulllength)
+                              << " " << token.width << std::endl;
+
+                    TemplatedUri::TokenReplacement replparam;
+
+                    switch(token.type)
                     {
-                        if(!dataset[i].str)
-                            return -1;
-                        replparam.str = std::string(dataset[i].str);
-                        break;
+                        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:
+                        {
+                            Expect(dataset[i].str);
+                            replparam.str = std::string(dataset[i].str);
+                            break;
+                        }
+                        case TemplatedUri::Token::TOKEN_ESCAPE:
+                            break;
+
+                        default:
+                            pos += token.fulllength;
+                            continue;
                     }
-                    case TemplatedUri::Token::TOKEN_ESCAPE:
-                        break;
 
-                    default:
-                        pos += token.fulllength;
-                        continue;
+                    std::string::size_type newlen =
+                            TemplatedUri::ReplaceDASHToken(str, pos, token, replparam);
+                    Expect(newlen != std::string::npos);
+                    pos += newlen;
                 }
-
-                std::string::size_type newlen =
-                    TemplatedUri::ReplaceDASHToken(str, pos, token, replparam);
-                if(newlen == std::string::npos)
-                    return -1;
-                pos += newlen;
+                else pos++;
             }
-            else pos++;
-        }
 
-        std::cout << " -> " << str << std::endl;
+            std::cerr << " -> " << str << std::endl;
 
-        if(std::strcmp(dataset[i].dst, str.c_str()))
-            return 1;
-    }
+            Expect(!std::strcmp(dataset[i].dst, str.c_str()));
+        }
 
-    return 0;
+        return 0;
+    }
+    catch (...)
+    {
+        return 1;
+    }
 }
diff --git a/modules/demux/adaptive/test/test.cpp b/modules/demux/adaptive/test/test.cpp
new file mode 100644
index 0000000000..07ce55226a
--- /dev/null
+++ b/modules/demux/adaptive/test/test.cpp
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * test.cpp
+ *****************************************************************************
+ * Copyright (C) 2018-2020 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 <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_demux.h>
+
+#include "test.hpp"
+
+extern const char vlc_module_name[] = "foobar";
+
+int main()
+{
+    return TemplatedUri_test();
+}
diff --git a/modules/demux/adaptive/test/test.hpp b/modules/demux/adaptive/test/test.hpp
new file mode 100644
index 0000000000..3f39ae15dd
--- /dev/null
+++ b/modules/demux/adaptive/test/test.hpp
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * test.hpp
+ *****************************************************************************
+ * Copyright (C) 2020 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.
+ *****************************************************************************/
+#ifndef ADAPTIVE_TEST_H
+#define ADAPTIVE_TEST_H
+#include <exception>
+#include <iostream>
+
+#define DoExpect(testcond, testcontext, testline) \
+    try {\
+        if (!(testcond)) \
+            throw 1;\
+    }\
+    catch (...)\
+    {\
+        std::cerr << testcontext << ": failed " \
+            " line " << testline << std::endl;\
+        std::rethrow_exception(std::current_exception());\
+    }
+
+#define Expect(testcond) DoExpect((testcond), __FUNCTION__, __LINE__)
+
+int TemplatedUri_test();
+
+#endif
diff --git a/test/Makefile.am b/test/Makefile.am
index cc7d5ccb34..54666fdc85 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -39,7 +39,6 @@ check_PROGRAMS = \
 	test_modules_packetizer_hevc \
 	test_modules_packetizer_mpegvideo \
 	test_modules_keystore \
-	test_modules_demux_dashuri \
 	test_modules_demux_timestamps_filter \
 	test_modules_demux_ts_pes \
 	$(NULL)
@@ -158,7 +157,6 @@ 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
 test_modules_demux_timestamps_filter_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_demux_timestamps_filter_SOURCES = modules/demux/timestamps_filter.c
 test_modules_demux_ts_pes_LDADD = $(LIBVLCCORE) $(LIBVLC)



More information about the vlc-commits mailing list