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

Function Test2

sdk/tests/test_feature/source/test_constobject.cpp:308–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

306
307
308bool Test2()
309{
310 bool fail = false;
311
312 int r;
313 COutStream out;
314 CBufferedOutStream bout;
315
316 asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
317 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
318 engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);
319
320 // Try calling a const method on a const object (success)
321 const char *script =
322 "class MyType \n"
323 "{ \n"
324 " int val; \n"
325 " void TestConst() const \n"
326 " { \n"
327 " assert(val == 5); \n"
328 " } \n"
329 "} \n"
330 "void Func(const MyType &in a) \n"
331 "{ \n"
332 " a.TestConst(); \n"
333 "} \n";
334
335 asIScriptModule *mod = engine->GetModule("module", asGM_ALWAYS_CREATE);
336 mod->AddScriptSection("script", script, strlen(script));
337 r = mod->Build();
338 if( r < 0 )
339 {
340 TEST_FAILED;
341 }
342
343 // Try calling a non-const method on a const object (should fail)
344 script =
345 "class MyType \n"
346 "{ \n"
347 " int val; \n"
348 " void TestConst() \n"
349 " { \n"
350 " assert(val == 5); \n"
351 " } \n"
352 "} \n"
353 "void Func(const MyType &in a) \n"
354 "{ \n"
355 " a.TestConst(); \n"
356 "} \n";
357
358 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
359
360 bout.buffer = "";
361 mod->AddScriptSection("script", script, strlen(script));
362 r = mod->Build();
363 if( r >= 0 )
364 {
365 TEST_FAILED;

Callers 1

TestFunction · 0.70

Calls 6

SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
GetModuleMethod · 0.45
BuildMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected