From 532e551d1cf54d47e97f5ad6b8a07090a32694cb Mon Sep 17 00:00:00 2001 From: Ramki Ananthakrishnan Date: Thu, 23 Feb 2017 18:28:31 -0800 Subject: [PATCH] Added test for string_helpers.c --- tests/CMakeLists.txt | 7 ++++ tests/test_string_helpers.c | 81 +++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/test_string_helpers.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2adfdf4..155e878 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -95,3 +95,10 @@ add_test(NAME test_spin_thread_s COMMAND test_spin_thread_s) add_executable(test_spin_thread_s test_spin_thread_s.c ../src/spin_thread.c) target_link_libraries (test_spin_thread_s ${PARODUS_COMMON_LIBS}) +#------------------------------------------------------------------------------- +# test_string_helpers success +#------------------------------------------------------------------------------- +add_test(NAME test_string_helpers COMMAND test_string_helpers) +add_executable(test_string_helpers test_string_helpers.c ../src/string_helpers.c) +target_link_libraries (test_string_helpers ${PARODUS_COMMON_LIBS}) + diff --git a/tests/test_string_helpers.c b/tests/test_string_helpers.c new file mode 100644 index 0000000..036d3c3 --- /dev/null +++ b/tests/test_string_helpers.c @@ -0,0 +1,81 @@ +/** + * Copyright 2010-2016 Comcast Cable Communications Management, LLC + * + * 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 +#include +#include +#include + +#include + +#include "../src/ParodusInternal.h" + +#define STRING_LENGTH 21 + +/*----------------------------------------------------------------------------*/ +/* Mocks */ +/*----------------------------------------------------------------------------*/ +char *strncpy(char *destStr, const char *srcStr, size_t destSize) +{ + (void) destStr; (void) srcStr; (void) destSize; + return NULL; +} + +/*----------------------------------------------------------------------------*/ +/* Tests */ +/*----------------------------------------------------------------------------*/ +void test_parStrncpy() +{ + char srcStr[] = "Sample source string"; + char destStr[STRING_LENGTH]; + int destSize = sizeof(destStr); + parStrncpy(destStr, srcStr, destSize); + + CU_ASSERT( '\0' == destStr[destSize - 1] ); +} + +void add_suites( CU_pSuite *suite ) +{ + ParodusInfo("--------Start of Test Cases Execution ---------\n"); + *suite = CU_add_suite( "tests", NULL, NULL ); + CU_add_test( *suite, "Test 1", test_parStrncpy ); +} + +/*----------------------------------------------------------------------------*/ +/* External Functions */ +/*----------------------------------------------------------------------------*/ +int main( void ) +{ + unsigned rv = 1; + CU_pSuite suite = NULL; + + if( CUE_SUCCESS == CU_initialize_registry() ) { + add_suites( &suite ); + + if( NULL != suite ) { + CU_basic_set_mode( CU_BRM_VERBOSE ); + CU_basic_run_tests(); + ParodusPrint( "\n" ); + CU_basic_show_failures( CU_get_failure_list() ); + ParodusPrint( "\n\n" ); + rv = CU_get_number_of_tests_failed(); + } + + CU_cleanup_registry(); + + } + + return rv; +}