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

Add logic to sample_lib for UT #10

Merged
merged 1 commit into from
Dec 30, 2019
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
21 changes: 21 additions & 0 deletions fsw/public_inc/sample_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@
/*************************************************************************
** Exported Functions
*************************************************************************/

/************************************************************************/
/** \brief Library Initialization Function
**
** \par Description
** This function is required by CFE to initialize the library
** It should be specified in the cfe_es_startup.scr file as part
** of loading this library. It is not directly invoked by
** applications.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \returns
** \retstmt Returns #CFE_SUCCESS if successful \endcode
** \endreturns
**
*************************************************************************/
int32 SAMPLE_LibInit(void);


/************************************************************************/
/** \brief Sample Lib Function
**
Expand Down
32 changes: 28 additions & 4 deletions fsw/src/sample_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@
#include "sample_lib.h"
#include "sample_lib_version.h"

/* for "strncpy()" */
#include <string.h>

/*************************************************************************
** Macro Definitions
*************************************************************************/

#define SAMPLE_LIB_BUFFER_SIZE 16


/*************************************************************************
** Private Function Prototypes
** Private Data Structures
*************************************************************************/
int32 SAMPLE_LibInit(void);
static char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE];

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
Expand All @@ -49,8 +54,27 @@ int32 SAMPLE_LibInit(void);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_LibInit(void)
{
/*
* Call a C library function, like strcpy(), and test its result.
*
* This is primary for a unit test example, to have more than
* one code path to exercise.
*
* The specification for strncpy() indicates that it should return
* 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)
{
return CFE_STATUS_NOT_IMPLEMENTED;
}

OS_printf ("SAMPLE Lib Initialized. Version %d.%d.%d.%d",
/* ensure termination */
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,
Expand All @@ -67,7 +91,7 @@ int32 SAMPLE_LibInit(void)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_Function( void )
{
OS_printf ("SAMPLE_Function called\n");
OS_printf ("SAMPLE_Function called, buffer=\'%s\'\n", SAMPLE_Buffer);

return(CFE_SUCCESS);

Expand Down