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

Function TestBStr

sdk/tests/test_feature/source/testbstr.cpp:17–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15}
16
17bool TestBStr()
18{
19 RET_ON_MAX_PORT
20
21 bool fail = false;
22 COutStream out;
23
24 asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
25 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
26 RegisterBStr(engine);
27
28 engine->RegisterGlobalFunction("bstr NewString(int)", asFUNCTION(NewString), asCALL_CDECL);
29 engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);
30
31 int r = ExecuteString(engine, "bstr s = NewString(10)");
32 if( r < 0 )
33 {
34 PRINTF("%s: ExecuteString() failed\n", TESTNAME);
35 TEST_FAILED;
36 }
37 else if( r != asEXECUTION_FINISHED )
38 {
39 PRINTF("%s: ExecuteString() returned %d\n", TESTNAME, r);
40 TEST_FAILED;
41 }
42
43 // Test passing bstr strings to a script function
44 asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
45 const char *script =
46 "void test(bstr a, bstr b) \n"
47 "{ \n"
48 " assert(a == \"a\"); \n"
49 " assert(b == \"b\"); \n"
50 "} \n";
51 mod->AddScriptSection("script", script);
52 r = mod->Build();
53 if( r < 0 )
54 {
55 TEST_FAILED;
56 }
57
58 asIScriptFunction *func = mod->GetFunctionByIndex(0);
59 asIScriptContext *ctx = engine->CreateContext();
60 ctx->Prepare(func);
61
62 // Create the object and initialize it, then give
63 // the pointer directly to the script engine.
64 // The script engine will free the object.
65 asBSTR *a = (asBSTR*)engine->CreateScriptObject(engine->GetTypeInfoByName("bstr"));
66 *a = asBStrAlloc(1);
67 strcpy((char*)*a, "a");
68 *(asBSTR**)ctx->GetAddressOfArg(0) = a;
69
70 // Create a local instance and have the script engine copy it.
71 // The application must free its copy of the object.
72 asBSTR b = asBStrAlloc(1);
73 strcpy((char*)b, "b");
74 ctx->SetArgObject(1, &b);

Callers 1

allTestsFunction · 0.85

Calls 15

RegisterBStrFunction · 0.85
ExecuteStringFunction · 0.85
asBStrAllocFunction · 0.85
asBStrFreeFunction · 0.85
SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
GetFunctionByIndexMethod · 0.80
CreateContextMethod · 0.80
CreateScriptObjectMethod · 0.80
SetArgObjectMethod · 0.80
ExecuteMethod · 0.80

Tested by

no test coverage detected