Salome HOME
ca377c32f91a62bdba62ec72241d3759bf0f851f
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_Entity.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <test_HYDROData_Entity.h>
20
21 #include <HYDROData_Document.h>
22 #include <HYDROData_Entity.h>
23
24 #include <QString>
25
26 void test_HYDROData_Entity::testName()
27 {
28   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
29
30   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object
31   static const QString aName("test_name");
32   anObj->SetName(aName);
33   CPPUNIT_ASSERT_EQUAL(aName.toStdString(), anObj->GetName().toStdString());
34   
35   aDoc->Close();
36 }
37
38 void test_HYDROData_Entity::testRemove()
39 {
40   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
41   
42   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object
43   CPPUNIT_ASSERT(!anObj->IsRemoved());
44   anObj->Remove();
45   CPPUNIT_ASSERT(anObj->IsRemoved());
46
47   aDoc->Close();
48 }
49
50 void test_HYDROData_Entity::testCopy()
51 {
52   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
53
54   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object
55   static const QString aName("test_name");
56   anObj->SetName(aName);
57
58   Handle(HYDROData_Entity) aCopy = aDoc->CreateObject(KIND_IMAGE); // object for copy
59   CPPUNIT_ASSERT(aCopy->GetName().isEmpty());
60   anObj->CopyTo(aCopy, false);
61
62   // check the copied object has same name as original
63   CPPUNIT_ASSERT_EQUAL(aName.toStdString(), aCopy->GetName().toStdString());
64
65   aDoc->Close();
66 }
67
68 void test_HYDROData_Entity::testPythonNameChoice()
69 {
70   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
71
72   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // any object
73   
74   anObj->SetName("test");
75   CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "test" ) );
76
77   anObj->SetName("test_1");
78   CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "test_1" ) );
79
80   anObj->SetName("test 1");
81   CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "test_1" ) );
82
83   anObj->SetName("  test abc    hello     ");
84   CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "__test_abc____hello_____" ) );
85
86   anObj->SetName("123");
87   CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "Image_123" ) );
88
89   anObj->SetName("  123");
90   CPPUNIT_ASSERT_EQUAL( anObj->GetObjPyName().toStdString(), std::string( "__123" ) );
91
92   aDoc->Close();
93 }
94
95 void test_HYDROData_Entity::testTypes()
96 {
97   for( int i=0; i<KIND_LAST; i++ )
98   {
99     CPPUNIT_ASSERT_EQUAL( false, HYDROData_Entity::Type( (ObjectKind)i ).isEmpty() );
100     CPPUNIT_ASSERT_EQUAL( false, HYDROData_Entity::Type( (ObjectKind)i ).contains(' ') );
101   }
102 }