OSC stubs
This commit is contained in:
81
tests/OscControlServerTests.cpp
Normal file
81
tests/OscControlServerTests.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "osc/OscControlServer.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
int gFailures = 0;
|
||||
|
||||
void Expect(bool condition, const std::string& message)
|
||||
{
|
||||
if (condition)
|
||||
return;
|
||||
|
||||
++gFailures;
|
||||
std::cerr << "FAILED: " << message << "\n";
|
||||
}
|
||||
|
||||
void ExpectEquals(const std::string& actual, const std::string& expected, const std::string& message)
|
||||
{
|
||||
if (actual == expected)
|
||||
return;
|
||||
|
||||
++gFailures;
|
||||
std::cerr << "FAILED: " << message << "\n"
|
||||
<< "expected: " << expected << "\n"
|
||||
<< "actual: " << actual << "\n";
|
||||
}
|
||||
|
||||
void TestDisabledWhenPortIsZero()
|
||||
{
|
||||
using namespace RenderCadenceCompositor;
|
||||
|
||||
OscControlServer server;
|
||||
OscControlServerConfig config;
|
||||
config.bindAddress = "127.0.0.1";
|
||||
config.port = 0;
|
||||
config.smoothing = 0.25;
|
||||
|
||||
std::string error;
|
||||
Expect(server.Start(config, error), "disabled OSC stub starts successfully");
|
||||
Expect(error.empty(), "disabled OSC stub does not report an error");
|
||||
Expect(!server.IsConfigured(), "port zero leaves OSC unconfigured");
|
||||
Expect(!server.IsListening(), "port zero does not listen");
|
||||
ExpectEquals(server.State().statusMessage, "OSC ingress disabled by config.", "disabled status is explicit");
|
||||
}
|
||||
|
||||
void TestConfiguredStubDoesNotListenYet()
|
||||
{
|
||||
using namespace RenderCadenceCompositor;
|
||||
|
||||
OscControlServer server;
|
||||
OscControlServerConfig config;
|
||||
config.bindAddress = "0.0.0.0";
|
||||
config.port = 9000;
|
||||
config.smoothing = 0.18;
|
||||
|
||||
std::string error;
|
||||
Expect(server.Start(config, error), "configured OSC stub starts successfully");
|
||||
Expect(error.empty(), "configured OSC stub does not report an error");
|
||||
Expect(server.IsConfigured(), "nonzero port marks OSC as configured");
|
||||
Expect(!server.IsListening(), "stub does not claim to listen before UDP ingress exists");
|
||||
ExpectEquals(server.State().bindAddress, "0.0.0.0", "bind address is retained");
|
||||
Expect(server.State().statusMessage.find("UDP listener is not implemented yet") != std::string::npos, "status reports stub state");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
TestDisabledWhenPortIsZero();
|
||||
TestConfiguredStubDoesNotListenYet();
|
||||
|
||||
if (gFailures != 0)
|
||||
{
|
||||
std::cerr << gFailures << " OscControlServer test failure(s).\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "OscControlServer tests passed.\n";
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user