12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /*
- * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
- *
- * 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_utils_writeEcho.c
- * @brief unittest for shellmatta utils_writeEcho
- * @author Stefan Strobel <stefan.strobel@shimatta.net>
- */
- #include "test/framework/catch.hpp"
- #include "src/shellmatta_utils.c"
- #include <string.h>
- static uint32_t write_callCnt = 0u;
- static const char *write_data;
- static uint32_t write_length;
- static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
- {
- write_callCnt ++;
- write_data = data;
- write_length = length;
- return SHELLMATTA_OK;
- }
- TEST_CASE( "shellmatta_writeEcho echo enabled" ) {
- shellmatta_instance_t inst;
- char buffer[20] = {0};
- char dummyData[29] = "asd";
- inst.buffer = buffer;
- inst.bufferSize = 20;
- inst.cursor = 10;
- inst.inputCount = 10;
- inst.echoEnabled = true;
- inst.write = writeFct;
- write_callCnt = 0u;
- write_data = 0u;
- write_length = 0u;
- utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
- CHECK( write_callCnt == 1u );
- CHECK( write_data == (char*)&dummyData );
- REQUIRE( write_length == sizeof(dummyData));
- }
- TEST_CASE( "shellmatta_writeEcho echo disabled" ) {
- shellmatta_instance_t inst;
- char buffer[20] = {0};
- char dummyData[29] = "asd";
- inst.buffer = buffer;
- inst.bufferSize = 20;
- inst.cursor = 10;
- inst.inputCount = 10;
- inst.echoEnabled = false;
- inst.write = writeFct;
- write_callCnt = 0u;
- write_data = 0u;
- write_length = 0u;
- utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
- CHECK( write_callCnt == 0u );
- CHECK( write_data == (char*)0u );
- REQUIRE( write_length == 0u );
- }
|