tst_neovimobject.cpp
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 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( 41 QStringLiteral("call rpcnotify(%1, \"test_event\", \"WAT\")").arg(m_c->channel()).toUtf8()); 42 n->vim_command( 43 QStringLiteral("call rpcnotify(%1, \"test_event\", 42)").arg(m_c->channel()).toUtf8()); 44 n->vim_command(QStringLiteral("call rpcnotify(%1, \"test_event\", [\"one\", \"two\", \"\"])") 45 .arg(m_c->channel()) 46 .toUtf8()); 47 } 48 49 void TestNeovimObject::test_event(const QByteArray& name, const QVariantList& params) 50 { 51 QVariant arg0 = params.at(0); 52 if ( (QMetaType::Type)arg0.type() == QMetaType::QByteArray ) { 53 QVERIFY(arg0.toString() == "WAT"); 54 m_test_event_string = true; 55 } 56 57 if ( (QMetaType::Type)arg0.type() == QMetaType::ULongLong ) { 58 QVERIFY(arg0.toInt() == 42); 59 m_test_event_uint = true; 60 } 61 62 if (arg0.canConvert(QMetaType::QStringList)) { 63 QStringList l = arg0.toStringList(); 64 m_test_event_stringlist = true; 65 } 66 } 67 68 // 69 // Tests start here 70 // 71 void TestNeovimObject::eventTypes() 72 { 73 QVERIFY(m_test_event_string); 74 QVERIFY(m_test_event_uint); 75 QVERIFY(m_test_event_stringlist); 76 } 77 78 /// Check EXT types with the Tabpage type 79 void TestNeovimObject::extDecodeApi0() 80 { 81 auto *obj = m_c->api0(); 82 QSignalSpy result(obj, SIGNAL(on_vim_get_current_tabpage(int64_t))); 83 QVERIFY(result.isValid()); 84 85 obj->vim_get_current_tabpage(); 86 QVERIFY(SPYWAIT(result)); 87 QCOMPARE(result.at(0).at(0), QVariant(1)); 88 } 89 90 void TestNeovimObject::extDecodeApi1() 91 { 92 auto *obj = m_c->api1(); 93 QSignalSpy result(obj, SIGNAL(on_nvim_get_current_tabpage(int64_t))); 94 QVERIFY(result.isValid()); 95 96 obj->nvim_get_current_tabpage(); 97 QVERIFY(SPYWAIT(result)); 98 QCOMPARE(result.at(0).at(0), QVariant(1)); 99 } 100 101 void TestNeovimObject::extDecodeApi2() 102 { 103 auto *obj = m_c->api2(); 104 QSignalSpy result(obj, SIGNAL(on_nvim_get_current_tabpage(int64_t))); 105 QVERIFY(result.isValid()); 106 107 obj->nvim_get_current_tabpage(); 108 QVERIFY(SPYWAIT(result)); 109 QCOMPARE(result.at(0).at(0), QVariant(1)); 110 } 111 112 void TestNeovimObject::initTestCase() 113 { 114 // needed for the nvim api signal spy 115 qRegisterMetaType<int64_t>("int64_t"); 116 m_c = NeovimQt::NeovimConnector::spawn({"-u", "NONE"}); 117 connect(m_c, &NeovimQt::NeovimConnector::ready, 118 this, &TestNeovimObject::delayedSetup); 119 QTest::qWait(1500); 120 QVERIFY(m_c->errorCause() == NeovimQt::NeovimConnector::NoError); 121 } 122 123 QTEST_MAIN(TestNeovimObject) 124 #include "tst_neovimobject.moc" 125