score-back/tests/test_cli.cpp
Artur Mukhamadiev 24b6f9937f feat(cloud_point): add OpenCV integration, stereo matching, and get-available-methods RPC
- Add OpenCV and stdexec dependencies
- ImageRPC type bridging OpenCV and RPC layers
- Stereo rectification boilerplate
- get-available-methods RPC method with get_count/get_method_name_by_id/get_method_names
- Tests for remote method retrieval
- CPU/GPU stereo matcher interfaces with SGBM implementation
- Documentation consistency pass across impl and docs

TG-5 #ready-for-test
TG-2 #in-progress
2026-07-12 22:28:21 +03:00

68 lines
2.0 KiB
C++

#include <chrono>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <iostream>
#include <sstream>
#include <thread>
#include "cloud_point_rpc/cli.hpp"
#include "cloud_point_rpc/rpc_server.hpp"
#include "cloud_point_rpc/tcp_server.hpp"
using namespace score;
class CliTest : public ::testing::Test {
public:
void start() { tcp_server->start(); }
protected:
void SetUp() override {
FLAGS_logtostderr = true;
if (!google::IsGoogleLoggingInitialized())
google::InitGoogleLogging("TestCli");
server_ip = "127.0.0.1";
server_port = 9096;
rpc_server = std::make_unique<RpcServer>();
tcp_server = std::make_unique<TcpServer>(
server_ip, server_port, [this](const std::string &req) {
return rpc_server->process(req);
});
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
void TearDown() override { tcp_server->stop(); }
std::string server_ip;
int server_port;
std::unique_ptr<RpcServer> rpc_server;
std::unique_ptr<TcpServer> tcp_server;
};
TEST_F(CliTest, SendsInputToServerAndReceivesResponse) {
std::stringstream input;
std::stringstream output;
// Select option 1 (get-intrinsic-params) then 0 (exit)
// First we need to make sure the rpc_server has the method registered.
// Our SetUp registers "hello", let's register "get-intrinsic-params" too.
rpc_server->register_method(
"get-intrinsic-params", [](const nlohmann::json &) {
return std::vector<double>{14589.0, 22489.0, 3123124.555};
});
this->start();
input << "1" << std::endl;
input << "0" << std::endl;
int result = run_cli(input, output, server_ip, server_port);
EXPECT_EQ(result, 0);
std::string response = output.str();
// Use more flexible check because of pretty printing
EXPECT_THAT(response, ::testing::HasSubstr("14589.0"));
EXPECT_THAT(response, ::testing::HasSubstr("22489.0"));
EXPECT_THAT(response, ::testing::HasSubstr("3123124.555"));
}