add some tests

This commit is contained in:
ruki
2018-11-19 22:59:07 +08:00
parent 9c75a63372
commit f084dd3b58
7 changed files with 420 additions and 59 deletions

60
src/ltui.lua Normal file
View File

@@ -0,0 +1,60 @@
--!A cross-platform build utility based on Lua
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
-- @file ltui.lua
--
-- define module
local ltui = ltui or {}
-- register modules
ltui.action = require("ltui/action")
ltui.application = require("ltui/application")
ltui.border = require("ltui/border")
ltui.boxdialog = require("ltui/boxdialog")
ltui.button = require("ltui/button")
ltui.canvas = require("ltui/canvas")
ltui.choicebox = require("ltui/choicebox")
ltui.choicedialog = require("ltui/choicedialog")
ltui.curses = require("ltui/curses")
ltui.desktop = require("ltui/desktop")
ltui.dialog = require("ltui/dialog")
ltui.event = require("ltui/event")
ltui.inputdialog = require("ltui/inputdialog")
ltui.label = require("ltui/label")
ltui.mconfdialog = require("ltui/mconfdialog")
ltui.menubar = require("ltui/menubar")
ltui.menuconf = require("ltui/menuconf")
ltui.object = require("ltui/object")
ltui.panel = require("ltui/panel")
ltui.point = require("ltui/point")
ltui.program = require("ltui/program")
ltui.rect = require("ltui/rect")
ltui.statusbar = require("ltui/statusbar")
ltui.textarea = require("ltui/textarea")
ltui.textdialog = require("ltui/textdialog")
ltui.textedit = require("ltui/textedit")
ltui.view = require("ltui/view")
ltui.window = require("ltui/window")
-- return module
return ltui

79
tests/desktop.lua Executable file
View File

@@ -0,0 +1,79 @@
--!A cross-platform build utility based on Lua
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
-- @file desktop.lua
--
require("tests/load")
-- requires
local ltui = require("ltui")
local label = ltui.label
local button = ltui.button
local application = ltui.application
local event = ltui.event
local rect = ltui.rect
-- the demo application
local demo = application()
-- init demo
function demo:init()
-- init name
application.init(self, "demo")
-- show desktop, menubar and statusbar
self:insert(self:desktop())
self:insert(self:menubar())
self:insert(self:statusbar())
-- init title
self:menubar():title():text_set("Menu Bar (Hello)")
-- add title label
self:desktop():insert(label:new("title", rect {0, 0, 12, 1}, "hello xmake!"):textattr_set("white"), {centerx = true})
-- add yes button
self:desktop():insert(button:new("yes", rect {0, 1, 7, 2}, "< Yes >"):textattr_set("white"), {centerx = true})
-- add no button
self:desktop():insert(button:new("no", rect {0, 2, 6, 3}, "< No >"):textattr_set("white"), {centerx = true})
end
-- on event
function demo:event_on(e)
if application.event_on(self, e) then
return true
end
if e.type == event.ev_keyboard then
self:statusbar():info():text_set(e.key_name)
if e.key_name == "s" then
self:statusbar():show(not self:statusbar():state("visible"))
elseif e.key_name == "m" then
self:menubar():show(not self:menubar():state("visible"))
elseif e.key_name == "d" then
self:desktop():show(not self:desktop():state("visible"))
end
end
end
-- run demo
demo:run()

85
tests/dialog.lua Normal file
View File

@@ -0,0 +1,85 @@
--!A cross-platform build utility based on Lua
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
-- @file dialog.lua
--
require("tests/load")
-- requires
local ltui = require("ltui")
local label = ltui.label
local button = ltui.button
local application = ltui.application
local event = ltui.event
local rect = ltui.rect
local boxdialog = ltui.boxdialog
local textdialog = ltui.textdialog
local inputdialog = ltui.inputdialog
-- the demo application
local demo = application()
-- init demo
function demo:init()
-- init name
application.init(self, "demo")
-- init background
self:background_set("blue")
-- init help dialog
local dialog_help = textdialog:new("dialog.help", rect {1, 1, self:width() - 1, self:height() - 1}, "README")
dialog_help:text():text_set("help text ...")
dialog_help:button_add("exit", "< Exit >", function (v) self:remove(dialog_help) end)
-- init main dialog
local dialog_main = boxdialog:new("dialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main dialog")
dialog_main:text():text_set("The project focuses on making development and building easier and provides many features (.e.g package, install, plugin, macro, action, option, task ...), so that any developer can quickly pick it up and enjoy the productivity boost when developing and building project.")
dialog_main:button_add("tips", "< Tips >", function (v) self:view("dialog.tips"):show(true, {focused = true}) end)
dialog_main:button_add("input", "< Input >", function (v) self:view("dialog.input"):show(true, {focused = true}) end)
dialog_main:button_add("help", "< Help >", function (v) self:insert(dialog_help) end)
dialog_main:button_add("quit", "< Quit >", "cm_quit")
self:insert(dialog_main)
-- init input dialog
local dialog_input = inputdialog:new("dialog.input", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background())
dialog_input:frame():background_set("cyan")
dialog_input:text():text_set("please input text:"):textattr_set("red")
dialog_input:button_add("no", "< No >", function (v) dialog_input:show(false) end)
dialog_input:button_add("yes", "< Yes >", function (v)
dialog_main:text():text_set(dialog_input:textedit():text())
dialog_input:show(false)
end)
self:insert(dialog_input, {centerx = true, centery = true})
dialog_input:show(false)
-- init tips dialog
local dialog_tips = textdialog:new("dialog.tips", rect {0, 0, 50, 8}):background_set(dialog_main:frame():background())
dialog_tips:frame():background_set("cyan")
dialog_tips:text():text_set("hello xmake! (http://xmake.io)\nA cross-platform build utility based on Lua"):textattr_set("red")
dialog_tips:button_add("yes", "< Yes >", function (v) dialog_tips:show(false) end)
dialog_tips:button_add("no", "< No >", function (v) dialog_tips:show(false) end)
self:insert(dialog_tips, {centerx = true, centery = true})
end
-- run demo
demo:run()

56
tests/inputdialog.lua Normal file
View File

@@ -0,0 +1,56 @@
--!A cross-platform build utility based on Lua
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
-- @file inputdialog.lua
--
require("tests/load")
-- requires
local ltui = require("ltui")
local label = ltui.label
local button = ltui.button
local application = ltui.application
local event = ltui.event
local rect = ltui.rect
local inputdialog = ltui.inputdialog
-- the demo application
local demo = application()
-- init demo
function demo:init()
-- init name
application.init(self, "demo")
-- init background
self:background_set("blue")
-- init input dialog
local dialog_input = inputdialog:new("dialog.input", rect {0, 0, 50, 8})
dialog_input:text():text_set("please input text:")
dialog_input:button_add("no", "< No >", function (v) dialog_input:quit() end)
dialog_input:button_add("yes", "< Yes >", function (v) dialog_input:quit() end)
self:insert(dialog_input, {centerx = true, centery = true})
end
-- run demo
demo:run()

View File

@@ -2,62 +2,3 @@
package.path = package.path .. ';./src/?.lua' package.path = package.path .. ';./src/?.lua'
package.cpath = package.cpath .. ';./build/ltui.dll;./build/libltui.so;./build/libltui.dylib' package.cpath = package.cpath .. ';./build/ltui.dll;./build/libltui.so;./build/libltui.dylib'
local os = require("ltui/base/os")
local ltui = require("ltui.curses")
print(ltui)
-- requires
local log = require("ltui/base/log")
local rect = require("ltui/rect")
local view = require("ltui/view")
local label = require("ltui/label")
local event = require("ltui/event")
local button = require("ltui/button")
local application = require("ltui/application")
-- the demo application
local demo = application()
-- init demo
function demo:init()
-- init name
application.init(self, "demo")
-- show desktop, menubar and statusbar
self:insert(self:desktop())
self:insert(self:menubar())
self:insert(self:statusbar())
-- init title
self:menubar():title():text_set("Menu Bar (Hello)")
-- add title label
self:desktop():insert(label:new("title", rect {0, 0, 12, 1}, "hello xmake!"):textattr_set("white"), {centerx = true})
-- add yes button
self:desktop():insert(button:new("yes", rect {0, 1, 7, 2}, "< Yes >"):textattr_set("white"), {centerx = true})
-- add no button
self:desktop():insert(button:new("no", rect {0, 2, 6, 3}, "< No >"):textattr_set("white"), {centerx = true})
end
-- on event
function demo:event_on(e)
if application.event_on(self, e) then
return true
end
if e.type == event.ev_keyboard then
self:statusbar():info():text_set(e.key_name)
if e.key_name == "s" then
self:statusbar():show(not self:statusbar():state("visible"))
elseif e.key_name == "m" then
self:menubar():show(not self:menubar():state("visible"))
elseif e.key_name == "d" then
self:desktop():show(not self:desktop():state("visible"))
end
end
end
-- main entry
demo:run()

88
tests/mconfdialog.lua Normal file
View File

@@ -0,0 +1,88 @@
--!A cross-platform build utility based on Lua
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
-- @file mconfdialog.lua
--
require("tests/load")
-- requires
local ltui = require("ltui")
local label = ltui.label
local button = ltui.button
local application = ltui.application
local event = ltui.event
local rect = ltui.rect
local action = ltui.action
local menuconf = ltui.menuconf
local mconfdialog = ltui.mconfdialog
-- the demo application
local demo = application()
-- init demo
function demo:init()
-- init name
application.init(self, "demo")
-- init background
self:background_set("blue")
-- init configs
local configs_sub2 = {}
table.insert(configs_sub2, menuconf.boolean {description = "boolean config sub-item2"})
table.insert(configs_sub2, menuconf.number {value = 10, default = 10, description = "number config sub-item2"})
table.insert(configs_sub2, menuconf.string {value = "armv7", description = "string config sub-item2"})
table.insert(configs_sub2, menuconf.menu {description = "menu config sub-item2"})
local configs_sub = {}
table.insert(configs_sub, menuconf.boolean {description = "boolean config sub-item"})
table.insert(configs_sub, menuconf.number {value = 90, default = 10, description = "number config sub-item"})
table.insert(configs_sub, menuconf.string {value = "arm64", description = "string config sub-item"})
table.insert(configs_sub, menuconf.menu {description = "menu config sub-item", configs = configs_sub2})
table.insert(configs_sub, menuconf.choice {value = 2, values = {2, 5, 16, 87}, description = "choice config sub-item"})
local configs = {}
table.insert(configs, menuconf.boolean {description = "boolean config item"})
table.insert(configs, menuconf.boolean {default = true, new = false, description = {"boolean config item2",
" - more description info",
" - more description info",
" - more description info"}})
table.insert(configs, menuconf.number {value = 6, default = 10, description = "number config item"})
table.insert(configs, menuconf.string {value = "x86_64", description = "string config item"})
table.insert(configs, menuconf.menu {description = "menu config item", configs = configs_sub})
table.insert(configs, menuconf.choice {value = 3, values = {1, 5, 6, 7}, description = "choice config item"})
-- init menu config dialog
local mconfdialog = mconfdialog:new("mconfdialog.main", rect {1, 1, self:width() - 1, self:height() - 1}, "menu config")
mconfdialog:load(configs)
mconfdialog:action_set(action.ac_on_exit, function (v) self:quit() end)
mconfdialog:action_set(action.ac_on_save, function (v)
for _, config in ipairs(configs) do
log:print("%s", config)
end
mconfdialog:quit()
end)
self:insert(mconfdialog)
end
-- run demo
demo:run()

52
tests/window.lua Normal file
View File

@@ -0,0 +1,52 @@
--!A cross-platform build utility based on Lua
--
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015 - 2018, TBOOX Open Source Group.
--
-- @author ruki
-- @file window.lua
--
require("tests/load")
-- requires
local ltui = require("ltui")
local label = ltui.label
local button = ltui.button
local application = ltui.application
local event = ltui.event
local rect = ltui.rect
local window = ltui.window
-- the demo application
local demo = application()
-- init demo
function demo:init()
-- init name
application.init(self, "demo")
-- init background
self:background_set("blue")
-- init main window
self:insert(window:new("window.main", rect {1, 1, self:width() - 1, self:height() - 1}, "main window", true))
end
-- run demo
demo:run()