1
2 #include <QtTest/QtTest>
3 #include <QLocalSocket>
4 #include <neovimconnector.h>
5 #include "common.h"
6
7 class TestNeovimObject: public QObject
8 {
9 Q_OBJECT
10 public slots:
11 void test_event(const QByteArray& name, const QVariantList&);
12
13 protected slots:
14 void delayedSetup();
15
16 private slots:
17 void initTestCase();
18 void eventTypes();
19 void extDecodeApi0();
20 void extDecodeApi1();
21 void extDecodeApi2();
22 private:
23 NeovimQt::NeovimConnector *m_c;
24 bool m_test_event_string;
25 bool m_test_event_uint;
26 bool m_test_event_stringlist;
27 };
28
delayedSetup()29 void TestNeovimObject::delayedSetup()
30 {
31 QVERIFY(m_c->neovimObject());
32 auto *n = m_c->neovimObject();
33
34 m_test_event_string = false;
35 m_test_event_uint = false;
36 m_test_event_stringlist = false;
37 connect(n, &NeovimQt::NeovimApi1::neovimNotification,
38 this, &TestNeovimObject::test_event);
39
40 n->vim_command(QString("call rpcnotify(%1, \"test_event\", \"WAT\")").arg(m_c->channel()).toUtf8());
41 n->vim_command(QString("call rpcnotify(%1, \"test_event\", 42)").arg(m_c->channel()).toUtf8());
42 n->vim_command(QString("call rpcnotify(%1, \"test_event\", [\"one\", \"two\", \"\"])").arg(m_c->channel()).toUtf8());
43 }
44
test_event(const QByteArray & name,const QVariantList & params)45 void TestNeovimObject::test_event(const QByteArray& name, const QVariantList& params)
46 {
47 QVariant arg0 = params.at(0);
48 if ( (QMetaType::Type)arg0.type() == QMetaType::QByteArray ) {
49 QVERIFY(arg0.toString() == "WAT");
50 m_test_event_string = true;
51 }
52
53 if ( (QMetaType::Type)arg0.type() == QMetaType::ULongLong ) {
54 QVERIFY(arg0.toInt() == 42);
55 m_test_event_uint = true;
56 }
57
58 if (arg0.canConvert(QMetaType::QStringList)) {
59 QStringList l = arg0.toStringList();
60 m_test_event_stringlist = true;
61 }
62 }
63
64 //
65 // Tests start here
66 //
eventTypes()67 void TestNeovimObject::eventTypes()
68 {
69 QVERIFY(m_test_event_string);
70 QVERIFY(m_test_event_uint);
71 QVERIFY(m_test_event_stringlist);
72 }
73
74 /// Check EXT types with the Tabpage type
extDecodeApi0()75 void TestNeovimObject::extDecodeApi0()
76 {
77 auto *obj = m_c->api0();
78 QSignalSpy result(obj, SIGNAL(on_vim_get_current_tabpage(int64_t)));
79 QVERIFY(result.isValid());
80
81 obj->vim_get_current_tabpage();
82 QVERIFY(SPYWAIT(result));
83 QCOMPARE(result.at(0).at(0), QVariant(1));
84 }
85
extDecodeApi1()86 void TestNeovimObject::extDecodeApi1()
87 {
88 auto *obj = m_c->api1();
89 QSignalSpy result(obj, SIGNAL(on_nvim_get_current_tabpage(int64_t)));
90 QVERIFY(result.isValid());
91
92 obj->nvim_get_current_tabpage();
93 QVERIFY(SPYWAIT(result));
94 QCOMPARE(result.at(0).at(0), QVariant(1));
95 }
96
extDecodeApi2()97 void TestNeovimObject::extDecodeApi2()
98 {
99 auto *obj = m_c->api2();
100 QSignalSpy result(obj, SIGNAL(on_nvim_get_current_tabpage(int64_t)));
101 QVERIFY(result.isValid());
102
103 obj->nvim_get_current_tabpage();
104 QVERIFY(SPYWAIT(result));
105 QCOMPARE(result.at(0).at(0), QVariant(1));
106 }
107
initTestCase()108 void TestNeovimObject::initTestCase()
109 {
110 // needed for the nvim api signal spy
111 qRegisterMetaType<int64_t>("int64_t");
112 m_c = NeovimQt::NeovimConnector::spawn({"-u", "NONE"});
113 connect(m_c, &NeovimQt::NeovimConnector::ready,
114 this, &TestNeovimObject::delayedSetup);
115 QTest::qWait(1500);
116 QVERIFY(m_c->errorCause() == NeovimQt::NeovimConnector::NoError);
117 }
118
119 QTEST_MAIN(TestNeovimObject)
120 #include "tst_neovimobject.moc"
121
122