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

Function Test

sdk/tests/test_feature/source/test_constobject.cpp:55–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53bool Test2();
54
55bool Test()
56{
57 bool fail = Test2();
58
59 int r;
60 COutStream out;
61 CBufferedOutStream bout;
62
63 // passing a const handle on to a function expecting a const ref
64 // http://www.gamedev.net/topic/681018-problem-in-arrayfind-with-a-const-param/
65 {
66 asIScriptEngine *engine = asCreateScriptEngine();
67 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
68 bout.buffer = "";
69 RegisterScriptArray(engine, false);
70
71 asIScriptModule *mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
72 mod->AddScriptSection("test",
73 "class CData { int a; } \n"
74 "void func(const CData @d) \n"
75 "{ \n"
76 " find(d); \n"
77 " array<CData@> arr; \n"
78 " arr.find(d); \n"
79 "} \n"
80 "void find(const CData@ &in f) \n"
81 "{ \n"
82 //" f.a = 42; \n" change is not allowed
83 "} \n");
84 r = mod->Build();
85 if (r < 0)
86 TEST_FAILED;
87
88 if (bout.buffer != "")
89 {
90 PRINTF("%s", bout.buffer.c_str());
91 TEST_FAILED;
92 }
93
94 engine->ShutDownAndRelease();
95 }
96
97 // Ordinary tests
98 SKIP_ON_MAX_PORT
99 {
100 asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
101 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
102
103 // Register an object type
104 r = engine->RegisterObjectType("obj", sizeof(CObj), asOBJ_REF); assert(r >= 0);
105 r = engine->RegisterObjectBehaviour("obj", asBEHAVE_FACTORY, "obj@ f()", asFUNCTION(CObj_Factory), asCALL_CDECL); assert(r >= 0);
106 r = engine->RegisterObjectBehaviour("obj", asBEHAVE_ADDREF, "void f()", asMETHOD(CObj, AddRef), asCALL_THISCALL); assert(r >= 0);
107 r = engine->RegisterObjectBehaviour("obj", asBEHAVE_RELEASE, "void f()", asMETHOD(CObj, Release), asCALL_THISCALL); assert(r >= 0);
108 r = engine->RegisterObjectMethod("obj", "obj &opAssign(const obj &in)", asMETHOD(CObj, operator=), asCALL_THISCALL); assert(r >= 0);
109 r = engine->RegisterObjectMethod("obj", "int &opIndex(int)", asMETHODPR(CObj, operator[], (int), int&), asCALL_THISCALL); assert(r >= 0);
110 r = engine->RegisterObjectMethod("obj", "const int &opIndex(int) const", asMETHODPR(CObj, operator[], (int) const, const int&), asCALL_THISCALL); assert(r >= 0);
111
112 r = engine->RegisterObjectType("prop", sizeof(int), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE); assert(r >= 0);

Callers

nothing calls this directly

Calls 14

RegisterScriptArrayFunction · 0.85
ExecuteStringFunction · 0.85
SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
ShutDownAndReleaseMethod · 0.80
RegisterObjectMethodMethod · 0.80
Test2Function · 0.70
RegisterScriptStringFunction · 0.70
GetModuleMethod · 0.45

Tested by

no test coverage detected