void ExecuteContext(asIScriptContext *pContext, const int id, const bool prepare) { if (prepare) { if (pContext->Prepare(id) < 0) { ETH_STREAM_DECL(ss) << GS_L("(ExecuteContext) Couldn't prepare context for function ID ") << id; ETHResourceProvider::Log(ss.str(), Platform::Logger::ERROR); return; } } const int r = pContext->Execute(); if (r != asEXECUTION_FINISHED) { if (r == asEXECUTION_EXCEPTION) { PrintException(pContext); ETH_STREAM_DECL(ss) << GS_L("Exception: ") << pContext->GetExceptionString(); #ifdef _DEBUG ss << static_cast<str_type::char_t>(0x07); #endif ShowMessage(ss.str(), ETH_ERROR); } } }
bool ProfilerHandler::Attach() { try { if (amx_path_.empty()) { return false; } if (state_ >= PROFILER_ATTACHED) { return false; } if (amxprof::HasDebugInfo(amx())) { if (debug_info_.Load(amx_path_)) { profiler_.set_debug_info(&debug_info_); } else { Printf("Error loading debug info: %s", aux_StrError(debug_info_.last_error())); } } if (debug_info_.is_loaded()) { Printf("Attached profiler to %s", amx_name_.c_str()); } else { Printf("Attached profiler to %s (no debug info)", amx_name_.c_str()); } state_ = PROFILER_ATTACHED; return true; } catch (const std::exception &e) { PrintException(e); } return false; }
bool AppInit(int argc, char* argv[]) { bool fRet = false; try { fRet = AppInit2(argc, argv); } catch (std::exception& e) { PrintException(&e, "AppInit()"); } catch (...) { PrintException(NULL, "AppInit()"); } if (!fRet) Shutdown(NULL); return fRet; }
int ProfilerHandler::Exec(cell *retval, int index) { if (profiler_.call_stack()->is_empty()) { switch (state_) { case PROFILER_ATTACHING: if (!Attach()) { break; } // fallthrough case PROFILER_STARTING: CompleteStart(); break; } } if (state_ == PROFILER_STARTED) { try { int error = profiler_.ExecHook(retval, index, amx_Exec); if (state_ == PROFILER_STOPPING && profiler_.call_stack()->is_empty()) { CompleteStop(); } return error; } catch (const std::exception &e) { PrintException(e); } } return amx_Exec(amx(), retval, index); }
LONG __fastcall Top_Level_Exception_Filter_hack2(int exception_id, struct _EXCEPTION_POINTERS *ExceptionInfo) { DWORD *eip = &(ExceptionInfo->ContextRecord->Eip); switch (*eip) { /* Fog of war crashes */ case 0x0046C7E2: *eip = 0x0046C837; return EXCEPTION_CONTINUE_EXECUTION; case 0x0046BA24: *eip = 0x0046BA55; return EXCEPTION_CONTINUE_EXECUTION; case 0x0046AF75: *eip = 0x0046AFB5; return EXCEPTION_CONTINUE_EXECUTION; case 0x00469129: *eip = 0x00469163; return EXCEPTION_CONTINUE_EXECUTION; case 0x00469AD6: *eip = 0x00469B1A; return EXCEPTION_CONTINUE_EXECUTION; case 0x0046C7A7: *eip = 0x0046C837; return EXCEPTION_CONTINUE_EXECUTION; case 0x0046AF6E: *eip = 0x0046AFB5; return EXCEPTION_CONTINUE_EXECUTION; case 0x00469AA0: *eip = 0x00469B1A; return EXCEPTION_CONTINUE_EXECUTION; case 0x0046B9E9: *eip = 0x0046BA55; return EXCEPTION_CONTINUE_EXECUTION; case 0x004681B4: *eip = 0x004681E6; return EXCEPTION_CONTINUE_EXECUTION; case 0x004690EF: *eip = 0x00469163; return EXCEPTION_CONTINUE_EXECUTION; case 0x0046AF8A: *eip = 0x0046AFB5; return EXCEPTION_CONTINUE_EXECUTION; /* non-fog of war crashes*/ case 0x006A8D16: *eip = 0x006A8D1F; return EXCEPTION_CONTINUE_EXECUTION; case 0x006703d4: *eip = 0x00670499; return EXCEPTION_CONTINUE_EXECUTION; case 0x004668a8: *eip = 0x004668AD; return EXCEPTION_CONTINUE_EXECUTION; default: return PrintException(exception_id, ExceptionInfo); } return 0; }
HRESULT WScriptJsrt::ModuleMessage::Call(LPCSTR fileName) { JsErrorCode errorCode; JsValueRef result = JS_INVALID_REFERENCE; HRESULT hr; if (specifier == nullptr) { errorCode = ChakraRTInterface::JsModuleEvaluation(moduleRecord, &result); if (errorCode != JsNoError) { PrintException(fileName, errorCode); } } else { LPCSTR fileContent = nullptr; char* specifierStr = nullptr; size_t length; errorCode = ChakraRTInterface::JsStringToPointerUtf8Copy(specifier, &specifierStr, &length); if (errorCode == JsNoError) { hr = Helpers::LoadScriptFromFile(specifierStr, fileContent); if (FAILED(hr)) { fprintf(stderr, "Couldn't load file.\n"); } else { LoadScript(nullptr, specifierStr, fileContent, "module", true); } } } return errorCode; }
int main(int argc, char **argv) try { if (argc < 3) { unsigned n = 100; if (argc > 1) { n = atoi(argv[1]); } TestTrace(Path(_T("test/data/09kc3ov3.igc")), n); } else { assert(argc >= 3); unsigned n = atoi(argv[2]); plan_tests(n); for (unsigned i=2; i<2+n; i++) { unsigned nt = pow(2,i); char buf[100]; sprintf(buf," trace size %d", nt); ok(TestTrace(PathName(argv[1]), nt),buf, 0); } } return 0; } catch (const std::runtime_error &e) { PrintException(e); return EXIT_FAILURE; }
// Callback from chakraCore when the module resolution is finished, either successfuly or unsuccessfully. JsErrorCode WScriptJsrt::NotifyModuleReadyCallback(_In_opt_ JsModuleRecord referencingModule, _In_opt_ JsValueRef exceptionVar) { if (exceptionVar != nullptr) { ChakraRTInterface::JsSetException(exceptionVar); JsValueRef specifier = JS_INVALID_REFERENCE; ChakraRTInterface::JsGetModuleHostInfo(referencingModule, JsModuleHostInfo_HostDefined, &specifier); AutoString fileName; size_t length; if (specifier != JS_INVALID_REFERENCE) { ChakraRTInterface::JsStringToPointerUtf8Copy(specifier, &fileName, &length); } PrintException(*fileName, JsErrorScriptException); } else { WScriptJsrt::ModuleMessage* moduleMessage = WScriptJsrt::ModuleMessage::Create(referencingModule, nullptr); if (moduleMessage == nullptr) { return JsErrorOutOfMemory; } WScriptJsrt::PushMessage(moduleMessage); } return JsNoError; }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(bitcoin); QApplication app(argc, argv); // Load language file for system locale QString locale = QLocale::system().name(); QTranslator translator; translator.load("bitcoin_"+locale); app.installTranslator(&translator); app.setQuitOnLastWindowClosed(false); try { if(AppInit2(argc, argv)) { { // Put this in a block, so that BitcoinGUI is cleaned up properly before // calling shutdown. BitcoinGUI window; ClientModel clientModel(pwalletMain); WalletModel walletModel(pwalletMain); guiref = &window; window.setClientModel(&clientModel); window.setWalletModel(&walletModel); window.show(); app.exec(); guiref = 0; } Shutdown(NULL); } else { return 1; } } catch (std::exception& e) { PrintException(&e, "Runaway exception"); } catch (...) { PrintException(NULL, "Runaway exception"); } return 0; }
int ProfilerHandler::Callback(cell index, cell *result, cell *params) { if (state_ == PROFILER_STARTED) { try { return profiler_.CallbackHook(index, result, params, prev_callback_); } catch (const std::exception &e) { PrintException(e); } } return prev_callback_(amx(), index, result, params); }
int main(int argc, char **argv) try { plan_tests(102); TestOpenAir(); TestTNP(); return exit_status(); } catch (const std::runtime_error &e) { PrintException(e); return EXIT_FAILURE; }
int main(int argc, char **argv) try { plan_tests(30); TestReader(); TestWriter(); return exit_status(); } catch (const std::runtime_error &e) { PrintException(e); return EXIT_FAILURE; }
/* Main function that builds and runs the application */ int main(void){ AsteroidGame::AsteroidGame application; try { application.Init(); application.MainLoop(); } catch (std::exception &e){ PrintException(e); } return 0; }
int ProfilerHandler::Debug() { if (state_ == PROFILER_STARTED) { try { return profiler_.DebugHook(prev_debug_); } catch (const std::exception &e) { PrintException(e); } } if (prev_debug_ != 0) { return prev_debug_(amx()); } return AMX_ERR_NONE; }
bool Test() { if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") ) { printf("%s: Skipped due to AS_MAX_PORTABILITY\n", TESTNAME); return false; } bool fail = false; int r; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); COutStream out; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); RegisterStdString(engine); engine->RegisterGlobalFunction("void Assert(bool)", asFUNCTION(Assert), asCALL_GENERIC); engine->RegisterObjectType("Dict", sizeof(CDict), asOBJ_VALUE | asOBJ_APP_CLASS_CDA); engine->RegisterObjectBehaviour("Dict", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Construct), asCALL_CDECL_OBJLAST); engine->RegisterObjectBehaviour("Dict", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destruct), asCALL_CDECL_OBJLAST); engine->RegisterObjectMethod("Dict", "Dict &opAssign(const Dict &in)", asMETHOD(CDict,operator=), asCALL_THISCALL); engine->RegisterObjectMethod("Dict", "Dict &opIndex(string)", asMETHOD(CDict, operator[]), asCALL_THISCALL); asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0); r = mod->Build(); if( r < 0 ) { TEST_FAILED; printf("%s: Failed to compile the script\n", TESTNAME); } asIScriptContext *ctx = engine->CreateContext(); r = ExecuteString(engine, "TestDict()", mod, ctx); if( r != asEXECUTION_FINISHED ) { if( r == asEXECUTION_EXCEPTION ) PrintException(ctx); printf("%s: Failed to execute script\n", TESTNAME); TEST_FAILED; } if( ctx ) ctx->Release(); engine->Release(); // Success return fail; }
HRESULT WScriptJsrt::CallbackMessage::CallFunction(LPCSTR fileName) { HRESULT hr = S_OK; JsValueRef global; JsValueRef result; JsValueRef stringValue; JsValueType type; JsErrorCode errorCode = JsNoError; IfJsrtErrorHR(ChakraRTInterface::JsGetGlobalObject(&global)); IfJsrtErrorHR(ChakraRTInterface::JsGetValueType(m_function, &type)); if (type == JsString) { AutoString script; size_t length = 0; IfJsrtErrorHR(ChakraRTInterface::JsConvertValueToString(m_function, &stringValue)); IfJsrtErrorHR(ChakraRTInterface::JsStringToPointerUtf8Copy(stringValue, &script, &length)); // Run the code #if ENABLE_TTD errorCode = ChakraRTInterface::JsTTDRunScript(this->GetId(), *script, JS_SOURCE_CONTEXT_NONE, "" /*sourceUrl*/, nullptr /*no result needed*/); #else errorCode = ChakraRTInterface::JsRunScriptUtf8(*script, JS_SOURCE_CONTEXT_NONE, "" /*sourceUrl*/, nullptr /*no result needed*/); #endif } else { #if ENABLE_TTD errorCode = ChakraRTInterface::JsTTDCallFunction(this->GetId(), m_function, &global, 1, &result); #else errorCode = ChakraRTInterface::JsCallFunction(m_function, &global, 1, &result); #endif } if (errorCode != JsNoError) { hr = E_FAIL; PrintException(fileName, errorCode); } Error: return hr; }
int main(int argc, char **argv) try { Args args(argc, argv, "PORT BAUD"); DebugPort debug_port(args); args.ExpectEnd(); ScopeGlobalAsioThread global_asio_thread; NullDataHandler handler; auto port = debug_port.Open(*asio_thread, handler); ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } char buffer[4096]; while (true) { switch (port->WaitRead(env, std::chrono::minutes(1))) { case Port::WaitResult::READY: break; case Port::WaitResult::TIMEOUT: continue; case Port::WaitResult::FAILED: return EXIT_FAILURE; case Port::WaitResult::CANCELLED: return EXIT_SUCCESS; } int nbytes = port->Read(buffer, sizeof(buffer)); if (nbytes < 0) break; fwrite((const void *)buffer, 1, nbytes, stdout); } return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "FILE.igc"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); GRecord g; g.Initialize(); g.VerifyGRecordInFile(path); fprintf(stderr, "G record is ok\n"); return EXIT_SUCCESS; } catch (const std::runtime_error &e) { PrintException(e); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "PATH"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); FileLineReaderA file(path); FlightParser parser(file); FlightInfo flight; while (parser.Read(flight)) Print(flight); return EXIT_SUCCESS; } catch (const std::runtime_error &e) { PrintException(e); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "FILE.lua"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); Lua::StatePtr state(Lua::NewBasicState()); Lua::InitLog(state.get()); lua_register(state.get(), "alert", l_alert); Lua::RunFile(state.get(), path); return EXIT_SUCCESS; } catch (const std::runtime_error &e) { PrintException(e); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "FILE"); const auto path = args.ExpectNextPath(); args.ExpectEnd(); FileReader file(path); GunzipReader gunzip(file); BufferedReader reader(gunzip); char *line; while ((line = reader.ReadLine()) != nullptr) puts(line); return EXIT_SUCCESS; } catch (const std::runtime_error &e) { PrintException(e); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "PORT BAUD [NAME=VALUE] [NAME] ..."); DebugPort debug_port(args); ScopeGlobalAsioThread global_asio_thread; NullDataHandler handler; auto port = debug_port.Open(*asio_thread, handler); ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } VegaDevice device(*port); while (!args.IsEmpty()) { const char *p = args.GetNext(); char *q = strdup(p); char *v = strchr(q, '='); if (v == NULL) { if (!device.RequestSetting(q, env)) printf("Error\n"); } else { *v++ = 0; if (!device.SendSetting(q, atoi(v), env)) printf("Error\n"); } free(q); } return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "DRIVER PORT BAUD"); tstring _driver_name = args.ExpectNextT(); const TCHAR *driver_name = _driver_name.c_str(); DebugPort debug_port(args); args.ExpectEnd(); ScopeGlobalAsioThread global_asio_thread; auto port = debug_port.Open(*asio_thread, *(DataHandler *)nullptr); const struct DeviceRegister *driver = FindDriverByName(driver_name); if (driver == NULL) { _ftprintf(stderr, _T("No such driver: %s\n"), driver_name); return EXIT_FAILURE; } ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } assert(driver->CreateOnPort != NULL); Device *device = driver->CreateOnPort(debug_port.GetConfig(), *port); assert(device != NULL); device->EnableNMEA(env); delete device; return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
int main(int argc, char **argv) try { const char *const usage = "PORT BAUD COMMAND\n\n" "Where COMMAND is one of:" "\n\tinfo" "\n\treboot" "\n\tpoweroff" "\n\tstartlogger" "\n\tstoplogger" "\n\tpilots" "\n\tnavpoints" ; Args args(argc, argv, usage); DebugPort debug_port(args); const char *command = args.ExpectNext(); args.ExpectEnd(); ScopeGlobalAsioThread global_asio_thread; auto port = debug_port.Open(*asio_thread, *(DataHandler *)nullptr); ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } CAI302Device device(debug_port.GetConfig(), *port); if (!RunCommand(device, command, env)) { fprintf(stderr, "error\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
bool TestInt64() { bool fail = false; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); engine->RegisterObjectType("Int64", 8, asOBJ_VALUE | asOBJ_POD | asOBJ_APP_PRIMITIVE); engine->RegisterGlobalFunction("void cfunction()", asFUNCTION(cfunction), asCALL_GENERIC); COutStream out; engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection("test", script); mod->Build(); int f = engine->GetModule(0)->GetFunctionIdByDecl("int Main()"); asIScriptContext *ctx = engine->CreateContext(); ctx->Prepare(f); int r = ctx->Execute(); if( r != asEXECUTION_FINISHED ) { printf("\n%s: The execution didn't finish correctly (code %d)\n", TESTNAME, r); TEST_FAILED; if( r == asEXECUTION_EXCEPTION ) PrintException(ctx); } if( called != 3 ) { printf("\n%s: cfunction called %d times. Expected 3 times\n", TESTNAME, called); TEST_FAILED; } ctx->Release(); engine->Release(); return fail; }
HRESULT WScriptJsrt::CallbackMessage::Call(LPCWSTR fileName) { HRESULT hr = S_OK; JsValueRef global; JsValueRef result; JsValueRef stringValue; JsValueType type; JsErrorCode errorCode = JsNoError; IfJsrtErrorHR(ChakraRTInterface::JsGetGlobalObject(&global)); IfJsrtErrorHR(ChakraRTInterface::JsGetValueType(m_function, &type)); if (type == JsString) { LPCWSTR script = nullptr; size_t length = 0; IfJsrtErrorHR(ChakraRTInterface::JsConvertValueToString(m_function, &stringValue)); IfJsrtErrorHR(ChakraRTInterface::JsStringToPointer(stringValue, &script, &length)); // Run the code errorCode = ChakraRTInterface::JsRunScript(script, JS_SOURCE_CONTEXT_NONE, L"" /*sourceUrl*/, nullptr /*no result needed*/); } else { errorCode = ChakraRTInterface::JsCallFunction(m_function, &global, 1, &result); } if (errorCode != JsNoError) { hr = E_FAIL; PrintException(fileName, errorCode); } Error: return hr; }
bool TestInt64() { bool ret = false; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); engine->RegisterObjectType("int64", 8, 0); engine->RegisterGlobalFunction("void cfunction()", asFUNCTION(cfunction), asCALL_CDECL); COutStream out; engine->AddScriptSection(0, "test", script, strlen(script), 0); engine->SetCommonMessageStream(&out); engine->Build(0); int f = engine->GetFunctionIDByDecl(0, "int Main()"); asIScriptContext *ctx = engine->CreateContext(); ctx->Prepare(f); int r = ctx->Execute(); if( r != asEXECUTION_FINISHED ) { printf("\n%s: The execution didn't finish correctly (code %d)\n", TESTNAME, r); ret = true; if( r == asEXECUTION_EXCEPTION ) PrintException(ctx); } if( called != 3 ) { printf("\n%s: cfunction called %d times. Expected 3 times\n", TESTNAME, called); ret = true; } ctx->Release(); engine->Release(); return ret; }
////////////////////////////////////////////////////////////////////////////// // // Start // bool AppInit(int argc, char* argv[]) { boost::thread_group threadGroup; bool fRet = false; try { // // Parameters // // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main() ParseParameters(argc, argv); if (!boost::filesystem::is_directory(GetDataDir(false))) { fprintf(stderr, "Error: Specified directory does not exist\n"); Shutdown(); } ReadConfigFile(mapArgs, mapMultiArgs); if (mapArgs.count("-?") || mapArgs.count("--help")) { // First part of help message is specific to bitcoind / RPC client std::string strUsage = _("FlappyCoin version") + " " + FormatFullVersion() + "\n\n" + _("Usage:") + "\n" + " FlappyCoind [options] " + "\n" + " FlappyCoind [options] <command> [params] " + _("Send command to -server or FlappyCoind") + "\n" + " FlappyCoind [options] help " + _("List commands") + "\n" + " FlappyCoind [options] help <command> " + _("Get help for a command") + "\n"; strUsage += "\n" + HelpMessage(); fprintf(stdout, "%s", strUsage.c_str()); return false; } // Command-line RPC for (int i = 1; i < argc; i++) if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "FlappyCoin:")) fCommandLine = true; if (fCommandLine) { if (!SelectParamsFromCommandLine()) { fprintf(stderr, "Error: invalid combination of -regtest and -testnet.\n"); return false; } int ret = CommandLineRPC(argc, argv); exit(ret); } #if !defined(WIN32) fDaemon = GetBoolArg("-daemon", false); if (fDaemon) { // Daemonize pid_t pid = fork(); if (pid < 0) { fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno); return false; } if (pid > 0) // Parent process, pid is child process id { CreatePidFile(GetPidFile(), pid); return true; } // Child process falls through to rest of initialization pid_t sid = setsid(); if (sid < 0) fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno); } #endif fRet = AppInit2(threadGroup); } catch (std::exception& e) { PrintException(&e, "AppInit()"); } catch (...) { PrintException(NULL, "AppInit()"); } if (!fRet) { threadGroup.interrupt_all(); // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of // the startup-failure cases to make sure they don't result in a hang due to some // thread-blocking-waiting-for-another-thread-during-startup case } else { WaitForShutdown(&threadGroup); } Shutdown(); return fRet; }
bool Test() { bool fail = Test2(); int r; COutStream out; asIScriptContext *ctx; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); RegisterScriptString_Generic(engine); engine->RegisterGlobalFunction("void Assert(bool)", asFUNCTION(Assert), asCALL_GENERIC); asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0); r = mod->Build(); if( r < 0 ) { fail = true; printf("%s: Failed to compile the script\n", TESTNAME); } r = engine->ExecuteString(0, "TestArray()", &ctx); if( r != asEXECUTION_FINISHED ) { if( r == asEXECUTION_EXCEPTION ) PrintException(ctx); printf("%s: Failed to execute script\n", TESTNAME); fail = true; } if( ctx ) ctx->Release(); mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script2, strlen(script2), 0); r = mod->Build(); if( r < 0 ) { fail = true; printf("%s: Failed to compile the script\n", TESTNAME); } r = engine->ExecuteString(0, "TestArrayException()"); if( r != asEXECUTION_EXCEPTION ) { printf("%s: No exception\n", TESTNAME); fail = true; } mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script3, strlen(script3), 0); r = mod->Build(); if( r < 0 ) { fail = true; printf("%s: Failed to compile the script\n", TESTNAME); } r = engine->ExecuteString(0, "TestArrayMulti()", &ctx); if( r != asEXECUTION_FINISHED ) { printf("%s: Failure\n", TESTNAME); fail = true; } if( r == asEXECUTION_EXCEPTION ) { PrintException(ctx); } if( ctx ) ctx->Release(); ctx = 0; mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script4, strlen(script4), 0); r = mod->Build(); if( r < 0 ) { fail = true; printf("%s: Failed to compile the script\n", TESTNAME); } r = engine->ExecuteString(0, "TestArrayChar()", &ctx); if( r != asEXECUTION_FINISHED ) { printf("%s: Failure\n", TESTNAME); fail = true; } if( r == asEXECUTION_EXCEPTION ) { PrintException(ctx); } if( ctx ) ctx->Release(); mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script5, strlen(script5), 0); r = mod->Build(); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "TestArrayInitList()", &ctx); if( r != asEXECUTION_FINISHED ) fail = true; if( r == asEXECUTION_EXCEPTION ) PrintException(ctx); if( ctx ) ctx->Release(); CBufferedOutStream bout; engine->SetMessageCallback(asMETHOD(CBufferedOutStream,Callback), &bout, asCALL_THISCALL); mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script6, strlen(script6), 0); r = mod->Build(); if( r >= 0 ) fail = true; if( bout.buffer != "TestArray (1, 1) : Info : Compiling void Test()\n" "TestArray (3, 15) : Error : Initialization lists cannot be used with 'int[]@'\n" "TestArray (4, 16) : Error : Initialization lists cannot be used with 'int'\n" ) fail = true; // Array object must call default constructor of the script classes engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script7, strlen(script7), 0); r = mod->Build(); if( r < 0 ) fail = true; r = engine->ExecuteString(0, "Test()"); if( r != asEXECUTION_FINISHED ) fail = true; // Test bool[] on Mac OS X with PPC CPU // Submitted by Edward Rudd const char *script8 = "bool[] f(10); \n" "for (int i=0; i<10; i++) { \n" " f[i] = false; \n" "} \n" "Assert(f[0] == false); \n" "Assert(f[1] == false); \n" "f[0] = true; \n" "Assert(f[0] == true); \n" "Assert(f[1] == false); \n"; r = engine->ExecuteString(0, script8); if( r != asEXECUTION_FINISHED ) fail = true; // Make sure it is possible to do multiple assignments with the array type r = engine->ExecuteString(0, "int[] a, b, c; a = b = c;"); if( r < 0 ) fail = true; engine->Release(); // Success return fail; }
bool Test() { if( strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY") ) { printf("%s: Skipped due to AS_MAX_PORTABILITY\n", TESTNAME); return false; } bool fail = false; int r; COutStream out; asIScriptEngine *engine; asIScriptModule *mod; asIScriptContext *ctx; engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); RegisterScriptString(engine); r = engine->RegisterObjectType("refclass", sizeof(CRefClass), asOBJ_REF); assert(r >= 0); r = engine->RegisterObjectBehaviour("refclass", asBEHAVE_FACTORY, "refclass@ f()", asFUNCTION(Factory), asCALL_CDECL); assert(r >= 0); r = engine->RegisterObjectBehaviour("refclass", asBEHAVE_ADDREF, "void f()", asMETHOD(CRefClass, AddRef), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectBehaviour("refclass", asBEHAVE_RELEASE, "void f()", asMETHOD(CRefClass, Release), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("refclass", "refclass &opAssign(refclass &in)", asMETHOD(CRefClass, operator=), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("refclass", "refclass &Do()", asMETHOD(CRefClass,Do), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("refclass", "refclass &opAdd(refclass &in)", asFUNCTION(CRefClass::Add), asCALL_CDECL_OBJFIRST); assert(r >= 0); r = engine->RegisterGlobalFunction("void Assert(bool)", asFUNCTION(Assert), asCALL_GENERIC); assert( r >= 0 ); mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script1, strlen(script1), 0); engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); r = mod->Build(); if( r < 0 ) { TEST_FAILED; printf("%s: Failed to compile the script\n", TESTNAME); } ctx = engine->CreateContext(); r = ExecuteString(engine, "TestObjHandle()", mod, ctx); if( r != asEXECUTION_FINISHED ) { if( r == asEXECUTION_EXCEPTION ) PrintException(ctx); TEST_FAILED; printf("%s: Execution failed\n", TESTNAME); } if( ctx ) ctx->Release(); // Call TestObjReturnHandle() from the application to verify that references are updated as necessary ctx = engine->CreateContext(); ctx->Prepare(engine->GetModule(0)->GetFunctionIdByDecl("refclass@ TestObjReturnHandle(refclass@)")); CRefClass *refclass = new CRefClass(); ctx->SetArgObject(0, refclass); r = ctx->Execute(); if( r != asEXECUTION_FINISHED ) { if( r == asEXECUTION_EXCEPTION ) PrintException(ctx); TEST_FAILED; printf("%s: Execution failed\n", TESTNAME); } if( refclass->refCount != 2 ) { TEST_FAILED; printf("%s: Ref count is wrong\n", TESTNAME); } refclass->Release(); if( ctx ) ctx->Release(); // Test returning a reference to the object from an object method r = engine->GarbageCollect(); asUINT gcCurrentSize; engine->GetGCStatistics(&gcCurrentSize, 0, 0); assert( gcCurrentSize == 10 ); // The script class types and functions are also in the gc r = ExecuteString(engine, "refclass ref; ref.Do()"); if( r != asEXECUTION_FINISHED ) { TEST_FAILED; } engine->Release(); //-------------------- engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL); RegisterScriptArray(engine, true); r = engine->RegisterGlobalFunction("void Assert(bool)", asFUNCTION(Assert), asCALL_GENERIC); assert( r >= 0 ); mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection(TESTNAME, script5, strlen(script5), 0); r = mod->Build(); if( r < 0 ) TEST_FAILED; r = ExecuteString(engine, "Test()", mod); if( r != asEXECUTION_FINISHED ) TEST_FAILED; engine->Release(); //---------------------- // It should be allowed to have a global function return a handle to a const object engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL); const char *scriptC = "class T {} const T@ func() {return T();}"; mod = engine->GetModule(0, asGM_ALWAYS_CREATE); mod->AddScriptSection("script", scriptC, strlen(scriptC)); r = mod->Build(); if( r < 0 ) TEST_FAILED; engine->Release(); //--------------------- // These tests are designed to make sure ambiguities with handles is avoided CBufferedOutStream bout; engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL); r = engine->RegisterObjectType("A", sizeof(CRefClass), asOBJ_REF); assert(r >= 0); r = engine->RegisterObjectBehaviour("A", asBEHAVE_FACTORY, "A@ f()", asFUNCTION(Factory), asCALL_CDECL); assert(r >= 0); r = engine->RegisterObjectBehaviour("A", asBEHAVE_ADDREF, "void f()", asMETHOD(CRefClass, AddRef), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectBehaviour("A", asBEHAVE_RELEASE, "void f()", asMETHOD(CRefClass, Release), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("A", "A &opAssign(const A &in)", asMETHOD(CRefClass, operator=), asCALL_THISCALL); assert(r >= 0); bout.buffer = ""; r = ExecuteString(engine, "A a; a == null;"); // Should give warning if( r < 0 || bout.buffer == "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; null == a;"); // Should give warning if( r < 0 || bout.buffer == "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; @a == null;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; null == @a;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; @a == a;"); // Should give warning if( r < 0 || bout.buffer == "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; a == @a;"); // Should give warning if( r < 0 || bout.buffer == "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; @a == @a;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A @a = null;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; A @b = a;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; A @b = @a;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; A b = @b;"); // Should give error if( r >= 0 || bout.buffer == "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A @a, b; @a = @b;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A @a, b; @a = b;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A @a, b; a = @b;"); // Should give error if( r >= 0 || bout.buffer == "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; null is a;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } bout.buffer = ""; r = ExecuteString(engine, "A a; a !is null;"); // OK if( r < 0 || bout.buffer != "" ) { TEST_FAILED; } engine->Release(); // Success return fail; }