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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include<test_HYDROData_Image.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_Image.h>
25 static QImage TestImage() {
26 QImage aPic(50, 40, QImage::Format_RGB32);
27 QPainter aPainter(&aPic);
28 aPainter.drawEllipse(6, 7, 38, 30);
29 aPainter.drawLine(0, 40, 10, 0);
30 aPainter.drawLine(10, 0, 25, 35);
31 aPainter.drawLine(25, 35, 40, 0);
32 aPainter.drawLine(40, 0, 50, 40);
36 void test_HYDROData_Image::testQImage()
38 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
40 Handle(HYDROData_Image) anImage =
41 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
43 QImage anEmpty = anImage->Image();
44 CPPUNIT_ASSERT(anEmpty.isNull());
46 // prepare Qt Image for testing
47 QImage aPic(TestImage());
48 anImage->SetImage(aPic);
49 QImage aRestored = anImage->Image();
51 CPPUNIT_ASSERT(!aRestored.isNull());
52 //aRestored.save("pic2.bmp");
53 CPPUNIT_ASSERT(aPic == aRestored);
58 void test_HYDROData_Image::testTrsf()
60 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
62 Handle(HYDROData_Image) anImage =
63 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
65 QTransform anEmpty = anImage->Trsf();
66 CPPUNIT_ASSERT(anEmpty.isIdentity());
68 // prepare Qt transformation for testing
70 aTrsf.translate(50, 50);
72 aTrsf.scale(0.5, 1.0);
74 anImage->SetTrsf(aTrsf);
75 QTransform aRestored = anImage->Trsf();
77 CPPUNIT_ASSERT(!aRestored.isIdentity());
78 CPPUNIT_ASSERT(aTrsf == aRestored);
83 void test_HYDROData_Image::testReferences()
85 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
87 Handle(HYDROData_Image) anImage1 =
88 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
89 Handle(HYDROData_Image) anImage2 =
90 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
91 Handle(HYDROData_Image) anImage3 =
92 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
94 // check initially there is no references
95 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0);
98 anImage3->AppendReference(anImage1);
99 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1);
100 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1));
103 anImage3->ChangeReference(0, anImage2);
104 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1);
105 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2));
107 // append one more reference
108 anImage3->AppendReference(anImage1);
109 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 2);
110 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2));
111 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(1), anImage1));
114 anImage3->RemoveReference(0);
115 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1);
116 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1));
119 anImage3->RemoveReference(0);
120 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0);
122 // append two references once again and remove all references
123 anImage3->ChangeReference(0, anImage1);
124 anImage3->ChangeReference(1, anImage2);
125 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 2);
126 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage1));
127 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(1), anImage2));
128 anImage3->ClearReferences();
129 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 0);
134 void test_HYDROData_Image::testCopy()
136 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
138 Handle(HYDROData_Image) anImage1 =
139 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
141 anImage1->SetImage(TestImage());
144 aTrsf.translate(50, 50);
146 aTrsf.scale(0.5, 1.0);
147 anImage1->SetTrsf(aTrsf);
149 Handle(HYDROData_Image) anImage2 =
150 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
152 anImage1->AppendReference(anImage2);
154 // copy image to the new one
155 Handle(HYDROData_Image) anImage3 =
156 Handle(HYDROData_Image)::DownCast(aDoc->CreateObject(KIND_IMAGE));
157 anImage1->CopyTo(anImage3);
159 // check all fields are correctly copied
160 CPPUNIT_ASSERT(anImage1->Image() == anImage3->Image());
161 CPPUNIT_ASSERT(anImage1->Trsf() == anImage3->Trsf());
162 CPPUNIT_ASSERT_EQUAL(anImage3->NbReferences(), 1);
163 CPPUNIT_ASSERT(IsEqual(anImage3->Reference(0), anImage2));