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

Function Test2

sdk/tests/test_feature/source/test_implicitcast.cpp:1207–1259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1205}
1206
1207static bool Test2()
1208{
1209 bool fail = false;
1210 COutStream out;
1211 int r;
1212
1213 asIScriptEngine * engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
1214 engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
1215 r = engine->RegisterObjectType("simple", sizeof(Simple), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE); assert(r >= 0);
1216 r = engine->RegisterObjectType("complex", sizeof(Complex), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE); assert(r >= 0);
1217 r = engine->RegisterObjectMethod("complex", "int opImplConv()", asFUNCTION(implicit), asCALL_GENERIC);
1218 r = engine->RegisterObjectMethod("complex", "double opImplConv()", asFUNCTION(implicit), asCALL_GENERIC);
1219 r = engine->RegisterObjectMethod("complex", "simple opImplConv()", asFUNCTION(implicit), asCALL_GENERIC);
1220
1221 const char script[] =
1222 "void main() {\n"
1223 " int i;\n"
1224 " double d;\n"
1225 " simple s;\n"
1226 " complex c;\n"
1227 " i = c;\n"
1228 " d = c;\n"
1229 " s = c;\n"
1230 "}";
1231 asIScriptModule * mod = engine->GetModule(0, asGM_ALWAYS_CREATE);
1232 r = mod->AddScriptSection("script", script, sizeof(script) - 1); assert(r >= 0);
1233 r = mod->Build();
1234 if( r < 0 )
1235 {
1236 TEST_FAILED;
1237 }
1238 else
1239 {
1240 asIScriptFunction *func = mod->GetFunctionByDecl("void main()"); assert(func);
1241 asIScriptContext * ctx = engine->CreateContext();
1242
1243 r = ctx->Prepare(func); assert(r >= 0);
1244 r = ctx->Execute(); assert(r >= 0);
1245
1246 ctx->Release();
1247 }
1248
1249 // It must be possible to cast using an explicit construct cast
1250 r = ExecuteString(engine, "complex c; simple s = simple(c);");
1251 if( r < 0 )
1252 {
1253 TEST_FAILED;
1254 }
1255
1256 engine->Release();
1257
1258 return fail;
1259}
1260
1261//========================================================================================
1262

Callers 1

TestFunction · 0.70

Calls 11

ExecuteStringFunction · 0.85
SetMessageCallbackMethod · 0.80
RegisterObjectMethodMethod · 0.80
AddScriptSectionMethod · 0.80
GetFunctionByDeclMethod · 0.80
CreateContextMethod · 0.80
ExecuteMethod · 0.80
GetModuleMethod · 0.45
BuildMethod · 0.45
PrepareMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected