MCPcopy Create free account
hub / github.com/anjo76/angelscript / TestModule

Function TestModule

sdk/tests/test_feature/source/test_inheritance.cpp:628–815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626}
627
628bool TestModule(const char *module, asIScriptEngine *engine)
629{
630 bool fail = false;
631 int r;
632 CBufferedOutStream bout;
633 COutStream out;
634 asIScriptModule *mod = engine->GetModule(module);
635
636 // Test that it is possible to declare a class that inherits from another
637 // Test that the inherited properties are available in the derived class
638 // Test that the inherited methods are available in the derived class
639 // Test that it is possible to override the inherited methods
640 // Test that it is possible to call base class methods from within overridden methods in derived class
641 asIScriptObject *obj = (asIScriptObject*)engine->CreateScriptObject(mod->GetTypeInfoByName("Derived"));
642 asIScriptContext *ctx = engine->CreateContext();
643 ctx->Prepare(obj->GetObjectType()->GetMethodByDecl("void func()"));
644 ctx->SetObject(obj);
645 r = ctx->Execute();
646 if( r != asEXECUTION_FINISHED )
647 {
648 TEST_FAILED;
649 }
650 ctx->Release();
651 obj->Release();
652
653 // Test that implicit cast from derived to base is working
654 r = ExecuteString(engine, "Derived d; Base @b = @d; assert( b !is null );", mod);
655 if( r != asEXECUTION_FINISHED )
656 {
657 TEST_FAILED;
658 }
659
660 // Test that cast from base to derived require explicit cast
661 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
662 bout.buffer = "";
663 r = ExecuteString(engine, "Base b; Derived @d = @b;", mod);
664 if( r >= 0 )
665 {
666 TEST_FAILED;
667 }
668 if( bout.buffer != "ExecuteString (1, 22) : Error : Can't implicitly convert from 'Base@&' to 'Derived@&'.\n" )
669 {
670 TEST_FAILED;
671 PRINTF("%s", bout.buffer.c_str());
672 }
673
674 // Test that it is possible to explicitly cast to derived class
675 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
676 r = ExecuteString(engine, "Derived d; Base @b = @d; assert( cast<Derived>(b) !is null );", mod);
677 if( r != asEXECUTION_FINISHED )
678 {
679 TEST_FAILED;
680 }
681
682 // Test the explicit cast behaviour for a non-handle script object
683 r = ExecuteString(engine, "Base b; assert( cast<Derived>(b) is null );", mod);
684 if( r != asEXECUTION_FINISHED )
685 {

Callers 1

TestFunction · 0.85

Calls 15

ExecuteStringFunction · 0.85
CreateScriptObjectMethod · 0.80
CreateContextMethod · 0.80
SetObjectMethod · 0.80
ExecuteMethod · 0.80
SetMessageCallbackMethod · 0.80
GetGCStatisticsMethod · 0.80
GetTypeInfoByIdMethod · 0.80
GetModuleMethod · 0.45
GetTypeInfoByNameMethod · 0.45
PrepareMethod · 0.45
GetMethodByDeclMethod · 0.45

Tested by

no test coverage detected