test motif editor
[mussa.git] / qui / motif_editor / test / TestMotifEditor.hpp
1 #ifndef TESTMOTIFEDITOR_HPP_
2 #define TESTMOTIFEDITOR_HPP_
3 #include <QtGui>
4 #include <QVariant>
5 #include <QtTest/QtTest>
6 #include <QtTest/QSignalSpy>
7
8 #include <vector>
9 #include "alg/sequence.hpp"
10
11 #include "qui/motif_editor/MotifEditor.hpp"
12 #include "qui/motif_editor/MotifModel.hpp"
13
14 class TestMotifEditor : public QObject
15 {
16   Q_OBJECT
17
18 private slots:
19
20   void testSimpleConstructor() {
21     MussaRef m1(new Mussa);
22     MotifEditor *editor = new MotifEditor(m1);
23     
24     QVERIFY(editor->get_analysis() == m1);
25     QVERIFY(editor->get_model() != 0);
26   }
27
28   // do we still have motifs in our sequences after hitting apply?
29   void testEditColorApply() {
30     std::vector<Sequence> motifs;
31     motifs.push_back("AAGG");
32     std::vector<Color> colors;
33     colors.push_back(Color(0.0, 0.0, 1.0));
34         
35     MussaRef m(new Mussa);
36     m->append_sequence("AAAAGGGGTTTT");
37     m->append_sequence("AAAAAAAACCCC");
38     m->set_motifs(motifs, colors);
39     
40     // do the sequences have the right motifs?
41     std::vector<SequenceRef> sequences1(m->sequences());
42     QVERIFY(sequences1[0]->motifs().size() == 1);
43     QVERIFY(sequences1[1]->motifs().size() == 0);
44     
45     // get color
46     boost::shared_ptr<AnnotationColors> cm(m->colorMapper());
47     QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 0.0, 1.0));
48         
49     MotifEditor *editor(new MotifEditor(m));
50     MotifModel *model(editor->get_model());
51     // the AAGG motif and the emtpy motif
52     QVERIFY(model->size() == 2);
53     QModelIndex row0_color(model->index(0, MotifModel::ColorCell));
54     
55     model->setData(row0_color, QVariant(QColor(0,255,0)));
56     // this is equivalent to pressing apply
57     editor->updateAnalysisMotifs();
58
59     std::vector<SequenceRef> sequences2(m->sequences());
60     QVERIFY(sequences2[0]->motifs().size() == 1);
61     QVERIFY(sequences2[1]->motifs().size() == 0);
62     QVERIFY(cm->lookup("motif", "AAGG") == Color(0.0, 1.0, 0.0));
63   }
64 /*
65   
66 public slots:
67   void updateModel();
68   void updateAnalysisMotifs();
69
70 signals:
71   void changedMotifs();
72   */
73 };
74 #endif /*TESTMOTIFEDITOR_HPP_*/