Unverified Commit 726e1b74 authored by RobLoach's avatar RobLoach Committed by GitHub
Browse files

Split up unit tests into individual modules (#165)

parent 759e1d7b
This software is distributed under the BSD License.
Copyright (c) 2005-2014, Philippe Fremy <phil at freehackers dot org>
Copyright (c) 2005-2018, Philippe Fremy <phil at freehackers dot org>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
This diff is collapsed.
function lutro.filesystem.setRequirePathTest()
local paths = lutro.filesystem.getRequirePath()
paths = paths .. ';/lutro.filesystem.setRequirePathTest/?.lua'
lutro.filesystem.setRequirePath(paths)
local paths = lutro.filesystem.getRequirePath()
local index = string.find(paths, 'setRequirePathTest')
unit.assertTrue(index > 1)
end
function lutro.filesystem.getRequirePathTest()
local paths = lutro.filesystem.getRequirePath()
unit.assertIsString(paths)
unit.assertEquals(paths, package.path)
end
function lutro.filesystem.getUserDirectoryTest()
local homeDir = lutro.filesystem.getUserDirectory()
-- @todo Find out how to make os.getenv('HOME') work on Windows?
local luaHomeDir = os.getenv("HOME")
unit.assertEquals(homeDir, luaHomeDir)
end
return {
lutro.filesystem.setRequirePathTest,
lutro.filesystem.getRequirePathTest,
lutro.filesystem.getUserDirectoryTest
}
\ No newline at end of file
function lutro.keyboard.getScancodeFromKeyTest()
local scancode = lutro.keyboard.getScancodeFromKey('f')
unit.assertIsNumber(scancode)
unit.assertEquals(scancode, 102)
end
function lutro.keyboard.getKeyFromScancodeTest()
local key = lutro.keyboard.getKeyFromScancode(102)
unit.assertIsString(key)
unit.assertEquals(key, 'f')
end
return {
lutro.keyboard.getScancodeFromKeyTest,
lutro.keyboard.getKeyFromScancodeTest
}
\ No newline at end of file
function lutro.math.setRandomSeedTest()
lutro.math.setRandomSeed(3)
lutro.math.setRandomSeed(3, 10)
end
function lutro.math.randomTest()
for i = 1, 1000, 1 do
actual = lutro.math.random(10, 20)
unit.assertTrue(actual >= 10 and actual <= 20)
end
for i = 1, 1000, 1 do
actual = lutro.math.random(10)
unit.assertTrue(actual >= 0 and actual <= 10)
end
for i = 1, 1000, 1 do
actual = lutro.math.random()
unit.assertTrue(actual >= 0 and actual <= 1)
end
end
return {
lutro.math.setRandomSeedTest,
lutro.math.randomTest
}
\ No newline at end of file
--http = require 'socket.http'
function UTF8Test()
local utf8 = require("utf8")
local actual = utf8.len("Hello World!")
unit.assertEquals(actual, 12)
end
-- function http.requestTest()
-- local http = require('socket.http')
-- local result = http.request('http://buildbot.libretro.com/assets/frontend/info/lutro_libretro.info')
-- unit.assertStrContains(result, 'display_name = "LUA Engine (Lutro)"')
--end
function lutro.getVersionTest()
local major, minor, revision, codename = lutro.getVersion()
unit.assertIsNumber(major)
unit.assertIsNumber(minor)
unit.assertIsNumber(revision)
unit.assertEquals(codename, 'Lutro')
end
function lutro.system.getPowerInfoTest()
local state, percent, seconds = lutro.system.getPowerInfo()
unit.assertIsString(state)
unit.assertEquals(state, 'unknown')
unit.assertIsNil(percent)
unit.assertIsNil(seconds)
end
function lutro.system.openURLTest()
local success = lutro.system.openURL('http://libretro.com')
unit.assertIsBoolean(success)
unit.assertEquals(success, false)
end
function lutro.system.vibrateTest()
local output = lutro.system.vibrate()
unit.assertIsNil(output)
lutro.system.vibrate(0.5)
end
function lutro.system.getProcessorCountTest()
local count = lutro.system.getProcessorCount()
unit.assertIsNumber(count)
unit.assertEquals(count, 1)
end
function lutro.system.getClipboardTextTest()
local clipboard = lutro.system.getClipboardText()
unit.assertIsString(clipboard)
unit.assertEquals(clipboard, "")
end
function lutro.system.setClipboardTextTest()
local clipboard = "Hello, World!"
lutro.system.setClipboardText(clipboard)
clipboard = "Goodbye, World!"
clipboard = lutro.system.getClipboardText()
unit.assertEquals(clipboard, "Hello, World!")
end
return {
UTF8Test,
-- http.requestTest,
lutro.getVersionTest,
lutro.system.getPowerInfoTest,
lutro.system.openURLTest,
lutro.system.vibrateTest,
lutro.system.getProcessorCountTest,
lutro.system.getClipboardTextTest,
lutro.system.setClipboardTextTest
}
\ No newline at end of file
function lutro.timer.getDeltaTest()
local delta = lutro.timer.getDelta()
unit.assertIsNumber(delta)
end
return {
lutro.timer.getDeltaTest
}
\ No newline at end of file
function lutro.window.minimizeTest()
lutro.window.minimize()
end
function lutro.window.maximizeTest()
lutro.window.maximize()
end
function lutro.window.getTitleTest()
local title = lutro.window.getTitle()
unit.assertIsString(title)
unit.assertEquals(title, "Lutro")
end
function lutro.window.setTitleTest()
lutro.window.setTitle("Hello World!")
end
function lutro.window.setPositionTest()
lutro.window.setPosition(1, 1)
lutro.window.setPosition(100, 200, 2)
end
function lutro.window.getPositionTest()
local x, y, display = lutro.window.getPosition()
unit.assertIsNumber(x)
unit.assertIsNumber(y)
unit.assertIsNumber(display)
unit.assertEquals(x, 0)
unit.assertEquals(y, 0)
unit.assertEquals(display, 1)
end
function lutro.window.requestAttentionTest()
lutro.window.requestAttention()
lutro.window.requestAttention("Test")
end
function lutro.window.getDisplayNameTest()
local display = lutro.window.getDisplayName()
unit.assertIsString(display)
unit.assertEquals(display, "libretro")
display = lutro.window.getDisplayName(3)
unit.assertIsString(display)
unit.assertEquals(display, "libretro")
end
function lutro.window.setDisplaySleepEnabledTest()
lutro.window.setDisplaySleepEnabled(true)
end
return {
lutro.window.minimizeTest,
lutro.window.maximizeTest,
lutro.window.getTitleTest,
lutro.window.setTitleTest,
lutro.window.setPositionTest,
lutro.window.getPositionTest,
lutro.window.requestAttentionTest,
lutro.window.getDisplayNameTest,
lutro.window.setDisplaySleepEnabledTest
}
\ No newline at end of file
......@@ -3,220 +3,22 @@ package.path = package.path .. './test/?.lua;./test/unit/?.lua;./test/unit/luaun
-- Dependencies
unit = require 'luaunit'
--http = require 'socket.http'
function UTF8Test()
local utf8 = require("utf8")
local actual = utf8.len("Hello World!")
unit.assertEquals(actual, 12)
end
function love.system.getProcessorCountTest()
local count = love.system.getProcessorCount()
unit.assertIsNumber(count)
unit.assertEquals(count, 1)
end
function lutro.filesystem.setRequirePathTest()
local paths = lutro.filesystem.getRequirePath()
paths = paths .. ';/lutro.filesystem.setRequirePathTest/?.lua'
lutro.filesystem.setRequirePath(paths)
local paths = lutro.filesystem.getRequirePath()
local index = string.find(paths, 'setRequirePathTest')
unit.assertTrue(index > 1)
end
function lutro.filesystem.getRequirePathTest()
local paths = lutro.filesystem.getRequirePath()
unit.assertIsString(paths)
unit.assertEquals(paths, package.path)
end
function lutro.keyboard.getScancodeFromKeyTest()
local scancode = lutro.keyboard.getScancodeFromKey('f')
unit.assertIsNumber(scancode)
unit.assertEquals(scancode, 102)
end
function lutro.keyboard.getKeyFromScancodeTest()
local key = lutro.keyboard.getKeyFromScancode(102)
unit.assertIsString(key)
unit.assertEquals(key, 'f')
end
function lutro.math.setRandomSeedTest()
lutro.math.setRandomSeed(3)
lutro.math.setRandomSeed(3, 10)
end
function lutro.math.randomTest()
for i = 1, 1000, 1 do
actual = lutro.math.random(10, 20)
unit.assertTrue(actual >= 10 and actual <= 20)
end
for i = 1, 1000, 1 do
actual = lutro.math.random(10)
unit.assertTrue(actual >= 0 and actual <= 10)
end
for i = 1, 1000, 1 do
actual = lutro.math.random()
unit.assertTrue(actual >= 0 and actual <= 1)
end
end
function lutro.filesystem.getUserDirectoryTest()
local homeDir = lutro.filesystem.getUserDirectory()
-- @todo Find out how to make os.getenv('HOME') work on Windows?
local luaHomeDir = os.getenv("HOME")
unit.assertEquals(homeDir, luaHomeDir)
end
-- function http.requestTest()
-- local http = require('socket.http')
-- local result = http.request('http://buildbot.libretro.com/assets/frontend/info/lutro_libretro.info')
-- unit.assertStrContains(result, 'display_name = "LUA Engine (Lutro)"')
--end
function lutro.getVersionTest()
local major, minor, revision, codename = lutro.getVersion()
unit.assertIsNumber(major)
unit.assertIsNumber(minor)
unit.assertIsNumber(revision)
unit.assertEquals(codename, 'Lutro')
end
function lutro.system.getPowerInfoTest()
local state, percent, seconds = lutro.system.getPowerInfo()
unit.assertIsString(state)
unit.assertEquals(state, 'unknown')
unit.assertIsNil(percent)
unit.assertIsNil(seconds)
end
function lutro.system.openURLTest()
local success = lutro.system.openURL('http://libretro.com')
unit.assertIsBoolean(success)
unit.assertEquals(success, false)
end
function lutro.system.vibrate()
local success = lutro.system.vibrate()
local success = lutro.system.vibrate(0.5)
end
function lutro.system.getProcessorCountTest()
local count = lutro.system.getProcessorCount()
unit.assertIsNumber(count)
unit.assertEquals(count, 1)
end
function lutro.system.getClipboardTextTest()
local clipboard = lutro.system.getClipboardText()
unit.assertIsString(clipboard)
unit.assertEquals(clipboard, "")
end
function lutro.system.setClipboardTextTest()
local clipboard = "Hello, World!"
lutro.system.setClipboardText(clipboard)
clipboard = "Goodbye, World!"
clipboard = lutro.system.getClipboardText()
unit.assertEquals(clipboard, "Hello, World!")
end
function lutro.timer.getDeltaTest()
local delta = lutro.timer.getDelta()
unit.assertIsNumber(delta)
end
function lutro.window.minimizeTest()
lutro.window.minimize()
end
function lutro.window.maximizeTest()
lutro.window.maximize()
end
function lutro.window.getTitleTest()
local title = lutro.window.getTitle()
unit.assertIsString(title)
unit.assertEquals(title, "Lutro")
end
function lutro.window.setTitleTest()
lutro.window.setTitle("Hello World!")
end
function lutro.window.setPositionTest()
lutro.window.setPosition(1, 1)
lutro.window.setPosition(100, 200, 2)
end
function lutro.window.getPositionTest()
local x, y, display = lutro.window.getPosition()
unit.assertIsNumber(x)
unit.assertIsNumber(y)
unit.assertIsNumber(display)
unit.assertEquals(x, 0)
unit.assertEquals(y, 0)
unit.assertEquals(display, 1)
end
function lutro.window.requestAttentionTest()
lutro.window.requestAttention()
lutro.window.requestAttention("Test")
end
function lutro.window.getDisplayNameTest()
local display = lutro.window.getDisplayName()
unit.assertIsString(display)
unit.assertEquals(display, "libretro")
display = lutro.window.getDisplayName(3)
unit.assertIsString(display)
unit.assertEquals(display, "libretro")
end
function lutro.window.setDisplaySleepEnabledTest()
lutro.window.setDisplaySleepEnabled(true)
end
-- Runs all the defined tests.
-- Runs all tests.
function runTests()
-- http.requestTest()
lutro.keyboard.getKeyFromScancodeTest()
lutro.keyboard.getScancodeFromKeyTest()
lutro.filesystem.getUserDirectoryTest()
lutro.getVersionTest()
lutro.math.randomTest()
lutro.math.setRandomSeedTest()
UTF8Test()
lutro.filesystem.getRequirePathTest()
lutro.filesystem.setRequirePathTest()
lutro.getVersionTest()
lutro.system.getPowerInfoTest()
lutro.system.openURLTest()
lutro.system.getProcessorCountTest()
love.system.getProcessorCountTest()
lutro.system.getClipboardTextTest()
lutro.system.setClipboardTextTest()
lutro.timer.getDeltaTest()
lutro.window.maximizeTest()
lutro.window.minimizeTest()
lutro.window.getTitleTest()
lutro.window.setTitleTest()
lutro.window.setPositionTest()
lutro.window.getPositionTest()
lutro.window.requestAttentionTest()
lutro.window.getDisplayNameTest()
lutro.window.setDisplaySleepEnabledTest()
local moduleTests = {
require 'modules/filesystem',
require 'modules/keyboard',
require 'modules/math',
require 'modules/system',
require 'modules/timer',
require 'modules/window'
}
for i, moduleTests in ipairs(moduleTests) do
for i, functionTest in ipairs(moduleTests) do
functionTest()
end
end
end
-- Return a load and draw function for running the unit
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment