Object Detection  5.0
Image Processing Using Qt and Opencv
tst_testobserversubjecttest.cpp
1 #include <QString>
2 #include <QtTest>
3 #include "subjectimpl.h"
4 #include "observerimpl.h"
5 using namespace Devices;
6 Q_DECLARE_METATYPE(ObserverImpl*)
7 Q_DECLARE_METATYPE(SubjectImpl*)
8 Q_DECLARE_METATYPE(ObservableData*)
9 Q_DECLARE_METATYPE(Observer*)
10 Q_DECLARE_METATYPE(Subject*)
11 class TestObserverSubjectTest : public QObject
12 {
13  Q_OBJECT
14 
15 public:
17 
18 private Q_SLOTS:
19  void testCaseObserversSignals();
20  void testCaseObserversSignals_data();
21 
22 };
23 
24 TestObserverSubjectTest::TestObserverSubjectTest()
25 {
26 }
27 
28 void TestObserverSubjectTest::testCaseObserversSignals()
29 {
30  QFETCH(ObservableData*, data);
31  QFETCH(ObserverImpl*, obs);
32  QFETCH(SubjectImpl*, sub);
33  obs->observe(sub);
34  QVERIFY2(sub->getObservers().size() == 1, "Num is not 1");
35  QSignalSpy spy{sub, SIGNAL(notifyObservers(ObservableData))};
36  emit sub->notifyObservers(*data);
37  QVERIFY2(spy.count() == 1, "More Than one Signal");
38  QList<QVariant> vars = spy.takeFirst();
39  QVERIFY2(vars.size() != 0, "Size Error");
40  QVERIFY2(!vars.at(0).isNull(), "Object Error");
41 
42 }
43 
44 void TestObserverSubjectTest::testCaseObserversSignals_data()
45 {
46  QTest::addColumn<ObservableData*>("data");
47  QTest::addColumn<ObserverImpl*>("obs");
48  QTest::addColumn<SubjectImpl*>("sub");
49  QTest::addRow("Test Data1") << new ObservableData << new ObserverImpl(this) << new SubjectImpl;
50 
51 }
52 
53 QTEST_APPLESS_MAIN(TestObserverSubjectTest)
54 
55 #include "tst_testobserversubjecttest.moc"