#include "cfe.h"
#include "ms5607_app.h"
#include "ms5607_test_utils.h"
#include "ms5607_app_test.h"
#include "uttest.h"
#include "ut_osapi_stubs.h"
#include "ut_cfe_sb_stubs.h"
#include "ut_cfe_sb_hooks.h"
#include "ut_cfe_es_stubs.h"
#include "ut_cfe_es_hooks.h"
#include "ut_cfe_evs_stubs.h"
#include "ut_cfe_evs_hooks.h"
#include "ut_cfe_time_stubs.h"
#include "ut_cfe_psp_memutils_stubs.h"
#include "ut_cfe_tbl_stubs.h"
#include "ut_cfe_fs_stubs.h"
#include "ut_cfe_time_stubs.h"

int32 hookCalledCount = 0;

void Test_MS5607_InitEvent_Fail_Register(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_EVENTS_SERVICE | CFE_EVS_NOT_IMPLEMENTED;
    int32 expected = CFE_EVS_APP_NOT_REGISTERED;

    Ut_CFE_EVS_SetReturnCode(UT_CFE_EVS_REGISTER_INDEX, expected, 1);

    result = oMS5607.InitEvent();

    UtAssert_True (result == expected, "InitEvent, failed EVS Register");
}

void Test_MS5607_InitPipe_Fail_CreateSCHPipe(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 1);

    result = oMS5607.InitPipe();

    UtAssert_True (result == expected, "InitPipe, fail SB create SCH pipe");
}

void Test_MS5607_InitPipe_Fail_SubscribeWakeup(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_SUBSCRIBEEX_INDEX, expected, 1);

    result = oMS5607.InitPipe();

    UtAssert_True (result == expected, "InitPipe, fail CFE_SB_SubscribeEx for wakeup");
}

void Test_MS5607_InitPipe_Fail_SubscribeSendHK(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_SUBSCRIBEEX_INDEX, expected, 2);

    result = oMS5607.InitPipe();

    UtAssert_True (result == expected, "InitPipe, fail CFE_SB_SubscribeEx for sendhk");
}

void Test_MS5607_InitPipe_Fail_CreateCMDPipe(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 2);

    result = oMS5607.InitPipe();

    UtAssert_True (result == expected, "InitPipe, fail SB create CMD pipe");
}

void Test_MS5607_InitPipe_Fail_SubscribeCMD(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_SUBSCRIBE_INDEX, expected, 1);

    result = oMS5607.InitPipe();

    UtAssert_True (result == expected, "InitPipe, fail CFE_SB_Subscribe for CMD");
}

void Test_MS5607_InitPipe_Fail_CreateDATAPipe(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 2);

    result = oMS5607.InitPipe();

    UtAssert_True (result == expected, "InitPipe, fail SB create DATA pipe");
}

void Test_MS5607_InitData(void)
{
    MS5607 oMS5607;

    int32 expected = CFE_SUCCESS;

    oMS5607.InitData();

}

void Test_MS5607_InitApp_Fail_InitEvent(void)
{
    MS5607 oMS5607;

    int32 result = CFE_SUCCESS;
    int32 expected = CFE_EVS_APP_NOT_REGISTERED;

    Ut_CFE_EVS_SetReturnCode(UT_CFE_EVS_REGISTER_INDEX, expected, 1);

    result = oMS5607.InitApp();

    UtAssert_True (result == expected, "InitApp, fail init event");
}

void Test_MS5607_InitApp_Fail_InitPipe(void)
{
    MS5607 oMS5607;

    int32 result = CFE_SUCCESS;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 1);

    result = oMS5607.InitApp();

    UtAssert_True (result == expected, "InitApp, fail init pipe");
}

void Test_MS5607_InitApp_Fail_InitData(void)
{
    MS5607 oMS5607;

    int32 result = 1;
    int32 expected = CFE_SUCCESS;

    result = oMS5607.InitApp();

    UtAssert_True (result == expected, "InitApp, fail init data");
}

void Test_MS5607_InitApp_Fail_InitConfigTbl(void)
{
    MS5607 oMS5607;

    int32 result = CFE_SUCCESS;
    int32 expected = CFE_TBL_ERR_INVALID_NAME;

    Ut_CFE_TBL_SetReturnCode(UT_CFE_TBL_REGISTER_INDEX, expected, 1);

    result = oMS5607.InitApp();

    UtAssert_True (result == expected, "InitApp, fail init config table");
}

void Test_MS5607_InitApp_Nominal(void)
{
    MS5607 oMS5607;

    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_EXECUTIVE_SERVICE | CFE_ES_ERR_APP_REGISTER;
    int32 expected = CFE_SUCCESS;

    result = oMS5607.InitApp();

    UtAssert_True (result == expected, "InitApp, nominal");
}

void Test_MS5607_AppMain_Fail_RegisterApp(void)
{
    MS5607 oMS5607;

    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_REGISTERAPP_INDEX, CFE_ES_ERR_APP_REGISTER, 1);

    oMS5607.AppMain();
}

void Test_MS5607_AppMain_Fail_InitApp(void)
{
    MS5607 oMS5607;

    Ut_CFE_EVS_SetReturnCode(UT_CFE_EVS_REGISTER_INDEX, CFE_EVS_APP_NOT_REGISTERED, 1);

    oMS5607.AppMain();
}

void Test_MS5607_AppMain_Fail_AcquireConfigPtrs(void)
{
    MS5607 oMS5607;

    Ut_CFE_TBL_SetReturnCode(UT_CFE_TBL_GETADDRESS_INDEX, CFE_TBL_ERR_INVALID_HANDLE, 2);

    oMS5607.AppMain();
}

void Test_MS5607_AppMain_InvalidSchMessage(void)
{
    MS5607 oMS5607;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_RCVMSG_INDEX, CFE_SUCCESS, 1);
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_GETMSGID_INDEX, 0, 1);

    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_RUNLOOP_INDEX, FALSE, 2);

    oMS5607.AppMain();

}

int32 Test_MS5607_AppMain_Nominal_SendHK_SendMsgHook(CFE_SB_Msg_t *MsgPtr)
{

    hookCalledCount++;

    return CFE_SUCCESS;
}

void Test_MS5607_AppMain_Nominal_SendHK(void)
{
    MS5607 oMS5607;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_RCVMSG_INDEX, CFE_SUCCESS, 1);
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_GETMSGID_INDEX, MS5607_SEND_HK_MID, 1);

    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_RUNLOOP_INDEX, FALSE, 2);

    hookCalledCount = 0;
    Ut_CFE_ES_SetFunctionHook(UT_CFE_SB_SENDMSG_INDEX, (void*)&Test_MS5607_AppMain_Nominal_SendHK_SendMsgHook);

    oMS5607.AppMain();

    UtAssert_True (hookCalledCount == 1, "AppMain_Nominal_SendHK");

}

void Test_MS5607_AppMain_Nominal_Wakeup(void)
{
    MS5607 oMS5607;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_RCVMSG_INDEX, CFE_SUCCESS, 1);
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_GETMSGID_INDEX, MS5607_MEASURE_MID, 1);

    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_RUNLOOP_INDEX, FALSE, 2);

}

void Test_MS5607_UpdateParamsFromTable_Nominal(void)
{
    MS5607 oMS5607;

    oMS5607.InitApp();
    oMS5607.UpdateParamsFromTable();

    UtAssert_True(oMS5607.m_Params.p1 == oMS5607.ConfigTblPtr->p1, "m_Param != ConfigTblPtr");
}

void Test_MS5607_CleanupCallback_Nominal(void)
{
    MS5607_CleanupCallback();
}

void MS5607_App_Test_AddTestCases(void)
{
    UtTest_Add(Test_MS5607_InitEvent_Fail_Register, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitEvent_Fail_Register");

    UtTest_Add(Test_MS5607_InitPipe_Fail_CreateSCHPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_CreateSCHPipe");
    UtTest_Add(Test_MS5607_InitPipe_Fail_SubscribeWakeup, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_SubscribeWakeup");
    UtTest_Add(Test_MS5607_InitPipe_Fail_SubscribeSendHK, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_SubscribeSendHK");
    UtTest_Add(Test_MS5607_InitPipe_Fail_CreateCMDPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_CreateCMDPipe");
    UtTest_Add(Test_MS5607_InitPipe_Fail_SubscribeCMD, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_SubscribeCMD");
    UtTest_Add(Test_MS5607_InitPipe_Fail_CreateDATAPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_CreateDATAPipe");

    UtTest_Add(Test_MS5607_InitData, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitData");

    UtTest_Add(Test_MS5607_InitApp_Fail_InitEvent, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitEvent");
    UtTest_Add(Test_MS5607_InitApp_Fail_InitPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitPipe");
    UtTest_Add(Test_MS5607_InitApp_Fail_InitData, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitData");
    UtTest_Add(Test_MS5607_InitApp_Fail_InitConfigTbl, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitConfigTbl");
    UtTest_Add(Test_MS5607_InitApp_Nominal, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Nominal");

    UtTest_Add(Test_MS5607_AppMain_Fail_RegisterApp, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Fail_RegisterApp");
    UtTest_Add(Test_MS5607_AppMain_Fail_InitApp, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Fail_InitApp");
    UtTest_Add(Test_MS5607_AppMain_Fail_AcquireConfigPtrs, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Fail_AcquireConfigPtrs");
    UtTest_Add(Test_MS5607_AppMain_InvalidSchMessage, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_InvalidSchMessage");
    UtTest_Add(Test_MS5607_AppMain_Nominal_SendHK, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Nominal_SendHK");
    UtTest_Add(Test_MS5607_AppMain_Nominal_Wakeup, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Nominal_Wakeup");
    UtTest_Add(Test_MS5607_UpdateParamsFromTable_Nominal, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_UpdateParamsFromTable_Nominal");
    UtTest_Add(Test_MS5607_CleanupCallback_Nominal, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_CleanupCallback_Nominal");
}
/****************************************************************************
*
*   Copyright (c) 2017 Windhover Labs, L.L.C. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in
*    the documentation and/or other materials provided with the
*    distribution.
* 3. Neither the name Windhover Labs nor the names of its
*    contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/

#include "cfe.h"
#include "ms5607_app.h"
#include "ms5607_test_utils.h"
#include "ms5607_app_test.h"
#include "uttest.h"
#include "ut_osapi_stubs.h"
#include "ut_cfe_sb_stubs.h"
#include "ut_cfe_sb_hooks.h"
#include "ut_cfe_es_stubs.h"
#include "ut_cfe_es_hooks.h"
#include "ut_cfe_evs_stubs.h"
#include "ut_cfe_evs_hooks.h"
#include "ut_cfe_time_stubs.h"
#include "ut_cfe_psp_memutils_stubs.h"
#include "ut_cfe_tbl_stubs.h"
#include "ut_cfe_fs_stubs.h"
#include "ut_cfe_time_stubs.h"

int32 hookCalledCount = 0;

/**************************************************************************
 * Tests for MS5607_InitEvent()
 **************************************************************************/

/**
 * Test MS5607_InitEvent() with failed CFE_EVS_Register
 */
void Test_MS5607_InitEvent_Fail_Register(void)
{
    MS5607 oMS5607;

    /* Set a fail result for EVS */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_EVENTS_SERVICE | CFE_EVS_NOT_IMPLEMENTED;
    int32 expected = CFE_EVS_APP_NOT_REGISTERED;

    Ut_CFE_EVS_SetReturnCode(UT_CFE_EVS_REGISTER_INDEX, expected, 1);

    /* Execute the function being tested */
    result = oMS5607.InitEvent();

    /* Verify results */
    UtAssert_True (result == expected, "InitEvent, failed EVS Register");
}


/**************************************************************************
 * Tests for MS5607_InitPipe()
 **************************************************************************/
/**
 * Test MS5607_InitPipe(), fail SCH CFE_SB_CreatePipe
 */
void Test_MS5607_InitPipe_Fail_CreateSCHPipe(void)
{
    MS5607 oMS5607;

    /* Set a fail result for SB */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 1);

    /* Execute the function being tested */
    result = oMS5607.InitPipe();

    /* Verify results */
    UtAssert_True (result == expected, "InitPipe, fail SB create SCH pipe");
}


/**
 * Test MS5607_InitPipe(), fail CFE_SB_SubscribeEx for wakeup
 */
void Test_MS5607_InitPipe_Fail_SubscribeWakeup(void)
{
    MS5607 oMS5607;

    /* Set a fail result for SB */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_SUBSCRIBEEX_INDEX, expected, 1);

    /* Execute the function being tested */
    result = oMS5607.InitPipe();

    /* Verify results */
    UtAssert_True (result == expected, "InitPipe, fail CFE_SB_SubscribeEx for wakeup");
}


/**
 * Test MS5607_InitPipe(), fail CFE_SB_SubscribeEx for sendhk
 */
void Test_MS5607_InitPipe_Fail_SubscribeSendHK(void)
{
    MS5607 oMS5607;

    /* Set a fail result for SB */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_SUBSCRIBEEX_INDEX, expected, 2);

    /* Execute the function being tested */
    result = oMS5607.InitPipe();

    /* Verify results */
    UtAssert_True (result == expected, "InitPipe, fail CFE_SB_SubscribeEx for sendhk");
}


/**
 * Test MS5607_InitPipe(), fail CMD CFE_SB_CreatePipe
 */
void Test_MS5607_InitPipe_Fail_CreateCMDPipe(void)
{
    MS5607 oMS5607;

    /* Set a fail result for SB */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 2);

    /* Execute the function being tested */
    result = oMS5607.InitPipe();

    /* Verify results */
    UtAssert_True (result == expected, "InitPipe, fail SB create CMD pipe");
}


/**
 * Test MS5607_InitPipe(), fail CFE_SB_Subscribe for CMD msg
 */
void Test_MS5607_InitPipe_Fail_SubscribeCMD(void)
{
    MS5607 oMS5607;

    /* Set a fail result for SB */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_SUBSCRIBE_INDEX, expected, 1);

    /* Execute the function being tested */
    result = oMS5607.InitPipe();

    /* Verify results */
    UtAssert_True (result == expected, "InitPipe, fail CFE_SB_Subscribe for CMD");
}


/**
 * Test MS5607_InitPipe(), fail DATA CFE_SB_CreatePipe
 */
void Test_MS5607_InitPipe_Fail_CreateDATAPipe(void)
{
    MS5607 oMS5607;

    /* Set a fail result for SB */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_SOFTWARE_BUS_SERVICE | CFE_SB_NOT_IMPLEMENTED;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 2);

    /* Execute the function being tested */
    result = oMS5607.InitPipe();

    /* Verify results */
    UtAssert_True (result == expected, "InitPipe, fail SB create DATA pipe");
}


/**************************************************************************
 * Tests for MS5607_InitData()
 **************************************************************************/
/**
 * Test MS5607_InitData()
 */
void Test_MS5607_InitData(void)
{
    MS5607 oMS5607;

    /* Set a fail result */
    int32 expected = CFE_SUCCESS;

    /* Execute the function being tested */
    oMS5607.InitData();

    /* Verify results */
    //UtAssert_True (result == expected, "InitData");
}


/**************************************************************************
 * Tests for MS5607_InitApp()
 **************************************************************************/
/**
 * Test MS5607_InitApp(), fail init event
 */
void Test_MS5607_InitApp_Fail_InitEvent(void)
{
    MS5607 oMS5607;

    int32 result = CFE_SUCCESS;
    int32 expected = CFE_EVS_APP_NOT_REGISTERED;

    Ut_CFE_EVS_SetReturnCode(UT_CFE_EVS_REGISTER_INDEX, expected, 1);

    /* Execute the function being tested */
    result = oMS5607.InitApp();

    /* Verify results */
    UtAssert_True (result == expected, "InitApp, fail init event");
}


/**
 * Test MS5607_InitApp(), fail init pipe
 */
void Test_MS5607_InitApp_Fail_InitPipe(void)
{
    MS5607 oMS5607;

    int32 result = CFE_SUCCESS;
    int32 expected = CFE_SB_BAD_ARGUMENT;

    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_CREATEPIPE_INDEX, expected, 1);

    /* Execute the function being tested */
    result = oMS5607.InitApp();

    /* Verify results */
    UtAssert_True (result == expected, "InitApp, fail init pipe");
}


/**
 * Test MS5607_InitApp(), fail init data.
 * NOTE: no current way to fail MS5607_InitData() in default
 */
void Test_MS5607_InitApp_Fail_InitData(void)
{
    MS5607 oMS5607;

    int32 result = 1;
    int32 expected = CFE_SUCCESS;

    /* Execute the function being tested */
    result = oMS5607.InitApp();

    /* Verify results */
    UtAssert_True (result == expected, "InitApp, fail init data");
}


/**
 * Test MS5607_InitApp(), fail init config table
 */
void Test_MS5607_InitApp_Fail_InitConfigTbl(void)
{
    MS5607 oMS5607;

    int32 result = CFE_SUCCESS;
    int32 expected = CFE_TBL_ERR_INVALID_NAME;

    Ut_CFE_TBL_SetReturnCode(UT_CFE_TBL_REGISTER_INDEX, expected, 1);

    /* Execute the function being tested */
    result = oMS5607.InitApp();

    /* Verify results */
    UtAssert_True (result == expected, "InitApp, fail init config table");
}


/**
 * Test MS5607_InitApp(), Nominal
 */
void Test_MS5607_InitApp_Nominal(void)
{
    MS5607 oMS5607;

    /* Set a fail result for SB */
    int32 result = (CFE_SEVERITY_BITMASK & CFE_SEVERITY_ERROR)
                   | CFE_EXECUTIVE_SERVICE | CFE_ES_ERR_APP_REGISTER;
    int32 expected = CFE_SUCCESS;

    /* Execute the function being tested */
    result = oMS5607.InitApp();

    /* Verify results */
    UtAssert_True (result == expected, "InitApp, nominal");
}

/**************************************************************************
 * Tests for MS5607_AppMain()
 **************************************************************************/
/**
 * Test MS5607_AppMain(), Fail RegisterApp
 */
void Test_MS5607_AppMain_Fail_RegisterApp(void)
{
    MS5607 oMS5607;

    /* fail the register app */
    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_REGISTERAPP_INDEX, CFE_ES_ERR_APP_REGISTER, 1);

    /* Execute the function being tested */
    oMS5607.AppMain();
}


/**
 * Test MS5607_AppMain(), Fail InitApp
 */
void Test_MS5607_AppMain_Fail_InitApp(void)
{
    MS5607 oMS5607;

    /* fail the register app */
    Ut_CFE_EVS_SetReturnCode(UT_CFE_EVS_REGISTER_INDEX, CFE_EVS_APP_NOT_REGISTERED, 1);

    /* Execute the function being tested */
    oMS5607.AppMain();
}


/**
 * Test MS5607_AppMain(), Fail AcquireConfigPtrs
 */
void Test_MS5607_AppMain_Fail_AcquireConfigPtrs(void)
{
    MS5607 oMS5607;

    /* fail the register app */
    Ut_CFE_TBL_SetReturnCode(UT_CFE_TBL_GETADDRESS_INDEX, CFE_TBL_ERR_INVALID_HANDLE, 2);

    /* Execute the function being tested */
    oMS5607.AppMain();
}


/**
 * Test MS5607_AppMain(), Invalid Schedule Message
 */
void Test_MS5607_AppMain_InvalidSchMessage(void)
{
    MS5607 oMS5607;

    /* The following will emulate behavior of receiving a SCH message to send HK */
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_RCVMSG_INDEX, CFE_SUCCESS, 1);
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_GETMSGID_INDEX, 0, 1);

    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_RUNLOOP_INDEX, FALSE, 2);

    /* Execute the function being tested */
    oMS5607.AppMain();

}


/**
 * Hook to support: MS5607_AppMain(), Nominal - SendHK
 */
int32 Test_MS5607_AppMain_Nominal_SendHK_SendMsgHook(CFE_SB_Msg_t *MsgPtr)
{
    /* TODO:  Test the contents of your HK message here. */

    hookCalledCount++;

    return CFE_SUCCESS;
}

/**
 * Test MS5607_AppMain(), Nominal - SendHK
 */
void Test_MS5607_AppMain_Nominal_SendHK(void)
{
    MS5607 oMS5607;

    /* The following will emulate behavior of receiving a SCH message to WAKEUP */
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_RCVMSG_INDEX, CFE_SUCCESS, 1);
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_GETMSGID_INDEX, MS5607_SEND_HK_MID, 1);

    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_RUNLOOP_INDEX, FALSE, 2);

    /* Used to verify HK was transmitted correctly. */
    hookCalledCount = 0;
    Ut_CFE_ES_SetFunctionHook(UT_CFE_SB_SENDMSG_INDEX, (void*)&Test_MS5607_AppMain_Nominal_SendHK_SendMsgHook);

    /* Execute the function being tested */
    oMS5607.AppMain();

    /* Verify results */
    UtAssert_True (hookCalledCount == 1, "AppMain_Nominal_SendHK");

}


/**
 * Test MS5607_AppMain(), Nominal - Wakeup
 */
void Test_MS5607_AppMain_Nominal_Wakeup(void)
{
    MS5607 oMS5607;

    /* The following will emulate behavior of receiving a SCH message to WAKEUP */
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_RCVMSG_INDEX, CFE_SUCCESS, 1);
    Ut_CFE_SB_SetReturnCode(UT_CFE_SB_GETMSGID_INDEX, MS5607_MEASURE_MID, 1);

    Ut_CFE_ES_SetReturnCode(UT_CFE_ES_RUNLOOP_INDEX, FALSE, 2);

    /* Execute the function being tested */
    //oMS5607.AppMain();

}


/**
 * Test UpdateParamsFromTable(), Nominal
 */
void Test_MS5607_UpdateParamsFromTable_Nominal(void)
{
    MS5607 oMS5607;
    
    oMS5607.InitApp();
    oMS5607.UpdateParamsFromTable();

    /* Verify results */
    UtAssert_True(oMS5607.m_Params.p1 == oMS5607.ConfigTblPtr->p1, "m_Param != ConfigTblPtr");
}


/**
 * Test MS5607_CleanupCallback(), Nominal
 * No way to fail cleanupcallback()
 */
void Test_MS5607_CleanupCallback_Nominal(void)
{
    MS5607_CleanupCallback();
}


/**************************************************************************
 * Rollup Test Cases
 **************************************************************************/
void MS5607_App_Test_AddTestCases(void)
{
    UtTest_Add(Test_MS5607_InitEvent_Fail_Register, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitEvent_Fail_Register");

    UtTest_Add(Test_MS5607_InitPipe_Fail_CreateSCHPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_CreateSCHPipe");
    UtTest_Add(Test_MS5607_InitPipe_Fail_SubscribeWakeup, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_SubscribeWakeup");
    UtTest_Add(Test_MS5607_InitPipe_Fail_SubscribeSendHK, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_SubscribeSendHK");
    UtTest_Add(Test_MS5607_InitPipe_Fail_CreateCMDPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_CreateCMDPipe");
    UtTest_Add(Test_MS5607_InitPipe_Fail_SubscribeCMD, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_SubscribeCMD");
    UtTest_Add(Test_MS5607_InitPipe_Fail_CreateDATAPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitPipe_Fail_CreateDATAPipe");

    UtTest_Add(Test_MS5607_InitData, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitData");

    UtTest_Add(Test_MS5607_InitApp_Fail_InitEvent, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitEvent");
    UtTest_Add(Test_MS5607_InitApp_Fail_InitPipe, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitPipe");
    UtTest_Add(Test_MS5607_InitApp_Fail_InitData, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitData");
    UtTest_Add(Test_MS5607_InitApp_Fail_InitConfigTbl, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Fail_InitConfigTbl");
    UtTest_Add(Test_MS5607_InitApp_Nominal, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_InitApp_Nominal");

    UtTest_Add(Test_MS5607_AppMain_Fail_RegisterApp, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Fail_RegisterApp");
    UtTest_Add(Test_MS5607_AppMain_Fail_InitApp, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Fail_InitApp");
    UtTest_Add(Test_MS5607_AppMain_Fail_AcquireConfigPtrs, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Fail_AcquireConfigPtrs");
    UtTest_Add(Test_MS5607_AppMain_InvalidSchMessage, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_InvalidSchMessage");
    UtTest_Add(Test_MS5607_AppMain_Nominal_SendHK, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Nominal_SendHK");
    UtTest_Add(Test_MS5607_AppMain_Nominal_Wakeup, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_AppMain_Nominal_Wakeup");
    UtTest_Add(Test_MS5607_UpdateParamsFromTable_Nominal, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_UpdateParamsFromTable_Nominal");
    UtTest_Add(Test_MS5607_CleanupCallback_Nominal, MS5607_Test_Setup, MS5607_Test_TearDown,
               "Test_MS5607_CleanupCallback_Nominal");
}


