⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voip_auto_test.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VOIP sample
 |
 |	Filename:   	voip_auto_test.c
 |
 |	Copyright:  	TelcoBridges 2002-2004, All Rights Reserved
 |
 |	Description:	This file contains the entry point of the state machine of this application
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.6 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.6 $";
#endif

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/
#include "voip_includes.h"

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Forward declarations
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipInitAutoTest				:	Initialize auto test 
 |
 |  ~								:	No parameters
 |									
 |  Note							:	~
 |									
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipInitAutoTest()
{
	PVOIP_AUTO_TEST_DELEGATE			pVoipTestDelegate;
	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* initialize the host test controller handle */
		g_pContext->TestModeContext.hHostHandle = 0;
		g_pContext->TestModeContext.fLaunchConfirmSend = TBX_FALSE;

		/* create pool of buffer */
		g_pContext->TestModeContext.hPoolTestFunction = TBXPoolOfBuffersCreate
		(
			VOIP_MAX_TEST_COUNT,
			sizeof(VOIP_AUTO_TEST_DELEGATE),
			VoipTestDelegatePoolGetKey,
			NULL,
			TBX_TRUE
		);
		if( g_pContext->TestModeContext.hPoolTestFunction == TBX_HANDLE_INVALID )
		{
			TBX_EXIT_ERROR ( TBX_RESULT_FAIL, 0, "Could not create test delegate pool of buffer." );
		}

		/* add all voip tests */
		/* start command test */
		/* first test is a dummy test */
		pVoipTestDelegate = TBXPoolOfBuffersAlloc(
			g_pContext->TestModeContext.hPoolTestFunction,
			(TBX_HASH_KEY)"testConnect01" );
		if( pVoipTestDelegate == NULL )
		{
			TBX_EXIT_ERROR ( TBX_RESULT_FAIL, 0, "Could not allocate delegate: testConnect01." );
		}
		strcpy( pVoipTestDelegate->szTestId, "testConnect01" );
		pVoipTestDelegate->pFctStartTest = VoipStartTestConnect01;
		pVoipTestDelegate->pFctStopTest = NULL/*VoipStopTestConnect01*/;

		/* second test will start a stress test */
		pVoipTestDelegate = TBXPoolOfBuffersAlloc(
			g_pContext->TestModeContext.hPoolTestFunction,
			(TBX_HASH_KEY)VOIP_TEST_STRESS_TEST_NAME );
		if( pVoipTestDelegate == NULL )
		{
			TBX_EXIT_ERROR ( TBX_RESULT_FAIL, 0, "Could not allocate delegate: TESTCONNECT01." );
		}
		strcpy( pVoipTestDelegate->szTestId, VOIP_TEST_STRESS_TEST_NAME );
		pVoipTestDelegate->pFctStartTest = VoipStartStressTest01;
		pVoipTestDelegate->pFctStopTest = VoipStopStressTest01;

#if 0
		/* third test will start but fail */
		pVoipTestDelegate = TBXPoolOfBuffersAlloc(
			g_pContext->TestModeContext.hPoolTestFunction,
			(TBX_HASH_KEY)"testStartFail01" );
		if( pVoipTestDelegate == NULL )
		{
			TBX_EXIT_ERROR ( TBX_RESULT_FAIL, 0, "Could not allocate delegate: testStartFail01." );
		}
		strcpy( pVoipTestDelegate->szTestId, "testStartFail01" );
		pVoipTestDelegate->pFctStartTest = VoipStartTestFail01;
		pVoipTestDelegate->pFctStopTest = NULL;

		/* fourth test will fail to start */
		pVoipTestDelegate = TBXPoolOfBuffersAlloc(
			g_pContext->TestModeContext.hPoolTestFunction,
			(TBX_HASH_KEY)"testStartDontStart01" );
		if( pVoipTestDelegate == NULL )
		{
			TBX_EXIT_ERROR ( TBX_RESULT_FAIL, 0, "Could not allocate delegate: testStartDontStart01." );
		}
		strcpy( pVoipTestDelegate->szTestId, "testStartDontStart01" );
		pVoipTestDelegate->pFctStartTest = VoipStartTestDontStart01;
		pVoipTestDelegate->pFctStopTest = NULL;

		/* stop command test */
		/* first test will start and stop a test successfully */
		pVoipTestDelegate = TBXPoolOfBuffersAlloc(
			g_pContext->TestModeContext.hPoolTestFunction,
			(TBX_HASH_KEY)"testStopSuccess01" );
		if( pVoipTestDelegate == NULL )
		{
			TBX_EXIT_ERROR ( TBX_RESULT_FAIL, 0, "Could not allocate delegate: testStopSuccess01." );
		}
		strcpy( pVoipTestDelegate->szTestId, "testStopSuccess01" );
		pVoipTestDelegate->pFctStartTest = VoipStopTestSuccess01;
		pVoipTestDelegate->pFctStopTest = VoipStopTestSuccess02;

		/* secont test will start a test but the stop command will fail */
		pVoipTestDelegate = TBXPoolOfBuffersAlloc(
			g_pContext->TestModeContext.hPoolTestFunction,
			(TBX_HASH_KEY)"testStopDontStop01" );
		if( pVoipTestDelegate == NULL )
		{
			TBX_EXIT_ERROR ( TBX_RESULT_FAIL, 0, "Could not allocate delegate: testStopDontStop01." );
		}
		strcpy( pVoipTestDelegate->szTestId, "testStopDontStop01" );
		pVoipTestDelegate->pFctStartTest = VoipStopTestDontStop01;
		pVoipTestDelegate->pFctStopTest = VoipStopTestDontStop02;
#endif
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ERROR,
			FRED,
			"VoipInitAutoTest: %s\n", TBX_ERROR_DESCRIPTION );
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
	
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipTestDelegatePoolGetKey			:	Function to get hash key from pointer of attached test application.
 |													The pool of buffers hash key is the adapter name.
 |
 |	in_pUserContext						:	Pointer to the user context (not used)
 |  in_pTestDirectoryContext			:	Pointer to an string that contains the test delegate
 |											(cast to PVOIP_HA_CALLCTRL_AUTO_TEST_DELEGATE)
 |
 |  Note								:	~
 |
 |  Return								:	TBX_HASH_KEY
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_HASH_KEY VoipTestDelegatePoolGetKey
(
	IN		PTBX_VOID				in_pUserContext,
	IN		PTBX_VOID				in_pTestDelegate
)
{
	(void)in_pUserContext;

	return (TBX_HASH_KEY) ( ( (PVOIP_AUTO_TEST_DELEGATE)in_pTestDelegate )->szTestId );
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipFreeAutoTest				:	Free the test function pool of buffer 
 |
 |  ~								:	No parameters
 |									
 |  Note							:	~
 |									
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipFreeAutoTest()
{
	PVOIP_AUTO_TEST_DELEGATE			pVoipTestDelegate;
	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* free each buffer */
		pVoipTestDelegate = TBXPoolOfBuffersFirst(	g_pContext->TestModeContext.hPoolTestFunction );
		while( pVoipTestDelegate != NULL )
		{
			TBXPoolOfBuffersFree( g_pContext->TestModeContext.hPoolTestFunction, pVoipTestDelegate );
			pVoipTestDelegate = TBXPoolOfBuffersFirst(	g_pContext->TestModeContext.hPoolTestFunction );
		}

		/* destroy the pool */
		TBXPoolOfBuffersDestroy( g_pContext->TestModeContext.hPoolTestFunction );

		/* set the host test controller handle to an invalid value */
		g_pContext->TestModeContext.hHostHandle = 0;

		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ERROR,
			FRED,
			"VoipFreeAutoTest: %s\n", TBX_ERROR_DESCRIPTION);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
	
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipDisplayTestAvailable		:	Display all available tests
 |
 |									
 |  Note							:	~
 |									
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID	VoipDisplayTestAvailable()
{
	PVOIP_AUTO_TEST_DELEGATE		pAutoTest;
	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		if( g_pContext->TestModeContext.hPoolTestFunction != TBX_HANDLE_INVALID )
		{
			pAutoTest = TBXPoolOfBuffersLast( g_pContext->TestModeContext.hPoolTestFunction );

			while( pAutoTest != NULL )
			{
				TbxCliToolsLogPrint(
					g_pContext->CliContext.hCliTools,
					TRACE_LEVEL_ALWAYS,
					FWHITE,
					"Test found: %s\n", pAutoTest->szTestId );
				pAutoTest = TBXPoolOfBuffersPrev( g_pContext->TestModeContext.hPoolTestFunction, pAutoTest );

			}
		}

		TBX_EXIT_SUCCESS (TBX_RESULT_OK);

	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ERROR,
			FRED,
			"VoipDisplayTestAvailable: %s\n", TBX_ERROR_DESCRIPTION );
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStartTestConnect01			:	This test will send a notification to the test controller that the test succeed
 |
 |	in_hMsg							:	Message received
 |  in_pszTestParameter				:	Parameters of the test
 |									
 |  Note							:	~
 |									
 |  Return							:	TBX_RESULT_OK if the function succeeded
 |										Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipStartTestConnect01
(
	IN		TBX_MSG_HANDLE				in_hMsg,
	IN		PTBX_CHAR					in_pszTestParameter
)
{
	TBX_RESULT			Result = TBX_RESULT_OK;
	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ALWAYS,
			FGREEN,
			"VoipStartTestConnect01 successfully started with parameter: %s\n", in_pszTestParameter );

		/* send confirmation */
		Result = TBTestLibSendConfirmStartTestMessage
		(
			g_pContext->hTbxLib,
			TBX_MSG_ADAPTER_HANDLE_GET( in_hMsg ),
			0,
			g_pContext->TestModeContext.un32TestId,
			TBX_RESULT_AUTOTEST_OK
		);
		if( TBX_RESULT_FAILURE( Result ) )
		{
			TbxCliToolsLogPrint(
				g_pContext->CliContext.hCliTools,
				TRACE_LEVEL_ERROR,
				FRED,
				"Start test confirmation message failed: 0x%X\n", Result);
		}

		/* send end test succeed message */
		Result = TBTestLibSendConfirmTestTerminateMessage
		(
			g_pContext->hTbxLib,
			TBX_MSG_ADAPTER_HANDLE_GET( in_hMsg ),
			0,
			g_pContext->TestModeContext.un32TestId,
			TBX_RESULT_AUTOTEST_OK
		);
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint(
			g_pContext->CliContext.hCliTools,
			TRACE_LEVEL_ERROR,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -