Salome HOME
#refs 522 (very draft) //import only
[modules/hydro.git] / src / HYDROData / test_HYDROData_Document.cxx
1 // Copyright (C) 2007-2015  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 #include<test_HYDROData_Document.h>
24
25 #include <HYDROData_Document.h>
26 #include <QFile>
27
28 void test_HYDROData_Document::testSaveOpen()
29 {
30   // temporarly created file name (in the current directory)
31   const char* aTestFile = "TestDoc.cbf";
32   // save
33   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
34   CPPUNIT_ASSERT(!aDoc.IsNull());
35   // keep some saved information to check after retreive
36   aDoc->NewID();
37   int anID = aDoc->NewID();
38   Data_DocError aStatus = aDoc->Save(aTestFile);
39   CPPUNIT_ASSERT(aStatus == DocError_OK);
40   aDoc->Close();
41   CPPUNIT_ASSERT(!HYDROData_Document::HasDocument(1));
42
43   // open
44   aStatus = HYDROData_Document::Load(aTestFile, 2);
45   CPPUNIT_ASSERT(aStatus == DocError_OK);
46   CPPUNIT_ASSERT(HYDROData_Document::HasDocument(2));
47   aDoc = HYDROData_Document::Document(2);
48   CPPUNIT_ASSERT(!aDoc.IsNull());
49   // check that retreived correctly
50   CPPUNIT_ASSERT(aDoc->NewID() == anID + 1);
51
52   // remove the created file using Qt functionality
53   QFile aFile(aTestFile);
54   aFile.remove();
55
56   aDoc->Close();
57 }
58
59 void test_HYDROData_Document::testOperations()
60 {
61   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
62   CPPUNIT_ASSERT(!aDoc.IsNull());
63   CPPUNIT_ASSERT(!aDoc->IsOperation());
64   CPPUNIT_ASSERT(!aDoc->IsModified());
65   // commit operation
66   aDoc->StartOperation();
67   CPPUNIT_ASSERT(aDoc->IsOperation());
68   int anID = aDoc->NewID();
69   aDoc->CommitOperation();
70   CPPUNIT_ASSERT(!aDoc->IsOperation());
71   CPPUNIT_ASSERT(aDoc->IsModified());
72   // abort operation
73   aDoc->StartOperation();
74   CPPUNIT_ASSERT(aDoc->IsOperation());
75   int anIDAborted = aDoc->NewID();
76   aDoc->AbortOperation();
77   CPPUNIT_ASSERT(!aDoc->IsOperation());
78   CPPUNIT_ASSERT(aDoc->IsModified());
79
80   CPPUNIT_ASSERT(anID + 1 == aDoc->NewID());
81
82   aDoc->Close();
83 }
84
85 void test_HYDROData_Document::testUndoRedo()
86 {
87   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
88   CPPUNIT_ASSERT(!aDoc.IsNull());
89   CPPUNIT_ASSERT(!aDoc->CanUndo());
90   CPPUNIT_ASSERT(!aDoc->CanRedo());
91   // commit operation
92   aDoc->StartOperation();
93   CPPUNIT_ASSERT(aDoc->IsOperation());
94   int anID = aDoc->NewID();
95   aDoc->CommitOperation();
96   CPPUNIT_ASSERT(aDoc->CanUndo());
97   CPPUNIT_ASSERT(!aDoc->CanRedo());
98   CPPUNIT_ASSERT(aDoc->IsModified());
99   // undo
100   aDoc->Undo();
101   CPPUNIT_ASSERT(!aDoc->CanUndo());
102   CPPUNIT_ASSERT(aDoc->CanRedo());
103   CPPUNIT_ASSERT(anID == aDoc->NewID());
104   CPPUNIT_ASSERT(!aDoc->IsModified());
105   // redo
106   aDoc->Redo();
107   CPPUNIT_ASSERT(aDoc->CanUndo());
108   CPPUNIT_ASSERT(!aDoc->CanRedo());
109   CPPUNIT_ASSERT(aDoc->IsModified());
110
111   aDoc->Close();
112 }