Skip to content

Commit

Permalink
Review fix: Removing log prints, adding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
parag-pv committed Sep 30, 2024
1 parent 1055cdc commit ca09400
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 1 addition & 9 deletions languages/cpp/src/shared/include/json_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class JsonEngine
// template <typename RESPONSE>
void MockRequest(const WPEFramework::Core::JSONRPC::Message* message)
{
std::cout << "Inside JSON engine MockRequest function" << std::endl;
std::string methodName = capitalizeFirstChar(message->Designator.Value().c_str());

/* TODO: Add a flag here that will be set to true if the method name is found in the rpc block, u
Expand All @@ -140,29 +139,23 @@ class JsonEngine

// ID Validation
// TODO: Check if id gets incremented by 1 for each request
std::cout << "MockRequest actual message.Id.Value(): " << message->Id.Value() << std::endl;
EXPECT_THAT(message->Id, AllOf(Ge(1),Le(std::numeric_limits<int>::max())));

// Schema validation
const json requestParams = json::parse(message->Parameters.Value());
std::cout << "Schema validator requestParams JSON: " << requestParams.dump() << std::endl;
if(method["params"].empty()) {
std::cout << "Params is empty" << std::endl;
std::cout << "Schema validation for empty parameters" << std::endl;
EXPECT_EQ(requestParams, "{}"_json);
}
else {
std::cout << "Params is NOT empty" << std::endl;
json_validator validator;
const json openRPCParams = method["params"];
for (auto& item : openRPCParams.items()) {
std::string key = item.key();
json currentSchema = item.value();
std::string paramName = currentSchema["name"];
std::cout << "paramName: " << paramName << std::endl;
if (requestParams.contains(paramName)) {
std::cout << "RequestParams contain paramName in rpc" << std::endl;
json dereferenced_schema = process_schema(currentSchema, _data);
std::cout << "schema JSON after $ref: " << dereferenced_schema.dump() << std::endl;
try{
validator.set_root_schema(dereferenced_schema["schema"]);
validator.validate(requestParams[paramName]);
Expand All @@ -181,7 +174,6 @@ class JsonEngine
template <typename RESPONSE>
Firebolt::Error MockResponse(WPEFramework::Core::JSONRPC::Message &message, RESPONSE &response)
{
std::cout << "Inside JSON engine MockResponse function" << std::endl;
std::string methodName = capitalizeFirstChar(message.Designator.Value().c_str());

// Loop through the methods to find the one with the given name
Expand Down
10 changes: 6 additions & 4 deletions languages/cpp/src/shared/src/Transport/Transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ namespace FireboltSDK
_adminLock.Unlock();
}

// Send requests to JSON engine's mockRequest method for unit testing instead of channel's submit method
#ifdef UNIT_TEST
void Submit(const WPEFramework::Core::ProxyType<INTERFACE> &message)
{
Expand Down Expand Up @@ -417,6 +418,7 @@ namespace FireboltSDK
Close();
}

// Always return true for unit testing
#ifdef UNIT_TEST
bool IsOpen()
{
Expand Down Expand Up @@ -449,7 +451,8 @@ namespace FireboltSDK
}
_adminLock.Unlock();
}


// Always return true for unit testing
#ifdef UNIT_TEST
bool Open(const uint32_t waitTime)
{
Expand Down Expand Up @@ -609,6 +612,7 @@ namespace FireboltSDK

public:

// Always return true for unit testing
#ifdef UNIT_TEST
inline bool IsOpen()
{
Expand Down Expand Up @@ -637,11 +641,11 @@ namespace FireboltSDK
_eventHandler = eventHandler;
}

// Invoke method is overriden for unit testing to call MockResponse method from JSON engine
#ifdef UNIT_TEST
template <typename PARAMETERS, typename RESPONSE>
Firebolt::Error Invoke(const string &method, const PARAMETERS &parameters, RESPONSE &response)
{
std::cout << "Inside Mock Transport Invoke function" << std::endl;
Entry slot;
uint32_t id = _channel->Sequence();
Firebolt::Error result = Send(method, parameters, id);
Expand All @@ -657,7 +661,6 @@ namespace FireboltSDK
template <typename PARAMETERS, typename RESPONSE>
Firebolt::Error Invoke(const string& method, const PARAMETERS& parameters, RESPONSE& response)
{
std::cout << "Inside Transport Invoke function" << std::endl;
Entry slot;
uint32_t id = _channel->Sequence();
Firebolt::Error result = Send(method, parameters, id);
Expand Down Expand Up @@ -871,7 +874,6 @@ namespace FireboltSDK

int32_t Submit(const WPEFramework::Core::ProxyType<WPEFramework::Core::JSONRPC::Message> &inbound)
{
std::cout << "Inside Transport Submit function 2" << std::endl;
int32_t result = WPEFramework::Core::ERROR_UNAVAILABLE;
WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch> job = WPEFramework::Core::ProxyType<WPEFramework::Core::IDispatch>(WPEFramework::Core::ProxyType<Transport::CommunicationJob>::Create(inbound, this));
WPEFramework::Core::IWorkerPool::Instance().Submit(job);
Expand Down

0 comments on commit ca09400

Please sign in to comment.