mirror of
https://gitlab.com/splashmapper/splash.git
synced 2026-02-12 23:10:49 +01:00
122 lines
3.8 KiB
C++
122 lines
3.8 KiB
C++
#include <string>
|
|
#include <vector>
|
|
|
|
#include <doctest.h>
|
|
|
|
#include "controller/controller_osc.h"
|
|
#include "core/root_object.h"
|
|
|
|
using namespace Splash;
|
|
|
|
int32_t int32 = 42;
|
|
int64_t int64 = 4242;
|
|
float float32 = 3.14159f;
|
|
double float64 = 3.14159;
|
|
char string[] = "param";
|
|
|
|
/*************/
|
|
class TestOSCController : public OSCController
|
|
{
|
|
public:
|
|
explicit TestOSCController(RootObject* root)
|
|
: OSCController(root)
|
|
{
|
|
}
|
|
using OSCController::setObjectCallback;
|
|
using OSCController::setObjectsOfTypeCallback;
|
|
using OSCController::setWorldCallback;
|
|
using OSCController::argsToValues;
|
|
};
|
|
|
|
/*************/
|
|
TEST_CASE("OSCController: setObjectCallback")
|
|
{
|
|
RootObject root;
|
|
TestOSCController oscController(&root);
|
|
|
|
std::string path = "/set_object";
|
|
std::string types = "ssihfds";
|
|
std::vector<lo_arg*> argv(7);
|
|
argv[0] = reinterpret_cast<lo_arg*>(const_cast<char*>("objectname"));
|
|
argv[1] = reinterpret_cast<lo_arg*>(const_cast<char*>("attribute"));
|
|
argv[2] = reinterpret_cast<lo_arg*>(&int32);
|
|
argv[3] = reinterpret_cast<lo_arg*>(&int64);
|
|
argv[4] = reinterpret_cast<lo_arg*>(&float32);
|
|
argv[5] = reinterpret_cast<lo_arg*>(&float64);
|
|
argv[6] = reinterpret_cast<lo_arg*>(string);
|
|
REQUIRE(types.size() == argv.size());
|
|
|
|
int result = oscController.setObjectCallback(path.c_str(), types.c_str(), argv.data(), types.size(), nullptr, &oscController);
|
|
REQUIRE(result == 1);
|
|
}
|
|
|
|
/*************/
|
|
TEST_CASE("OSCController: setObjectsOfTypeCallback")
|
|
{
|
|
RootObject root;
|
|
TestOSCController oscController(&root);
|
|
|
|
std::string path = "/set_objects_of_type";
|
|
std::string types = "ssihfds";
|
|
std::vector<lo_arg*> argv(7);
|
|
argv[0] = reinterpret_cast<lo_arg*>(const_cast<char*>("type"));
|
|
argv[1] = reinterpret_cast<lo_arg*>(const_cast<char*>("attribute"));
|
|
argv[2] = reinterpret_cast<lo_arg*>(&int32);
|
|
argv[3] = reinterpret_cast<lo_arg*>(&int64);
|
|
argv[4] = reinterpret_cast<lo_arg*>(&float32);
|
|
argv[5] = reinterpret_cast<lo_arg*>(&float64);
|
|
argv[6] = reinterpret_cast<lo_arg*>(string);
|
|
REQUIRE(types.size() == argv.size());
|
|
|
|
int result = oscController.setObjectsOfTypeCallback(path.c_str(), types.c_str(), argv.data(), types.size(), nullptr, &oscController);
|
|
REQUIRE(result == 0);
|
|
}
|
|
|
|
/*************/
|
|
TEST_CASE("OSCController: setWorldCallback")
|
|
{
|
|
RootObject root;
|
|
TestOSCController oscController(&root);
|
|
|
|
std::string path = "/set_world";
|
|
std::string types = "sihfds";
|
|
std::vector<lo_arg*> argv(6);
|
|
argv[0] = reinterpret_cast<lo_arg*>(const_cast<char*>("attribute"));
|
|
argv[1] = reinterpret_cast<lo_arg*>(&int32);
|
|
argv[2] = reinterpret_cast<lo_arg*>(&int64);
|
|
argv[3] = reinterpret_cast<lo_arg*>(&float32);
|
|
argv[4] = reinterpret_cast<lo_arg*>(&float64);
|
|
argv[5] = reinterpret_cast<lo_arg*>(string);
|
|
REQUIRE(types.size() == argv.size());
|
|
|
|
int result = oscController.setWorldCallback(path.c_str(), types.c_str(), argv.data(), types.size(), nullptr, &oscController);
|
|
REQUIRE(result == 0);
|
|
}
|
|
|
|
/*************/
|
|
TEST_CASE("OSCController: argsToValues")
|
|
{
|
|
std::string types = "ihfds";
|
|
std::vector<lo_arg*> argv(5);
|
|
argv[0] = reinterpret_cast<lo_arg*>(&int32);
|
|
argv[1] = reinterpret_cast<lo_arg*>(&int64);
|
|
argv[2] = reinterpret_cast<lo_arg*>(&float32);
|
|
argv[3] = reinterpret_cast<lo_arg*>(&float64);
|
|
argv[4] = reinterpret_cast<lo_arg*>(string);
|
|
|
|
Values expectedValues;
|
|
expectedValues.push_back(int32);
|
|
expectedValues.push_back(int64);
|
|
expectedValues.push_back(float32);
|
|
expectedValues.push_back(float64);
|
|
expectedValues.push_back(string);
|
|
|
|
TestOSCController oscController(nullptr);
|
|
Values result = oscController.argsToValues(types, argv, 0);
|
|
REQUIRE(result == expectedValues);
|
|
|
|
types = "sddi";
|
|
result = oscController.argsToValues(types, argv, 0);
|
|
REQUIRE(result == Values());
|
|
}
|