| 70 | int init(); |
| 71 | |
| 72 | bool Test_main() |
| 73 | { |
| 74 | RET_ON_MAX_PORT |
| 75 | |
| 76 | bool fail = false; |
| 77 | int r; |
| 78 | CBufferedOutStream bout; |
| 79 | |
| 80 | gEngine = asCreateScriptEngine(ANGELSCRIPT_VERSION); |
| 81 | |
| 82 | // The script compiler will send any compiler messages to the callback |
| 83 | gEngine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL); |
| 84 | |
| 85 | r = gEngine->RegisterGlobalFunction("void print(int)", asFUNCTION(PrintNumber), asCALL_CDECL); assert( r >= 0 ); |
| 86 | r = gEngine->RegisterObjectType("Foo", sizeof(Foo), asOBJ_VALUE | asOBJ_APP_CLASS_CD); |
| 87 | r = gEngine->RegisterObjectBehaviour("Foo", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(defaultConstruct<Foo>), asCALL_CDECL_OBJLAST); |
| 88 | r = gEngine->RegisterObjectBehaviour("Foo", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(destruct<Foo>), asCALL_CDECL_OBJLAST); |
| 89 | |
| 90 | // Compile the script code |
| 91 | const char* scriptStr= |
| 92 | "class Bar {" |
| 93 | " Bar() {}" // explicitly define default constructor to avoid auto generated copy constructor |
| 94 | " private Foo foo;" |
| 95 | " void method(){" |
| 96 | " print(666);" |
| 97 | " }" |
| 98 | "};"; |
| 99 | |
| 100 | asIScriptModule *mod = gEngine->GetModule("script", asGM_ALWAYS_CREATE); |
| 101 | mod->AddScriptSection("test", scriptStr); |
| 102 | r = mod->Build(); |
| 103 | if( r < 0 ) |
| 104 | TEST_FAILED; |
| 105 | |
| 106 | if (r >= 0) |
| 107 | { |
| 108 | // Create the script object with the Foo member |
| 109 | createBar(); |
| 110 | |
| 111 | // Now release the created script object so that it is destroyed, which will |
| 112 | // trigger Foo to attempt to access the object from within the destructor |
| 113 | // of asCScriptObject |
| 114 | gBar->Release(); |
| 115 | } |
| 116 | |
| 117 | if( bout.buffer != " (0, 0) : Error : The script object of type 'Bar' is being resurrected illegally during destruction\n" ) |
| 118 | { |
| 119 | PRINTF("%s", bout.buffer.c_str()); |
| 120 | TEST_FAILED; |
| 121 | } |
| 122 | |
| 123 | gEngine->Release(); |
| 124 | |
| 125 | return fail; |
| 126 | } |
| 127 | |
| 128 | } |
| 129 |
no test coverage detected