Back to index

salome-gui  6.5.0
tester.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "QtHelper.hxx"
00021 
00022 //
00023 // =================================================================
00024 // Helper functions for DataObject and DataModel classes
00025 // =================================================================
00026 //
00027 
00028 // ----
00029 // A DataObject can't be used as is but must be specialized to
00030 // specify the behavior in the hierarchic model.
00031 #include "MyDataModel.hxx"
00032 
00033 void TEST_DataObject() {
00034   // In this test, the object id should increase at each instance
00035   DataObject * dataObject;
00036   for (int i=0; i<100; i++) {
00037     dataObject = new MyDataObject();
00038     QLOG("object nameId = " << dataObject->getNameId().c_str());
00039   }
00040   QLOG("path     = " << dataObject->getPath().c_str());
00041   QLOG("pathname = " << dataObject->getPathName().c_str());
00042 
00043   QLOG("serialize= " << dataObject->toString().c_str());
00044 
00045 }
00046 
00047 void TEST_DataModel() {
00048   MyDataModel * dataModel = new MyDataModel();
00049 
00050   int refIter = 53;
00051   string refNameId;
00052 
00053   DataObject * dataObject;
00054   for (int i=0; i<100; i++) {
00055     // We can either create the data object using its constructor or
00056     // using the factory of the model (the prefered way):
00057     // dataObject = new MyDataObject();
00058     dataObject = dataModel->newDataObject();
00059     dataObject->setLabel("myobject"+ToString(i));
00060     if ( i == refIter ) {
00061       refNameId = dataObject->getNameId();
00062     }
00063     dataModel->addDataObject(dataObject);
00064   }
00065 
00066   dataObject = dataModel->getDataObject(refNameId);
00067   QLOG("object nameId = " << dataObject->getNameId().c_str());
00068   QLOG("path     = " << dataObject->getPath().c_str());
00069   QLOG("pathname = " << dataObject->getPathName().c_str());
00070 }
00071 
00072 //
00073 // =================================================================
00074 //
00075 int main(int argc, char * argv[ ])
00076 {
00077   TEST_DataObject();
00078   //TEST_DataModel();
00079 }