Skip to content

Commit bd0b8a0

Browse files
committed
Add DM Tests [NugetDeploy]
1 parent 0a3ee8a commit bd0b8a0

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,10 @@ paket-files/
258258

259259
# Python Tools for Visual Studio (PTVS)
260260
__pycache__/
261-
*.pyc
261+
*.pyc
262+
263+
# DM artifacts
264+
265+
*.dmb
266+
*.int
267+
*.lk

Byond.TopicSender.Tests/IntegrationTests.cs

+39
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,45 @@ public async Task TestGoonstation()
1919
}, logger);
2020

2121
var response = await topicSender.SendTopic("goon2.goonhub.com", "?status", 26200);
22+
Assert.IsNotNull(response);
23+
}
24+
25+
[TestMethod]
26+
public async Task TestEnvironmentString()
27+
{
28+
using var loggerFactory = LoggerFactory.Create(builder => builder.AddDebug());
29+
var logger = loggerFactory.CreateLogger<TopicClient>();
30+
var topicSender = new TopicClient(new SocketParameters
31+
{
32+
SendTimeout = 10000,
33+
ReceiveTimeout = 10000
34+
}, logger);
35+
36+
var data = "expecting_this=response";
37+
var response = await topicSender.SendTopic("localhost", $"?{data}", 61612);
38+
Assert.IsNotNull(response);
39+
Assert.IsFalse(response.FloatData.HasValue);
40+
Assert.IsNotNull(response.StringData);
41+
Assert.AreEqual($"Received: {data}", response.StringData);
42+
}
43+
44+
[TestMethod]
45+
public async Task TestEnvironmentFloat()
46+
{
47+
using var loggerFactory = LoggerFactory.Create(builder => builder.AddDebug());
48+
var logger = loggerFactory.CreateLogger<TopicClient>();
49+
var topicSender = new TopicClient(new SocketParameters
50+
{
51+
SendTimeout = 10000,
52+
ReceiveTimeout = 10000
53+
}, logger);
54+
55+
var data = "return_float=1";
56+
var response = await topicSender.SendTopic("localhost", $"?{data}", 61612);
57+
Assert.IsNotNull(response);
58+
Assert.IsNull(response.StringData);
59+
Assert.IsTrue(response.FloatData.HasValue);
60+
Assert.AreEqual(3.14f, response.FloatData.Value);
2261
}
2362
}
2463
}

Byond.TopicSender/TopicResponse.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ public TopicResponse(byte[] rawData)
6060
var floatBytes = new byte[4];
6161

6262
var lilEndy = BitConverter.IsLittleEndian;
63-
floatBytes[lilEndy ? 3 : 0] = rawData[5];
64-
floatBytes[lilEndy ? 2 : 1] = rawData[6];
65-
floatBytes[lilEndy ? 1 : 2] = rawData[7];
66-
floatBytes[lilEndy ? 0 : 3] = rawData[8];
63+
floatBytes[lilEndy ? 0 : 3] = rawData[5];
64+
floatBytes[lilEndy ? 1 : 2] = rawData[6];
65+
floatBytes[lilEndy ? 2 : 1] = rawData[7];
66+
floatBytes[lilEndy ? 3 : 0] = rawData[8];
6767

6868
FloatData = BitConverter.ToSingle(floatBytes);
6969

TestEnvironment/DMTest.dm

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/world/Topic(T)
2+
var/log_message = "Received: [T]"
3+
world.log << log_message
4+
5+
var/list/as_params = params2list(T)
6+
if(as_params["return_float"])
7+
return 3.14
8+
9+
return log_message

TestEnvironment/DMTest.dme

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// DM Environment file for DMTest.dme.
2+
// All manual changes should be made outside the BEGIN_ and END_ blocks.
3+
// New source code should be placed in .dm files: choose File/New --> Code File.
4+
5+
// BEGIN_INTERNALS
6+
// END_INTERNALS
7+
8+
// BEGIN_FILE_DIR
9+
#define FILE_DIR .
10+
// END_FILE_DIR
11+
12+
// BEGIN_PREFERENCES
13+
// END_PREFERENCES
14+
15+
// BEGIN_INCLUDE
16+
#include "DMTest.dm"
17+
// END_INCLUDE
18+

0 commit comments

Comments
 (0)