Document on testing
Introduction to test object
This suite tests the performance of ISDK. It consists of a major test file (setest.c) and some other files, which will support different aspects of the test. There are several features with the test object. At this time, the features includeTest.assert, Test.start, Test.assertNumEqual, Test.setAttributes, and Test.end. The most significant one is Test.assert() function. It performs almost all tests on ISDK performance. Lets first review how it works, then look at some examples. In fact, the behavior of Test.assert() is very much like assertion function in standard C/C++. It takes an expression as its argument. If the expression was evaluated to be true, the assertion is successful and the execution will go on, otherwise, assertion is failed and the execution will terminate with an error message. Here are some examples.
Test.assert( "Hello" + " world!" == "Hello world!" );
Test.assert( Math.max (2, -2) == 2 );
Above assertions will be successful, since the arguments are true statements.
Test.assert( "cat" == "dog" );
Above assertion will be failed, since the argument is a false statement.
The expression you are going to test (i.e. the argument you are going to write) is a predicate, either true or false. So, you may want to have all your expression true in order to make the test execution go through. Of cause those assumptions should be built on the performance of specific software. For example, if you have designed "cat" equaled to "dog" (although it is less likely), the above "cat" == "dog" example would not fail.
SE:ISDK is designed to meet ECMA standard. So, in testecma suite, the tests for assertions are designed based on ECMAScript Language Specification.
Write your own test script
Suppose you want to test the performance of String object, a sample script looks like this.
var s = new String("Hello");
var t = "World";
Test.assert(s != t); // string comparison
Test.assert(s.length == 5); // length property
Test.assert(s + t == "HelloWorld"); // string concatenation
Theoretically, the test would be able to catch any possible errors, as long as you could complete the test cases in your script.
Porting test suite to your system
To make the test build correctly, you must first compile each of the files contained in the project and link them with a ScriptEase Interpreter Engine library file. The exact steps will vary with the compiler you are using. Your compiler choice and whether or not your target operating system supports DLLs will probably dictate your library file choice. For example, if you are using Microsoft Visual C++ 5.0 on Windows 98 and want to use a static library, you could use the library file serte41.lib (located in the seisdk\tests\lang\testecma\win32\msvc50\ directory). There are also two directories of headers you need to make available to the compiler: \seisdk\incjse and \seisdk\srcmisc.
Usually, you do not need to change too much to configure SE:ISDK to suit your specific system, because the header file jseopt.h would have done most of this for you. You have to add the piece"__JSE_XXXXX__" where XXXXX is the platform you are targeting (for example, __JSE_WIN32__, __JSE_MAC__, etc.) to your project setting, or to the jseopt.h file to indicate your targeting system.
You may also want to modify or add more features to the test object, then you can work with setest.c file. All methods of test object can be found in that file. After making the project executable, you are ready to run tests on your own scripts.
Run test on your script
First, you have to build the project correctly. It will export an executable file. Then, you can run this executable file on your script file. If all test cases passed, the execution will terminate normally with message "Good-bye" at the end. If any of the assertion failed, the execution will stop immediately. An error message will display on screen and be written to the ERROR.LOG file at same time. The message tells where the error occurs (with the error line number) and what the error is, so you could identify the problem quickly. You could check ERROR.LOG file for your error record in case that you lost your screen display.
If you want to run all tests at once, you should make a batch file to include all your script files. You may add new script files into the test suite by adding them into the batch file. Individual script file could be written as described in earlier section. You may also add more tests to a specific script file to complete that specific test. You are encouraged to do so and send them back to us. Any kind of new script or supplement to current script will be welcome by Nombas.
This suite tests each API call. These tests are extremely useful for those who are porting the ISDK to other platforms (with an appropriate license from Nombas, of course), to ensure that the port has worked correctly for every calling the API. There is a jsetest.c file, which is included by all tests. Test failure is handled by thejseTestAssert() function in jsetest.c. If an API call failed, this function will print out some error message and terminate the program.
Porting test suite to your system
As mentioned in testecma section, in order to compile any of the tests, you must first link them with a ScriptEase Interpreter Engine library file. The exact steps will vary with the compiler you are using. Your compiler choice and whether or not your target operating system supports DLLs will probably dictate your library file choice. For instance, use the library file, serte41.lib (located in the seisdk\tests\lang\testecma\win32\msvc50\ directory) if you are using Visual C++ on the Windows 95/98 platform and want to use a static library. There are also two directories of headers you need to make available to the compiler: \seisdk\incjse and \seisdk\srcmisc.
Next, you have to edit the jseopt.h file, which is included in all of the tests. The jseopt.h file is designed to allow you to configure the SE:ISDK to fit the particulars of your platform and specify the options you choose to use. There are two#defines you will need to configure in order to successfully run the tests. The first is your target operating system, which takes the form "__JSE_XXXXX__" where XXXXX is the platform you are targeting (for example, __JSE_WIN32__, __JSE_MAC__, etc. ). The second will be one of the following: __JSE_LIB__ for the static library version of the interpreter engine, __JSE_DLLLOAD__ for load-time DLL version, or __JSE_DLLRUN__ for run-time DLL version. If you are using Microsoft Visual Studio, you may put your options into the project setting as an alternative.
Finally, if you want to modify the jsetest.c file. The jsetest.c file holds all of the common code for the tests, which allows you to change the behavior of all the tests in one place. There are two specific functions, which you may need to configure in order to suit your system:
Once you have configured the jseopt.h and jsetest.c files, you are ready to run the tests. Just chose the test you wish to run and then compile and link it. If you want to run all tests at once, just make a batch file to include them all. As described above, the test will report success or failure depending on how you configured the jsetest.c file.