COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-ui-core-commit-details.cpp
Go to the documentation of this file.
1 
2 // Copyright (C) 2010-2011 von Karman Institute for Fluid Dynamics, Belgium
3 //
4 // This software is distributed under the terms of the
5 // GNU Lesser General Public License version 3 (LGPLv3).
6 // See doc/lgpl.txt and doc/gpl.txt for the license text.
7 
8 #define BOOST_TEST_DYN_LINK
9 #define BOOST_TEST_MODULE "Test module for the ui CommitDetails class"
10 
13 
15 
16 using namespace cf3;
17 using namespace cf3::common;
18 using namespace cf3::ui::core;
19 
22 
23 BOOST_AUTO_TEST_SUITE( uiCoreCommitDetailsSuite )
24 
25 
28 {
29  application();
30 
35 }
36 
38 
40 {
41  CommitDetails cd;
42  Qt::ItemDataRole role = Qt::DisplayRole;
43 
44  cd.set_option("Option1", "OldVal1", "NewVal1");
45  cd.set_option("Option2", "OldVal2", "");
46  cd.set_option("Option3", "", "NewVal3");
47 
48  // 1. invalid index
49  BOOST_CHECK( !cd.data(QModelIndex(), Qt::DecorationRole).isValid() );
50 
51  // 2. everything is ok (row 0)
52  BOOST_CHECK_EQUAL( cd.data( cd.index(0, 0), role).toString().toStdString(), std::string("Option1") );
53  BOOST_CHECK_EQUAL( cd.data( cd.index(0, 1), role).toString().toStdString(), std::string("\"OldVal1\"") );
54  BOOST_CHECK_EQUAL( cd.data( cd.index(0, 2), role).toString().toStdString(), std::string("\"NewVal1\"") );
55 
56  // 3. new value is empty (row 1)
57  BOOST_CHECK_EQUAL( cd.data( cd.index(1, 0), role).toString().toStdString(), std::string("Option2") );
58  BOOST_CHECK_EQUAL( cd.data( cd.index(1, 1), role).toString().toStdString(), std::string("\"OldVal2\"") );
59  BOOST_CHECK_EQUAL( cd.data( cd.index(1, 2), role).toString().toStdString(), std::string("--") );
60 
61  // 4. old value is empty (row 2)
62  BOOST_CHECK_EQUAL( cd.data( cd.index(2, 0), role).toString().toStdString(), std::string("Option3") );
63  BOOST_CHECK_EQUAL( cd.data( cd.index(2, 1), role).toString().toStdString(), std::string("--") );
64  BOOST_CHECK_EQUAL( cd.data( cd.index(2, 2), role).toString().toStdString(), std::string("\"NewVal3\"") );
65 
66  // 5. wrong rolw
67  BOOST_CHECK( !cd.data( cd.index(0, 0), Qt::DecorationRole).isValid() );
68 }
69 
71 
72 BOOST_AUTO_TEST_CASE( header_data )
73 {
74  CommitDetails cd;
75  Qt::ItemDataRole role = Qt::DisplayRole;
76 
77  // 1. check column headers
78  BOOST_CHECK_EQUAL( cd.headerData(0, Qt::Horizontal, role).toString().toStdString(), std::string("Name") );
79  BOOST_CHECK_EQUAL( cd.headerData(1, Qt::Horizontal, role).toString().toStdString(), std::string("Old Value") );
80  BOOST_CHECK_EQUAL( cd.headerData(2, Qt::Horizontal, role).toString().toStdString(), std::string("New Value") );
81 
82  // 2. check row headers
83  BOOST_CHECK_EQUAL( cd.headerData(0, Qt::Vertical, role).toString().toStdString(), std::string("Option #1") );
84  BOOST_CHECK_EQUAL( cd.headerData(14, Qt::Vertical, role).toString().toStdString(), std::string("Option #15") );
85  BOOST_CHECK_EQUAL( cd.headerData(8790, Qt::Vertical, role).toString().toStdString(), std::string("Option #8791") );
86 
87  // 3. wrong column number
88  BOOST_CHECK( !cd.headerData(3, Qt::Horizontal, role).isValid() );
89 
90  // 4. wrong role
91  BOOST_CHECK( !cd.headerData(1, Qt::Horizontal, Qt::DecorationRole).isValid() );
92 }
93 
95 
97 {
98  CommitDetails cd;
99 
100  BOOST_CHECK( !cd.index(0, 0).isValid() );
101 
102  cd.set_option("Option1", "OldVal", "NewVal");
103 
104  QModelIndex index = cd.index(0, 0);
105  CommitDetailsItem * item = static_cast<CommitDetailsItem*>(index.internalPointer());
106  BOOST_CHECK( is_not_null(item) );
107 
108  BOOST_CHECK_EQUAL( item->option_name().toStdString(), std::string("Option1") );
109  BOOST_CHECK_EQUAL( item->old_value().toStdString(), std::string("OldVal") );
110  BOOST_CHECK_EQUAL( item->current_value().toStdString(), std::string("NewVal") );
111 
112  BOOST_CHECK( !cd.index(0, 0, index).isValid() );
113 }
114 
116 
117 BOOST_AUTO_TEST_CASE( set_option )
118 {
119  CommitDetails cd;
120 
121  BOOST_CHECK( !cd.has_options() );
122  cd.set_option("Option1", "OldVal", "NewVal");
123  BOOST_CHECK( cd.has_options() );
124 }
125 
127 
129 {
130  CommitDetails cd(nullptr, "//Path/To/Node");
131 
132  BOOST_CHECK( !cd.has_options() );
133 
134  BOOST_CHECK_EQUAL( cd.node_path().toStdString(), std::string("//Path/To/Node") );
135  cd.set_option("Option1", "OldVal", "NewVal");
136 
137  BOOST_CHECK( cd.has_options() );
138 
139  cd.clear();
140 
141  BOOST_CHECK( !cd.has_options() );
142  BOOST_CHECK( cd.node_path().isEmpty() );
143 }
144 
147 
148 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(init)
QApplication * application()
Definition: Application.hpp:11
bool AssertionThrows
assertions throw exceptions
Definition: Assertions.hpp:67
bool ExceptionOutputs
if exception contructor should output
Definition: Exception.hpp:32
static AssertionManager & instance()
Gets the instance of the manager.
Definition: Assertions.cpp:33
Basic Classes for client-core library used by coolfluid-client application.
Definition: CNode.cpp:57
bool AssertionDumps
assertions dump backtraces
Definition: Assertions.hpp:65
Model that handles modified options details.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Reimplements QAbstractItemModel::headerData()
bool has_options() const
Checks whether the internal container has options.
bool ExceptionDumps
if exception contructor should dump backtrace
Definition: Exception.hpp:34
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Implements QAbstractItemModel::index()
QVariant data(const QModelIndex &index, int role) const
Implements QAbstractItemModel::data()
QString old_value() const
Give the old value.
Basic item used by CommitDetails class.
void set_option(const QString &optionName, const QString &oldValue, const QString &currentValue)
Sets a option.
QString node_path() const
Gives the node path.
QString current_value() const
Gives the current value.
Top-level namespace for coolfluid.
Definition: Action.cpp:18
static ExceptionManager & instance()
Gets the instance of the manager.
Definition: Exception.cpp:34
QString option_name() const
Gives the option name.
void clear()
Removes all options and clears the node path.
Most basic kernel library.
Definition: Action.cpp:19
bool is_not_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:147
Send comments to:
COOLFluiD Web Admin