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

Function TestStdWString

sdk/tests/test_feature/source/teststdstring.cpp:520–562  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

518}
519
520bool TestStdWString()
521{
522 // wchar_t on Linux is 32bits in size. Thus this test fails on Linux.
523 if (!strstr(asGetLibraryOptions(), "AS_WIN"))
524 {
525 PRINTF("TestStdWString is skipped because wstring is platform dependent and this test only works on Windows\n");
526 return false;
527 }
528
529 bool fail = false;
530 COutStream out;
531 int r;
532
533 asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
534 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
535 engine->SetEngineProperty(asEP_STRING_ENCODING, 1);
536
537 engine->RegisterObjectType("string", sizeof(wstring), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK);
538 engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(WStringConstruct), asCALL_CDECL_OBJLAST);
539 engine->RegisterObjectBehaviour("string", asBEHAVE_CONSTRUCT, "void f(const string &in)", asFUNCTION(WStringCopyConstruct), asCALL_CDECL_OBJLAST);
540 engine->RegisterObjectBehaviour("string", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(WStringDestruct), asCALL_CDECL_OBJLAST);
541 engine->RegisterObjectMethod("string", "string &opAssign(const string &in)", asMETHODPR(wstring, operator=, (const wstring &), wstring &), asCALL_THISCALL);
542 engine->RegisterStringFactory("string", &wstringFactory);
543 engine->RegisterGlobalFunction("void SetQuestClassByRef(const string &in mod)", asFUNCTION(SetQuestClassByRef), asCALL_CDECL);
544 engine->RegisterGlobalFunction("void SetQuestClassByVal(string mod)", asFUNCTION(SetQuestClassByVal), asCALL_CDECL);
545
546 r = ExecuteString(engine, "SetQuestClassByRef('Tutorial');");
547 if (r != asEXECUTION_FINISHED)
548 TEST_FAILED;
549
550 // TODO: bug: This should also work. It doesn't though, because AngelScript moves the object to the
551 // stack, and this causes an internal pointer in the string object to point to the wrong
552 // address (the original location). This problem seems to be unique to MSVC/x86 and debug mode.
553 // http://www.gamedev.net/topic/646508-weird-string-crash/
554/*
555 r = ExecuteString(engine, "SetQuestClassByVal('Tutorial');");
556 if( r != asEXECUTION_FINISHED )
557 TEST_FAILED;
558*/
559 engine->Release();
560
561 return fail;
562}

Callers 1

TestStdStringFunction · 0.85

Calls 9

asGetLibraryOptionsFunction · 0.85
ExecuteStringFunction · 0.85
SetMessageCallbackMethod · 0.80
SetEnginePropertyMethod · 0.80
RegisterObjectMethodMethod · 0.80
RegisterStringFactoryMethod · 0.80
ReleaseMethod · 0.45

Tested by

no test coverage detected