]> git.sesse.net Git - vlc/commitdiff
lua: automatic test for some lua functions.
authorRémi Duraffort <ivoire@videolan.org>
Fri, 15 Jul 2011 08:06:59 +0000 (10:06 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Sun, 17 Jul 2011 18:51:02 +0000 (20:51 +0200)
This is really basic for the moment but already allows to find (and fix) one bug.
The test is not activated by default. VLC quits if the test succeed or wait forever
if the test fails so run it with the following command:
"timeout 5 ./vlc -I luaintf --lua-intf=test"

share/lua/intf/test.lua [new file with mode: 0644]

diff --git a/share/lua/intf/test.lua b/share/lua/intf/test.lua
new file mode 100644 (file)
index 0000000..20259e0
--- /dev/null
@@ -0,0 +1,52 @@
+function assert_url(result, protocol, username, password, host, port, path)
+    assert(result.protocol == protocol)
+    assert(result.username == username)
+    assert(result.password == password)
+    assert(result.host     == host)
+    assert(result.port     == port)
+    assert(result.path     == path)
+end
+
+local timer_count = 0
+function timer_callback()
+  timer_count = timer_count + 1
+end
+
+vlc.msg.info('---- Testing misc functions ----')
+vlc.msg.info('version: ' .. vlc.misc.version())
+vlc.msg.info('copyright: ' .. vlc.misc.copyright())
+vlc.msg.info('license: ' .. vlc.misc.license())
+vlc.msg.info('datadir: ' .. vlc.misc.datadir())
+vlc.msg.info('userdatadir: ' .. vlc.misc.userdatadir())
+vlc.msg.info('homedir: ' .. vlc.misc.homedir())
+vlc.msg.info('configdir: ' .. vlc.misc.configdir())
+vlc.msg.info('cachedir: ' .. vlc.misc.cachedir())
+vlc.msg.info('mdate: ' .. vlc.misc.mdate())
+
+vlc.msg.info(' * Testing the timer')
+local timer = vlc.misc.timer('timer_callback')
+timer:schedule(true, 100, 0)
+vlc.misc.mwait(vlc.misc.mdate()+1000000)
+assert(timer_count == 1)
+vlc.msg.info('   [done]')
+
+vlc.msg.info('---- Testing net functions ----')
+vlc.msg.info(' * testing vlc.net.url_parse')
+vlc.msg.info('    "filename.ext"')
+assert_url(vlc.net.url_parse('file:///filename.ext'), 'file', nil, nil,
+           nil, 0, '/filename.ext')
+vlc.msg.info('    "http://server.org/path/file.ext"')
+assert_url(vlc.net.url_parse('http://server.org/path/file.ext'),
+           'http', nil, nil, 'server.org', 0, '/path/file.ext')
+vlc.msg.info('    "rtmp://server.org:4212/bla.ext"')
+assert_url(vlc.net.url_parse('rtmp://server.org:4212/bla.ext'),
+           'rtmp', nil, nil, 'server.org', 4212, '/bla.ext')
+vlc.msg.info('    "ftp://userbla@server.org:4567/bla.ext"')
+assert_url(vlc.net.url_parse('rtmp://userbla@server.org:4567/bla.ext'),
+           'rtmp', 'userbla', nil, 'server.org', 4567, '/bla.ext')
+vlc.msg.info('    "sftp://userbla:Passw0rd@server.org/bla.ext"')
+assert_url(vlc.net.url_parse('sftp://userbla:Passw0rd@server.org/bla.ext'),
+           'sftp', 'userbla', 'Passw0rd', 'server.org', 0, '/bla.ext')
+vlc.msg.info("")
+
+vlc.misc.quit()