From: srn Date: Thu, 14 Dec 2006 14:50:27 +0000 (+0000) Subject: Added additional tests for incorrect input parameters X-Git-Tag: SALOMEDS_UnitTests_1_2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7b7414b5a3d589f4bf9eb88bedb9f060fb7b521c;p=modules%2Fkernel.git Added additional tests for incorrect input parameters --- diff --git a/src/SALOMEDS/Test/SALOMEDSTest_SObject.cxx b/src/SALOMEDS/Test/SALOMEDSTest_SObject.cxx index f31f9f225..5b4d221fe 100755 --- a/src/SALOMEDS/Test/SALOMEDSTest_SObject.cxx +++ b/src/SALOMEDS/Test/SALOMEDSTest_SObject.cxx @@ -77,8 +77,10 @@ void SALOMEDSTest::testSObject() _PTR(GenericAttribute) ga; CPPUNIT_ASSERT(so->FindAttribute(ga, "AttributeIOR")); - //Check method ReferencedObject + //Try to find attribute with empty type + CPPUNIT_ASSERT(!so->FindAttribute(ga, "")); + //Check method ReferencedObject studyBuilder->Addreference(so1, so); _PTR(SObject) so2; CPPUNIT_ASSERT(so1->ReferencedObject(so2)); diff --git a/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx b/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx index fa275f9a2..aef1f9c2a 100755 --- a/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx +++ b/src/SALOMEDS/Test/SALOMEDSTest_Study.cxx @@ -57,6 +57,8 @@ void SALOMEDSTest::testStudy() study->Name("Test"); //Check method URL (get/set) + study->URL(""); + CPPUNIT_ASSERT(study->URL() == ""); study->URL("some url"); CPPUNIT_ASSERT(study->URL() == "some url"); @@ -73,6 +75,10 @@ void SALOMEDSTest::testStudy() _PTR(SObject) so = study->CreateObjectID("0:2:1:3"); CPPUNIT_ASSERT(so); + //Try to create SObject with empty and invalid entries + CPPUNIT_ASSERT(!study->CreateObjectID("")); + CPPUNIT_ASSERT(!study->CreateObjectID("entry")); + //Check method NewChildIterator _PTR(ChildIterator) childIterator = study->NewChildIterator(so); CPPUNIT_ASSERT(childIterator); @@ -89,6 +95,9 @@ void SALOMEDSTest::testStudy() CPPUNIT_ASSERT(name_attr_sco1); name_attr_sco1->SetValue("sco1"); + //Try to find component with empty type + CPPUNIT_ASSERT(!study->FindComponent("")); + //Check method GetComponentNames vector components = study->GetComponentNames(""); //The context doesn't matter CPPUNIT_ASSERT(components.size() == 1 && components[0] == "sco1"); @@ -97,6 +106,9 @@ void SALOMEDSTest::testStudy() _PTR(SComponent) sco3 = study->FindComponentID(sco1->GetID()); CPPUNIT_ASSERT(sco3 && sco3->GetID() == sco1->GetID()); + //Try to find component with empty id + CPPUNIT_ASSERT(!study->FindComponentID("")); + _PTR(SObject) so1 = studyBuilder->NewObject(sco1); CPPUNIT_ASSERT(so1); _PTR(AttributeName) name_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName"); @@ -120,14 +132,23 @@ void SALOMEDSTest::testStudy() _PTR(SObject) so3 = study->FindObject("so1"); CPPUNIT_ASSERT(so3 && so3->GetID() == so1->GetID()); + //Try to find SObject with empty name + CPPUNIT_ASSERT(!study->FindObject("")); + //Check method FindObjectID _PTR(SObject) so4 = study->FindObjectID(so1->GetID()); CPPUNIT_ASSERT(so4 && so4->GetID() == so1->GetID()); + //Try to find SObject with empty ID + CPPUNIT_ASSERT(!study->FindObjectID("")); + //Check method FindObjectByName vector< _PTR(SObject) > v = study->FindObjectByName("so1", sco1->ComponentDataType()); CPPUNIT_ASSERT(v.size()==1 && v[0]->GetID() == so1->GetID()); + //Try to find SObject with empty name and empty component type + CPPUNIT_ASSERT((study->FindObjectByName("", "")).size() == 0); + //Check method FindObjectByPath _PTR(SObject) path_so = study->FindObjectByPath("/"+sco1->GetName()+"/"+so1->GetName()); CPPUNIT_ASSERT(path_so && path_so->GetID() == so1->GetID()); @@ -136,9 +157,17 @@ void SALOMEDSTest::testStudy() _PTR(SObject) so5 = study->FindObjectIOR(ior); CPPUNIT_ASSERT(so5 && so5->GetID() == so1->GetID()); + //Try to find SObject with empty IOR + CPPUNIT_ASSERT(!study->FindObjectIOR("")); + //Check method GetObjectPath string path = study->GetObjectPath(so2); + //Try to get path of NULL SObject + _PTR(SObject) emptySO; + path = study->GetObjectPath(emptySO); + CPPUNIT_ASSERT(path.empty()); + //Check method SetContext study->SetContext("/sco1"); CPPUNIT_ASSERT(study->GetContext() == "/sco1"); @@ -147,6 +176,11 @@ void SALOMEDSTest::testStudy() _PTR(SObject) so6 = study->FindObjectByPath("so1"); CPPUNIT_ASSERT(so6 && so6->GetID() == so1->GetID()); + + //Try to find SObject with empty path + _PTR(SObject) tmp = study->FindObjectByPath(""); //Must return the Context SObject + CPPUNIT_ASSERT(tmp && tmp->GetID() == sco1->GetID()); + study->SetContext("/"); //Root //Check method GetObjectNames @@ -192,7 +226,6 @@ void SALOMEDSTest::testStudy() CPPUNIT_ASSERT(sp); //Check Lock functionality - //_PTR(AttributeName) name_attr_so1 = studyBuilder->FindOrCreateAttribute(so1, "AttributeName"); sp->SetLocked(true); bool isLockRaised = false; try { @@ -253,6 +286,7 @@ void SALOMEDSTest::testStudy() //Check method GetUseCaseBuilder _PTR(UseCaseBuilder) ub = study->GetUseCaseBuilder(); + CPPUNIT_ASSERT(ub); //Check method SetStudyLock study->SetStudyLock("locker1"); diff --git a/src/SALOMEDS/Test/SALOMEDSTest_StudyBuilder.cxx b/src/SALOMEDS/Test/SALOMEDSTest_StudyBuilder.cxx index c9967d461..4ce06a578 100755 --- a/src/SALOMEDS/Test/SALOMEDSTest_StudyBuilder.cxx +++ b/src/SALOMEDS/Test/SALOMEDSTest_StudyBuilder.cxx @@ -57,6 +57,9 @@ void SALOMEDSTest::testStudyBuilder() _PTR(SComponent) sco2 = study->FindComponent("Test"); CPPUNIT_ASSERT(!sco2); + //Try to create and find the component with empty type + _PTR(SComponent) sco_empty = studyBuilder->NewComponent(""); + CPPUNIT_ASSERT(!sco_empty); _PTR(SComponent) sco3 = studyBuilder->NewComponent("NewComp"); CPPUNIT_ASSERT(sco3); @@ -77,10 +80,24 @@ void SALOMEDSTest::testStudyBuilder() _PTR(AttributeName) an3 = studyBuilder->FindOrCreateAttribute(so3, "AttributeName"); CPPUNIT_ASSERT(an3); + cout << endl << "########## 1" << endl; + + //Try to create attribute with invalid type + CPPUNIT_ASSERT(!studyBuilder->FindOrCreateAttribute(so3, "invalid type")); + + cout << endl << "########## 2" << endl; + //Check method FindAttribute _PTR(GenericAttribute) ga; CPPUNIT_ASSERT(studyBuilder->FindAttribute(so3, ga, "AttributeName")); + cout << endl << "########## 3" << endl; + + //Try to find attribute with invalid type + CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "invalid type")); + + cout << endl << "########## 4" << endl; + //Check method RemoveObject studyBuilder->RemoveObject(so3); CPPUNIT_ASSERT(!studyBuilder->FindAttribute(so3, ga, "AttributeName")); @@ -103,6 +120,17 @@ void SALOMEDSTest::testStudyBuilder() _PTR(SObject) refSO; CPPUNIT_ASSERT(so2->ReferencedObject(refSO) && refSO->GetID() == so1->GetID()); + //Try to set reference to NULL SObject + bool isRaised = false; + _PTR(SObject) empty_so; + try { + studyBuilder->Addreference(so2, empty_so); + } + catch(...) { + isRaised = true; + } + CPPUNIT_ASSERT(isRaised); + //Check method RemoveReference studyBuilder->RemoveReference(so2); CPPUNIT_ASSERT(!so2->ReferencedObject(refSO)); @@ -112,6 +140,16 @@ void SALOMEDSTest::testStudyBuilder() studyBuilder->SetGUID(so1, value); CPPUNIT_ASSERT(studyBuilder->IsGUID(so1, value)); + //Try to set invalid GUID + isRaised = false; + try { + studyBuilder->SetGUID(so1, "invalid GUID"); + } + catch(...) { + isRaised = true; + } + CPPUNIT_ASSERT(isRaised); + //Check method UndoLimit (set/get) studyBuilder->UndoLimit(10); CPPUNIT_ASSERT(studyBuilder->UndoLimit() == 10); @@ -145,10 +183,22 @@ void SALOMEDSTest::testStudyBuilder() studyBuilder->SetName(so1, "new name"); CPPUNIT_ASSERT(so1->GetName() == "new name"); + //Try to set empty Name + studyBuilder->SetName(so1, ""); + CPPUNIT_ASSERT(so1->GetName() == ""); + //Check method SetComment studyBuilder->SetComment(so1, "new comment"); CPPUNIT_ASSERT(so1->GetComment() == "new comment"); + //Check method empty Comment + studyBuilder->SetComment(so1, ""); + CPPUNIT_ASSERT(so1->GetComment() == ""); + + //Try to set empty IOR + studyBuilder->SetIOR(so1, ""); + CPPUNIT_ASSERT(so1->GetIOR() == ""); + //Check method SetIOR studyBuilder->SetIOR(so1, ior); CPPUNIT_ASSERT(so1->GetIOR() == ior); @@ -184,7 +234,7 @@ void SALOMEDSTest::testStudyBuilder() SALOMEDS::Driver_var drv2 = SALOMEDS::Driver::_narrow(obj2); ior = _orb->object_to_string(drv2); - bool isRaised = false; + isRaised = false; try { sb3->LoadWith(aComp, ior); } diff --git a/src/SALOMEDS/Test/SALOMEDSTest_StudyManager.cxx b/src/SALOMEDS/Test/SALOMEDSTest_StudyManager.cxx index 04a121e69..f20d68208 100755 --- a/src/SALOMEDS/Test/SALOMEDSTest_StudyManager.cxx +++ b/src/SALOMEDS/Test/SALOMEDSTest_StudyManager.cxx @@ -36,11 +36,20 @@ void SALOMEDSTest::testStudyManager() _PTR(Study) study2 = sm->NewStudy("Study2"); CPPUNIT_ASSERT(study2); - //Check method FindStudyByName + //Check method GetStudyByName _PTR(Study) study3 = sm->GetStudyByName("Study1"); CPPUNIT_ASSERT(study3->StudyId() == study1->StudyId()); CPPUNIT_ASSERT(study3->Name() == study1->Name()); + //Check method GetStudyByName with empty name + CPPUNIT_ASSERT(!sm->GetStudyByName("")); + + //Try to create Study with empty name + _PTR(Study) study_empty = sm->NewStudy(""); + CPPUNIT_ASSERT(study_empty); + CPPUNIT_ASSERT(sm->GetStudyByName("")); + sm->Close(study_empty); + //Check method FindStudyByID _PTR(Study) study4 = sm->GetStudyByID(study2->StudyId()); CPPUNIT_ASSERT(study4->StudyId() == study2->StudyId()); @@ -55,6 +64,9 @@ void SALOMEDSTest::testStudyManager() sm->Close(study2); CPPUNIT_ASSERT(!sm->GetStudyByID(id)); + //Check method GetStudyByID for invalid ID + CPPUNIT_ASSERT(!sm->GetStudyByID(-1)); + //Check methods CanPaste, CanCopy, Copy, Paste _PTR(StudyBuilder) sb1 = study1->NewBuilder(); _PTR(SComponent) sco1 = sb1->NewComponent("Test"); @@ -87,6 +99,7 @@ void SALOMEDSTest::testStudyManager() //Check method Open _PTR(Study) study1_opened = sm->Open("srn_UnitTest_Save.hdf"); //Contains Test component system("rm -f srn_UnitTest_Save.hdf"); + url = study1->URL(); CPPUNIT_ASSERT(study1_opened); CPPUNIT_ASSERT(url == "srn_UnitTest_Save.hdf"); @@ -145,7 +158,6 @@ void SALOMEDSTest::testStudyManager() _PTR(StudyBuilder) sb6 = study4_opened->NewBuilder(); _PTR(AttributeName) na6 = sb6->FindOrCreateAttribute(so6, "AttributeName"); CPPUNIT_ASSERT(na6 && na6->Value() == "Saved study ASCII"); //Compare the value of restored attribute with string that has to be saved. - }