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

Function Test

sdk/tests/test_feature/source/test_addon_scriptsocket.cpp:18–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18bool Test()
19{
20 bool fail = false;
21 CBufferedOutStream bout;
22 asIScriptEngine* engine;
23 int r;
24
25 // TODO: Test trying to listen to a port that is already occupied
26 // TODO: Test that it is possible to successfully detect if the remove socket is closed/lost
27
28 // Test setting up a listener socket and then connecting to it to both send and receive
29 {
30 engine = asCreateScriptEngine();
31 engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
32 engine->RegisterGlobalFunction("void assert(bool)", asFUNCTION(Assert), asCALL_GENERIC);
33 bout.buffer = "";
34
35 RegisterScriptArray(engine, false);
36 RegisterStdString(engine);
37 RegisterScriptDictionary(engine);
38
39 CContextMgr ctxMgr;
40 ctxMgr.RegisterCoRoutineSupport(engine);
41
42 RegisterScriptSocket(engine);
43#ifdef AS_MAX_PORTABILITY
44 engine->RegisterGlobalFunction("void print(const string &in)", WRAP_FN(print), asCALL_GENERIC);
45#else
46 engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_CDECL);
47#endif
48
49 bool success = false;
50 engine->RegisterGlobalProperty("bool success", &success);
51
52 asIScriptModule* mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
53 mod->AddScriptSection("test", R"script(
54 void main()
55 {
56 socket a;
57 a.listen(39000); // Start listener socket
58 print("Server: Listening on 39000...\n");
59 createCoRoutine(client, null); // Create the client co-routine
60 bool sent = false;
61 string msg;
62 socket @b;
63 for(;;)
64 {
65 if( b is null )
66 {
67 @b = a.accept();
68 if( b !is null )
69 print("Server: Identified a client\n");
70 }
71 if ( b !is null )
72 {
73 if( !sent )
74 {
75 print("Server: Sending 'hello'\n");

Callers

nothing calls this directly

Calls 15

RegisterScriptArrayFunction · 0.85
RegisterStdStringFunction · 0.85
RegisterScriptDictionaryFunction · 0.85
RegisterScriptSocketFunction · 0.85
SetMessageCallbackMethod · 0.80
AddScriptSectionMethod · 0.80
AddContextMethod · 0.80
GetFunctionByNameMethod · 0.80
ExecuteScriptsMethod · 0.80

Tested by

no test coverage detected