Salome HOME
e133b6e42c0f3cc24f3c42c5665b15573e1dfc65
[modules/kernel.git] / src / SALOMEDS / Test / SALOMEDSTest_AttributeSequenceOfInteger.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 /*!
24  * Check all methods of SALOMEDS_AttributeSequenceOfInteger
25  * Use code of SALOMEDS_AttributeSequenceOfInteger.cxx
26  */
27 void SALOMEDSTest::testAttributeSequenceOfInteger()
28 {
29   //Create Study
30   _PTR(Study) study(new SALOMEDS_Study(_study));
31
32   CPPUNIT_ASSERT(study);
33
34   //Create Study Builder
35   _PTR(StudyBuilder) studyBuilder = study->NewBuilder();
36
37   CPPUNIT_ASSERT(studyBuilder);
38
39   //Create a SObject with entry 0:1:1
40   _PTR(SObject) so = study->CreateObjectID("0:1:1");
41
42   CPPUNIT_ASSERT(so);
43
44   //Create an attribute AttributeSequenceOfInteger
45   _PTR(AttributeSequenceOfInteger) _attr = studyBuilder->FindOrCreateAttribute(so, "AttributeSequenceOfInteger");
46
47   //Check the attribute creation
48   CPPUNIT_ASSERT(_attr);
49
50   //Check method Length
51   CPPUNIT_ASSERT(_attr->Length() == 0);
52
53   //Check method Add
54   _attr->Add(1);
55
56   _attr->Add(2);
57
58   _attr->Add(3);
59
60   _attr->Add(4);
61
62   CPPUNIT_ASSERT(_attr->Length() == 4);
63
64   CPPUNIT_ASSERT(_attr->Value(2) == 2);
65
66   //Check method Remove
67   _attr->Remove(3);
68
69   //Check method Value
70   CPPUNIT_ASSERT(_attr->Value(3) == 4);
71
72   //Check method ChangeValue
73   _attr->ChangeValue(3, 3);
74
75   CPPUNIT_ASSERT(_attr->Value(3) == 3);
76
77   //Check method CorbaSequence
78   std::vector<int> v = _attr->CorbaSequence();
79   CPPUNIT_ASSERT(v.size() == 3);
80
81
82   for(int i = 0; i<(int)v.size(); i++) 
83     CPPUNIT_ASSERT((i+1) == v[i]);
84
85   v.push_back(5);
86
87   //Check method Assign
88   _attr->Assign(v);
89
90   CPPUNIT_ASSERT(_attr->Length() == 4);
91
92   CPPUNIT_ASSERT(_attr->Value(4) == 5);
93
94   //Check processing of invalid indices
95   bool isRaised = false;
96   try {
97     _attr->Value(-1);
98   }
99   catch(...) {
100     isRaised = true;
101   }
102   CPPUNIT_ASSERT(isRaised);
103   isRaised = false;
104   try {
105     _attr->ChangeValue(12, 1);
106   }
107   catch(...) {
108     isRaised = true;
109   }
110   CPPUNIT_ASSERT(isRaised);
111   isRaised = false;
112   try {
113     _attr->Remove(10);
114   }
115   catch(...) {
116     isRaised = true;
117   }
118   CPPUNIT_ASSERT(isRaised);
119
120   study->Clear();
121 }
122
123
124