Files
Nonemm/tests/Nonemm.Network.Tests/RadioMirrorTests.cs
T
erikbrockoandClaude Sonnet 5.5 072c04883e Mirror a radio from another computer's broadcast data
Listen for Radio broadcast data from another Nonemm or N1MM computer and
record its frequency, mode and split as this computer's own radio. No
radio is controlled. The settings are in the Configure Radios dialog.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 05:16:27 +00:00

37 lines
1.3 KiB
C#

using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Nonemm.Network.Tests;
public class RadioMirrorTests
{
[Fact]
public async Task A_radio_message_sent_to_the_port_is_raised_and_other_data_is_not()
{
int port = FreePort();
using RadioMirror mirror = new(port);
TaskCompletionSource<RadioBroadcast> received = new();
mirror.Received += (_, message) => received.TrySetResult(message);
using UdpClient sender = new();
IPEndPoint target = new(IPAddress.Loopback, port);
byte[] other = Encoding.UTF8.GetBytes("<spot><dxcall>DL1ABC</dxcall></spot>");
await sender.SendAsync(other, target);
byte[] radio = Encoding.UTF8.GetBytes(BroadcastMessages.Radio(
new RadioReport(1, 7_012_300, 7_012_300, "CW", "OK1ABC", "OK1ABC", false, 1, false, 1, false, "", true),
"RUN-PC"));
await sender.SendAsync(radio, target);
RadioBroadcast message = await received.Task.WaitAsync(TimeSpan.FromSeconds(5));
Assert.Equal("RUN-PC", message.StationName);
Assert.Equal(7_012_300, message.Radio.Frequency);
}
private static int FreePort()
{
using UdpClient probe = new(new IPEndPoint(IPAddress.Loopback, 0));
return ((IPEndPoint)probe.Client.LocalEndPoint!).Port;
}
}