/* * Copyright (c) 2023 Fancy Code. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ServersMock.h" #include "ILog.h" #include "servers.h" #include extern const char *APP_GET_PRODUCT_INFO; std::shared_ptr &ServersMock::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); if (impl) { if (instance.use_count() == 1) { LogInfo("Instance changed succeed.\n"); instance = *impl; } else { LogError("Can't changing the instance becase of using by some one.\n"); } } return instance; } ServersMock::ServersMock() { // mServerUrl = APP_MANAGER_HTTP_SERVER_IP ":" + std::to_string(APP_MANAGER_HTTP_SERVER_PORT); } void ServersMock::MockGetProductInfo(void) { ServerParam init = { .logFlag = LOG_FLAG_ENABLE, .sslVerifyFlag = SSL_VERIFY_DISABLE, }; ServersInit(init); LogInfo("servers test start.\n"); std::string mockRequest = mServerUrl + APP_GET_PRODUCT_INFO; ServerHttp *http = NewServersHttp(mockRequest.c_str()); if (http) { HttpGet(http); if (http->reply) { char *replyStr = (char *)malloc(http->replyLength + 1); memset(replyStr, 0, http->replyLength + 1); memcpy(replyStr, http->reply, http->replyLength); LogInfo("HttpGet response :\n%s\n", replyStr); free(replyStr); } DeleteServersHttp(http); } } void ServersMock::MockUploadFiles(void) { ServerParam init = { .logFlag = LOG_FLAG_ENABLE, .sslVerifyFlag = SSL_VERIFY_DISABLE, }; ServersInit(init); LogInfo("servers test start.\n"); std::string mockRequest = mServerUrl + "/upload"; ServerHttp *http = NewServersHttp(mockRequest.c_str()); if (http) { http->filePath = (char *)"./web/test.mp4"; HttpPostFile(http); if (http->reply) { char *replyStr = (char *)malloc(http->replyLength + 1); memset(replyStr, 0, http->replyLength + 1); memcpy(replyStr, http->reply, http->replyLength); LogInfo("HttpPost response :\n%s\n", replyStr); free(replyStr); } DeleteServersHttp(http); } }