File indexing completed on 2024-05-19 05:41:30
0001 #include <QTest> 0002 0003 #include <QSignalSpy> 0004 #include "rwidgets/delegates/statedelegate.h" 0005 #include "model/characterstatemodel.h" 0006 #include <helper.h> 0007 #include <QComboBox> 0008 0009 0010 class StateDelegateTest : public QObject 0011 { 0012 Q_OBJECT 0013 public: 0014 StateDelegateTest() = default; 0015 0016 private slots: 0017 void init(); 0018 0019 void setAndGetTest(); 0020 void nullableTest(); 0021 0022 private: 0023 std::unique_ptr<StateDelegate> m_delegate; 0024 std::unique_ptr<CharacterStateModel> m_states; 0025 std::unique_ptr<QComboBox> m_combox; 0026 }; 0027 0028 0029 void StateDelegateTest::init() 0030 { 0031 m_combox.reset(new QComboBox); 0032 0033 m_states.reset(new CharacterStateModel); 0034 CharacterState a; 0035 a.setId("ii"); 0036 a.setLabel("State 1"); 0037 a.setColor(Qt::green); 0038 a.setImagePath(":/img/arbre_square_500.jpg"); 0039 m_states->appendState(std::move(a)); 0040 0041 CharacterState b; 0042 b.setId("iO"); 0043 b.setLabel("State 2"); 0044 b.setColor(Qt::blue); 0045 b.setImagePath(":/img/lion.jpg"); 0046 m_states->appendState(std::move(b)); 0047 0048 m_delegate.reset(new StateDelegate(m_states.get())); 0049 } 0050 0051 void StateDelegateTest::setAndGetTest() 0052 { 0053 m_combox->setModel(m_states.get()); 0054 m_combox->setItemDelegate(m_delegate.get()); 0055 0056 m_combox->show(); 0057 0058 m_combox->setCurrentIndex(1); 0059 0060 m_combox->setCurrentIndex(2); 0061 0062 } 0063 0064 void StateDelegateTest::nullableTest() 0065 { 0066 m_delegate->setEditorData(nullptr, QModelIndex()); 0067 m_delegate->setModelData(nullptr, nullptr, QModelIndex()); 0068 } 0069 0070 0071 QTEST_MAIN(StateDelegateTest); 0072 #include "tst_state.moc"