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

Function Test

sdk/tests/test_feature/source/test_array.cpp:174–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172}
173
174bool Test()
175{
176 bool fail = Test2();
177 int r;
178 COutStream out;
179 CBufferedOutStream bout;
180 asIScriptContext *ctx;
181
182 // Test anonymous initialization list with short hand version of array type
183 // Reported by Phong Ba
184 {
185 asIScriptEngine* engine = asCreateScriptEngine();
186 bout.buffer = "";
187 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
188 RegisterScriptArray(engine, true);
189
190 asIScriptModule* mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
191 mod->AddScriptSection("test",
192 "void func(int[]@ arr) {} \n"
193 "void main() \n"
194 "{ \n"
195 " func(array<int> = {1,2,3}); \n"
196 " func(int[] = {1,2,3}); \n"
197 "} \n");
198 r = mod->Build();
199 if (r < 0)
200 TEST_FAILED;
201
202 if (bout.buffer != "")
203 {
204 PRINTF("%s", bout.buffer.c_str());
205 TEST_FAILED;
206 }
207
208 engine->ShutDownAndRelease();
209 }
210
211 // Test initializing list with value type and opAssign returning void
212 // https://www.gamedev.net/forums/topic/709865-build-a-script-containing-array-of-string-failed-with-corrupted-vm-stack/
213 SKIP_ON_MAX_PORT
214 {
215 asIScriptEngine* engine = asCreateScriptEngine();
216 bout.buffer = "";
217 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
218 RegisterScriptArray(engine, false);
219
220 // Register a string type but with opAssign returning null
221 r = engine->RegisterObjectType("string", sizeof(string), asOBJ_VALUE); assert(r >= 0);
222 r = engine->RegisterStringFactory("string", reinterpret_cast<asIStringFactory*>(GetStdStringFactorySingleton()));
223 r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructString), asCALL_CDECL_OBJLAST); assert(r >= 0);
224 r = engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f(const string &in)", asFUNCTION(CopyConstructString), asCALL_CDECL_OBJLAST); assert(r >= 0);
225 r = engine->RegisterObjectBehaviour("string", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructString), asCALL_CDECL_OBJLAST); assert(r >= 0);
226 r = engine->RegisterObjectMethod("string", "void opAssign(const string &in)", asFUNCTION(AssignString), asCALL_CDECL_OBJFIRST); assert(r >= 0);
227
228 asIScriptModule* mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
229 mod->AddScriptSection("test",
230 "void main() \n"
231 "{ \n"

Callers

nothing calls this directly

Calls 11

RegisterScriptArrayFunction · 0.85
SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
ShutDownAndReleaseMethod · 0.80
RegisterStringFactoryMethod · 0.80
RegisterObjectMethodMethod · 0.80
Test2Function · 0.70
GetModuleMethod · 0.45
BuildMethod · 0.45

Tested by

no test coverage detected