| 42 | }; |
| 43 | |
| 44 | bool TestVector3() |
| 45 | { |
| 46 | bool fail = false; |
| 47 | COutStream out; |
| 48 | CBufferedOutStream bout; |
| 49 | int r; |
| 50 | asIScriptEngine *engine = 0; |
| 51 | |
| 52 | // Test reported bug with vector3 class that has no registered copy constructor |
| 53 | // https://www.gamedev.net/forums/topic/693832-overloaded-operator-results-in-null-pointer-exception-when-result-isnt-stored-in-variable/ |
| 54 | SKIP_ON_MAX_PORT |
| 55 | { |
| 56 | engine = asCreateScriptEngine(); |
| 57 | engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL); |
| 58 | |
| 59 | engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC); |
| 60 | |
| 61 | engine->RegisterObjectType("vec3", sizeof(vec3), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<vec3>() | asOBJ_APP_CLASS_ALLFLOATS); |
| 62 | |
| 63 | engine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTIONPR(vec3::vec3Construct, (vec3*), void), asCALL_CDECL_OBJLAST); |
| 64 | engine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f(float,float,float)", asFUNCTIONPR(vec3::vec3Construct, (float,float,float,vec3*),void), asCALL_CDECL_OBJLAST); |
| 65 | engine->RegisterObjectBehaviour("vec3", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(vec3::vec3Destruct), asCALL_CDECL_OBJLAST); |
| 66 | |
| 67 | engine->RegisterObjectMethod("vec3", "vec3 opSub(const vec3)", asMETHOD(vec3, opSub), asCALL_THISCALL); |
| 68 | |
| 69 | engine->RegisterGlobalFunction("float length2(const vec3)", asFUNCTION(vec3::length2), asCALL_CDECL); |
| 70 | |
| 71 | asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE); |
| 72 | mod->AddScriptSection("test", |
| 73 | "class Test { vec3 &getPosition() { return pos; } vec3 pos(1,0,0); } \n" |
| 74 | "vec3 global(2,0,0); \n"); |
| 75 | r = mod->Build(); |
| 76 | if (r < 0) |
| 77 | TEST_FAILED; |
| 78 | |
| 79 | r = ExecuteString(engine, "Test s; float length = length2(s.getPosition() - global); assert( length == 1 );", mod); |
| 80 | if (r != asEXECUTION_FINISHED) |
| 81 | TEST_FAILED; |
| 82 | |
| 83 | engine->ShutDownAndRelease(); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | // Standard tests |
no test coverage detected