Tutorial 7 - Setup and exit

// tutorial7.ot
group "tutorial_7";

global
{
  char* str;
}

setup
{
  str = new char[10];
  op_strcpy(str, "Hello");
}

exit
{
  delete [] str;
}

test("Test heap allocated string")
{
  verify(op_strcmp(str, "Hello") == 0);
}

In this example, the keywords setup and exit are introduced. With setup you can initialize everything in the global section that need initialization. In this example we allocate the string str and sets its value. setup will run before all the tests in the group run. After all tests in the group has run, exit will be called. In exit, you can add your cleanup code. In this example, the string is deallocated.

In the test, the global variable str is used, with the initialized value "Hello".

=========================================================================
Opera Testsuite
=========================================================================

=========================================================================
E:/src/operaclean/opera-windows7/modules/selftest/documentation/tutorial/tutorial7.ot(2):  tutorial_7 
=========================================================================
  Test heap allocated string .................................... Passed
=========================================================================
1 test run, 0 tests failed, 0 tests skipped, 1 test OK
=========================================================================