mirror of
				https://gitee.com/jiuyilian/embedded-framework.git
				synced 2025-10-24 18:20:15 -04:00 
			
		
		
		
	Backup.
This commit is contained in:
		
							parent
							
								
									6c8bb74be1
								
							
						
					
					
						commit
						6bd70cc0e5
					
				| 
						 | 
				
			
			@ -25,6 +25,8 @@ using std::placeholders::_3;
 | 
			
		|||
// clang-format off
 | 
			
		||||
const char *TCP_RESULT_MSGID                  = "msgid";
 | 
			
		||||
const char *CJSON_INFO_STRING                 = "info";
 | 
			
		||||
const char *CJSON_ITEMS_STRING                = "items";
 | 
			
		||||
const char *CJSON_INDEX_STRING                = "index";
 | 
			
		||||
const char *CJSON_FILES_STRING                = "files";
 | 
			
		||||
const char *APP_GET_PRODUCT_INFO              = "/app/getproductinfo";
 | 
			
		||||
const char *APP_GET_DEVICE_ATTR               = "/app/getdeviceattr";
 | 
			
		||||
| 
						 | 
				
			
			@ -32,6 +34,7 @@ const char *APP_GET_MEDIA_INFO                = "/app/getmediainfo";
 | 
			
		|||
const char *APP_GET_SD_CARD_INFO              = "/app/getsdinfo";
 | 
			
		||||
const char *APP_GET_BATTERY_INFO              = "/app/getbatteryinfo";
 | 
			
		||||
const char *APP_GET_PARAM_VALUE               = "/app/getparamvalue";
 | 
			
		||||
const char *APP_GET_PARAM_ITEMS               = "/app/getparamitems";
 | 
			
		||||
const char *APP_GET_CAPABILITY                = "/app/capability";
 | 
			
		||||
const char *APP_GET_LOCK_VIDEO_STATUS         = "/app/getlockvideostatus";
 | 
			
		||||
const char *APP_GET_STORAGE_INFO              = "/app/getstorageinfo";
 | 
			
		||||
| 
						 | 
				
			
			@ -72,6 +75,7 @@ SixFrameHandle::SixFrameHandle()
 | 
			
		|||
    mResquesHandleFunc[APP_GET_SD_CARD_INFO] = std::bind(&SixFrameHandle::RequestGetSdCardInfo, this, _1, _2, _3);
 | 
			
		||||
    mResquesHandleFunc[APP_GET_BATTERY_INFO] = std::bind(&SixFrameHandle::RequestGetBatteryInfo, this, _1, _2, _3);
 | 
			
		||||
    mResquesHandleFunc[APP_GET_PARAM_VALUE] = std::bind(&SixFrameHandle::RequestGetParamValue, this, _1, _2, _3);
 | 
			
		||||
    mResquesHandleFunc[APP_GET_PARAM_ITEMS] = std::bind(&SixFrameHandle::RequestGetParamItems, this, _1, _2, _3);
 | 
			
		||||
    mResquesHandleFunc[APP_GET_CAPABILITY] = std::bind(&SixFrameHandle::RequestGetCapability, this, _1, _2, _3);
 | 
			
		||||
    mResquesHandleFunc[APP_GET_LOCK_VIDEO_STATUS] =
 | 
			
		||||
        std::bind(&SixFrameHandle::RequestGetLockVideoStatus, this, _1, _2, _3);
 | 
			
		||||
| 
						 | 
				
			
			@ -302,6 +306,11 @@ void inline SixFrameHandle::RequestParamValueParse(const std::string &url, std::
 | 
			
		|||
                parseImpl->mData["rec"] = true; // means app want to get rec value.
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if ("param" == key) {
 | 
			
		||||
            if ("mic" == value) {
 | 
			
		||||
                parseImpl->mData["mic"] = true; // means app want to get mic value.
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    std::shared_ptr<VParseUrl> parse = std::make_shared<ParseUrl<std::map<std::string, bool>>>();
 | 
			
		||||
    std::shared_ptr<ParseUrl<std::map<std::string, bool>>> parseImpl =
 | 
			
		||||
| 
						 | 
				
			
			@ -375,6 +384,92 @@ void inline SixFrameHandle::ResponseGetParamValue(cJSON *result, const AppParamV
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
void SixFrameHandle::RequestGetParamItems(const std::string &url, ResponseHandle responseHandle, void *context)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("RequestGetParamItems.\n");
 | 
			
		||||
    std::map<std::string, bool> paramList;
 | 
			
		||||
    RequestParamValueParse(url, paramList);
 | 
			
		||||
    AppGetCapability paramDevice;
 | 
			
		||||
    // mAppMonitor->GetParamValue(paramDevice);
 | 
			
		||||
    cJSON *result = MakeResponseResult(ResposeResult::SUCCESSFUL);
 | 
			
		||||
    if (nullptr == result) {
 | 
			
		||||
        LogError("MakeResponseResult failed.\n");
 | 
			
		||||
        responseHandle("Device run out of memory.", context);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    ResponseGetParamItems(result, paramDevice, paramList);
 | 
			
		||||
    ResponseJsonString(result, responseHandle, context);
 | 
			
		||||
    cJSON_Delete(result);
 | 
			
		||||
}
 | 
			
		||||
void SixFrameHandle::ResponseGetParamItems(cJSON *result, const AppGetCapability ¶m,
 | 
			
		||||
                                           const std::map<std::string, bool> ¶mList)
 | 
			
		||||
{
 | 
			
		||||
    auto it = paramList.find("all");
 | 
			
		||||
    if (it != paramList.end()) {
 | 
			
		||||
        cJSON *info = cJSON_CreateArray();
 | 
			
		||||
        if (nullptr == info) {
 | 
			
		||||
            LogError("cJSON_CreateArray failed.\n");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
 | 
			
		||||
        {
 | 
			
		||||
            cJSON *mic = cJSON_CreateObject();
 | 
			
		||||
            cJSON *items = cJSON_CreateArray();
 | 
			
		||||
            cJSON *index = cJSON_CreateArray();
 | 
			
		||||
            if (nullptr != mic && nullptr != items && nullptr != index) {
 | 
			
		||||
                cJSON_AddItemToArray(info, mic);
 | 
			
		||||
                cJSON_AddStringToObject(mic, "name", "mic");
 | 
			
		||||
                cJSON_AddItemToObject(mic, CJSON_ITEMS_STRING, items);
 | 
			
		||||
                cJSON_AddItemToObject(mic, CJSON_INDEX_STRING, index);
 | 
			
		||||
                cJSON_AddItemToArray(items, cJSON_CreateString("on"));
 | 
			
		||||
                cJSON_AddItemToArray(items, cJSON_CreateString("off"));
 | 
			
		||||
                cJSON_AddItemToArray(index, cJSON_CreateNumber(0));
 | 
			
		||||
                cJSON_AddItemToArray(index, cJSON_CreateNumber(1));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // {
 | 
			
		||||
        //     cJSON *rec = cJSON_CreateObject();
 | 
			
		||||
        //     cJSON *items = cJSON_CreateArray();
 | 
			
		||||
        //     cJSON *index = cJSON_CreateArray();
 | 
			
		||||
        //     if (nullptr != rec && nullptr != items && nullptr != index) {
 | 
			
		||||
        //         cJSON_AddItemToArray(info, rec);
 | 
			
		||||
        //         cJSON_AddStringToObject(rec, "name", "rec");
 | 
			
		||||
        //         cJSON_AddItemToObject(rec, CJSON_ITEMS_STRING, items);
 | 
			
		||||
        //         cJSON_AddItemToObject(rec, CJSON_INDEX_STRING, index);
 | 
			
		||||
        //         cJSON_AddItemToArray(items, cJSON_CreateString("on"));
 | 
			
		||||
        //         cJSON_AddItemToArray(items, cJSON_CreateString("off"));
 | 
			
		||||
        //         cJSON_AddItemToArray(index, cJSON_CreateNumber(0));
 | 
			
		||||
        //         cJSON_AddItemToArray(index, cJSON_CreateNumber(1));
 | 
			
		||||
        //     }
 | 
			
		||||
        // }
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        cJSON *info = cJSON_CreateObject();
 | 
			
		||||
        if (nullptr == info) {
 | 
			
		||||
            LogError("cJSON_CreateObject failed.\n");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        cJSON_AddItemToObject(result, CJSON_INFO_STRING, info);
 | 
			
		||||
        {
 | 
			
		||||
            auto it = paramList.find("mic");
 | 
			
		||||
            if (it != paramList.end()) {
 | 
			
		||||
                cJSON *items = cJSON_CreateArray();
 | 
			
		||||
                cJSON *index = cJSON_CreateArray();
 | 
			
		||||
                if (nullptr == items || nullptr == index) {
 | 
			
		||||
                    LogError("cJSON_CreateArray failed.\n");
 | 
			
		||||
                    return;
 | 
			
		||||
                }
 | 
			
		||||
                cJSON_AddItemToObject(info, CJSON_ITEMS_STRING, items);
 | 
			
		||||
                cJSON_AddItemToObject(info, CJSON_INDEX_STRING, index);
 | 
			
		||||
                cJSON_AddItemToArray(items, cJSON_CreateString("on"));
 | 
			
		||||
                cJSON_AddItemToArray(items, cJSON_CreateString("off"));
 | 
			
		||||
                cJSON_AddItemToArray(index, cJSON_CreateNumber(0));
 | 
			
		||||
                cJSON_AddItemToArray(index, cJSON_CreateNumber(1));
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
void SixFrameHandle::RequestGetCapability(const std::string &url, ResponseHandle responseHandle, void *context)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("RequestGetCapability.\n");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -81,6 +81,9 @@ private:
 | 
			
		|||
    void RequestParamValueParse(const std::string &url, std::map<std::string, bool> ¶mList);
 | 
			
		||||
    void RequestGetParamValue(const std::string &url, ResponseHandle responseHandle, void *context);
 | 
			
		||||
    void ResponseGetParamValue(cJSON *result, const AppParamValue ¶m, const std::map<std::string, bool> ¶mList);
 | 
			
		||||
    void RequestGetParamItems(const std::string &url, ResponseHandle responseHandle, void *context);
 | 
			
		||||
    void ResponseGetParamItems(cJSON *result, const AppGetCapability ¶m,
 | 
			
		||||
                               const std::map<std::string, bool> ¶mList);
 | 
			
		||||
    void RequestGetCapability(const std::string &url, ResponseHandle responseHandle, void *context);
 | 
			
		||||
    void ResponseGetCapability(cJSON *result, const AppGetCapability ¶m);
 | 
			
		||||
    void RequestGetLockVideoStatus(const std::string &url, ResponseHandle responseHandle, void *context);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -190,6 +190,30 @@ TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamValue2)
 | 
			
		|||
    IAppManager::GetInstance()->UnInit();
 | 
			
		||||
}
 | 
			
		||||
// ../output_files/test/bin/AppManagerTest
 | 
			
		||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamItems
 | 
			
		||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamItems)
 | 
			
		||||
{
 | 
			
		||||
    std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
 | 
			
		||||
    IAppManager::GetInstance()->Init(mAppParam);
 | 
			
		||||
    IAppManager::GetInstance()->SetAppMonitor(monitor);
 | 
			
		||||
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
 | 
			
		||||
    AppManagerTestTool::MockGetParamItems("all");
 | 
			
		||||
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
 | 
			
		||||
    IAppManager::GetInstance()->UnInit();
 | 
			
		||||
}
 | 
			
		||||
// ../output_files/test/bin/AppManagerTest
 | 
			
		||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamItems2
 | 
			
		||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetParamItems2)
 | 
			
		||||
{
 | 
			
		||||
    std::shared_ptr<VAppMonitor> monitor = AppManagerTestTool::MakeMonitorMock();
 | 
			
		||||
    IAppManager::GetInstance()->Init(mAppParam);
 | 
			
		||||
    IAppManager::GetInstance()->SetAppMonitor(monitor);
 | 
			
		||||
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
 | 
			
		||||
    AppManagerTestTool::MockGetParamItems("mic");
 | 
			
		||||
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
 | 
			
		||||
    IAppManager::GetInstance()->UnInit();
 | 
			
		||||
}
 | 
			
		||||
// ../output_files/test/bin/AppManagerTest
 | 
			
		||||
// --gtest_filter=AppManagerTest.INTEGRATION_AppManager_EXAMPLE_AUTO_GetCapability
 | 
			
		||||
TEST_F(AppManagerTest, INTEGRATION_AppManager_EXAMPLE_AUTO_GetCapability)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,6 +35,7 @@ protected: // About http
 | 
			
		|||
    void MockSetTimeZone(void);
 | 
			
		||||
    void MockUploadFiles(void);
 | 
			
		||||
    void MockGetParamValue(const std::string ¶mName);
 | 
			
		||||
    void MockGetParamItems(const std::string ¶mName);
 | 
			
		||||
    void MockGetCapability(void);
 | 
			
		||||
    void MockGetLockVideoStatus(void);
 | 
			
		||||
    void MockGetStorageInfo(void);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -132,6 +132,16 @@ void AppManagerTestTool::MockGetParamValue(const std::string ¶mName)
 | 
			
		|||
    }
 | 
			
		||||
    ServersMock::GetInstance()->MockGetParamValue(paramName);
 | 
			
		||||
}
 | 
			
		||||
void AppManagerTestTool::MockGetParamItems(const std::string ¶mName)
 | 
			
		||||
{
 | 
			
		||||
    // std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
 | 
			
		||||
    // if (mock) {
 | 
			
		||||
    //     EXPECT_CALL(*mock.get(), GetParamValueTrace(_))  // TODO:
 | 
			
		||||
    //         .Times(ONLY_BE_CALLED_ONCE)
 | 
			
		||||
    //         .WillOnce(DoAll(Return(CreateStatusCode(STATUS_CODE_VIRTUAL_FUNCTION))));
 | 
			
		||||
    // }
 | 
			
		||||
    ServersMock::GetInstance()->MockGetParamItems(paramName);
 | 
			
		||||
}
 | 
			
		||||
void AppManagerTestTool::MockGetCapability(void)
 | 
			
		||||
{
 | 
			
		||||
    std::shared_ptr<AppMonitorMock> mock = std::dynamic_pointer_cast<AppMonitorMock>(mAppMonitorMock);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,7 @@ extern const char *APP_GET_MEDIA_INFO;
 | 
			
		|||
extern const char *APP_GET_SD_CARD_INFO;
 | 
			
		||||
extern const char *APP_GET_BATTERY_INFO;
 | 
			
		||||
extern const char *APP_GET_PARAM_VALUE;
 | 
			
		||||
extern const char *APP_GET_PARAM_ITEMS;
 | 
			
		||||
extern const char *APP_GET_CAPABILITY;
 | 
			
		||||
extern const char *APP_GET_LOCK_VIDEO_STATUS;
 | 
			
		||||
extern const char *APP_GET_STORAGE_INFO;
 | 
			
		||||
| 
						 | 
				
			
			@ -65,256 +66,97 @@ void ServersMock::MockGetProductInfo(void)
 | 
			
		|||
{
 | 
			
		||||
    LogInfo("APP_GET_PRODUCT_INFO 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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetDeviceAttr(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_DEVICE_ATTR test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_DEVICE_ATTR;
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetMediaInfo(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_MEDIA_INFO test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_MEDIA_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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetSdCardInfo(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_SD_CARD_INFO test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_SD_CARD_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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetBatteryInfo(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_BATTERY_INFO test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_BATTERY_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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetParamValue(const std::string ¶mName)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_PARAM_VALUE test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_PARAM_VALUE + "?param=" + paramName;
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetParamItems(const std::string ¶mName)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_PARAM_ITEMS test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_PARAM_ITEMS + "?param=" + paramName;
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetCapability(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_CAPABILITY test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_CAPABILITY;
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetLockVideoStatus(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_LOCK_VIDEO_STATUS test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_LOCK_VIDEO_STATUS;
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetStorageInfo(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_STORAGE_INFO test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_STORAGE_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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockGetStorageFileList(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_GET_FILE_LIST test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_GET_FILE_LIST + "?folder=loop&start=0&end=99";
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockSetDateTime(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_SET_DATE_TIME test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_SET_DATE_TIME + "?date=20240101010101";
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockSetTimeZone(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_SET_TIME_ZONE test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_SET_TIME_ZONE + "?timezone=8";
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockSetParamValue(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_SET_PARAM_VALUE test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_SET_PARAM_VALUE + "?param=switchcam&value=1";
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockEnterRecorder(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_ENTER_RECORDER test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_ENTER_RECORDER + "?timezone=8"; // TODO:
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockAppPlayback(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("APP_PLAYBACK test start.\n");
 | 
			
		||||
    std::string mockRequest = mServerUrl + APP_PLAYBACK + "?param=enter";
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    MockHttpGet(mockRequest);
 | 
			
		||||
}
 | 
			
		||||
#ifndef PLATFORM_PATH
 | 
			
		||||
    #error Add the code in your linux.toolchain.cmake : add_definitions(-DPLATFORM_PATH="${PLATFORM_PATH}")
 | 
			
		||||
| 
						 | 
				
			
			@ -337,4 +179,22 @@ void ServersMock::MockUploadFiles(void)
 | 
			
		|||
        }
 | 
			
		||||
        DeleteServersHttp(http);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
void ServersMock::MockHttpGet(const std::string &mockRequest)
 | 
			
		||||
{
 | 
			
		||||
    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);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        LogWarning("http is null.\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -14,6 +14,7 @@
 | 
			
		|||
 */
 | 
			
		||||
#ifndef SERVERS_MOCK_H
 | 
			
		||||
#define SERVERS_MOCK_H
 | 
			
		||||
#include "servers.h"
 | 
			
		||||
#include <memory>
 | 
			
		||||
class ServersMock
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -29,6 +30,7 @@ public:
 | 
			
		|||
    virtual void MockGetSdCardInfo(void);
 | 
			
		||||
    virtual void MockGetBatteryInfo(void);
 | 
			
		||||
    virtual void MockGetParamValue(const std::string ¶mName);
 | 
			
		||||
    virtual void MockGetParamItems(const std::string ¶mName);
 | 
			
		||||
    virtual void MockGetCapability(void);
 | 
			
		||||
    virtual void MockGetLockVideoStatus(void);
 | 
			
		||||
    virtual void MockGetStorageInfo(void);
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +42,9 @@ public:
 | 
			
		|||
    virtual void MockAppPlayback(void);
 | 
			
		||||
    virtual void MockUploadFiles(void);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void MockHttpGet(const std::string &mockRequest);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    std::string mServerUrl;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user