]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/test_HYDROData_Document.cxx
Salome HOME
Access methods for object groups added.
[modules/hydro.git] / src / HYDROData / test_HYDROData_Document.cxx
1 #include<test_HYDROData_Document.h>
2
3 #include <HYDROData_Document.h>
4 #include <QFile>
5
6 void test_HYDROData_Document::testSaveOpen()
7 {
8   // temporarly created file name (in the current directory)
9   const char* aTestFile = "TestDoc.cbf";
10   // save
11   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
12   CPPUNIT_ASSERT(!aDoc.IsNull());
13   // keep some saved information to check after retreive
14   aDoc->NewID();
15   int anID = aDoc->NewID();
16   Data_DocError aStatus = aDoc->Save(aTestFile);
17   CPPUNIT_ASSERT(aStatus == DocError_OK);
18   aDoc->Close();
19   CPPUNIT_ASSERT(!HYDROData_Document::HasDocument(1));
20
21   // open
22   aStatus = HYDROData_Document::Load(aTestFile, 2);
23   CPPUNIT_ASSERT(aStatus == DocError_OK);
24   CPPUNIT_ASSERT(HYDROData_Document::HasDocument(2));
25   aDoc = HYDROData_Document::Document(2);
26   CPPUNIT_ASSERT(!aDoc.IsNull());
27   // check that retreived correctly
28   CPPUNIT_ASSERT(aDoc->NewID() == anID + 1);
29
30   // remove the created file using Qt functionality
31   QFile aFile(aTestFile);
32   aFile.remove();
33
34   aDoc->Close();
35 }
36
37 void test_HYDROData_Document::testOperations()
38 {
39   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
40   CPPUNIT_ASSERT(!aDoc.IsNull());
41   CPPUNIT_ASSERT(!aDoc->IsOperation());
42   CPPUNIT_ASSERT(!aDoc->IsModified());
43   // commit operation
44   aDoc->StartOperation();
45   CPPUNIT_ASSERT(aDoc->IsOperation());
46   int anID = aDoc->NewID();
47   aDoc->CommitOperation();
48   CPPUNIT_ASSERT(!aDoc->IsOperation());
49   CPPUNIT_ASSERT(aDoc->IsModified());
50   // abort operation
51   aDoc->StartOperation();
52   CPPUNIT_ASSERT(aDoc->IsOperation());
53   int anIDAborted = aDoc->NewID();
54   aDoc->AbortOperation();
55   CPPUNIT_ASSERT(!aDoc->IsOperation());
56   CPPUNIT_ASSERT(aDoc->IsModified());
57
58   CPPUNIT_ASSERT(anID + 1 == aDoc->NewID());
59
60   aDoc->Close();
61 }
62
63 void test_HYDROData_Document::testUndoRedo()
64 {
65   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
66   CPPUNIT_ASSERT(!aDoc.IsNull());
67   CPPUNIT_ASSERT(!aDoc->CanUndo());
68   CPPUNIT_ASSERT(!aDoc->CanRedo());
69   // commit operation
70   aDoc->StartOperation();
71   CPPUNIT_ASSERT(aDoc->IsOperation());
72   int anID = aDoc->NewID();
73   aDoc->CommitOperation();
74   CPPUNIT_ASSERT(aDoc->CanUndo());
75   CPPUNIT_ASSERT(!aDoc->CanRedo());
76   CPPUNIT_ASSERT(aDoc->IsModified());
77   // undo
78   aDoc->Undo();
79   CPPUNIT_ASSERT(!aDoc->CanUndo());
80   CPPUNIT_ASSERT(aDoc->CanRedo());
81   CPPUNIT_ASSERT(anID == aDoc->NewID());
82   CPPUNIT_ASSERT(!aDoc->IsModified());
83   // redo
84   aDoc->Redo();
85   CPPUNIT_ASSERT(aDoc->CanUndo());
86   CPPUNIT_ASSERT(!aDoc->CanRedo());
87   CPPUNIT_ASSERT(aDoc->IsModified());
88
89   aDoc->Close();
90 }