From bfe3f48c60e35638e4497131ec9b05cb64c61eb1 Mon Sep 17 00:00:00 2001 From: ActoryOu Date: Tue, 4 Jul 2023 13:45:12 +0800 Subject: [PATCH] Make CELLULAR_AT_MAX_STRING_SIZE configurable (#140) * Make CELLULAR_AT_MAX_STRING_SIZE configurable * Add large string test in Cellular_ATStrStartWith --- source/include/cellular_config_defaults.h | 12 ++++++++++++ source/include/common/cellular_at_core.h | 17 +++++++---------- test/unit-test/cellular_at_core_utest.c | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/source/include/cellular_config_defaults.h b/source/include/cellular_config_defaults.h index fd1d8cc8..320af51a 100644 --- a/source/include/cellular_config_defaults.h +++ b/source/include/cellular_config_defaults.h @@ -440,6 +440,18 @@ ( !( CELLULAR_CHECK_IS_PREFIX_LEADING_CHAR( inputChar ) ) ) ) #endif +/** + * @brief Cellular AT string length.
+ * + * The maximum length of an AT string.
+ * + * Possible values:`Any positive integer`
+ * Default value (if undefined): 256 + */ +#ifndef CELLULAR_AT_MAX_STRING_SIZE + #define CELLULAR_AT_MAX_STRING_SIZE ( 256U ) +#endif + /** * @brief Macro that is called in the cellular library for logging "Error" level * messages. diff --git a/source/include/common/cellular_at_core.h b/source/include/common/cellular_at_core.h index 68d08a3b..bfe094db 100644 --- a/source/include/common/cellular_at_core.h +++ b/source/include/common/cellular_at_core.h @@ -45,17 +45,14 @@ /* Standard includes. */ #include -/*-----------------------------------------------------------*/ - -/** - * @brief Maximum size of an AT string. - */ -#define CELLULAR_AT_MAX_STRING_SIZE ( 256U ) +/* Cellular includes. */ +#ifndef CELLULAR_DO_NOT_USE_CUSTOM_CONFIG + /* Include custom config file before other headers. */ + #include "cellular_config.h" +#endif +#include "cellular_config_defaults.h" -/** - * @brief Maximum size of an AT prefix. - */ -#define CELLULAR_AT_MAX_PREFIX_SIZE ( 32 ) +/*-----------------------------------------------------------*/ /** * @brief The array size of an array. diff --git a/test/unit-test/cellular_at_core_utest.c b/test/unit-test/cellular_at_core_utest.c index 7accfd06..42cf7377 100644 --- a/test/unit-test/cellular_at_core_utest.c +++ b/test/unit-test/cellular_at_core_utest.c @@ -888,6 +888,20 @@ void test_Cellular_ATStrStartWith_Empty_Prefix( void ) TEST_ASSERT_EQUAL( CELLULAR_AT_BAD_PARAMETER, cellularStatus ); } +/** + * @brief Test the long string case for Cellular_ATStrStartWith to return CELLULAR_AT_BAD_PARAMETER. + */ +void test_Cellular_ATStrStartWith_ATStringTooLong( void ) +{ + CellularATError_t cellularStatus = CELLULAR_AT_SUCCESS; + bool result; + char * pPrefix = ""; + char pStringSuccess[] = CELLULAR_SAMPLE_PREFIX_STRING_LARGE_INPUT; + + cellularStatus = Cellular_ATStrStartWith( pStringSuccess, pPrefix, &result ); + TEST_ASSERT_EQUAL( CELLULAR_AT_BAD_PARAMETER, cellularStatus ); +} + /** * @brief Test that any NULL parameter causes Cellular_ATStrtoi to return CELLULAR_AT_BAD_PARAMETER. */