1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_SQLITE_OBJECT_DBI_UNIT_TESTS_H_
23 #define _U2_SQLITE_OBJECT_DBI_UNIT_TESTS_H_
24 
25 #include <unittest.h>
26 
27 #include "core/dbi/DbiTest.h"
28 
29 namespace U2 {
30 
31 class SQLiteDbi;
32 class SQLiteObjectDbi;
33 class U2AttributeDbi;
34 class U2MsaDbi;
35 class U2SequenceDbi;
36 
37 class SQLiteObjectDbiTestData {
38 public:
39     static void init();
40 
41     static void shutdown();
42 
43     static SQLiteDbi *getSQLiteDbi();
44     static SQLiteObjectDbi *getSQLiteObjectDbi();
45     static U2AttributeDbi *getAttributeDbi();
46     static U2MsaDbi *getMsaDbi();
47     static U2SequenceDbi *getSequenceDbi();
48 
49     static U2DataId createTestMsa(bool enableModTracking, U2OpStatus &os);
50     static void addTestRow(const U2DataId &msaId, U2OpStatus &os);
51 
52 private:
53     static TestDbiProvider dbiProvider;
54     static const QString &SQLITE_OBJ_DB_URL;
55     static U2AttributeDbi *attributeDbi;
56     static U2MsaDbi *msaDbi;
57     static U2SequenceDbi *sequenceDbi;
58     static SQLiteObjectDbi *sqliteObjectDbi;
59     static SQLiteDbi *sqliteDbi;
60 };
61 
62 /**
63  * Remove a MSA object from the database, the following must be removed:
64  *   1) Records in "Attribute" table (MSA info)
65  *   2) Records in "StringAttribute"
66  *   3) Records in "MsaRow"
67  *   4) Records in "MsaRowGap"
68  *   5) Records in "Sequence" (not used by other objects)
69  *   6) The record in "Msa"
70  *   7) The record in "Object"
71  * Records of another MSA object are not removed.
72  */
73 DECLARE_TEST(SQLiteObjectDbiUnitTests, removeMsaObject);
74 DECLARE_TEST(SQLiteObjectDbiUnitTests, setTrackModType);
75 
76 /**
77  * canUndoRedo: check canUndo() and canRedo() functions.
78  *  ^ noTrack                   - modification tracking is turned off: no undo, no redo.
79  *  ^ noAction                  - no action happened with object after creation: no undo, no redo.
80  *  ^ lastState                 - object is in the last state: undo, no redo.
81  *  ^ firstState                - object is in the first state: no undo, redo.
82  *  ^ midState                  - object is in the middle state: undo, redo.
83  *  ^ oneUserStep               - object gets two actions with one user step, then undo: no undo, redo.
84  */
85 DECLARE_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_noTrack);
86 DECLARE_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_noAction);
87 DECLARE_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_lastState);
88 DECLARE_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_firstState);
89 DECLARE_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_midState);
90 DECLARE_TEST(SQLiteObjectDbiUnitTests, canUndoRedo_oneUserStep);
91 
92 /**
93  * Common tests for undo/redo and modification steps.
94  *   ^ user2MultiVersions    - verify the master object version, version in the userModStep and
95  *                             canUndo/canRedo when there is one user mod step with 3 multi steps.
96  *   ^ actionAfterUndo       - verify that modification steps are removed properly when an action is
97  *                             done after undo. Verify undo/redo after this.
98  *   ^ actionUndoActionUndo1 - do an action, undo it, do another action, undo it. User steps are created manually.
99  *   ^ actionUndoActionUndo2 - do an action, undo it, do another action, undo it. User steps are created automatically.
100  *   ^ actionUndoActionUndo3 - do an action (userModStep is created automatically), undo, do an action (userModStep
101  *                             is created manually), undo
102  *   ^ actionUndoActionUndo4 - do an action (userModStep is created manually), undo, do an action (userModStep
103  *                             is created automatically), undo
104  *   ^ user3Single6          - create a user step manually (with 2 multi/single steps), create a user step
105  *                             automatically (with 1 multi/step step), create 3rd user step manually
106  *                             with 2 multi steps and 3 single steps (i.e. add row + update row content).
107  *                             Do undo/redo. Verify versions and canUndo/canRedo.
108  */
109 DECLARE_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_user3Multi);
110 DECLARE_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_actionAfterUndo);
111 DECLARE_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo1);
112 DECLARE_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo2);
113 DECLARE_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo3);
114 DECLARE_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo4);
115 DECLARE_TEST(SQLiteObjectDbiUnitTests, commonUndoRedo_user3Single6);
116 
117 }  // namespace U2
118 
119 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, removeMsaObject);
120 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, setTrackModType);
121 
122 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, canUndoRedo_noTrack);
123 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, canUndoRedo_noAction);
124 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, canUndoRedo_lastState);
125 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, canUndoRedo_firstState);
126 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, canUndoRedo_midState);
127 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, canUndoRedo_oneUserStep);
128 
129 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, commonUndoRedo_user3Multi);
130 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, commonUndoRedo_actionAfterUndo);
131 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo1);
132 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo2);
133 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo3);
134 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, commonUndoRedo_actionUndoActionUndo4);
135 DECLARE_METATYPE(SQLiteObjectDbiUnitTests, commonUndoRedo_user3Single6);
136 
137 #endif
138