#include #include #include #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 argv(7); argv[0] = reinterpret_cast(const_cast("objectname")); argv[1] = reinterpret_cast(const_cast("attribute")); argv[2] = reinterpret_cast(&int32); argv[3] = reinterpret_cast(&int64); argv[4] = reinterpret_cast(&float32); argv[5] = reinterpret_cast(&float64); argv[6] = reinterpret_cast(string); REQUIRE(types.size() == argv.size()); int result = oscController.setObjectCallback(path.c_str(), types.c_str(), argv.data(), types.size(), nullptr, &oscController); REQUIRE(result == 0); } /*************/ TEST_CASE("OSCController: setObjectsOfTypeCallback") { RootObject root; TestOSCController oscController(&root); std::string path = "/set_objects_of_type"; std::string types = "ssihfds"; std::vector argv(7); argv[0] = reinterpret_cast(const_cast("type")); argv[1] = reinterpret_cast(const_cast("attribute")); argv[2] = reinterpret_cast(&int32); argv[3] = reinterpret_cast(&int64); argv[4] = reinterpret_cast(&float32); argv[5] = reinterpret_cast(&float64); argv[6] = reinterpret_cast(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 argv(6); argv[0] = reinterpret_cast(const_cast("attribute")); argv[1] = reinterpret_cast(&int32); argv[2] = reinterpret_cast(&int64); argv[3] = reinterpret_cast(&float32); argv[4] = reinterpret_cast(&float64); argv[5] = reinterpret_cast(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 argv(5); argv[0] = reinterpret_cast(&int32); argv[1] = reinterpret_cast(&int64); argv[2] = reinterpret_cast(&float32); argv[3] = reinterpret_cast(&float64); argv[4] = reinterpret_cast(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()); }