| 75 | } |
| 76 | |
| 77 | bool Test() |
| 78 | { |
| 79 | RET_ON_MAX_PORT |
| 80 | |
| 81 | bool fail = false; |
| 82 | int r; |
| 83 | COutStream out; |
| 84 | asIScriptEngine *engine; |
| 85 | asIScriptModule *mod; |
| 86 | asIScriptContext *ctx; |
| 87 | CBufferedOutStream bout; |
| 88 | |
| 89 | // Test declaring a function to take funcdef by value must give error |
| 90 | // Reported by Sam Tupy |
| 91 | { |
| 92 | engine = asCreateScriptEngine(); |
| 93 | engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL); |
| 94 | bout.buffer = ""; |
| 95 | |
| 96 | mod = engine->GetModule("test", asGM_ALWAYS_CREATE); |
| 97 | mod->AddScriptSection("test", R"( |
| 98 | funcdef void func_callback(); |
| 99 | void set_callback(func_callback cb) { } |
| 100 | )"); |
| 101 | r = mod->Build(); |
| 102 | if (r >= 0) |
| 103 | TEST_FAILED; |
| 104 | |
| 105 | engine->ShutDownAndRelease(); |
| 106 | |
| 107 | if (bout.buffer != "test (3, 1) : Info : Compiling void set_callback(func_callback)\n" |
| 108 | "test (3, 1) : Error : Parameter type can't be 'func_callback', because the type cannot be instantiated.\n") |
| 109 | { |
| 110 | PRINTF("%s", bout.buffer.c_str()); |
| 111 | TEST_FAILED; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // Test cast from non-handle (should implicitly add the handle) |
| 116 | // Reported by Paril |
| 117 | { |
| 118 | engine = asCreateScriptEngine(); |
| 119 | engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL); |
| 120 | bout.buffer = ""; |
| 121 | |
| 122 | RegisterScriptAny(engine); |
| 123 | |
| 124 | engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC); |
| 125 | |
| 126 | mod = engine->GetModule("test", asGM_ALWAYS_CREATE); |
| 127 | mod->AddScriptSection("test", R"( |
| 128 | funcdef bool test_function_f(int); |
| 129 | |
| 130 | void test() |
| 131 | { |
| 132 | any st_any; |
| 133 | st_any.store(cast<test_function_f>(function(v) { return false; })); |
| 134 |
nothing calls this directly
no test coverage detected