add c-api test
This commit is contained in:
47
test/test_ipc_python_cpp.cpp
Normal file
47
test/test_ipc_python_cpp.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <thread>
|
||||
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include "ipc/api.hpp"
|
||||
|
||||
int
|
||||
main(int /* argc */, char** /* argv */)
|
||||
{
|
||||
using fmt::format;
|
||||
using fmt::print;
|
||||
using ipc::Ipc;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
int verbose = 0;
|
||||
ipc::init(); // default name
|
||||
|
||||
ipc::start_external("python test_server.py", true);
|
||||
|
||||
print("[client] pre-start\n");
|
||||
auto client = Ipc(false, verbose);
|
||||
print("[client] start\n");
|
||||
|
||||
double answer;
|
||||
auto hline = "\n------------------------\n";
|
||||
for (int i = 2; i <= 5; ++i) {
|
||||
std::this_thread::sleep_for(500ms);
|
||||
print(hline);
|
||||
|
||||
{
|
||||
client.write(i);
|
||||
print("[client] write int({})\n", i);
|
||||
}
|
||||
|
||||
{
|
||||
client.read(answer);
|
||||
print("[client] read double({:.2e})\n", answer);
|
||||
}
|
||||
}
|
||||
|
||||
print(hline);
|
||||
print("[client] finish the work\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user