Salome HOME
bfd34c7ff09c0b4c0846f7ec418674d4c80765c1
[modules/gui.git] / src / TreeData / Test / tester.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "QtHelper.hxx"
21
22 //
23 // =================================================================
24 // Helper functions for DataObject and DataModel classes
25 // =================================================================
26 //
27
28 // ----
29 // A DataObject can't be used as is but must be specialized to
30 // specify the behavior in the hierarchic model.
31 #include "MyDataModel.hxx"
32
33 void TEST_DataObject() {
34   // In this test, the object id should increase at each instance
35   DataObject * dataObject;
36   for (int i=0; i<100; i++) {
37     dataObject = new MyDataObject();
38     QLOG("object nameId = " << dataObject->getNameId().c_str());
39   }
40   QLOG("path     = " << dataObject->getPath().c_str());
41   QLOG("pathname = " << dataObject->getPathName().c_str());
42
43   QLOG("serialize= " << dataObject->toString().c_str());
44
45 }
46
47 void TEST_DataModel() {
48   MyDataModel * dataModel = new MyDataModel();
49
50   int refIter = 53;
51   string refNameId;
52
53   DataObject * dataObject;
54   for (int i=0; i<100; i++) {
55     // We can either create the data object using its constructor or
56     // using the factory of the model (the prefered way):
57     // dataObject = new MyDataObject();
58     dataObject = dataModel->newDataObject();
59     dataObject->setLabel("myobject"+ToString(i));
60     if ( i == refIter ) {
61       refNameId = dataObject->getNameId();
62     }
63     dataModel->addDataObject(dataObject);
64   }
65
66   dataObject = dataModel->getDataObject(refNameId);
67   QLOG("object nameId = " << dataObject->getNameId().c_str());
68   QLOG("path     = " << dataObject->getPath().c_str());
69   QLOG("pathname = " << dataObject->getPathName().c_str());
70 }
71
72 //
73 // =================================================================
74 //
75 int main(int argc, char * argv[ ])
76 {
77   TEST_DataObject();
78   //TEST_DataModel();
79 }