TEST(TNEANet, AddEdgeAttributeError) { PNEANet Graph; Graph = TNEANet::New(); TStr StrAttr("name"); TStr FltAttr("weight"); TStr IntAttr("test"); Graph->AddStrAttrE(StrAttr); Graph->AddFltAttrE(FltAttr); Graph->AddIntAttrE(IntAttr); int NumEdges = 5; for (int i = 0; i < NumEdges + 1; i++) { Graph->AddNode(i); } for (int i = 0; i < NumEdges; i++) { Graph->AddEdge(i, i+1, i); Graph->AddIntAttrDatE(i, TInt(i), IntAttr); Graph->AddFltAttrDatE(i, TFlt(i), FltAttr); TInt Val(i); Graph->AddStrAttrDatE(i, Val.GetStr(), StrAttr); } Graph->DelNode(0); for (int j = 1; j < NumEdges; j++) { ASSERT_EQ(Graph->GetIntAttrDatE(j, IntAttr), TInt(j)); ASSERT_EQ(Graph->GetFltAttrDatE(j, FltAttr), TFlt(j)); TInt Val(j); ASSERT_EQ(Graph->GetStrAttrDatE(j, StrAttr), Val.GetStr()); } }
// Test node, edge attribute functionality TEST(TNEANet, AddEdgeNodeAfterAttrAdded) { PNEANet Graph; Graph = TNEANet::New(); TStr StrAttr("name"); TStr EIntAttr("weight"); TStr NIntAttr("test"); Graph->AddStrAttrN(StrAttr); Graph->AddIntAttrN(NIntAttr); Graph->AddIntAttrE(EIntAttr); Graph->AddNode(0); Graph->AddNode(1); Graph->AddNode(2); Graph->AddStrAttrDatN(0, "zero", StrAttr); Graph->AddStrAttrDatN(1, "one", StrAttr); Graph->AddStrAttrDatN(2, "two", StrAttr); Graph->AddEdge(0, 1); Graph->AddEdge(1, 2); Graph->AddEdge(2, 0); for (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) { Graph->AddIntAttrDatE(EI.GetId(), EI.GetId()*3+1, EIntAttr); } for (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) { TInt AttrVal = Graph->GetIntAttrDatE(EI.GetId(), EIntAttr); ASSERT_EQ(EI.GetId()*3+1, AttrVal); } }
TEST(TNEANet, DelSAttrDatE) { PNEANet Graph; Graph = TNEANet::New(); Graph->AddNode(0); Graph->AddNode(1); Graph->AddEdge(0, 1, 0); TStr IntAttr("TestInt"); TInt IntId; Graph->AddSAttrE(IntAttr, atInt, IntId); TStr FltAttr("TestFlt"); TInt FltId; Graph->AddSAttrE(FltAttr, atFlt, FltId); TStr StrAttr("TestStr"); TInt StrId; Graph->AddSAttrE(StrAttr, atStr, StrId); TInt Id(0); int status = Graph->DelSAttrDatE(Id, IntAttr); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatE(Id, IntId); EXPECT_EQ(-1, status); TInt IntVal(5); Graph->AddSAttrDatE(Id, IntId, IntVal); status = Graph->DelSAttrDatE(Id, IntAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatE(Id, IntId, IntVal); status = Graph->DelSAttrDatE(Id, IntId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatE(Id, IntId); EXPECT_EQ(-1, status); TInt ErrorId(1); status = Graph->DelSAttrDatE(ErrorId, IntId); EXPECT_EQ(-1, status); TFlt FltVal(5.0); Graph->AddSAttrDatE(Id, FltId, FltVal); status = Graph->DelSAttrDatE(Id, FltAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatE(Id, FltId, FltVal); status = Graph->DelSAttrDatE(Id, FltId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatE(Id, FltId); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatE(ErrorId, FltId); EXPECT_EQ(-1, status); TStr StrVal("5"); Graph->AddSAttrDatE(Id, StrId, StrVal); status = Graph->DelSAttrDatE(Id, StrAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatE(Id, StrId, StrVal); status = Graph->DelSAttrDatE(Id, StrId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatE(Id, StrId); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatE(ErrorId, StrId); EXPECT_EQ(-1, status); }
TEST(TNEANet, GetIdVSAttrE) { PNEANet Graph; Graph = TNEANet::New(); TStr IntAttr("TestInt"); TInt IntId; Graph->AddSAttrE(IntAttr, atInt, IntId); TStr FltAttr("TestFlt"); TInt FltId; Graph->AddSAttrE(FltAttr, atFlt, FltId); TStr StrAttr("TestStr"); TInt StrId; Graph->AddSAttrE(StrAttr, atStr, StrId); TInt IntVal(0); TFlt FltVal(0); TStr StrVal("test"); Graph->AddNode(0); for (int i = 0; i < 10; i++) { Graph->AddNode(i+1); Graph->AddEdge(i, i+1, i); TInt Id(i); Graph->AddSAttrDatE(Id, IntId, IntVal); if (i%2 == 0) { Graph->AddSAttrDatE(Id, FltId, FltVal); } } Graph->AddSAttrDatE(0, StrId, StrVal); TIntV IdV; Graph->GetIdVSAttrE(IntAttr, IdV); EXPECT_EQ(10, IdV.Len()); Graph->GetIdVSAttrE(IntId, IdV); EXPECT_EQ(10, IdV.Len()); Graph->GetIdVSAttrE(FltAttr, IdV); EXPECT_EQ(5, IdV.Len()); Graph->GetIdVSAttrE(FltId, IdV); EXPECT_EQ(5, IdV.Len()); Graph->GetIdVSAttrE(StrAttr, IdV); EXPECT_EQ(1, IdV.Len()); Graph->GetIdVSAttrE(StrId, IdV); EXPECT_EQ(1, IdV.Len()); }
TEST(TNEANet, GetSAttrVE) { PNEANet Graph; Graph = TNEANet::New(); Graph->AddNode(0); Graph->AddNode(1); Graph->AddEdge(0, 1, 0); TStr IntAttr("TestInt"); TInt IntId; Graph->AddSAttrE(IntAttr, atInt, IntId); TStr FltAttr("TestFlt"); TInt FltId; Graph->AddSAttrE(FltAttr, atFlt, FltId); TStr StrAttr("TestStr"); TInt StrId; Graph->AddSAttrE(StrAttr, atStr, StrId); TInt Id(0); TInt IntVal(5); Graph->AddSAttrDatE(Id, IntId, IntVal); TFlt FltVal(5.0); Graph->AddSAttrDatE(Id, FltId, FltVal); TStr StrVal("5"); Graph->AddSAttrDatE(Id, StrId, StrVal); TAttrPrV AttrV; int status = Graph->GetSAttrVE(Id, atInt, AttrV); EXPECT_EQ(0, status); EXPECT_EQ(1, AttrV.Len()); status = Graph->GetSAttrVE(Id, atFlt, AttrV); EXPECT_EQ(0, status); EXPECT_EQ(1, AttrV.Len()); status = Graph->GetSAttrVE(Id, atStr, AttrV); EXPECT_EQ(0, status); EXPECT_EQ(1, AttrV.Len()); //status = Graph->GetSAttrVE(Id, atAny, AttrV); //EXPECT_EQ(0, status); //EXPECT_EQ(3, AttrV.Len()); //status = Graph->GetSAttrVE(Id, atUndef, AttrV); //EXPECT_EQ(0, status); //EXPECT_EQ(0, AttrV.Len()); //TInt ErrorId(1); //status = Graph->GetSAttrVE(ErrorId, atUndef, AttrV); //EXPECT_EQ(-1, status); }
// --- tDWORD CBaseInfo::TypeName( const CSpecificTypeInfo* ti, char* val, tDWORD size ) const { if ( !m_curr ) return 0; tDWORD type_id = TypeID(); tDWORD type_of_type = TypeOfType(); if ( (type_of_type == VE_NTT_GLOBALTYPE) && (type_id != tid_VOID) && ti && *ti ) { tDWORD ret = ti->Name( type_id, val, size ); if ( ret ) return ret; } tDWORD id; switch( m_en_type ) { case ifPlugin : return 0; case ifIFace : id = I(_OBJECTTYPE); break; case ifType : id = I(T_BASETYPENAME); break; case ifConstant : id = I(C_BASETYPENAME); break; case ifErrCode : case ifMsgClass : case ifMsg : if ( val && size ) { if ( size < 7 ) { *val = 0; return 0; } else ::memcpy( val, "tDWORD", 7 ); } return 7; case ifProperty : id = I(P_TYPENAME); break; case ifPubMethod : id = I(M_RESULTTYPENAME); break; case ifIntMethod : id = I(M_RESULTTYPENAME); break; case ifMethodParam : id = I(MP_TYPENAME); break; case ifDataStruct : id = I(D_DATASTRUCTURENAME); break; case ifDataStructMember : id = I(DM_TYPENAME); break; default : return 0; } return StrAttr( id, val, size ); }
// --- bool CBaseInfo::Guid( tGUID& val ) const { tCHAR str_guid[40]; tDWORD len = StrAttr( VE_PID_UNIQUEID, str_guid, sizeof(str_guid) ); if ( !len ) return false; #if 0 && defined (_WIN32) { tWCHAR wstr_guid[40]; ::mbstowcs( wstr_guid, str_guid, len ); ::CoInitialize( 0 ); ::IIDFromString( wstr_guid, &val ); ::CoUninitialize(); } #else ::mIIDFromString( str_guid, val ); #endif return true; }
// --- tDWORD CBaseInfo::Name( char* val, tDWORD size ) const { tDWORD id; if ( !m_curr ) return 0; switch( m_en_type ) { case ifPlugin : id = VE_PID_PL_PLUGINNAME; break; case ifIFace : id = I(_INTERFACENAME); break; case ifType : id = I(T_TYPENAME); break; case ifConstant : id = I(C_CONSTANTNAME); break; case ifErrCode : id = I(E_ERRORCODENAME); break; case ifProperty : id = I(P_PROPNAME); break; case ifPubMethod : id = I(M_METHODNAME); break; case ifIntMethod : id = I(M_METHODNAME); break; case ifMethodParam : id = I(MP_PARAMETERNAME); break; case ifDataStruct : id = I(D_DATASTRUCTURENAME); break; case ifDataStructMember : id = I(DM_MEMBERNAME); break; case ifMsgClass : id = I(M_MESSAGECLASSNAME); break; case ifMsg : id = I(M_MESSAGENAME); break; default : return 0; } return StrAttr( id, val, size ); }
// --- tDWORD CBaseInfo::Value( char* val, tDWORD size ) const { tDWORD id; if ( !m_curr ) return 0; switch( m_en_type ) { case ifPlugin : case ifIFace : case ifType : return 0; case ifConstant : id = I(C_VALUE); break; case ifErrCode : return DWAttrAsStr( I(E_ERRORCODEVALUE), val, size, false ); case ifProperty : id = I(PSS_VARIABLEDEFVALUE); break; case ifPubMethod : case ifIntMethod : id = I(M_RESULTDEFVALUE); break; case ifMsgClass : return DWAttrAsStr( I(M_MESSAGECLASSID), val, size, false ); break; case ifMsg : return DWAttrAsStr( I(M_MESSAGEID), val, size, false ); break; case ifMethodParam : case ifDataStruct : case ifDataStructMember : default : return 0; } return StrAttr( id, val, size ); }
// --- tDWORD CBaseInfo::Guid( char* val, tDWORD size ) const { return StrAttr( VE_PID_UNIQUEID, val, size ); }
// --- tDWORD CBaseInfo::BehaviorComment( char* val, tDWORD size ) const { return m_curr ? StrAttr( VE_PID_BEHAVIORCOMMENT, val, size ) : 0; }
// --- tDWORD CBaseInfo::ValueComment( char* val, tDWORD size ) const { return m_curr ? StrAttr( VE_PID_VALUECOMMENT, val, size ) : 0; }
// --- tDWORD CBaseInfo::ExtComment( char* val, tDWORD size ) const { return m_curr ? StrAttr( VE_PID_LARGECOMMENT, val, size ) : 0; }
// --- tDWORD CBaseInfo::ShortComment ( char* val, tDWORD size ) const { return m_curr ? StrAttr( VE_PID_SHORTCOMMENT, val, size ) : 0; }