📄 tcmisd.cpp
字号:
rdn3.Dump( g_OmcDump );
cout << endl;
pos = rdn3.FindElementIndex( rdn3.GetCount() - 1 );
ASSERT( pos != NULL );
rdn3.RemoveElement( *(rdn3.GetElementAt( pos )) );
cout << "rdn3 remove element, rdn3 count is " << rdn3.GetCount() << ", rdn3 is : " << endl;
rdn3.Dump( g_OmcDump );
cout << endl;
cout << "rdn2 is equal rdn3 : " << (rdn2.IsEqual( rdn3 ) ) << endl;
cout << "rdn2 is subset of rdn3 : " << ( rdn2.IsSubSetOf( rdn3 ) ) << endl;
cout << "rdn2 is superset of rdn3 : " << ( rdn2.IsSuperSetOf( rdn3 ) ) << endl;
cout << "rdn2 has intersection with rdn3 : " << ( rdn2.HasIntersection( rdn3 ) ) << endl;
/**/ CAsnBuffer b;
cout << "rdn3 encode : ";
if ( rdn3.Serialize( b, TRUE ) )
b.Dump( g_OmcDump );
CRDN rdn4;
cout << "rdn4 decode : ";
if ( rdn4.Serialize( b, FALSE ) )
{
cout << "rdn3 == rdn4 : " << ( rdn3 == rdn4 ) << endl;
rdn4.Dump( g_OmcDump );
}
/**/
WaitForNextTest( "CRDN has tested ! \0 " );
}
void CTestCmisd::TestDN()
{
cout << "Test CDN : ........................................" << endl;
CDN dn1;
POSITION pos;
CRDN* prdn = dn1.NewElement( pos );
ASSERT( prdn );
CAttribute* pa = prdn->NewElement( pos );
ASSERT( pa );
pa->Set( 100, CAsnInteger( 1212 ) );
cout << "dn1 NewElement at tail, dn1 is : " << endl;
dn1.Dump( g_OmcDump );
cout << endl;
dn1.AddAttributeValueAssertion( 3005, CAsnBoolean( TRUE ) );
cout << "dn1 NewElement at head, dn1 is : " << endl;
dn1.Dump( g_OmcDump );
cout << endl;
CDN dn2 = dn1;
cout << "dn2 = dn1 : " << (dn1 == dn2 ) << endl;
CDN dn3;
dn3 += dn1;
cout << "dn3 += dn1, dn3 is : " << endl;
dn3.Dump( g_OmcDump );
cout << endl;
dn3 += *prdn;
cout << "dn3 += *prdn, dn3 is : " << endl;
dn3.Dump( g_OmcDump );
cout << endl;
CRDN* prdn2 = new CRDN(*prdn);
dn3 += prdn2;
cout << "dn3 += prdn2, dn3 is : " << endl;
dn3.Dump( g_OmcDump );
cout << endl;
cout << "dn3 search aid 3005 : \n";
INT nIndex = 0;
pos = dn3.GetHeadElementPosition();
while ( pos != NULL )
{
cout << "dn3 found No" << nIndex++ << ", value is : " << endl;
prdn = (CRDN*)(dn2.GetNextElement(pos ));
ASSERT( prdn );
prdn->Dump( g_OmcDump );
cout << endl;
}
cout << "dn3 element count is " << dn3.GetCount() << endl;
dn3.RemoveTailElement(2);
cout << "dn3 remove tail 2 element, dn3 element count is "
<< dn3.GetCount() << ", dn3 is : " << endl;
dn3.Dump( g_OmcDump );
cout << endl;
cout << "dn2 == dn3 : " << (dn2 == dn3 ) << endl;
CRDN rdn;
rdn.AddTailElement( 3004, CAsnReal((ASNREALTYPE)12.222) );
dn3.AddHeadElement( rdn );
dn3.AddTailElement( new CRDN( rdn ) );
cout << "dn3 add head and tail element, count is " << dn3.GetCount() << endl;
CDN * pdn = new CDN(dn3);
cout << "*pdn == dn3 : " << ( *pdn == dn3 ) << endl;
dn3.AddTailElement( pdn );
cout << "dn3 add tail pdn, dn3 count is " << dn3.GetCount() << ", dn3 is : " << endl;
dn3.Dump( g_OmcDump );
cout << endl;
cout << "pdn count is " << pdn->GetCount() << ", pdn is : " << endl;
pdn->Dump( g_OmcDump );
cout << endl;
delete pdn;
dn3.RemoveTailElement();
cout << "dn3 remove tail element, dn3 count is " << dn3.GetCount() << ", dn3 is : " << endl;
dn3.Dump( g_OmcDump );
cout << endl;
pos = dn3.FindElementIndex( dn3.GetCount() - 1 );
ASSERT( pos != NULL );
dn3.RemoveElementAt( pos );
cout << "dn3 remove element, dn3 count is " << dn3.GetCount() << ", dn3 is : " << endl;
dn3.Dump( g_OmcDump );
cout << endl;
CAsnBuffer b;
cout << "dn3 encode : ";
if ( dn3.Serialize( b, TRUE ) )
b.Dump( g_OmcDump );
CDN dn4;
/**/ if ( dn4.Serialize( b, FALSE ) )
{
cout << "dn3 == dn4 : " << ( dn3 == dn4 ) << endl;
dn4.Dump( g_OmcDump );
}
/**/
/* if ( dn4.Serialize( b, len4, FALSE, FLG_SER_ONLYDECODELENGTH ) )
{
cout << "len = " << len4 << endl;
}
*/
b.PutByte( 0x33 );
b.PutByte( 0x0 );
b.PutByte( 0x1 );
cout << "dn4 decode" << endl;
b.Dump( g_OmcDump );
if ( dn4.Serialize( b, FALSE, FLG_SER_ONLYDECODELENGTH ) )
{
cout << "dn4 decode : ";
cout << "len = " << b.GetLength() << endl;
b.Dump( g_OmcDump );
}
WaitForNextTest( "CDN has tested ! \0 " );
}
void CTestCmisd::TestFilter()
{
cout << "Test CCmisFilter : ........................................" << endl;
CCmisFilter f1, fx;
CAttributeId cAttribId(3005);
CAttribute cAttrib( cAttribId, new CAsnBoolean(FALSE) );
SET_CMIS_FILTER ( f1,
CMIS_FLT_OR( 3 ,
CMIS_FLT_ITEM ( CMIS_FLT_EQUALITY, cAttrib ),
CMIS_FLT_AND ( 2,
CMIS_FLT_ITEM ( CMIS_FLT_EQUALITY, cAttrib ),
CMIS_FLT_ITEM ( CMIS_FLT_GREATEOREQUAL, cAttrib )),
CMIS_FLT_NOT (
CMIS_FLT_ITEM ( CMIS_FLT_PRESENT, cAttribId ))));
/**/ CAsnBuffer b;
cout << "f1 Encode : ";
if ( f1.Serialize( b, TRUE ) )
{
b.Dump(g_OmcDump);
}
cout << "fx Decode : " << endl;
if ( fx.Serialize( b, FALSE ) )
{
cout << "fx Success " << endl;
cout << "f1 == fx : " << ( f1 == fx ) << endl;
fx.Dump( g_OmcDump );
}
/**/
WaitForNextTest( "CCmisFilter has tested ! \0 " );
}
void CTestCmisd::TestGetReqArgument()
{
cout << "Test CGetReqArgument : ........................................" << endl;
// 发送M-GET请求命令
CGetArgument getarg1;
//设置M-GET参数. 可以预先在其他地方设置好, 这里直接发送.
// 构造DN
POSITION tPos;
CDistinguishedName cDN;
CRelativeDistinguishedName * pcRDN = cDN.NewElement(tPos);
CAsnInteger * pcValue = new CAsnInteger( 2 );
ASSERT ( pcValue );
pcRDN->NewElement(tPos)->Set( 100, pcValue );
// 设置基管理对象类:使用INTEGER形式
getarg1.GetBaseManagedObjectClass().Set( 101 );
// 设置基管理对象实例:使用DN形式
getarg1.GetBaseManagedObjectInstance().Set( cDN );
// 设置ACCESSCONTROL: OPTIONAL不用设置
//getarg1.GetAccessControl().Set();
// 设置同步: DEFAULT不用设置
getarg1.SetCmisSync( CMIS_SYN_ATOMIC );
// 设置范围: DEFAULT不用设置
getarg1.SetScope( CMIS_SCP_FIRSTLEVELONLY );
// 设置筛选器: DEFAULT不用设置
getarg1.PresentCmisFilter();
CAttributeId cAttribId(3005);
CAttribute cAttrib( cAttribId, new CAsnBoolean(FALSE) );
SET_CMIS_FILTER ( getarg1.GetCmisFilter(),
CMIS_FLT_NOT (
CMIS_FLT_AND ( 3,
CMIS_FLT_ITEM ( CMIS_FLT_EQUALITY, 3006, new CAsnInteger(2) ) ,
CMIS_FLT_OR ( 1,
CMIS_FLT_ITEM ( CMIS_FLT_EQUALITY, cAttrib ) ),
CMIS_FLT_ITEM ( CMIS_FLT_PRESENT, cAttribId ) ) ) ) ;
/**/ CAsnBuffer b;
cout << "getarg1 Encode : ";
if ( getarg1.Serialize( b, TRUE ) )
{
b.Dump(g_OmcDump);
}
CGetReqArgument getarg2;
cout << "getarg2 Decode " << endl;
if ( getarg2.Serialize( b, FALSE ) )
{
cout << "getarg2 success " << endl;
cout << "getarg1 == getarg2 : " << ( getarg1.Compare( &getarg2 ) == 0 ) << endl;
getarg2.Dump( g_OmcDump );
//cout << " getarg1 == getarg2 : " << getarg1 == getarg2 << endl;
}
/**/
WaitForNextTest( "CGetReqArgument has tested ! \0 " );
}
void CTestCmisd::TestNewInstance()
{
char wait;
cin >> wait;
cout << "Test if we can get the object instance from the class name " << endl;
CAsnType *pAny = NULL;
ASNINTEGERTYPE tTypeId;
const CString name("CGetArgument");
//CString name;
g_cIdRegister.GetCmisArgumentId( name, tTypeId );
g_cIdRegister.GetCmisArgumentIdRegister().CreateValue(tTypeId, pAny);
if( pAny == NULL )
cout << "---- > Test Failed :-( " << endl;
cout << "---- > Test Success :-) " << endl;
delete pAny;
cin >> wait;
}
int g_iBraceNum = 0;
ifstream *g_cfgFile = NULL;
void CTestCmisd::TestComposeStruct( int iOriginalBraceNum , int &iCmpsEleNum,
CAsnType *pArray[MAX_ELEMENT] )
{
char strLine[MAX_LINE_LEN];
string strClassName;
char cFlag = 0;
iCmpsEleNum = 0;
if ( g_cfgFile == NULL )
g_cfgFile = new ifstream("conf\\cmis.ini");
while( g_iBraceNum == iOriginalBraceNum ){
if( g_cfgFile->eof() )
break;
g_cfgFile->getline( strLine, MAX_LINE_LEN );
istringstream strmLine(strLine);
strmLine >> strClassName >> cFlag;
//skip the empty line.
if( strClassName == "" )
continue;
//encounter to the struct end.
if( strClassName == "}" ){
g_iBraceNum --;
break;
}
ASNINTEGERTYPE tTypeId = 0xffffffff;
g_cIdRegister.GetId( CString(strClassName.c_str()) , tTypeId );
if( tTypeId == 0xffffffff ){
cout << ":-( Failed Get TypeId for Class \"" << strClassName
<< " \"" << endl;
goto exit_func;
}
if( g_cIdRegister.GetCmisArgumentIdRegister().CreateValue(tTypeId, pArray[iCmpsEleNum]) == FALSE )
g_cIdRegister.CreateValue(tTypeId, pArray[iCmpsEleNum]);
if( pArray[iCmpsEleNum] == NULL ){
cout << ":-( Failed Create Instrance for Class \"" << strClassName
<< " \"" << endl;
goto exit_func;
}
iCmpsEleNum ++;
if( cFlag == '{' ){
g_iBraceNum ++;
TestComposeStruct( g_iBraceNum, iCmpsEleNum, pArray );
cout << "Compose the structed class" << endl;
for( int i = 0; i < iCmpsEleNum; i ++ ){
delete pArray[i];
pArray[i] = NULL;
}
}
}
if( g_iBraceNum == 0 ){
exit_func:
g_cfgFile->close();
delete g_cfgFile;
return;
}
}
/*
g_cIdRegister.GetValue( tTypeID, tTypeNo );
switch ( tTypeNo ){
case TYPE_CGetArgument:
((CGetArgument*)pAny)->GetBaseManagedObjectClass().Set( 101 );
break;
default:
break;
case TYPE_CInteger:
break;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -