Integrated Development Environment (IDE) Modules in NPL

Source code and documentation of most IDE modules can be found at script/ide/ folder. This topic provides an overview of useful IDE modules that developers can use to debug application, make UI, and complete various other common tasks. Most IDE modules are wrappers of relatively low level NPL functions or other IDE modules. This means that developers can always mix the use of IDE modules and raw NPL functions in their applications.

IDE UI modules

UI are the largest collection in IDE modules. They are in namespace CommonCtrl.

MultiLineEditbox

Multiline editbox is a collection of single line editbox in a TreeView control.

Features:

  • Mouse/Key board based text selection
  • Copy & Paste from/to clipboard
  • Arrow key, Home/End key navigation from line to line
  • Right click context menu for text selection
  • Syntax highlighting: support user defined syntax coloring scheme
  • International character input, such as Chinese, English.
  • Automatic word wrapping and line breaking

related: TreeView, imeeditbox, MCML_Controls, ContextMenu

TreeView

gui_helper

MessageBox

HTMLRenderer

DataBinding

Common Library

Common library contains modules for debugging, testing, data structuring, serialization, etc. They are in namespace commonlib

Unit Test Module

The unit test module parses a test file, optionally replace test case input with user supplied ones, and finally output the test result to file and log.

Test file markup: A test file may contain a group of test cases. Test cases can be declared in NPL comment block with the following format:

   %TESTCASE{"<test_case_name>", func = "<test_function>", input = <default_input>, output="<result_file>"}%
The content inside TESTCASE is actually an NPL table, where
  • test_case_name is test case name, test_function is the name of the function to be called for the test case.
  • The test function is usually defined in the test file itself and should use global name.
  • default_input is input to the test case function.
  • result_file is where to save the test result. if this is nil, it will be saved to testfile.result

For an example test file, please see script/ide/UnitTest/sample_test_file.lua.

--[[
Title: Unit Test sample file
Author(s): LiXizhi
Date: 2008/3/5
Desc: 
use the lib:
------------------------------------------------------------
NPL.load("(gl)script/ide/UnitTest/sample_test_file.lua");
test.Example_Test_Function()

-- result at temp/test_result.txt
%TESTCASE{"Example Test", func="test.Example_Test_Function", input={varInt = 1, 
   varString = "this is a string"}, output="temp/test_result.txt"}%
-- result at script/ide/UnitTest/sample_test_file.lua.result
%TESTCASE{"Example Test 2", func="test.Example_Test_Function", input={varInt2 = 2, 
   varString2 = "Another input"}}%
-------------------------------------------------------
]]

if(not test) then test ={} end

-- passed by LiXizhi 2008.3.5
function test.Example_Test_Function(input)
   log(commonlib.serialize(input).." Test Succeed\n")
end

The result of "Example Test" will be saved to "temp/test_result.txt". It is in TWiki format which one can post to twiki topic.

---+++ case 1
_case_: Example Test

Input:
<verbatim>
{
  ["varString"] = "this is a string",
  ["varInt"] = 1,
}
</verbatim>

_Result_:
<verbatim>
{
  ["varString"] = "this is a string",
  ["varInt"] = 1,
}
 Test Succeed
</verbatim>

TIP To invoke unit test programmatically, use following code

-------------------------------------------------------
NPL.load("(gl)script/ide/UnitTest/unit_test.lua");
local test = commonlib.UnitTest:new();
if(test:ParseFile("script/ide/UnitTest/sample_test_file.lua")) then
   test:Run();
end
-- or one can call individually with user input. 
local test = commonlib.UnitTest:new();
if(test:ParseFile("script/ide/UnitTest/sample_test_file.lua")) then
   test:ClearResult();
   local i, count = 1, test:GetTestCaseCount()
   for i = 1, count do
      test:RunTestCase(i, {"any user input"});
   end
end
-------------------------------------------------------

TIP To invoke unit test from a graphically user interface, please install the DeveloperApp. Alternatively, one can integrate unit testing UI in any place by calling unit_test_dlg.lua.

  • TestConsole: It can be opened by selecting Menu->Help->TestConsole
    TestConsole.jpg
Topic revision: r3 - 2008-03-06 - LiXizhi
 
  • Edit
  • Attach
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback