/* * Copyright (c) 2019 - 2024 Stefan Strobel * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ /** * @file test_integration_auth.cpp * @brief integration test implementation for the authentication functions * @author Stefan Strobel */ #include "test/framework/catch.hpp" extern "C" { #include "shellmatta.h" } #include static uint32_t write_callCnt = 0u; static char write_data[1024]; static uint32_t write_length; static uint32_t busyCallCnt; static uint32_t notBusyCallCnt; static bool suspendBusy; static shellmatta_retCode_t writeFct(const char* data, uint32_t length) { write_callCnt ++; while((length > 0) && (write_length < sizeof(write_data))) { write_data[write_length] = *data; data ++; length --; write_length ++; } return SHELLMATTA_OK; } static shellmatta_retCode_t publicCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length) { (void) handle; (void) arguments; (void) length; shellmatta_retCode_t ret = SHELLMATTA_OK; return ret; } shellmatta_cmd_t publicCmd = {(char*)"public", (char*)"p", NULL, NULL, publicCmdFct, NULL, NULL}; static shellmatta_retCode_t privateCmdFct(shellmatta_handle_t handle, const char *arguments, uint32_t length) { (void) handle; (void) arguments; (void) length; return SHELLMATTA_OK; } shellmatta_cmd_t privateCmd = {(char*)"private", (char*)"r", NULL, NULL, privateCmdFct, NULL, NULL}; TEST_CASE( "check unauthenticated help" ) { shellmatta_retCode_t ret; shellmatta_instance_t inst; shellmatta_handle_t handle; char buffer[1024] = {0}; char historyBuffer[1024] = {0}; char *dummyData = (char*) ""; shellmatta_doInit( &inst, &handle, buffer, sizeof(buffer), historyBuffer, sizeof(historyBuffer), "shellmatta->", NULL, writeFct); busyCallCnt = 0u; notBusyCallCnt = 0u; write_callCnt = 0u; memset(write_data, 0, sizeof(write_data)); write_length = 0u; suspendBusy = false; shellmatta_addCmd(handle, &publicCmd); shellmatta_addCmd(handle, &privateCmd); do { ret = shellmatta_processData(handle, (char*)"help\r", 5); } while (SHELLMATTA_BUSY == ret); CHECK( write_length == strlen(dummyData)); REQUIRE_THAT(write_data, Catch::Matchers::Equals(dummyData)); }