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

Function Test

sdk/tests/test_feature/source/test_functionptr.cpp:77–2960  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77bool 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"(
98funcdef void func_callback();
99void 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"(
128funcdef bool test_function_f(int);
129
130void test()
131{
132 any st_any;
133 st_any.store(cast<test_function_f>(function(v) { return false; }));
134

Callers

nothing calls this directly

Calls 15

RegisterScriptAnyFunction · 0.85
ExecuteStringFunction · 0.85
GetExceptionInfoFunction · 0.85
RegisterStdStringFunction · 0.85
RegisterScriptArrayFunction · 0.85
RegisterScriptDictionaryFunction · 0.85
WriteConfigToStreamFunction · 0.85
ConfigEngineFromStreamFunction · 0.85
SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
ShutDownAndReleaseMethod · 0.80

Tested by

no test coverage detected