/*
 * Define this as your 'main script' in game.sgm and run the game to unit test 'objects.js'.
 * 4 scripts are needed for this test:
 *   unittest.js - The unittest library with all the unittest functions
 *   ss_functions.table - The file with all Sphere functions defined (you need to update it with each Sphere release)
 *   objects.js - The libary we're going to test (not this time, commented out)
 *   game_unittest_objects.js - this file, the defined tests for objects.js
 */

// First define the unit test library
RequireSystemScript("unittest.js");


// And create the function game(), those were all the objects you may create globally
function game(){

	// Define your variables before declaring UnitTest(); (I just like short variable names)
	var A,B,C,D,E,F,G,H,I,J,K,L,M,N, Z;

	// Create an instance of UnitTest()
	var UT = UnitTest();
	UT.checkglobals = true; // Enable Global variable tainting. Doesnt work all that well in Sphere 1.13 (coredumps)
	UT.setDEBUG(false).LogOnErrorsOnly(false);

	// Check the objects library script, and 'register' all loaded functions (used in taint checking)
	//UT.PrepareScript("objects.js")

	// Set it to check lingering variables.
	UT.setThat(this);

	// Define what to do as a constructor, this can be run before each test suite.
	UT.setup( function(){ 
		
		// Those defined variables? We now define them with default values (not required, just for lazy testing)
		A = 56;
		B = "hello";
		C = CreateColor(5, 6, 7, 8);
		D = GetSystemFont();
		E = GetSystemArrow();
		F = E.createSurface();
		G = CreateColorMatrix(1,2,3,4, 5,6,7,8, 9,10,11,12);
		H = GetSystemWindowStyle();
		I = CreateByteArray(5);
		J = null;
		K = undefined;
		L = "This is a test of a very long string. But remember, the anwser is always 41.999999535532";
		M = undefined;
		N = undefined;
		Z = { A:A, B:B, C:C, J:J, K:K };

	} );

	// Define what to do as a destructor (not much, in this case)
	UT.teardown( function(){ } );



	// Now run the setup and first batch of tests
	// Note that we need to have a test for all defined functions for a correct unittest.

	// This way we execute tests in 'this' context (makes the tests readable)
	
	eval( UT.readfile('../scripts/test_sfxr.js'));
	eval( UT.readfile('../scripts/test_spherefunctions.js'));
	
	// But you can also just do the tests right here:	
	UT.setup().runtests({
	
		// Each entry is the name of a test suite, usually a function or object so you can clearly identify where tests fail
		APROX:function(that){
		A=5.5;
		UT.assertAprox(A, 5, 1, 'around 5 +- 1')
		}
	});


	// Finally show all results...
	UT.showResults();

}

