Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #15, Apply standard style #23

Merged
merged 2 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions fsw/public_inc/sample_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**
** File: sample_lib.h
**
** Purpose:
** Purpose:
** Specification for the sample library functions.
**
*************************************************************************/
Expand Down Expand Up @@ -58,21 +58,20 @@
*************************************************************************/
int32 SAMPLE_LibInit(void);


/************************************************************************/
/** \brief Sample Lib Function
**
/** \brief Sample Lib Function
**
** \par Description
** This is a sample function
**
** \par Assumptions, External Events, and Notes:
** None
**
**
** \return Execution status, see \ref CFEReturnCodes
**
**
**
*************************************************************************/
int32 SAMPLE_Function( void );
int32 SAMPLE_Function(void);

#endif /* _sample_lib_h_ */

Expand Down
33 changes: 14 additions & 19 deletions fsw/src/sample_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**
** File: sample_lib.c
**
** Purpose:
** Purpose:
** Sample CFS library
**
*************************************************************************/
Expand All @@ -42,7 +42,7 @@ char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE];
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Library Initialization Routine */
/* cFE requires that a library have an initialization routine */
/* cFE requires that a library have an initialization routine */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_LibInit(void)
Expand All @@ -57,37 +57,32 @@ int32 SAMPLE_LibInit(void)
* the pointer to the destination buffer, so it should be impossible
* for this to ever fail when linked with a compliant C library.
*/
if (strncpy(SAMPLE_Buffer, "SAMPLE DATA", sizeof(SAMPLE_Buffer)-1) !=
SAMPLE_Buffer)
if (strncpy(SAMPLE_Buffer, "SAMPLE DATA", sizeof(SAMPLE_Buffer) - 1) != SAMPLE_Buffer)
{
return CFE_STATUS_NOT_IMPLEMENTED;
}

/* ensure termination */
SAMPLE_Buffer[sizeof(SAMPLE_Buffer)-1] = 0;
SAMPLE_Buffer[sizeof(SAMPLE_Buffer) - 1] = 0;

OS_printf("SAMPLE Lib Initialized. Version %d.%d.%d.%d\n", SAMPLE_LIB_MAJOR_VERSION, SAMPLE_LIB_MINOR_VERSION,
SAMPLE_LIB_REVISION, SAMPLE_LIB_MISSION_REV);

OS_printf ("SAMPLE Lib Initialized. Version %d.%d.%d.%d\n",
SAMPLE_LIB_MAJOR_VERSION,
SAMPLE_LIB_MINOR_VERSION,
SAMPLE_LIB_REVISION,
SAMPLE_LIB_MISSION_REV);

return CFE_SUCCESS;
}/* End SAMPLE_LibInit */

} /* End SAMPLE_LibInit */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Sample Lib function */
/* Sample Lib function */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_Function( void )
int32 SAMPLE_Function(void)
{
OS_printf ("SAMPLE_Function called, buffer=\'%s\'\n", SAMPLE_Buffer);
OS_printf("SAMPLE_Function called, buffer=\'%s\'\n", SAMPLE_Buffer);

return (CFE_SUCCESS);

return(CFE_SUCCESS);

} /* End SAMPLE_Function */

/************************/
Expand Down
6 changes: 2 additions & 4 deletions fsw/src/sample_lib_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**
** File: sample_lib_internal.h
**
** Purpose:
** Purpose:
** An example of an internal (private) header file for SAMPLE Lib
**
** Notes:
Expand All @@ -36,8 +36,7 @@
** Macro Definitions
*************************************************************************/

#define SAMPLE_LIB_BUFFER_SIZE 16

#define SAMPLE_LIB_BUFFER_SIZE 16

/*************************************************************************
** Internal Data Structures
Expand All @@ -53,7 +52,6 @@ extern char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE];
*/
int32 SAMPLE_LibInit(void);


#endif /* _sample_lib_internal_h_ */

/************************/
Expand Down
10 changes: 4 additions & 6 deletions fsw/src/sample_lib_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@
#ifndef _sample_lib_version_h_
#define _sample_lib_version_h_


#define SAMPLE_LIB_MAJOR_VERSION 1
#define SAMPLE_LIB_MINOR_VERSION 1
#define SAMPLE_LIB_REVISION 3
#define SAMPLE_LIB_MISSION_REV 0

#define SAMPLE_LIB_MAJOR_VERSION 1
#define SAMPLE_LIB_MINOR_VERSION 1
#define SAMPLE_LIB_REVISION 3
#define SAMPLE_LIB_MISSION_REV 0

#endif /* _sample_lib_version_h_ */

Expand Down
30 changes: 6 additions & 24 deletions unit-test/coveragetest/coveragetest_sample_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ typedef struct

} SAMPLE_Function_TestState_t;


/*
* A local helper (hook) function for the OS_printf stub provided by OSAL.
* This confirms internal content of the format string and arguments.
*/
static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount,
const UT_StubContext_t *Context, va_list va)
static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context,
va_list va)
{
SAMPLE_Function_TestState_t *State = UserObj;

Expand All @@ -77,9 +76,7 @@ static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount,
* detail would not be needed, but this serves as an example
* of how it can be done.
*/
if (Context->ArgCount > 0 &&
strcmp(Context->ArgPtr[0],
"SAMPLE_Function called, buffer=\'%s\'\n") == 0)
if (Context->ArgCount > 0 && strcmp(Context->ArgPtr[0], "SAMPLE_Function called, buffer=\'%s\'\n") == 0)
{
State->format_string_valid = true;

Expand All @@ -98,8 +95,6 @@ static int32 UT_printf_hook(void *UserObj, int32 StubRetcode, uint32 CallCount,
return 0;
}



/*
**********************************************************************************
** TEST CASE FUNCTIONS
Expand All @@ -115,8 +110,7 @@ void Test_SAMPLE_LibInit(void)

/* Set a data buffer for strncpy()
* This overriddes what it would normally do */
UT_SetDataBuffer(UT_KEY(OCS_strncpy), UT_TESTBUFFER,
sizeof (UT_TESTBUFFER), false);
UT_SetDataBuffer(UT_KEY(OCS_strncpy), UT_TESTBUFFER, sizeof(UT_TESTBUFFER), false);

/* nominal case should return SUCCESS */
UT_TEST_FUNCTION_RC(SAMPLE_LibInit(), CFE_SUCCESS);
Expand All @@ -132,8 +126,7 @@ void Test_SAMPLE_LibInit(void)
* This requires use of the local accessor routine to get to the
* internal buffer, which is declared "static"
*/
UtAssert_StrCmp(UT_TESTBUFFER, SAMPLE_Buffer,
"Internal buffer content valid");
UtAssert_StrCmp(UT_TESTBUFFER, SAMPLE_Buffer, "Internal buffer content valid");

/* Test failure of the underlying library call */
UT_SetForceFail(UT_KEY(OCS_strncpy), -1);
Expand Down Expand Up @@ -170,8 +163,6 @@ void Test_SAMPLE_Function(void)
UtAssert_True(state.printf_content_valid, "OS_printf content test");
}



/*
* Setup function prior to every test
*/
Expand All @@ -183,11 +174,7 @@ void Sample_UT_Setup(void)
/*
* Teardown function after every test
*/
void Sample_UT_TearDown(void)
{

}

void Sample_UT_TearDown(void) {}

/*
* Register the test cases to execute with the unit test tool
Expand All @@ -197,8 +184,3 @@ void UtTest_Setup(void)
ADD_TEST(SAMPLE_LibInit);
ADD_TEST(SAMPLE_Function);
}





16 changes: 7 additions & 9 deletions unit-test/coveragetest/sample_lib_coveragetest_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,18 @@
* frequent case where a function needs to be called and
* an int32 return code needs to be tested.
*/
#define UT_TEST_FUNCTION_RC(func,exp) \
{ \
int32 rcexp = exp; \
int32 rcact = func; \
UtAssert_True(rcact == rcexp, "%s (%ld) == %s (%ld)", \
#func, (long)rcact, #exp, (long)rcexp); \
}
#define UT_TEST_FUNCTION_RC(func, exp) \
{ \
int32 rcexp = exp; \
int32 rcact = func; \
UtAssert_True(rcact == rcexp, "%s (%ld) == %s (%ld)", #func, (long)rcact, #exp, (long)rcexp); \
}

/*
* Macro to add a test case to the list of tests to execute
* This just simplifies the use of UtTest_Add()
*/
#define ADD_TEST(test) UtTest_Add((Test_ ## test),Sample_UT_Setup,Sample_UT_TearDown, #test)
#define ADD_TEST(test) UtTest_Add((Test_##test), Sample_UT_Setup, Sample_UT_TearDown, #test)

/*
* Setup function prior to every test
Expand All @@ -74,4 +73,3 @@ void Sample_UT_Setup(void);
void Sample_UT_TearDown(void);

#endif

4 changes: 1 addition & 3 deletions unit-test/inc/OCS_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
/* prototypes normally declared in string.h */
/* ----------------------------------------- */

extern char *OCS_strncpy (char * dest, const char * src, unsigned long size);

extern char *OCS_strncpy(char *dest, const char *src, unsigned long size);

#endif /* _STUB_STRING_H_ */

4 changes: 1 addition & 3 deletions unit-test/override_inc/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
/* mappings for declarations in string.h */
/* ----------------------------------------- */

#define strncpy OCS_strncpy

#define strncpy OCS_strncpy

#endif /* _OVERRIDE_STRING_H_ */

5 changes: 2 additions & 3 deletions unit-test/override_src/libc_string_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,12 @@
*/
#include <OCS_string.h>


/* **********************************
* Implementation of OCS_strncpy stub
* **********************************/
char *OCS_strncpy(char *dst, const char *src, unsigned long size)
{
int32 Status;
int32 Status;
uint32 CopySize;

Status = UT_DEFAULT_IMPL(OCS_strncpy);
Expand All @@ -66,7 +65,7 @@ char *OCS_strncpy(char *dst, const char *src, unsigned long size)
* a "failure" response -
* the real C library would never do this.
*/
return (char*)0;
return (char *)0;
}
/*
* Demonstrate use of a test-provided local data buffer
Expand Down
6 changes: 2 additions & 4 deletions ut-stubs/sample_lib_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ int32 SAMPLE_LibInit(void)
*/
return UT_DEFAULT_IMPL(SAMPLE_LibInit);

}/* End SAMPLE_LibInit */
} /* End SAMPLE_LibInit */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Sample Lib function stub */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_Function( void )
int32 SAMPLE_Function(void)
{
return UT_DEFAULT_IMPL(SAMPLE_Function);

} /* End SAMPLE_Function */