#include "./include/CUnit.h"
#include "./include/CUError.h"
#include "./include/Automated.h"
#define MGC_TEST_ENABLE 


#include "../../public/src/include/includes.h"
#include "../../public/src/include/public.h"



#include "../src/include/mgc_struct.h"
#include "../src/include/mgc_8ecp.h"
#include "../src/include/mgc_chnl_info.h"
#include "../src/include/mgc_conn_info.h"
#include "../src/include/mgc_ctl.h"
#include "../src/include/mgc_internal.h"
#include "../src/include/mgc_mgcp.h"
#include "../src/include/mgc_mg_info.h"
#include "../src/include/mgc_port_info.h"
#include "../src/include/mgc_phy_port.h"
#include "../src/include/mgc.h"
#include "../src/include/mgc_debug.h"
#include "../src/include/mgc_tandem_info.h"
#include "../src/include/mgc_sur_info.h"

#include "../../mgcp/src/include/mgcp.h"

#include "../src/mgc.c"
#include "../src/mgc_8ecp.c"
#include "../src/mgc_chnl_info.c"
#include "../src/mgc_conn_info.c"
#include "../src/mgc_ctl.c"
#include "../src/mgc_internal.c"
#include "../src/mgc_mgcp.c"
#include "../src/mgc_mg_info.c"
#include "../src/mgc_phy_port.c"
#include "../src/mgc_port_info.c"
#include "../src/mgc_tandem_info.c"
#include "../src/mgc_sur_info.c"

#include "../src/mgc_debug.c"
#include "../../rtp/src/include/rtp.h"


extern void mgcp_init(void);
extern void mgcp_timer(void);
extern	void debug_init();
extern int iptrMainInit();
extern 	void snmp_init(WORD nport);

#define MGC_TEST_SAP_NUM 10
#define MGC_TEST_MG_NUM 1025

typedef enum
{
    OPERA_STATE_UNDEF =-1,
    OPERA_STATE_SEND,
	OPERA_STATE_GET,			
}OPERA_STATE;


typedef struct _opera_struct
{
    int userPort;
	OPERA_STATE status;
    MGC_OPER_RESULT	result;
}opera_struct;


typedef struct _test_mgc_sap
{
	int id;
	MGC_SAP mgcSap;
	int sapIndex;
}test_mgc_sap;


typedef struct _test_mg
{
    int mgNo;
	int userPort;	
	int PortType;
	int portNo;
	BOOL enable;
	MG_ATTR mgAttr;
	test_mgc_sap *pMgcsap;
}test_mg;

typedef struct _MGC_RTP_SAP
{
	RTP_SAP rtpSap;
	int rtpSapIndex;
	int hdlport;
	int userPort;
	WORD localport;
	char localIP[33];
}MGC_RTP_SAP;



test_mg mgA , mgB , mgRtpProxy , mgAas;
test_mgc_sap testSap[MGC_TEST_SAP_NUM];
opera_struct testOpera;
MGC_RTP_SAP mgcRtpSap;


int	mgc_rtp_handshake(WORD usrPort, WORD hdlPort, WORD rtpPort)
{
    return 1;
}

int mgc_rtp_recv(WORD usrPort, WORD hdlPort, BYTE pt, WORD sn, BYTE *payload, WORD len)
{
    
	fputs(payload, stdout);    
	memset(payload , 0 , len);
    return 0;
}

BOOL mgc_test_rtp_bind(MGC_RTP_SAP *pRtpSap)
{
    RTP_SAP *pSap;
    if(pRtpSap == NULL)
        return FALSE;
    
    pSap = &(pRtpSap->rtpSap);
    sprintf(pSap->name , "MGC_RTP_SAP");
	pSap->rtp_handshake = mgc_rtp_handshake;
	pSap->rtp_recv = mgc_rtp_recv;
    pRtpSap->rtpSapIndex = rtp_bind(pSap);

    if(pRtpSap->rtpSapIndex < 0)
        return FALSE;		

    return TRUE;    	
}


opera_struct *mgc_find_owner(WORD usrPort , WORD mgcPort)
{
    opera_struct *pOpera;

    pOpera = &testOpera;
    if(pOpera->userPort == usrPort)
	    return pOpera ;

    return NULL;	
}

int mgc_ind_test(CHNL chnl, MGC_CMD_TYPE cmd, WORD *usrPort, WORD mgcPort, MEDIA_ATTR *pMediaAttr)
{
    PUB_SDP_MSG *pSdp;
    MGC_DEBUG("mg[%d]port[%d]chnl[%d]conn[%d] get ind %s from mgcPort[%d]",
		        chnl.mgNo , chnl.portNo , chnl.chlNo , chnl.connectNo , mgc_port_info_print_cmd(cmd) , mgcPort);
    switch(cmd)
    {
        case MGC_CMD_AUEP:
			 *usrPort = mgcPort;
			 mgc_rsp(cmd, *usrPort, mgcPort, 200 , NULL);
			break;
		case MGC_CMD_CRCX:
			 *usrPort = mgcPort;
              if(pMediaAttr != NULL)		
              {
                  pSdp = &pMediaAttr->sdp;
				  MGC_DEBUG("remote ip : %s:%d" , pSdp->c.addr , pSdp->medias.medias[0].m.port);
              }
			  mgc_rsp(cmd, *usrPort, mgcPort, 200 , NULL);			
			  break;
		case MGC_CMD_DLCX:
			 *usrPort = mgcPort;
			  mgc_rsp(cmd, *usrPort, mgcPort, 250 , NULL);			
			  break;			  
		default:
			break;
    }

    return 0;
}

int mgc_cnf_test(WORD usrPort, WORD mgcPort, MGC_MG_OPER_ID_TYPE operId, MGC_OPER_RESULT success, WORD cause)
{
    opera_struct *pOpera = NULL;

    pOpera = mgc_find_owner(usrPort, mgcPort);
	if(pOpera)
	{
		if(pOpera->status== OPERA_STATE_SEND)
		{
			pOpera->status= OPERA_STATE_GET;
			pOpera->result = success;
			MGC_DEBUG("opera[%d] get response %s" , pOpera->userPort , success?"success":"failure");			
		}
		else
		{
			pOpera->result = MGC_OPER_FAILURE;		
			MGC_WARN("opera[%d] error state" , pOpera->userPort); 	
			CU_ASSERT_EQUAL_FATAL(pOpera->status , OPERA_STATE_SEND);
		}
	}
	else
	{
		MGC_WARN("usrPort :%d mgcPort :%d , lost owner" , usrPort , mgcPort);
	}
		

    return 0;
}


void test_mgc_wait_time(opera_struct *pOpera , int seconds)
{
	struct timeval t1 ,t2 , t3;


    if(pOpera == NULL)
        return;		

	MGC_DEBUG(" wait %d seconds....." , seconds);
	gettimeofday(&t2 , NULL);  	
	gettimeofday(&t3 , NULL);  
    while(1)
    {
         gettimeofday(&t1 , NULL);   
		 if(t1.tv_usec - t2.tv_usec > 10)	 
        {
			iptrans_timer();			
			mgcp_timer();
			debug_rt(); 
			rtp_timer();
			mgc_timer(); 			
			gettimeofday(&t2 , NULL); 
        }

	    if(t1.tv_sec - t3.tv_sec > seconds)
			pOpera->status = OPERA_STATE_UNDEF;
		    	

        if(pOpera->status!= OPERA_STATE_SEND)
		    return;	
    }

    return;		

}


void mgc_test_sap_init(test_mgc_sap *pSap , int id)
{
    if(pSap == NULL)
        return;

    pSap->id = id;
	sprintf(pSap->mgcSap.usrName , "test_mgcsap[%d]" , id);
	pSap->mgcSap.usrType = MGC_USER_TYPE_MGC;
	pSap->mgcSap.cnf_func = mgc_cnf_test;
	pSap->mgcSap.ind_func = NULL;
	return;
}

void mgc_test_mg_init(test_mg *pMg , char *name , char *mgAddr , int mgType , int PortType)
{
    if((pMg == NULL) ||(name == NULL)||(mgAddr == NULL))
        return;

    pMg->enable = FALSE;
	pMg->mgNo = -1;
    pMg->userPort = -1;
	pMg->PortType = PortType;

    pMg->pMgcsap = NULL;
	pMg->mgAttr.mgType = mgType;

    sprintf(pMg->mgAttr.domain, "%s" , name);
	pMg->mgAttr.codecList.num = 6;
	pMg->mgAttr.codecList.priority = 0;
    pMg->mgAttr.codecList.codec[0] = MGC_VCTYPE_PCMA;
    pMg->mgAttr.codecList.codec[1] = MGC_VCTYPE_PCMU;
    pMg->mgAttr.codecList.codec[2] = MGC_VCTYPE_GSM;
    pMg->mgAttr.codecList.codec[3] = MGC_VCTYPE_GSM_EFR;
    pMg->mgAttr.codecList.codec[4] = MGC_VCTYPE_AMR_12_2;
    pMg->mgAttr.codecList.codec[5] = MGC_VCTYPE_G729B;

    pMg->mgAttr.ctrlType = MGC_MG_CTRL_TYPE_MGCP;
	if(pMg->mgAttr.mgType == MGC_MG_TYPE_TANDEM)
	{	 
	   pMg->mgAttr.epDes = MGCP_EP_NAME_UNSTRUCTURED;
	}
	else
	{
	   pMg->mgAttr.epDes = MGCP_EP_NAME_STRUCTURED;
	}	
    pMg->mgAttr.toneCap = 1;
	pMg->mgAttr.ip = inet_addr(mgAddr);
	pMg->mgAttr.maxChnls = 512;
	pMg->mgAttr.ptime = 4*20;// 80ms	
	pMg->mgAttr.maxPorts = 30;
	pMg->mgAttr.auditTimer = 15*10;
	pMg->portNo = 0;
	return;    		
}


int mgc_cunit_clean(void)
{

    return 0;
}

BOOL mgc_get_local_ip(char *ipAddr)
{
    struct hostent  *host;
	char localName[50];

    if(ipAddr == NULL)
        return FALSE;

    if (gethostname(localName , 50) == -1)
    {
        return FALSE;
    }	

    if ((host = gethostbyname(localName)) == NULL)
    {
        return FALSE;
    }	

    sprintf(ipAddr, "%d.%d.%d.%d", 
            (BYTE)host->h_addr_list[0][0],
			(BYTE)host->h_addr_list[0][1],
			(BYTE)host->h_addr_list[0][2],
			(BYTE)host->h_addr_list[0][3]);	  

    return TRUE;	
}



int mgc_test_cunit_init(void)
{
    test_mgc_sap *pSap;
	char ipAddr[33];
    int i;
    debug_init();	
    iptrMainInit();
    mgcp_init();
	rtp_init();
	snmp_init(4957);
	mgc_get_local_ip(ipAddr);
    mgc_test_mg_init(&mgA , "mg-4444" , "172.54.240.202" , MGC_MG_TYPE_AudioCoder , MGC_PHY_PORT_TYPE_E1 );
    mgc_test_mg_init(&mgB , "mg-5555" , "172.54.240.214" , MGC_MG_TYPE_AudioCoder , MGC_PHY_PORT_TYPE_E1 );
    mgc_test_mg_init(&mgRtpProxy, "rtpproxy-1234" , "172.54.240.201" , MGC_MG_TYPE_TANDEM, MGC_PHY_VIRTUAL_TYPE_TANDEM);
    mgc_test_mg_init(&mgAas , "aas", ipAddr , MGC_MG_TYPE_ANN , MGC_PHY_VIRTUAL_TYPE_ANN);
    for(i=0 ; i<MGC_TEST_SAP_NUM ; i++)
    {
        pSap = &testSap[i];
		mgc_test_sap_init(pSap, i);
    }
    return 0;
}






void test_mgc_init(void)
{
    char localIp[35];

	MGC_DEBUG("enter %s", __FUNCTION__);
    mgc_get_local_ip(localIp);
	mgc_init(1234, inet_addr(localIp),  inet_addr("172.54.240.178"));
	
    return;
}


void test_mgc_sap_bind_and_unbind(void)
{
    int i , num ,ret;
    test_mgc_sap *pSap;

    num = 0;
    for(i=0 ; i<MGC_TEST_SAP_NUM ; i++)
    {
        pSap = &testSap[i];
		pSap->sapIndex = mgc_bind(&pSap->mgcSap);
		if(pSap->sapIndex >= 0)
		    num++;
    }
    MGC_DEBUG("testSap bind success %d" , num);
	CU_ASSERT_EQUAL_FATAL(num , MGC_MAX_NUM_OF_SAP-1);

    for(i=0 ; i<MGC_TEST_SAP_NUM ; i++)
    {
        pSap = &testSap[i];
		ret = mgc_unbind(&pSap->mgcSap , pSap->sapIndex);
        if(i < num)
        {
            CU_ASSERT_FATAL(ret>=0);
        }
		else
		{
		    CU_ASSERT_FATAL(ret < 0);
		}

		mgc_test_sap_init(pSap, pSap->id);
    }	

    return;	
}


void test_mgc_mg_create_and_delete(void)
{
    int i , num ,ret , k ;
    test_mgc_sap *pSap;
    test_mg mgTest[MGC_TEST_MG_NUM];
	test_mg *pMg = NULL;
    char buf[32];
	
    pSap = &testSap[0];
	ret = mgc_bind(&pSap->mgcSap);
    CU_ASSERT(ret>=0);
	pSap->sapIndex = ret;

    num = 0;
	k = mgc_mg_info_created_num();
    for(i=0 ; i<MGC_TEST_MG_NUM ; i++)
    {
        pMg = &mgTest[i];
		sprintf(buf , "testmg[%d]" , i);
        mgc_test_mg_init(pMg, buf , "192.168.1.20" , MGC_MG_TYPE_AudioCoder , MGC_PHY_PORT_TYPE_E1);
		pMg->pMgcsap = pSap;
		ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr);
		if(ret>=0)
		    num++;	
		pMg->mgNo = ret;
    }

    CU_ASSERT_EQUAL_FATAL(num , (mgc_mg_info_created_num()-k));
	CU_ASSERT_EQUAL_FATAL(mgc_mg_info_created_num() , mgc_ctl_mg_num());

    for(i=0 ; i<MGC_TEST_MG_NUM ; i++)
    {
        pMg = &mgTest[i];
        ret = mgc_delete_MG(pMg->pMgcsap->sapIndex , pMg->mgNo);
		if(i < num)
		{
            CU_ASSERT_FATAL(ret>=0);
		
		}
		else
		{
            CU_ASSERT_FATAL(ret<0);		
		}
	}

    CU_ASSERT_EQUAL_FATAL(mgc_mg_info_created_num() , mgc_ctl_mg_num());
    CU_ASSERT_EQUAL_FATAL(k , mgc_ctl_mg_num());    
	mgc_unbind(&pSap->mgcSap , pSap->sapIndex);
    return;	
}




void test_mgc_mg_max_num_ctl(void)
{
    int i , num ,ret , k , maxNum;
    test_mgc_sap *pSap;
    test_mg mgTest[MGC_TEST_MG_NUM];
	test_mg *pMg = NULL;
    char buf[32];
	
    pSap = &testSap[0];
	ret = mgc_bind(&pSap->mgcSap);
    CU_ASSERT(ret>=0);
	pSap->sapIndex = ret;

    maxNum = MGC_TEST_MG_NUM/2;
	mgc_ctl_set_mg_max_num(maxNum);
    num = 0;
	k = mgc_mg_info_created_num();
    for(i=0 ; i<MGC_TEST_MG_NUM ; i++)
    {
        pMg = &mgTest[i];
		sprintf(buf , "testmg[%d]" , i);
        mgc_test_mg_init(pMg, buf , "192.168.1.20" , MGC_MG_TYPE_AudioCoder , MGC_PHY_PORT_TYPE_E1);
		pMg->pMgcsap = pSap;
		ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr);
		if(ret>=0)
		    num++;	
		pMg->mgNo = ret;
    }
    CU_ASSERT_EQUAL_FATAL(num , maxNum);
    CU_ASSERT_EQUAL_FATAL(num , (mgc_mg_info_created_num()-k));
	CU_ASSERT_EQUAL_FATAL(mgc_mg_info_created_num() , mgc_ctl_mg_num());
    
    for(i=0 ; i<MGC_TEST_MG_NUM ; i++)
    {
        pMg = &mgTest[i];
        ret = mgc_delete_MG(pMg->pMgcsap->sapIndex , pMg->mgNo);
		if(i < num)
		{
            CU_ASSERT_FATAL(ret>=0);
		
		}
		else
		{
            CU_ASSERT_FATAL(ret<0);		
		}
	}

    CU_ASSERT_EQUAL_FATAL(mgc_mg_info_created_num() , mgc_ctl_mg_num());
    CU_ASSERT_EQUAL_FATAL(k , mgc_ctl_mg_num());
    mgc_ctl_set_mg_max_num(MGC_MAX_NUM_OF_MG);	
	mgc_unbind(&pSap->mgcSap , pSap->sapIndex);
    return;	
}



void test_mgc_mg_create_twice(void)
{
    int num ,ret , k ;
    test_mgc_sap *pSap;
	test_mg *pMg = NULL;

	pMg = &mgA;
    pSap = &testSap[0];
	ret = mgc_bind(&pSap->mgcSap);
    CU_ASSERT(ret>=0);
	pSap->sapIndex = ret;

	num = mgc_mg_info_created_num();
	pMg->pMgcsap = pSap;   
    ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr); 
	CU_ASSERT(ret >= 0);
	pMg->mgNo = ret;

    k = mgc_mg_info_created_num();	
    ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr); 
	CU_ASSERT(ret >= 0);
	CU_ASSERT_EQUAL_FATAL(ret , pMg->mgNo);
	CU_ASSERT_EQUAL_FATAL(k , mgc_mg_info_created_num());
	CU_ASSERT_EQUAL_FATAL(k , mgc_ctl_mg_num());

    ret = mgc_delete_MG(pMg->pMgcsap->sapIndex , pMg->mgNo);
	CU_ASSERT(ret >= 0);	
    ret = mgc_delete_MG(pMg->pMgcsap->sapIndex , pMg->mgNo);
	CU_ASSERT(ret < 0);	
	CU_ASSERT_EQUAL_FATAL(num , mgc_mg_info_created_num());	
	mgc_unbind(&pSap->mgcSap , pSap->sapIndex);
    return;
}


void test_mgc_port_add_and_delete(void)
{
    int i , num ,ret , k ;
    test_mgc_sap *pSap;
	test_mg *pMg = NULL;
    PHY_PORT_INFO phyPort;
	
	pMg = &mgA;
    pSap = &testSap[0];
	ret = mgc_bind(&pSap->mgcSap);
    CU_ASSERT(ret>=0);
	pSap->sapIndex = ret;

    num = mgc_chnl_info_assigned_num();	
    pMg->pMgcsap = pSap;   
    ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr); 
    CU_ASSERT(ret >= 0);
    pMg->mgNo = ret;

    k = 0;
    for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
    {
        ret = mgc_add_port(pMg->pMgcsap->sapIndex ,pMg->mgNo, i , pMg->PortType);
		if(ret >= 0)
		{
		    mgc_phy_port_set_chnl_num(&phyPort, pMg->PortType);
			k += phyPort.chnlNum;
		}
    }

	CU_ASSERT_EQUAL_FATAL(k , mgc_ctl_chnl_num()-num);
	CU_ASSERT_EQUAL_FATAL(mgc_ctl_chnl_num() , mgc_chnl_info_assigned_num());

    for(i=0 ; i<MGC_MAX_PHY_PORT_PER_MG ; i++)
    {
	    ret = mgc_delete_port(pMg->pMgcsap->sapIndex ,pMg->mgNo, i);
    }

	CU_ASSERT_EQUAL_FATAL(num , mgc_chnl_info_assigned_num());
	CU_ASSERT_EQUAL_FATAL(mgc_ctl_chnl_num() , mgc_chnl_info_assigned_num());	
	mgc_unbind(&pSap->mgcSap , pSap->sapIndex);
	return;
}


void test_mgc_create_mg_a(void)
{
    int ret;
	opera_struct opera;
    test_mgc_sap *pSap;
	test_mg *pMg = NULL;
    MG_INFO *pMgInfo;
    pSap = &testSap[0];
    ret = mgc_bind(&pSap->mgcSap);
    CU_ASSERT(ret>=0);
    pSap->sapIndex = ret;

	MGC_DEBUG("enter %s", __FUNCTION__);
	
	pMg = &mgA;
	pMg->pMgcsap = pSap;
	ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr);
	CU_ASSERT(ret >= 0);
	pMg->mgNo = ret;

    pMg->portNo = 0;
	ret = mgc_add_port(pMg->pMgcsap->sapIndex  ,pMg->mgNo , pMg->portNo , pMg->PortType);
	CU_ASSERT(ret >= 0);

    opera.status = OPERA_STATE_SEND;
	test_mgc_wait_time(&opera , 2);
	pMgInfo = mgc_mg_info_get_index_mg(pMg->mgNo);
	CU_ASSERT_PTR_NOT_NULL_FATAL(pMgInfo);
    if(pMgInfo->enable == FALSE)
    {
        MGC_ERROR("mg[%d] %s is not detected" , pMg->mgNo, pMg->mgAttr.domain);
    }
	CU_ASSERT_TRUE_FATAL(pMgInfo->enable);
  	
	MGC_DEBUG("mg[%d] %s  , bind mgcSap[%d] , attach phyport[%d]" , pMg->mgNo, pMg->mgAttr.domain , 
		                pMg->pMgcsap->sapIndex , ret);		
	return;
}


void test_mgc_create_mg_b(void)
{
    int ret;
	opera_struct opera;
    test_mgc_sap *pSap;
	test_mg *pMg = NULL;
    MG_INFO *pMgInfo;
    pSap = &testSap[0];
    ret = mgc_bind(&pSap->mgcSap);
    CU_ASSERT(ret>=0);
    pSap->sapIndex = ret;

	MGC_DEBUG("enter %s", __FUNCTION__);	
	pMg = &mgB;
	pMg->pMgcsap = pSap;
	ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr);
	CU_ASSERT(ret >= 0);
	pMg->mgNo = ret;

    pMg->portNo = 0;
	ret = mgc_add_port(pMg->pMgcsap->sapIndex  ,pMg->mgNo , pMg->portNo , pMg->PortType);
	CU_ASSERT(ret >= 0);

    opera.status = OPERA_STATE_SEND;
	test_mgc_wait_time(&opera , 2);
	pMgInfo = mgc_mg_info_get_index_mg(pMg->mgNo);
	CU_ASSERT_PTR_NOT_NULL_FATAL(pMgInfo);
    if(pMgInfo->enable == FALSE)
    {
        MGC_ERROR("mg[%d] %s is not detected" , pMg->mgNo, pMg->mgAttr.domain);
    }
	CU_ASSERT_TRUE_FATAL(pMgInfo->enable);
    	
	MGC_DEBUG("mg[%d] %s  , bind mgcSap[%d] , attach phyport[%d]" , pMg->mgNo, pMg->mgAttr.domain , 
		                pMg->pMgcsap->sapIndex , ret);	
	return;

}


void test_mgc_create_tandem(void)
{
    int ret;
	opera_struct opera;
    test_mgc_sap *pSap;
	test_mg *pMg = NULL;
    MG_INFO *pMgInfo;


	
	MGC_DEBUG("enter %s", __FUNCTION__);
    pSap = &testSap[0];
    ret = mgc_bind(&pSap->mgcSap);
    CU_ASSERT(ret>=0);
    pSap->sapIndex = ret;

    pMg = &mgRtpProxy;
    pMg->pMgcsap = pSap;
    ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr);
    CU_ASSERT(ret >= 0);
    pMg->mgNo = ret;

    opera.status = OPERA_STATE_SEND;
    test_mgc_wait_time(&opera , 2);
    pMgInfo = mgc_mg_info_get_index_mg(pMg->mgNo);
    CU_ASSERT_PTR_NOT_NULL_FATAL(pMgInfo);
    if(pMgInfo->enable == FALSE)
    {
	    MGC_ERROR("mg[%d] %s is not detected" , pMg->mgNo, pMg->mgAttr.domain);
    }
    CU_ASSERT_TRUE_FATAL(pMgInfo->enable);
	MGC_DEBUG("mg[%d] %s  , bind mgcSap[%d] , attach phyport[%d]" , pMg->mgNo, pMg->mgAttr.domain , 
		                pMg->pMgcsap->sapIndex , ret);	
	return;
}


void test_mgc_create_aas_mg_and_mgc(void)
{
    int ret;
	opera_struct opera;
    test_mgc_sap *pSap;
	test_mg *pMg = NULL;
    MG_INFO *pMgInfo;


	MGC_DEBUG("enter %s", __FUNCTION__);
	pMg = &mgAas;
    pSap = &testSap[1];
    pSap->mgcSap.usrType = MGC_USER_TYPE_MGC;
    MGC_DEBUG("create mgc aas");
    ret = mgc_bind(&pSap->mgcSap);
	CU_ASSERT(ret > 0);
    pSap->sapIndex = ret;
    pMg->pMgcsap = pSap;
	ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr);
	CU_ASSERT(ret >= 0);
	pMg->mgNo = ret;	
    pMgInfo = mgc_mg_info_get_index_mg(pMg->mgNo);
    opera.status = OPERA_STATE_SEND;
    test_mgc_wait_time(&opera , 2);	
    CU_ASSERT(pMgInfo->enable);
    
    MGC_DEBUG("create mg aas");
    pSap = &testSap[2];
    pSap->mgcSap.usrType = MGC_USER_TYPE_MG;
    pSap->mgcSap.ind_func = mgc_ind_test;
	pSap->mgcSap.cnf_func = NULL;
    ret = mgc_bind(&pSap->mgcSap);
	CU_ASSERT(ret > 0);
    pSap->sapIndex = ret;
    pMg->pMgcsap = pSap;
	ret = mgc_create_MG(pMg->pMgcsap->sapIndex , &pMg->mgAttr);
	CU_ASSERT(ret >= 0);
	pMg->mgNo = ret;		
    opera.status = OPERA_STATE_SEND;
    test_mgc_wait_time(&opera , 2);

	
    pMgInfo = mgc_mg_info_get_index_mg(pMg->mgNo);
    CU_ASSERT(pMgInfo->enable);
    pMgInfo = mgc_mg_info_get_index_mg(pMg->mgNo);
    CU_ASSERT_PTR_NOT_NULL_FATAL(pMgInfo);
    if(pMgInfo->enable == FALSE)
    {
	    MGC_ERROR("mg[%d] %s is not detected" , pMg->mgNo, pMg->mgAttr.domain);
    }
    CU_ASSERT_TRUE_FATAL(pMgInfo->enable);
	return;    	
}




void test_mgc_crcx_and_dlcx(void)
{
	int ret , num;	
    MG_INFO *pMgInfo;
	test_mg *pMg = &mgA;
	CHNL chnl;
	opera_struct *pOpera = &testOpera;

    MGC_DEBUG("test crcx and dlcx");
    pMgInfo = mgc_mg_info_get_index_mg(pMg->mgNo);	
	CU_ASSERT_PTR_NOT_NULL_FATAL(pMgInfo);	
	CU_ASSERT_TRUE_FATAL(pMgInfo->enable);
	
	chnl.mgNo = pMg->mgNo;
	chnl.portNo = pMg->portNo;
	chnl.chlNo = 1;
	chnl.connectNo = 0 ;

	MGC_DEBUG("enter %s", __FUNCTION__);

    num = mgc_connect_inused_num();

    pOpera->userPort++;				
    ret = mgc_crcx_chnl(pOpera->userPort , chnl);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);    
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS);  	

    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 10);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS);  		
	//MGC_DEBUG("before num %d , after num %d " , num , mgc_connect_inused_num());
    CU_ASSERT_EQUAL_FATAL(num , mgc_connect_inused_num());
    return;
}






void test_mgc_connect(void)
{
    int ret , num;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;

	MGC_DEBUG("enter %s", __FUNCTION__);

    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	

    num = mgc_connect_inused_num();

    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);	
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 


	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 60);
	
    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	
    CU_ASSERT_EQUAL_FATAL(num , mgc_connect_inused_num());	
    return;
}


void test_mgc_connect_tone(void)
{
    int ret ;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;


    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	
	MGC_DEBUG("enter %s", __FUNCTION__);

	pOpera->userPort++;
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 3);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 3);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 10);

    pOpera->userPort++;	
    ret = mgc_connect_tone(pOpera->userPort , chnl_b , chnl_a , 8 , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 3);
  //  CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 	
//	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 
/*
    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 5);

*/
	pOpera->userPort++;
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 10);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 10);


    pOpera->userPort++;	
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;			
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

    pOpera->userPort++;		
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	
    return;
}



void test_mgc_connect_aas(void)
{
    int ret ;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;


    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	

    pOpera->userPort++;	
	MGC_DEBUG("enter %s", __FUNCTION__);
	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 10);

    MGC_DEBUG("connect chnl_a to aas");
    pOpera->userPort++;	
    ret = mgc_connect_AAS(pOpera->userPort , chnl_b , chnl_a , 8 , 1 ,3);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 60);
    CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;	
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 10);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	
	
    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 10);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	
    return;
}


void test_mgc_connect_tandem_to_connection(void)
{
    int ret ,  tandemId;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;

	MGC_DEBUG("enter %s", __FUNCTION__);

    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	

	tandemId = mgc_get_idle_tandem_id();
	pOpera->userPort++;
	ret = mgc_bind_chnl_to_tandem(pOpera->userPort , chnl_a ,tandemId);
	CU_ASSERT(ret >= 0);
    pOpera->status = OPERA_STATE_SEND;		
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 2);	
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 


    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);	
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 15);


	
    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	


    pOpera->userPort++;			
    ret = mgc_delete_tandem(pOpera->userPort , tandemId);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	return;

}



void test_mgc_connect_connection_to_tandem(void)
{
    int ret ,  tandemId;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;

	MGC_DEBUG("enter %s", __FUNCTION__);

    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	

	tandemId = mgc_get_idle_tandem_id();
	pOpera->userPort++;
	ret = mgc_bind_chnl_to_tandem(pOpera->userPort , chnl_b ,tandemId);
	CU_ASSERT(ret >= 0);
    pOpera->status = OPERA_STATE_SEND;		
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 2);	
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 


    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);	
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 15);


	
    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_delete_tandem(pOpera->userPort , tandemId);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 


	return;

}




void test_mgc_connect_tandem_to_tandem(void)
{
    int ret ,  tandemId_a , tandemId_b;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;


    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	
	MGC_DEBUG("enter %s", __FUNCTION__);

	tandemId_a = mgc_get_idle_tandem_id();
	pOpera->userPort++;
	ret = mgc_bind_chnl_to_tandem(pOpera->userPort , chnl_a ,tandemId_a);
	CU_ASSERT(ret >= 0);
    pOpera->status = OPERA_STATE_SEND;		
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 2);	
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	tandemId_b = mgc_get_idle_tandem_id();
	pOpera->userPort++;
	ret = mgc_bind_chnl_to_tandem(pOpera->userPort , chnl_b ,tandemId_b);
	CU_ASSERT(ret >= 0);
    pOpera->status = OPERA_STATE_SEND;		
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 2);	
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 



    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);	
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 15);


	
    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_delete_tandem(pOpera->userPort , tandemId_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_delete_tandem(pOpera->userPort , tandemId_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 		

	return;

}




void test_mgc_connect_tandem_to_aas(void)
{
    int ret ,tandemId;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;


    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	

	MGC_DEBUG("enter %s", __FUNCTION__);

	tandemId = mgc_get_idle_tandem_id();
	pOpera->userPort++;
	ret = mgc_bind_chnl_to_tandem(pOpera->userPort , chnl_b ,tandemId);
	CU_ASSERT(ret >= 0);
    pOpera->status = OPERA_STATE_SEND;		
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 2);	
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 



    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 10);

    MGC_DEBUG("connect chnl_a to aas");
    pOpera->userPort++;	
    ret = mgc_connect_AAS(pOpera->userPort , chnl_b , chnl_a , 8 , 1 ,3);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 60);
    CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;	
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 10);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	
	
    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 10);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	
    return;
}




void test_mgc_tandem_fork(void)
{
    int ret ,  tandemId;
    opera_struct *pOpera = &testOpera;
    test_mg *pMgA = &mgA;
    CHNL chnl_a;

    test_mg *pMgB = &mgB;
    CHNL chnl_b;
	CHNL chnl_c;
	CHNL chnl_tandem;
	CHNL chnl_fork;

	MGC_DEBUG("enter %s", __FUNCTION__);

    chnl_a.mgNo = pMgA->mgNo;
	chnl_a.portNo = pMgA->portNo;
	chnl_a.chlNo = 1;
	chnl_a.connectNo = 0 ;	

    chnl_b.mgNo = pMgB->mgNo;
	chnl_b.portNo = pMgB->portNo;
	chnl_b.chlNo = 1;
	chnl_b.connectNo = 0 ;	

    chnl_c.mgNo = pMgB->mgNo;
	chnl_c.portNo = pMgB->portNo;
	chnl_c.chlNo = 2;
	chnl_c.connectNo = 0;

	tandemId = mgc_get_idle_tandem_id();
	pOpera->userPort++;
	ret = mgc_bind_chnl_to_tandem(pOpera->userPort , chnl_a ,tandemId);
	CU_ASSERT(ret >= 0);
    pOpera->status = OPERA_STATE_SEND;		
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 2);	
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);	
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 


    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_a , chnl_b , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);	
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_b , chnl_a , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

	pOpera->userPort++;	
    mgc_get_tandem_near_end(tandemId , &chnl_tandem);
	ret = mgc_fork_chnl(pOpera->userPort , chnl_tandem , &chnl_fork);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	  
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	


    pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_c , chnl_fork, 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);	
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	pOpera->userPort++;	
    ret = mgc_connect_chnl(pOpera->userPort , chnl_fork, chnl_c , 0);
    MGC_DEBUG("ret %d" , ret);
    CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;		
    test_mgc_wait_time(pOpera, 5);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	



    pOpera->userPort++;
    pOpera->status = OPERA_STATE_SEND;		
    test_mgc_wait_time(pOpera , 45);

	
    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_a);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET);
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_b);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	

    pOpera->userPort++;			
    ret = mgc_dlcx_chnl(pOpera->userPort , chnl_c);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 	


    pOpera->userPort++;			
    ret = mgc_delete_tandem(pOpera->userPort , tandemId);
	MGC_DEBUG("ret %d" , ret);
	CU_ASSERT_FATAL(ret>=0);
    pOpera->status = OPERA_STATE_SEND;	
	pOpera->result = MGC_OPER_FAILURE;	
    test_mgc_wait_time(pOpera, 2);
	CU_ASSERT_EQUAL_FATAL(pOpera->status ,OPERA_STATE_GET); 
	CU_ASSERT_EQUAL_FATAL(pOpera->result ,MGC_OPER_SUCCESS); 

	return;

}





void test_mgc_sur_info_list(void)
{
    int i,j, repeat;
	MGC_SUR_INFO_LIST list;
	MGC_SUR_INFO_NODE *pNode;
	CONNECT_INFO *pConn;
	BOOL result;

    repeat = MGC_MAX_NUM_OF_SURVEILLANCE_CONN; //0
	mgc_sur_info_list_init(&list);
	CU_ASSERT_PTR_NULL(list.pHead);
	CU_ASSERT_EQUAL(list.len, 0);
	for(i=0 ; i< repeat; i++)
	{
	    pConn = &mgcSurvillanceConn[i];

		result = mgc_sur_info_add_conn_to_list(&list, pConn);
		CU_ASSERT_TRUE(result);
		CU_ASSERT_EQUAL(list.len, i+1);
	}

    pConn = &mgcSurvillanceConn[5];
    pNode = mgc_sur_info_find_conn_in_list(&list, pConn);
	CU_ASSERT_PTR_NOT_NULL(pNode);
	CU_ASSERT_EQUAL(pNode->id, 5);
/*
	for(i=0 ; i< repeat; i++)
	{
	    pConn = &mgcSurvillanceConn[i];
        j = list.len;
		result = mgc_sur_info_remove_conn_to_list(&list, pConn);
		CU_ASSERT_TRUE(result);
		CU_ASSERT_EQUAL(list.len, j-1);
	}	
*/
    mgc_sur_info_clear_list(&list);
	CU_ASSERT_PTR_NULL(list.pHead);
	CU_ASSERT_EQUAL(list.len, 0);

	return;
}


CU_BOOL	mgc_add_test(void)
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("MGC_TEST", mgc_test_cunit_init , mgc_cunit_clean);

    if(NULL == pSuite)
        return CU_FALSE;    	

    if((NULL == CU_add_test(pSuite, "test of mgc init", test_mgc_init))||
 /*     (NULL == CU_add_test(pSuite, "test of mgc bind and unbind", test_mgc_sap_bind_and_unbind))||
      (NULL == CU_add_test(pSuite, "test of mg create and delete", test_mgc_mg_create_and_delete))||
      (NULL == CU_add_test(pSuite, "test of mg create and delete twice", test_mgc_mg_create_twice))||
      (NULL == CU_add_test(pSuite, "test of mg port add and delete", test_mgc_port_add_and_delete))||       */
	// (NULL == CU_add_test(pSuite, "test of mg create mgA", test_mgc_create_mg_a))|| 
	//  (NULL == CU_add_test(pSuite, "test of mg create mgB", test_mgc_create_mg_b))||
    //  (NULL == CU_add_test(pSuite, "test of create aas mg and mgc ", test_mgc_create_aas_mg_and_mgc))||
     // (NULL == CU_add_test(pSuite, "test of mg create tandem", test_mgc_create_tandem))||
     (NULL == CU_add_test(pSuite, "test of sur info lis operatioin", test_mgc_sur_info_list))  
	 // (NULL == CU_add_test(pSuite, "test of mg crcx and dlcx", test_mgc_crcx_and_dlcx))
    //  (NULL == CU_add_test(pSuite, "test of mg connect", test_mgc_connect))	  
	//  (NULL == CU_add_test(pSuite, "test of connect aas ", test_mgc_connect_aas))||
     //   (NULL == CU_add_test(pSuite, "test of rtp proxy connect tone ", test_mgc_connect_tone))
     //  (NULL == CU_add_test(pSuite, "test of mg connect tandem to connection", test_mgc_connect_tandem_to_connection))     
 	 //  (NULL == CU_add_test(pSuite, "test of mg connect connection to tandem", test_mgc_connect_connection_to_tandem))	 
	//   (NULL == CU_add_test(pSuite, "test of mg connect tandem to tandem", test_mgc_connect_tandem_to_tandem))   
	//  (NULL == CU_add_test(pSuite, "test of mg connect tandem to aas", test_mgc_connect_tandem_to_aas))  	
   //    (NULL == CU_add_test(pSuite, "test of tandem fork", test_mgc_tandem_fork))  	
      )
    return CU_FALSE;  

    return CU_TRUE;
}


int main(int argc, char* argv[])
{
	CU_BOOL Run = CU_FALSE ;
	
	setvbuf(stdout, NULL, _IONBF, 0);
	
	if (argc > 1) {
	  if (!strcmp("-i", argv[1])) {
		Run = CU_TRUE ;
		CU_set_error_action(CUEA_IGNORE);
	  }
	  else if (!strcmp("-f", argv[1])) {
		Run = CU_TRUE ;
		CU_set_error_action(CUEA_FAIL);
	  }
	  else if (!strcmp("-A", argv[1])) {
		Run = CU_TRUE ;
		CU_set_error_action(CUEA_ABORT);
	  }
	  else if (!strcmp("-e", argv[1])) {
		//print_example_results();
	  }
	  else {
		printf("\nUsage:  AutomatedTest [option]\n\n"
				 "		  Options: -i  Run, ignoring framework errors [default].\n"
				 "				   -f  Run, failing on framework error.\n"
				 "				   -A  Run, aborting on framework error.\n"
				 "				   -e  Print expected test results and exit.\n"
				 "				   -h  Print this message.\n\n");
	  }
	}
	else {
	  Run = CU_TRUE;
	  CU_set_error_action(CUEA_IGNORE);
	}

	if (CU_TRUE == Run) {
	  if (CU_initialize_registry()) {
		printf("\nInitialization of Test Registry failed.");
	  }
	  else {
		if(mgc_add_test() == CU_FALSE)
		{
		     CU_cleanup_registry(); 
			 CU_get_error();
		}
		
		CU_set_output_filename("mgc_unit_test");
		CU_list_tests_to_file();
		CU_automated_run_tests();
		CU_cleanup_registry();
	  }
	}


    return 1;
}

