1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #include <gtest/gtest.h>
- #include <json.hpp>
- #include <httplib.h>
- //#define private public
- #include <ProcessorManual.h>
- #include <ModuleHTTP.h>
- #include <ModuleMath.h>
- #include <ModuleSwitch.h>
- #include <math.h>
- using namespace mdd;
- using namespace httplib;
- TEST(ModuleHTTP, updateLayout_create){
- Server svr;
- svr.Get("/inputs", [](const Request& req, Response& res) {
- json input_body;
- for (int i = 0; i < 5; ++i) {
- json entity;
- entity["type"] = "INPUT";
- entity["value"] = i;
- input_body.push_back(entity);
- }
- std::cout<<"RECIVED: /inputs" <<std::endl;
- res.set_content(input_body.dump(), "application/json");
- auto data = new std::string(input_body.dump());
- res.set_content_provider(
- data->size(), // Content length
- [data](size_t offset, size_t length, DataSink &sink) {
- const auto &d = *data;
- sink.write(&d[offset], std::min(length, length));
- return true; // return 'false' if you want to cancel the process.
- },
- [data] { delete data; });
- });
- svr.Get("/outputs", [](const Request& req, Response& res) {
- json output_body;
- for (int i = 0; i < 3; ++i) {
- json entity;
- entity["type"] = "OUTPUT";
- entity["value"] = i*2;
- output_body.push_back(entity);
- }
- std::cout<<"RECIVED: /outputs" <<std::endl;
- res.set_content(output_body.dump(), "application/json");
- });
- svr.listen("localhost",8888);
- json input_body;
- for (int i = 0; i < 5; ++i) {
- json entity;
- entity["type"] = "INPUT";
- entity["value"] = i;
- input_body.push_back(entity);
- }
- ModuleHTTP module("","localhost",8888);
- auto inputs_types = module.getInputs();
- auto inputs_ids = module.getInputIDs();
- for(int i = 0; i < 5; ++i){
- EXPECT_EQ(inputs_types[i], "INPUT");
- EXPECT_EQ(module.getInput(inputs_ids[i])->getValue()["value"].get<int>(), i);
- }
- auto outputs_types = module.getOutputs();
- auto outputs_ids = module.getOutputIDs();
- for(int i = 0; i < 3; ++i){
- EXPECT_EQ(outputs_types[i], "OUTPUT");
- EXPECT_EQ(module.getOutput(outputs_ids[i])->getValue()["value"].get<int>(), i*2);
- }
- }
|