From f084dd3b583954e93922017b6ec7fce07e37bc76 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 19 Nov 2018 22:59:07 +0800 Subject: [PATCH] add some tests --- src/ltui.lua | 60 +++++++++++++++++++++++++++++ tests/desktop.lua | 79 ++++++++++++++++++++++++++++++++++++++ tests/dialog.lua | 85 +++++++++++++++++++++++++++++++++++++++++ tests/inputdialog.lua | 56 +++++++++++++++++++++++++++ tests/load.lua | 59 ----------------------------- tests/mconfdialog.lua | 88 +++++++++++++++++++++++++++++++++++++++++++ tests/window.lua | 52 +++++++++++++++++++++++++ 7 files changed, 420 insertions(+), 59 deletions(-) create mode 100644 src/ltui.lua create mode 100755 tests/desktop.lua create mode 100644 tests/dialog.lua create mode 100644 tests/inputdialog.lua create mode 100644 tests/mconfdialog.lua create mode 100644 tests/window.lua diff --git a/src/ltui.lua b/src/ltui.lua new file mode 100644 index 0000000..9b1085c --- /dev/null +++ b/src/ltui.lua @@ -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 diff --git a/tests/desktop.lua b/tests/desktop.lua new file mode 100755 index 0000000..87276ad --- /dev/null +++ b/tests/desktop.lua @@ -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() diff --git a/tests/dialog.lua b/tests/dialog.lua new file mode 100644 index 0000000..dcf12f9 --- /dev/null +++ b/tests/dialog.lua @@ -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() diff --git a/tests/inputdialog.lua b/tests/inputdialog.lua new file mode 100644 index 0000000..7d7896b --- /dev/null +++ b/tests/inputdialog.lua @@ -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() diff --git a/tests/load.lua b/tests/load.lua index d860d81..3cbd8d8 100755 --- a/tests/load.lua +++ b/tests/load.lua @@ -2,62 +2,3 @@ package.path = package.path .. ';./src/?.lua' 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() diff --git a/tests/mconfdialog.lua b/tests/mconfdialog.lua new file mode 100644 index 0000000..300d186 --- /dev/null +++ b/tests/mconfdialog.lua @@ -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() diff --git a/tests/window.lua b/tests/window.lua new file mode 100644 index 0000000..51c6c8e --- /dev/null +++ b/tests/window.lua @@ -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()