| 407 | } |
| 408 | |
| 409 | bool TestTwoStringTypes() |
| 410 | { |
| 411 | bool fail = false; |
| 412 | int r; |
| 413 | COutStream out; |
| 414 | |
| 415 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); |
| 416 | engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL); |
| 417 | RegisterStdString(engine); |
| 418 | |
| 419 | // Register the second string type |
| 420 | engine->RegisterObjectType("_String", sizeof(_String), asOBJ_VALUE | asOBJ_APP_CLASS_CDA); |
| 421 | engine->RegisterObjectBehaviour("_String", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(stringDefaultCoonstructor), asCALL_CDECL_OBJLAST); |
| 422 | engine->RegisterObjectBehaviour("_String", asBEHAVE_CONSTRUCT, "void f(const _String &in )", asFUNCTION(stringCopyConstructor), asCALL_CDECL_OBJLAST); |
| 423 | engine->RegisterObjectBehaviour("_String", asBEHAVE_CONSTRUCT, "void f(const string &in)", asFUNCTION(stringStringConstructor), asCALL_CDECL_OBJLAST); |
| 424 | engine->RegisterObjectBehaviour("_String", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(stringDecontructor), asCALL_CDECL_OBJLAST); |
| 425 | // = |
| 426 | engine->RegisterObjectMethod("_String", "_String &opAssign(const string &in )", asMETHODPR(_String, operator=, (const string &), _String&), asCALL_THISCALL); |
| 427 | engine->RegisterObjectMethod("_String", "_String &opAssign(const _String &in )", asMETHODPR(_String, operator=, (const _String &), _String&), asCALL_THISCALL); |
| 428 | // += |
| 429 | engine->RegisterObjectMethod("_String", "_String &opAddAssign(const string &in )", asMETHODPR(_String, operator+=, (const string &), _String&), asCALL_THISCALL); |
| 430 | engine->RegisterObjectMethod("_String", "_String &opAddAssign(const _String &in )", asMETHODPR(_String, operator+=, (const _String &), _String&), asCALL_THISCALL); |
| 431 | // comparison |
| 432 | /* engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, "bool f(const _String &in, const _String &in)", asFUNCTION(compare_StringEqual), asCALL_CDECL); |
| 433 | engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, "bool f(const _String &in, const string &in)", asFUNCTION(compare_StringStringEqual), asCALL_CDECL); |
| 434 | engine->RegisterGlobalBehaviour(asBEHAVE_EQUAL, "bool f(const string &in, const _String &in)", asFUNCTION(compareString_StringEqual), asCALL_CDECL); |
| 435 | // not equal |
| 436 | engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL , "bool f(const _String &in, const _String &in)", asFUNCTION(compare_StringNotEqual), asCALL_CDECL); |
| 437 | engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL , "bool f(const _String &in, const string &in)", asFUNCTION(compare_StringStringNotEqual), asCALL_CDECL); |
| 438 | engine->RegisterGlobalBehaviour(asBEHAVE_NOTEQUAL , "bool f(const string &in, const _String &in)", asFUNCTION(compareString_StringNotEqual), asCALL_CDECL); |
| 439 | */ // + |
| 440 | r = engine->RegisterObjectMethod("_String", "_String opAdd(const _String &in) const", asFUNCTION(operation_StringAdd), asCALL_CDECL_OBJFIRST); assert(r >= 0); |
| 441 | r = engine->RegisterObjectMethod("_String", "_String opAdd(const string &in) const", asFUNCTION(operation_StringStringAdd), asCALL_CDECL_OBJFIRST); assert(r >= 0); |
| 442 | r = engine->RegisterObjectMethod("_String", "_String opAdd_r(const string &in) const", asFUNCTION(operationString_StringAdd), asCALL_CDECL_OBJLAST); assert(r >= 0); |
| 443 | |
| 444 | r = ExecuteString(engine, "_String('ab') + 'a'"); |
| 445 | if (r < 0) |
| 446 | TEST_FAILED; |
| 447 | |
| 448 | r = ExecuteString(engine, "_String a; a+= 'a' + 'b' ; _String b = 'c'; a += b + 'c';"); |
| 449 | if (r < 0) |
| 450 | TEST_FAILED; |
| 451 | |
| 452 | r = ExecuteString(engine, "string a; a+= 'a' + 'b' ; string b = 'c'; a += b + 'c';"); |
| 453 | if (r < 0) |
| 454 | TEST_FAILED; |
| 455 | |
| 456 | engine->Release(); |
| 457 | |
| 458 | return fail; |
| 459 | } |
| 460 | |
| 461 | |
| 462 | //================================================================================= |
no test coverage detected