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

Function Test

sdk/tests/test_feature/source/test_addon_stdstring.cpp:21–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19 }
20
21 bool Test()
22 {
23 bool fail = false;
24 int r;
25
26 COutStream out;
27 CBufferedOutStream bout;
28
29 // scan
30 {
31 asIScriptEngine* engine = asCreateScriptEngine();
32 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
33 RegisterStdString(engine);
34 engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_GENERIC);
35
36 bout.buffer = "";
37
38 engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);
39
40 g_buf = "";
41 asIScriptContext* ctx = engine->CreateContext();
42 r = ExecuteString(engine,
43 "int i; float f; string s;\n"
44 "uint scanned = scan('123 3.14 hello', i, f, s);\n"
45 "print('Scanned ' + scanned + ' result(s): ' + i + ', ' + f + ', ' + s);\n"
46 "assert(i == 123);\n"
47 "float diff = f - 3.14f; assert(diff * diff < 0.00001f);\n"
48 "assert(s == 'hello');"
49 );
50 if (r != asEXECUTION_FINISHED)
51 {
52 TEST_FAILED;
53 if (r == asEXECUTION_EXCEPTION)
54 {
55 PRINTF("%s\n", GetExceptionInfo(ctx).c_str());
56 }
57 }
58 if (g_buf != "Scanned 3 result(s): 123, 3.14, hello\n")
59 {
60 TEST_FAILED;
61 PRINTF("%s\n", g_buf.c_str());
62 }
63 ctx->Release();
64
65 engine->ShutDownAndRelease();
66 }
67
68 // format
69 {
70 asIScriptEngine* engine = asCreateScriptEngine();
71 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
72 RegisterStdString(engine);
73 engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_GENERIC);
74
75 bout.buffer = "";
76
77 engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);
78

Callers

nothing calls this directly

Calls 15

RegisterStdStringFunction · 0.85
ExecuteStringFunction · 0.85
GetExceptionInfoFunction · 0.85
asGetLibraryOptionsFunction · 0.85
RegisterScriptArrayFunction · 0.85
RegisterStdStringUtilsFunction · 0.85
SetMessageCallbackMethod · 0.80
CreateContextMethod · 0.80
ShutDownAndReleaseMethod · 0.80
AddScriptSectionMethod · 0.80
GetAddressOfGlobalVarMethod · 0.80

Tested by

no test coverage detected