From 46b0f079cfa5a9ef087a1a65828903a2ac000b3c Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 15 Jul 2018 20:58:54 +0200 Subject: [PATCH] Skipping HTTP tests rather than disabling them With this commit, tests are logged as skipped and not just omitted, if HTTP support is not enabled (neighter Qt nor curl) --- .../pcb/unit_tests/dbGerberImport.cc | 5 ++++ src/rdb/unit_tests/rdb.cc | 9 +++++++ src/tl/tl/tlHttpStream.h | 11 ++++++++ src/tl/tl/tlHttpStreamCurl.cc | 18 ++++++++++++- src/tl/tl/tlHttpStreamNoQt.cc | 12 +++++++++ src/tl/tl/tlHttpStreamQt.cc | 12 +++++++++ src/tl/tl/tlXMLParser.cc | 18 +++++++++++++ src/tl/tl/tlXMLParser.h | 5 ++++ src/tl/unit_tests/tlHttpStream.cc | 26 ++++++++++--------- src/tl/unit_tests/tlWebDAV.cc | 25 +++++++++++++++--- src/tl/unit_tests/unit_tests.pro | 23 ++-------------- 11 files changed, 126 insertions(+), 38 deletions(-) diff --git a/src/plugins/streamers/pcb/unit_tests/dbGerberImport.cc b/src/plugins/streamers/pcb/unit_tests/dbGerberImport.cc index 7319bba0b..2b5a324ad 100644 --- a/src/plugins/streamers/pcb/unit_tests/dbGerberImport.cc +++ b/src/plugins/streamers/pcb/unit_tests/dbGerberImport.cc @@ -29,11 +29,16 @@ #include "dbGerberImporter.h" #include "tlUnitTest.h" +#include "tlXMLParser.h" #include static void run_test (tl::TestBase *_this, const char *dir) { + if (! tl::XMLParser::is_available ()) { + throw tl::CancelException (); + } + db::LoadLayoutOptions options; db::Layout layout; diff --git a/src/rdb/unit_tests/rdb.cc b/src/rdb/unit_tests/rdb.cc index 1905d90f9..fab2f3135 100644 --- a/src/rdb/unit_tests/rdb.cc +++ b/src/rdb/unit_tests/rdb.cc @@ -26,6 +26,7 @@ #include "tlUnitTest.h" #include "dbBox.h" #include "dbEdge.h" +#include "tlXMLParser.h" TEST(1) { @@ -215,6 +216,10 @@ TEST(4) TEST(5) { + if (! tl::XMLParser::is_available ()) { + throw tl::CancelException (); + } + std::string tmp_file = tl::TestBase::tmp_file ("tmp_5.lyrdb"); { @@ -358,6 +363,10 @@ TEST(5) TEST(5a) { + if (! tl::XMLParser::is_available ()) { + throw tl::CancelException (); + } + std::string tmp_file = tl::TestBase::tmp_file ("tmp_5a.lyrdb"); { diff --git a/src/tl/tl/tlHttpStream.h b/src/tl/tl/tlHttpStream.h index 7d17b0603..8d3c1149b 100644 --- a/src/tl/tl/tlHttpStream.h +++ b/src/tl/tl/tlHttpStream.h @@ -87,6 +87,17 @@ public: */ static void set_credential_provider (HttpCredentialProvider *cp); + /** + * @brief Returns true, if HTTP support is compiled in + */ + static bool is_available (); + + /** + * @brief Polling: call this function regularily to explicitly establish polling + * (in the Qt framework, this is done automatically within the event loop) + */ + void tick (); + /** * @brief Sends the request for data * To ensure prompt delivery of data, this method can be used prior to diff --git a/src/tl/tl/tlHttpStreamCurl.cc b/src/tl/tl/tlHttpStreamCurl.cc index a9d7ceb82..d7c610f17 100644 --- a/src/tl/tl/tlHttpStreamCurl.cc +++ b/src/tl/tl/tlHttpStreamCurl.cc @@ -642,6 +642,18 @@ InputHttpStream::filename () const return mp_data->filename (); } +bool +InputHttpStream::is_available () +{ + return true; +} + +void +InputHttpStream::tick () +{ + CurlNetworkManager::instance ()->tick (); +} + // ---------------------------------------------------------------------- // CurlConnection implementation @@ -1063,7 +1075,11 @@ void CurlNetworkManager::release_connection (CurlConnection *connection) void CurlNetworkManager::on_tick () { if (tick ()) { - dm_tick (); + // NOTE: don't reschedule if there is no DM scheduler. This will cause deep + // recursion. + if (tl::DeferredMethodScheduler::instance ()) { + dm_tick (); + } } } diff --git a/src/tl/tl/tlHttpStreamNoQt.cc b/src/tl/tl/tlHttpStreamNoQt.cc index 88355a79a..976111907 100644 --- a/src/tl/tl/tlHttpStreamNoQt.cc +++ b/src/tl/tl/tlHttpStreamNoQt.cc @@ -130,4 +130,16 @@ InputHttpStream::filename () const return std::string (); } +bool +InputHttpStream::is_available () +{ + return false; +} + +void +InputHttpStream::tick () +{ + // .. nothing yet .. +} + } diff --git a/src/tl/tl/tlHttpStreamQt.cc b/src/tl/tl/tlHttpStreamQt.cc index fab1ad0ab..3f70e60af 100644 --- a/src/tl/tl/tlHttpStreamQt.cc +++ b/src/tl/tl/tlHttpStreamQt.cc @@ -186,6 +186,18 @@ InputHttpStream::filename () const return mp_data->filename (); } +bool +InputHttpStream::is_available () +{ + return true; +} + +void +InputHttpStream::tick () +{ + QCoreApplication::processEvents (QEventLoop::ExcludeUserInputEvents); +} + // --------------------------------------------------------------- // InputHttpStreamPrivateData implementation diff --git a/src/tl/tl/tlXMLParser.cc b/src/tl/tl/tlXMLParser.cc index 399088aa5..adb5826ec 100644 --- a/src/tl/tl/tlXMLParser.cc +++ b/src/tl/tl/tlXMLParser.cc @@ -371,6 +371,12 @@ XMLParser::parse (XMLSource &source, XMLStructureHandler &struct_handler) mp_data->check_error (); } +bool +XMLParser::is_available () +{ + return true; +} + } #elif defined(HAVE_QT) @@ -761,6 +767,12 @@ XMLParser::parse (XMLSource &source, XMLStructureHandler &struct_handler) mp_data->parse (source.source (), false /*=not incremental*/); } +bool +XMLParser::is_available () +{ + return true; +} + } #else @@ -867,6 +879,12 @@ XMLParser::parse (XMLSource &, XMLStructureHandler &) tl_assert (false); } +bool +XMLParser::is_available () +{ + return false; +} + } #endif diff --git a/src/tl/tl/tlXMLParser.h b/src/tl/tl/tlXMLParser.h index 761761d4e..1e8bc1766 100644 --- a/src/tl/tl/tlXMLParser.h +++ b/src/tl/tl/tlXMLParser.h @@ -424,6 +424,11 @@ public: void parse (XMLSource &source, XMLStructureHandler &handler); + /** + * @brief Returns true, if XML support is compiled in + */ + static bool is_available (); + private: XMLParserPrivateData *mp_data; }; diff --git a/src/tl/unit_tests/tlHttpStream.cc b/src/tl/unit_tests/tlHttpStream.cc index cbfd6fe3a..0c45328da 100644 --- a/src/tl/unit_tests/tlHttpStream.cc +++ b/src/tl/unit_tests/tlHttpStream.cc @@ -25,17 +25,15 @@ #include "tlUnitTest.h" #include "tlTimer.h" -#if defined(HAVE_QT) || defined(HAVE_CURL) - -#if defined(HAVE_QT) -# include -#endif - static std::string test_url1 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata/text"); static std::string test_url2 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata/dir1"); TEST(1) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::InputHttpStream stream (test_url1); char b[100]; @@ -46,6 +44,10 @@ TEST(1) TEST(2) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::InputHttpStream stream (test_url2); stream.add_header ("User-Agent", "SVN"); stream.add_header ("Depth", "1"); @@ -94,22 +96,25 @@ public: } -#if defined(HAVE_QT) - // async mode TEST(3) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::InputHttpStream stream (test_url1); Receiver r; stream.ready ().add (&r, &Receiver::handle); + EXPECT_EQ (stream.data_available (), false); stream.send (); EXPECT_EQ (stream.data_available (), false); tl::Clock start = tl::Clock::current (); while (! r.flag && (tl::Clock::current () - start).seconds () < 10) { - QCoreApplication::processEvents (QEventLoop::ExcludeUserInputEvents); + stream.tick (); } EXPECT_EQ (r.flag, true); EXPECT_EQ (stream.data_available (), true); @@ -120,6 +125,3 @@ TEST(3) EXPECT_EQ (res, "hello, world.\n"); } -#endif - -#endif diff --git a/src/tl/unit_tests/tlWebDAV.cc b/src/tl/unit_tests/tlWebDAV.cc index 5f5c23c09..beccaec35 100644 --- a/src/tl/unit_tests/tlWebDAV.cc +++ b/src/tl/unit_tests/tlWebDAV.cc @@ -22,11 +22,10 @@ #include "tlWebDAV.h" +#include "tlHttpStream.h" #include "tlUnitTest.h" #include "tlFileUtils.h" -#if defined(HAVE_QT) || defined(HAVE_CURL) - static std::string test_url1 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata"); static std::string test_url2 ("http://www.klayout.org/svn-public/klayout-resources/trunk/testdata/text"); @@ -49,6 +48,10 @@ static std::string collection2string (const tl::WebDAVObject &coll) TEST(1) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::WebDAVObject collection; collection.read (test_url1, 1); @@ -65,6 +68,10 @@ TEST(1) TEST(2) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::WebDAVObject collection; collection.read (test_url1, 0); @@ -75,6 +82,10 @@ TEST(2) TEST(3) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::WebDAVObject collection; collection.read (test_url2, 1); @@ -85,6 +96,10 @@ TEST(3) TEST(4) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::WebDAVObject collection; collection.read (test_url2, 0); @@ -95,6 +110,10 @@ TEST(4) TEST(5) { + if (! tl::InputHttpStream::is_available ()) { + throw tl::CancelException (); + } + tl::WebDAVObject collection; std::string tmp_dir (tmp_file ("tmp")); @@ -123,5 +142,3 @@ TEST(5) EXPECT_EQ (ba21, "A text II.I.\n"); text21.close (); } - -#endif diff --git a/src/tl/unit_tests/unit_tests.pro b/src/tl/unit_tests/unit_tests.pro index 212db744c..e6a32108d 100644 --- a/src/tl/unit_tests/unit_tests.pro +++ b/src/tl/unit_tests/unit_tests.pro @@ -32,10 +32,9 @@ SOURCES = \ tlXMLParser.cc \ tlUri.cc \ tlWebDAV.cc \ + tlHttpStream.cc \ -equals(HAVE_QT, "0") { - # nothing -} else { +!equals(HAVE_QT, "0") { SOURCES += \ tlDeferredExecution.cc \ @@ -43,24 +42,6 @@ equals(HAVE_QT, "0") { } -equals(HAVE_CURL, "1") { - - SOURCES += \ - tlHttpStream.cc \ - -} else { - equals(HAVE_QT, "0") { - # no HTTP stream available - } else { - - SOURCES += \ - tlHttpStream.cc \ - - } -} - - - INCLUDEPATH += $$TL_INC DEPENDPATH += $$TL_INC