Exemplo n.º 1
0
int main(int argc, char **argv)
{
	DetectMemoryLeaks();

	printf("Performance test");
#ifdef _DEBUG 
	printf(" (DEBUG)");
#endif
	printf("\n");
	printf("AngelScript %s\n", asGetLibraryVersion()); 

	TestBasic::Test();
	TestBasic2::Test();
	TestCall::Test();
	TestCall2::Test();
	TestInt::Test();
	TestIntf::Test();
	TestMthd::Test();
	TestString::Test();
	TestString2::Test();
	
	printf("--------------------------------------------\n");
	printf("Press any key to quit.\n");
	while(!getch());
	return 0;
}
Exemplo n.º 2
0
bool CScriptEngine::Initialize()
{
    // register custom memory management
    //asSetGlobalMemoryFunctions()

    m_vm = asCreateScriptEngine(ANGELSCRIPT_VERSION);
    m_vm->SetEngineProperty(asEP_USE_CHARACTER_LITERALS, true); // treat 'a' as character literal of type uint8
    if( m_vm == 0 )
    {
        CON( MSG_ERR, _W("Failed to create script engine!") );
        return false;
    }

    // set compiler message callback
    m_vm->SetMessageCallback(asFUNCTION(ScriptMessageCallback), 0, asCALL_CDECL);

    // write version info
    CON( MSG_INFO, _W(" AngelScript version %s successfuly initialized."), _A2W( asGetLibraryVersion() ) );
    CON( MSG_INFO, _W(" Build flags: %s"), _A2W( asGetLibraryOptions() ) );

    // register basic types
    RegisterBasicTypesToScript(m_vm);

    // Script UnitTest
    LoadScriptString(\
                     "void UnitTest()\n"\
                     "{\n"\
                     "Log(\"--- Script engine unit test ---\");\n"\

                     "\n"\
                     "Log( \"String comparison: \" + ( (\"str\"==\"str\") ? \"OK\" : \"ERROR\" ) );\n"\

                     "\n"\
                     "String float2str = 0.123f;\n"\
                     "Log(\"Float-to-String: \" + float2str);\n"\
                     "String strTrue = true; String strFalse = false;\n"\
                     "Log(\"Bool-to-String: \" + ( (strTrue == \"True\") && (strFalse == \"False\") ? \"OK\" : \"ERROR\" ) );\n"\
                     "Log(\"String index operator: \" + ( (\"str\"[2]=='r') ? \"OK\" : \"ERROR\") );\n"\
                     "Log(\"String length(): \" + ( (\"str\".length()==3) ? \"OK\" : \"ERROR\") );\n"\

                     "\n"\
                     "float f = 0.123f;\n"\
                     "float f2 = sin(f);\n"\
                     "Log(\"sin(\" + f + \") = \" + f2 );\n"\

                     "\n"\
                     "Log(\"rand(0.1f, 0.7f) = \" + rand(0.1f, 0.7f) );\n"\
                     "}\n"\
                     ,0,"UnitTestSection");

    ExecuteString("UnitTest();");

    return true;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	DetectMemoryLeaks();

	printf("Build performance test");
#ifdef _DEBUG 
	printf(" (DEBUG)");
#endif
	printf("\n");
	printf("AngelScript %s\n", asGetLibraryVersion()); 

	TestBasic::Test();
	TestBigArrays::Test();
	TestManySymbols::Test();
	TestManyFuncs::Test();
	TestComplex::Test();
	
	printf("--------------------------------------------\n");
	printf("Press any key to quit.\n");
	while(!getch());
	return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
	DetectMemoryLeaks();

	printf("AngelScript version: %s\n", asGetLibraryVersion());
	printf("AngelScript options: %s\n", asGetLibraryOptions());

#ifdef __dreamcast__
	fs_chdir(asTestDir);
#endif

	InstallMemoryManager();

	if( TestScriptRetRef::Test()       ) goto failed; else printf("-- TestScriptRetRef passed\n");
	if( TestGarbageCollect::Test()     ) goto failed; else printf("-- TestGarbageCollect passed\n");
	if( TestFunctionPtr::Test()        ) goto failed; else printf("-- TestFunctionPtr passed\n");
	if( TestModule::Test()             ) goto failed; else printf("-- TestModule passed\n");
	if( TestGetSet::Test()             ) goto failed; else printf("-- TestGetSet passed\n");
	if( Test_Addon_ScriptArray::Test() ) goto failed; else printf("-- Test_Addon_ScriptArray passed\n");
	if( TestOperator::Test()           ) goto failed; else printf("-- TestOperator passed\n");
	if( TestTemplate::Test()           ) goto failed; else printf("-- TestTemplate passed\n");
	if( TestDump::Test()               ) goto failed; else printf("-- TestDump passed\n");
	if( TestInheritance::Test()        ) goto failed; else printf("-- TestInheritance passed\n");
	if( TestScriptClassMethod::Test()  ) goto failed; else printf("-- TestScriptClassMethod passed\n");
	if( TestScriptString::Test()       ) goto failed; else printf("-- TestScriptString passed\n");
	if( TestSaveLoad::Test()           ) goto failed; else printf("-- TestSaveLoad passed\n");
	if( TestInterface::Test()          ) goto failed; else printf("-- TestInterface passed\n");
	if( TestCastOp::Test()             ) goto failed; else printf("-- TestCastOp passed\n");
	if( Test2Modules()                 ) goto failed; else printf("-- Test2Modules passed\n");
	if( TestFile::Test()               ) goto failed; else printf("-- TestFile passed\n");
	if( TestArrayObject::Test()        ) goto failed; else printf("-- TestArrayObject passed\n");
	if( TestCompiler::Test()           ) goto failed; else printf("-- TestCompiler passed\n");
	if( TestOptimize()                 ) goto failed; else printf("-- TestOptimize passed\n");
	if( TestConversion::Test()         ) goto failed; else printf("-- TestConversion passed\n");
	if( TestRegisterType::Test()       ) goto failed; else printf("-- TestRegisterType passed\n");
	if( TestRefArgument::Test()        ) goto failed; else printf("-- TestRefArgument passed\n");
	if( TestStream::Test()             ) goto failed; else printf("-- TestStream passed\n");
	if( TestEnum::Test()               ) goto failed; else printf("-- TestEnum passed\n");
	if( TestDynamicConfig::Test()      ) goto failed; else printf("-- TestDynamicConfig passed\n");
	if( TestObjHandle::Test()          ) goto failed; else printf("-- TestObjHandle passed\n");
	if( TestGlobalVar()                ) goto failed; else printf("-- TestGlobalVar passed\n");
	if( TestScriptStruct::Test()       ) goto failed; else printf("-- TestScriptStruct passed\n");
	if( TestRZ::Test()                 ) goto failed; else printf("-- TestRZ passed\n");
	if( TestArray::Test()              ) goto failed; else printf("-- TestArray passed\n");
	if( TestAny::Test()                ) goto failed; else printf("-- TestAny passed\n");
	if( TestObjHandle2::Test()         ) goto failed; else printf("-- TestObjHandle2 passed\n");
	if( TestMetaData::Test()           ) goto failed; else printf("-- TestMetaData passed\n");
	if( TestDictionary::Test()         ) goto failed; else printf("-- TestDictionary passed\n");
	if( TestVector3()                  ) goto failed; else printf("-- TestVector3 passed\n");
	if( TestConstObject::Test()        ) goto failed; else printf("-- TestConstObject passed\n");
	if( TestImplicitCast::Test()       ) goto failed; else printf("-- TestImplicitCast passed\n");
	if( TestImplicitHandle::Test()     ) goto failed; else printf("-- TestImplicitHandle passed\n");
	if( TestFor::Test()                ) goto failed; else printf("-- TestFor passed\n");
	if( TestRefCast::Test()            ) goto failed; else printf("-- TestRefCast passed\n");
	if( TestStdString()                ) goto failed; else printf("-- TestStdString passed\n");
	if( TestStack2::Test()             ) goto failed; else printf("-- TestStack2 passed\n");
	if( TestStdVector::Test()          ) goto failed; else printf("-- TestStdVector passed\n");
	if( TestArrayHandle::Test()        ) goto failed; else printf("-- TestArrayHandle passed\n");
	if( TestDict::Test()               ) goto failed; else printf("-- TestDict passed\n");
	if( TestMultiAssign::Test()        ) goto failed; else printf("-- TestMultiAssign passed\n");
	if( TestException()                ) goto failed; else printf("-- TestException passed\n");
	if( TestInt8::Test()               ) goto failed; else printf("-- TestInt8 passed\n");
	if( TestGeneric::Test()            ) goto failed; else printf("-- TestGeneric passed\n");
	if( TestBStr()                     ) goto failed; else printf("-- TestBStr passed\n");
	if( TestTypedef::Test()            ) goto failed; else printf("-- TestTypedef passed\n");
	if( TestImport::Test()             ) goto failed; else printf("-- TestImport passed\n");
	if( TestAssign::Test()             ) goto failed; else printf("-- TestAssign passed\n");
	if( TestSwitch()                   ) goto failed; else printf("-- TestSwitch passed\n");
	if( TestExceptionMemory::Test()    ) goto failed; else printf("-- TestExceptionMemory passed\n");
	if( TestObject::Test()             ) goto failed; else printf("-- TestObject passed\n");
	if( TestFactory::Test()            ) goto failed; else printf("-- TestFactory passed\n");
	if( TestFuncOverload()             ) goto failed; else printf("-- TestFuncOverload passed\n");
	if( TestObjZeroSize::Test()        ) goto failed; else printf("-- TestObjZeroSize passed\n");
	if( TestSingleton::Test()          ) goto failed; else printf("-- TestSingleton passed\n");
	if( TestCondition()                ) goto failed; else printf("-- TestCondition passed\n");
	if( TestObject2::Test()            ) goto failed; else printf("-- TestObject2 passed\n");
	if( TestShark::Test()              ) goto failed; else printf("-- TestShark passed\n");
	if( TestBool::Test()               ) goto failed; else printf("-- TestBool passed\n");
	if( TestBits::Test()               ) goto failed; else printf("-- TestBits passed\n");
	if( TestDestructor::Test()         ) goto failed; else printf("-- TestDestructor passed\n");
	if( TestConstructor2::Test()       ) goto failed; else printf("-- TestConstructor2 passed\n");
	if( TestUnsafeRef::Test()          ) goto failed; else printf("-- TestUnsafeRef passed\n");
	if( TestVarType::Test()            ) goto failed; else printf("-- TestVarType passed\n");
	if( TestScriptMath::Test()         ) goto failed; else printf("-- TestScriptMath passed\n");
	if( TestDebug::Test()              ) goto failed; else printf("-- TestDebug passed\n");
	if( TestGetArgPtr::Test()          ) goto failed; else printf("-- TestGetArgPtr passed\n");
	if( TestAutoHandle::Test()         ) goto failed; else printf("-- TestAutoHandle passed\n");
	if( TestObject3::Test()            ) goto failed; else printf("-- TestObject3 passed\n");
	if( TestArrayIntf::Test()          ) goto failed; else printf("-- TestArrayIntf passed\n");
	if( TestConstProperty::Test()      ) goto failed; else printf("-- TestConstProperty passed\n");
	if( TestSuspend::Test()            ) goto failed; else printf("-- TestSuspend passed\n");
	if( TestVector3_2::Test()          ) goto failed; else printf("-- TestVector3_2 passed\n");
	if( TestNested()                   ) goto failed; else printf("-- TestNested passed\n");
	if( TestConstructor()              ) goto failed; else printf("-- TestConstructor passed\n");
	if( TestExecuteScript()            ) goto failed; else printf("-- TestExecuteScript passed\n");
	if( TestCustomMem::Test()          ) goto failed; else printf("-- TestCustomMem passed\n");
	if( TestPostProcess::Test()        ) goto failed; else printf("-- TestPostProcess passed\n");
	if( TestArgRef::Test()             ) goto failed; else printf("-- TestArgRef passed\n");
	if( TestNotInitialized()           ) goto failed; else printf("-- TestNotInitialized passed\n");
	if( TestConfig::Test()             ) goto failed; else printf("-- TestConfig passed\n");
	if( TestInt64()                    ) goto failed; else printf("-- TestInt64 passed\n");
	if( TestImport2::Test()            ) goto failed; else printf("-- TestImport2 passed\n");
	if( TestEnumGlobVar()              ) goto failed; else printf("-- TestEnumGlobVar passed\n");
	if( TestConfigAccess::Test()       ) goto failed; else printf("-- TestConfigAccess passed\n");
	if( TestDiscard::Test()            ) goto failed; else printf("-- TestDiscard passed\n");
	if( TestParser::Test()             ) goto failed; else printf("-- TestParser passed\n");
	if( TestFloat::Test()              ) goto failed; else printf("-- TestFloat passed\n");
	if( TestTempVar()                  ) goto failed; else printf("-- TestTempVar passed\n");
	if( TestModuleRef()                ) goto failed; else printf("-- TestModuleRef passed\n");
	if( TestExecuteString()            ) goto failed; else printf("-- TestExecuteString passed\n");
	if( TestStack()                    ) goto failed; else printf("-- TestStack passed\n");
	if( TestCreateEngine()             ) goto failed; else printf("-- TestCreateEngine passed\n");
	if( TestLongToken()                ) goto failed; else printf("-- TestLongToken passed\n");
	if( TestOutput::Test()             ) goto failed; else printf("-- TestOutput passed\n");
	if( Test2Func::Test()              ) goto failed; else printf("-- Test2Func passed\n");
	if( TestCircularImport::Test()     ) goto failed; else printf("-- TestCircularImport passed\n");
	if( TestNeverVisited()             ) goto failed; else printf("-- TestNeverVisited passed\n");

	// The following tests are designed specifically to test the native calling conventions.
	// These are grouped by calling convention and ordered in increasing complexity.
	{
		// cdecl
		if( TestExecute()                 ) goto failed; else printf("-- TestExecute passed\n");
		if( TestCDeclReturn::Test()       ) goto failed; else printf("-- TestCDeclReturn passed\n");
		if( TestExecute1Arg()             ) goto failed; else printf("-- TestExecute1Arg passed\n");
		if( TestExecute2Args()            ) goto failed; else printf("-- TestExecute2Args passed\n");
		if( TestExecute4Args()            ) goto failed; else printf("-- TestExecute4Args passed\n");
		if( TestExecute4Argsf()           ) goto failed; else printf("-- TestExecute4Argsf passed\n");
		if( TestExecuteMixedArgs()        ) goto failed; else printf("-- TestExecuteMixedArgs passed\n");
		if( TestExecute32Args()           ) goto failed; else printf("-- TestExecute32Args passed\n");
		if( TestExecute32MixedArgs()      ) goto failed; else printf("-- TestExecute32MixedArgs passed\n");
		if( TestCDecl_Class()             ) goto failed; else printf("-- TestCDecl_Class passed\n");
		if( TestCDecl_ClassA()            ) goto failed; else printf("-- TestCDecl_ClassA passed\n");
		if( TestCDecl_ClassC()            ) goto failed; else printf("-- TestCDecl_ClassC passed\n");
		if( TestCDecl_ClassD()            ) goto failed; else printf("-- TestCDecl_ClassD passed\n");

		// cdecl_objlast and cdecl_objfirst
		if( TestReturnString::Test()      ) goto failed; else printf("-- TestReturnString passed\n");
		if( TestNegateOperator()          ) goto failed; else printf("-- TestNegateOperator passed\n");
		if( TestReturnWithCDeclObjFirst() ) goto failed; else printf("-- TestReturnWithCDeclObjFirst passed\n");

		// thiscall
		if( TestExecuteThis32MixedArgs()  ) goto failed; else printf("-- TestExecuteThis32MixedArgs passed\n");
		if( TestNotComplexThisCall()      ) goto failed; else printf("-- TestNotComplexThisCall passed\n");
		if( TestVirtualMethod()           ) goto failed; else printf("-- TestVirtualMethod passed\n");
		if( TestMultipleInheritance()     ) goto failed; else printf("-- TestMultipleInheritance passed\n");
		if( TestVirtualInheritance()      ) goto failed; else printf("-- TestVirtualInheritance passed\n");

		// stdcall
		if( TestStdcall4Args()            ) goto failed; else printf("-- TestStdcall4Args passed\n");
		if( TestNotComplexStdcall()       ) goto failed; else printf("-- TestNotComplexStdcall passed\n");
	}

	// This test uses ATL::CString thus it is turned off by default
//	if( TestCString::Test()           ) goto failed; else printf("-- TestCString passed\n");
	// Pointers are not supported by AngelScript at the moment, but they may be in the future
//	if( TestPointer::Test()           ) goto failed; else printf("-- TestPointer passed\n");

	RemoveMemoryManager();

//succeed:
	printf("--------------------------------------------\n");
	printf("All of the tests passed with success.\n\n");
#if !defined(DONT_WAIT) && (defined(WIN32) || defined(_WIN64))
	printf("Press any key to quit.\n");
	while(!_getch());
#endif
	return 0;

failed:
	printf("--------------------------------------------\n");
	printf("One of the tests failed, see details above.\n\n");
#if !defined(DONT_WAIT) && (defined(WIN32) || defined(_WIN64))
	printf("Press any key to quit.\n");
	while(!_getch());
#endif
	return -1;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
	DetectMemoryLeaks();

	printf("Performance test");
#ifdef _DEBUG 
	printf(" (DEBUG)");
#endif
	printf("\n");
	printf("AngelScript %s\n", asGetLibraryVersion()); 

	int n;
	for( n = 0; n < 18; n++ )
		testTimesBest[n] = 1000;

	for( n = 0; n < 3; n++ )
	{
		TestBasic::Test(&testTimes[0]); printf("."); fflush(stdout);
		TestBasic2::Test(&testTimes[1]); printf("."); fflush(stdout);
		TestCall::Test(&testTimes[2]); printf("."); fflush(stdout);
		TestCall2::Test(&testTimes[3]); printf("."); fflush(stdout);
		TestFib::Test(&testTimes[4]); printf("."); fflush(stdout);
		TestInt::Test(&testTimes[5]); printf("."); fflush(stdout);
		TestIntf::Test(&testTimes[6]); printf("."); fflush(stdout);
		TestMthd::Test(&testTimes[7]); printf("."); fflush(stdout);
		TestString::Test(&testTimes[8]); printf("."); fflush(stdout);
		TestString2::Test(&testTimes[9]); printf("."); fflush(stdout);
		TestStringPooled::Test(&testTimes[10]); printf("."); fflush(stdout);
		TestThisProp::Test(&testTimes[11]); printf("."); fflush(stdout);
		TestVector3::Test(&testTimes[12]); printf("."); fflush(stdout);
		TestAssign::Test(&testTimes[13]); printf("."); fflush(stdout);

		for( int t = 0; t < 18; t++ )
		{
			if( testTimesBest[t] > testTimes[t] )
				testTimesBest[t] = testTimes[t];
		}

		printf("\n");
	}
	
	printf("Basic          %.3f    %.3f    %.3f%s\n", testTimesOrig[ 0], testTimesOrig2[ 0], testTimesBest[ 0], testTimesBest[ 0] < testTimesOrig2[ 0] ? " +" : " -"); 
	printf("Basic2         %.3f    %.3f    %.3f%s\n", testTimesOrig[ 1], testTimesOrig2[ 1], testTimesBest[ 1], testTimesBest[ 1] < testTimesOrig2[ 1] ? " +" : " -"); 
	printf("Call           %.3f    %.3f    %.3f%s\n", testTimesOrig[ 2], testTimesOrig2[ 2], testTimesBest[ 2], testTimesBest[ 2] < testTimesOrig2[ 2] ? " +" : " -"); 
	printf("Call2          %.3f    %.3f    %.3f%s\n", testTimesOrig[ 3], testTimesOrig2[ 3], testTimesBest[ 3], testTimesBest[ 3] < testTimesOrig2[ 3] ? " +" : " -"); 
	printf("Fib            %.3f    %.3f    %.3f%s\n", testTimesOrig[ 4], testTimesOrig2[ 4], testTimesBest[ 4], testTimesBest[ 4] < testTimesOrig2[ 4] ? " +" : " -"); 
	printf("Int            %.3f    %.3f    %.3f%s\n", testTimesOrig[ 5], testTimesOrig2[ 5], testTimesBest[ 5], testTimesBest[ 5] < testTimesOrig2[ 5] ? " +" : " -"); 
	printf("Intf           %.3f    %.3f    %.3f%s\n", testTimesOrig[ 6], testTimesOrig2[ 6], testTimesBest[ 6], testTimesBest[ 6] < testTimesOrig2[ 6] ? " +" : " -"); 
	printf("Mthd           %.3f    %.3f    %.3f%s\n", testTimesOrig[ 7], testTimesOrig2[ 7], testTimesBest[ 7], testTimesBest[ 7] < testTimesOrig2[ 7] ? " +" : " -"); 
	printf("String         %.3f    %.3f    %.3f%s\n", testTimesOrig[ 8], testTimesOrig2[ 8], testTimesBest[ 8], testTimesBest[ 8] < testTimesOrig2[ 8] ? " +" : " -"); 
	printf("String2        %.3f    %.3f    %.3f%s\n", testTimesOrig[ 9], testTimesOrig2[ 9], testTimesBest[ 9], testTimesBest[ 9] < testTimesOrig2[ 9] ? " +" : " -"); 
	printf("StringPooled   %.3f    %.3f    %.3f%s\n", testTimesOrig[10], testTimesOrig2[10], testTimesBest[10], testTimesBest[10] < testTimesOrig2[10] ? " +" : " -"); 
	printf("ThisProp       %.3f    %.3f    %.3f%s\n", testTimesOrig[11], testTimesOrig2[11], testTimesBest[11], testTimesBest[11] < testTimesOrig2[11] ? " +" : " -"); 
	printf("Vector3        %.3f    %.3f    %.3f%s\n", testTimesOrig[12], testTimesOrig2[12], testTimesBest[12], testTimesBest[12] < testTimesOrig2[12] ? " +" : " -"); 
	printf("Assign.1       %.3f    %.3f    %.3f%s\n", testTimesOrig[13], testTimesOrig2[13], testTimesBest[13], testTimesBest[13] < testTimesOrig2[13] ? " +" : " -"); 
	printf("Assign.2       %.3f    %.3f    %.3f%s\n", testTimesOrig[14], testTimesOrig2[14], testTimesBest[14], testTimesBest[14] < testTimesOrig2[14] ? " +" : " -"); 
	printf("Assign.3       %.3f    %.3f    %.3f%s\n", testTimesOrig[15], testTimesOrig2[15], testTimesBest[15], testTimesBest[15] < testTimesOrig2[15] ? " +" : " -"); 
	printf("Assign.4       %.3f    %.3f    %.3f%s\n", testTimesOrig[16], testTimesOrig2[16], testTimesBest[16], testTimesBest[16] < testTimesOrig2[16] ? " +" : " -"); 
	printf("Assign.5       %.3f    %.3f    %.3f%s\n", testTimesOrig[17], testTimesOrig2[17], testTimesBest[17], testTimesBest[17] < testTimesOrig2[17] ? " +" : " -"); 

	printf("--------------------------------------------\n");
	printf("Press any key to quit.\n");
#if defined(WIN32)
	while(!_getch());
#endif
	return 0;
}