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