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

Function TestStack

sdk/tests/test_feature/source/teststack.cpp:12–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12bool TestStack()
13{
14 bool fail = false;
15 COutStream out;
16
17 // Test limiting the data stack size
18 {
19 asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
20 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
21
22 asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
23 mod->AddScriptSection(TESTNAME,
24 "void recursive(int n) \n"
25 "{ \n"
26 " if( n > 0 ) \n"
27 " recursive(n - 1); \n"
28 "} \n");
29 int r = mod->Build();
30 if (r < 0)
31 {
32 PRINTF("%s: Failed to build script\n", TESTNAME);
33 TEST_FAILED;
34 }
35
36 asIScriptContext *ctx = engine->CreateContext();
37 engine->SetEngineProperty(asEP_INIT_STACK_SIZE, 256); // 256 byte initial size
38 engine->SetEngineProperty(asEP_MAX_STACK_SIZE, 256); // 256 byte limit
39 ctx->Prepare(engine->GetModule(0)->GetFunctionByDecl("void recursive(int)"));
40 ctx->SetArgDWord(0, 100);
41 r = ctx->Execute();
42 if (r != asEXECUTION_EXCEPTION)
43 {
44 PRINTF("%s: Execution didn't throw an exception as was expected\n", TESTNAME);
45 TEST_FAILED;
46 }
47
48 ctx->Release();
49 engine->Release();
50 }
51
52 // Test limiting the call stack size
53 {
54 asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
55 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
56
57 asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
58 mod->AddScriptSection(TESTNAME,
59 "void recursive(int n) \n"
60 "{ \n"
61 " if( n > 0 ) \n"
62 " recursive(n - 1); \n"
63 "} \n");
64 int r = mod->Build();
65 if (r < 0)
66 {
67 PRINTF("%s: Failed to build script\n", TESTNAME);
68 TEST_FAILED;
69 }

Callers 1

allTestsFunction · 0.85

Calls 11

SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
CreateContextMethod · 0.80
SetEnginePropertyMethod · 0.80
GetFunctionByDeclMethod · 0.80
SetArgDWordMethod · 0.80
ExecuteMethod · 0.80
GetModuleMethod · 0.45
BuildMethod · 0.45
PrepareMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected