浏览代码

Add some new tests and parse some old

Jakob Truelsen 16 年之前
父节点
当前提交
8dbe2d9867
共有 6 个文件被更改,包括 51 次插入9 次删除
  1. 17 2
      scripts/test.sh
  2. 15 1
      src/multipageloader.cc
  3. 1 1
      src/multipageloader_p.hh
  4. 15 2
      src/pageconverter.cc
  5. 2 0
      src/pageconverter_p.hh
  6. 1 3
      src/wkhtmltopdf.cc

+ 17 - 2
scripts/test.sh

@@ -166,7 +166,20 @@ function testBuild() {
     fi
     fi
     make -j2 >/dev/null 2>/dev/null && good "Build $1" || bad "Build $1 (3)"
     make -j2 >/dev/null 2>/dev/null && good "Build $1" || bad "Build $1 (3)"
     cd ..
     cd ..
-    rm -rf wkhtmltopdf
+}
+
+function testNoneStatic() {
+    ([ -f wkhtmltopdf/wkhtmltopdf ] && echo "<html><body>Foo</body></html>" | wkhtmltopdf/wkhtmltopdf - - | pdftotext /dev/stdin /dev/stdout | grep -q Foo) && good "None Static" || bad "None Static"
+}
+
+function testAgsFrmStdin() {
+    echo "<html><body>XFooZ</body></html>" > tmp.html
+    wk --read-args-from-stdin <<EOF
+-q tmp.html tmp1.pdf
+-q tmp.html tmp2.pdf
+EOF
+    (   [ -f tmp1.pdf ] && pdftotext tmp1.pdf /dev/stdout | grep -q XFooZ &&
+	[ -f tmp2.pdf ] && pdftotext tmp2.pdf /dev/stdout | grep -q XFooZ) && good "Args from stdin" || bad "Arg from stdin"
 }
 }
 
 
 good TestTest
 good TestTest
@@ -191,7 +204,9 @@ testRemote
 testSSL
 testSSL
 testHeaderFooter
 testHeaderFooter
 testBuild qmake
 testBuild qmake
+testNoneStatic
+testAgsFrmStdin
 #testBuild cmake
 #testBuild cmake
 #Lets clean up
 #Lets clean up
-rm -rf *.pdf *.html
+rm -rf *.pdf *.html wkhtmltopdf
 exit $failed 
 exit $failed 

+ 15 - 1
src/multipageloader.cc

@@ -46,11 +46,13 @@ void MultiPageLoaderPrivate::authenticationRequired(QNetworkReply *reply, QAuthe
 		//If no username is given, complain the such is required
 		//If no username is given, complain the such is required
 		emit outer.error("Authentication Required");
 		emit outer.error("Authentication Required");
 		reply->abort();
 		reply->abort();
+		fail();
 	} else if (loginTry >= 2) {
 	} else if (loginTry >= 2) {
 		//If the login has failed a sufficient number of times,
 		//If the login has failed a sufficient number of times,
 		//the username or password must be wrong
 		//the username or password must be wrong
 		emit outer.error("Invalid username or password");
 		emit outer.error("Invalid username or password");
 		reply->abort();
 		reply->abort();
+		fail();
 	} else {
 	} else {
 		authenticator->setUser(settings.username);
 		authenticator->setUser(settings.username);
 		authenticator->setPassword(settings.password);
 		authenticator->setPassword(settings.password);
@@ -80,6 +82,7 @@ void MultiPageLoaderPrivate::sslErrors(QNetworkReply *reply, const QList<QSslErr
 	//We ignore any ssl error, as it is next to impossible to send or receive
 	//We ignore any ssl error, as it is next to impossible to send or receive
 	//any private information with wkhtmltopdf anyhow, seeing as you cannot authenticate
 	//any private information with wkhtmltopdf anyhow, seeing as you cannot authenticate
 	reply->ignoreSslErrors();
 	reply->ignoreSslErrors();
+	emit outer.warning("SSL error ignored");
 }
 }
 
 
 MultiPageLoaderPrivate::MultiPageLoaderPrivate(Settings & s, MultiPageLoader & o): 
 MultiPageLoaderPrivate::MultiPageLoaderPrivate(Settings & s, MultiPageLoader & o): 
@@ -125,7 +128,7 @@ QWebPage * MultiPageLoaderPrivate::addResource(const QUrl & url) {
 	pages.push_back(page);
 	pages.push_back(page);
 	urls.push_back(url);
 	urls.push_back(url);
 	page->setNetworkAccessManager(&networkAccessManager);
 	page->setNetworkAccessManager(&networkAccessManager);
-	//Todo multipage loader foobar
+
 	page->mainFrame()->setZoomFactor(settings.zoomFactor);
 	page->mainFrame()->setZoomFactor(settings.zoomFactor);
 
 
 	pageToIndex[page] = pages.size()-1;
 	pageToIndex[page] = pages.size()-1;
@@ -168,6 +171,12 @@ void MultiPageLoaderPrivate::cancel() {
 		page->triggerAction(QWebPage::Stop);
 		page->triggerAction(QWebPage::Stop);
 }
 }
 
 
+void MultiPageLoaderPrivate::fail() {
+	error = true;
+	cancel();
+	clearResources();
+}
+
 
 
 /*!
 /*!
  * Once loading starting, this is called
  * Once loading starting, this is called
@@ -196,11 +205,16 @@ void MultiPageLoaderPrivate::loadProgress(int progress) {
 }
 }
 
 
 void MultiPageLoaderPrivate::loadFinished(bool ok) {
 void MultiPageLoaderPrivate::loadFinished(bool ok) {
+
 	loadingPages--;
 	loadingPages--;
 	error = error || !ok;
 	error = error || !ok;
 	if (!pageToIndex.count(QObject::sender())) return;
 	if (!pageToIndex.count(QObject::sender())) return;
 	
 	
 	int idx=pageToIndex[QObject::sender()];
 	int idx=pageToIndex[QObject::sender()];
+
+	if (!ok)
+		emit outer.error(QString("Failed loading page ") + urls[idx].toString());
+
 	if (!finishedList[idx]) {
 	if (!finishedList[idx]) {
 		finishedList[idx] = true;
 		finishedList[idx] = true;
 		finishedSum += 1;
 		finishedSum += 1;

+ 1 - 1
src/multipageloader_p.hh

@@ -52,7 +52,7 @@ public:
 	void load();
 	void load();
 	void clearResources();
 	void clearResources();
 	void cancel();
 	void cancel();
-
+	void fail();
 public slots:
 public slots:
 	void loadStarted();
 	void loadStarted();
 	void loadProgress(int progress);
 	void loadProgress(int progress);

+ 15 - 2
src/pageconverter.cc

@@ -67,15 +67,29 @@ PageConverterPrivate::PageConverterPrivate(Settings & s, PageConverter & o) :
 #endif
 #endif
 
 
 	connect(&pageLoader, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
 	connect(&pageLoader, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
-	connect(&hfLoader, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
 	connect(&pageLoader, SIGNAL(loadFinished(bool)), this, SLOT(preparePrint(bool)));
 	connect(&pageLoader, SIGNAL(loadFinished(bool)), this, SLOT(preparePrint(bool)));
+	connect(&pageLoader, SIGNAL(error(QString)), this, SLOT(forwardError(QString)));
+	connect(&pageLoader, SIGNAL(warning(QString)), this, SLOT(forwardWarning(QString)));
+
+	connect(&hfLoader, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
 	connect(&hfLoader, SIGNAL(loadFinished(bool)), this, SLOT(printPage(bool)));
 	connect(&hfLoader, SIGNAL(loadFinished(bool)), this, SLOT(printPage(bool)));
+	connect(&hfLoader, SIGNAL(error(QString)), this, SLOT(forwardError(QString)));
+	connect(&hfLoader, SIGNAL(warning(QString)), this, SLOT(forwardWarning(QString)));
 }
 }
 
 
 PageConverterPrivate::~PageConverterPrivate() {
 PageConverterPrivate::~PageConverterPrivate() {
 	clearResources();
 	clearResources();
 }
 }
 
 
+void PageConverterPrivate::forwardError(QString error) {
+	emit outer.error(error);
+}
+
+void PageConverterPrivate::forwardWarning(QString warning) {
+	emit outer.warning(warning);
+}
+
+
 /*!
 /*!
  * Called when the page is loading, display some progress to the using
  * Called when the page is loading, display some progress to the using
  * \param progress the loading progress in percent
  * \param progress the loading progress in percent
@@ -506,7 +520,6 @@ bool PageConverterPrivate::convert() {
 void PageConverterPrivate::clearResources() {
 void PageConverterPrivate::clearResources() {
 	pageLoader.clearResources();
 	pageLoader.clearResources();
 	hfLoader.clearResources();
 	hfLoader.clearResources();
-	error = 0;
 	foreach(QWebPage * page, pages)
 	foreach(QWebPage * page, pages)
 		delete page;
 		delete page;
 	pages.clear();
 	pages.clear();

+ 2 - 0
src/pageconverter_p.hh

@@ -83,6 +83,8 @@ public slots:
 	void beginConvert();
 	void beginConvert();
 	void cancel();
 	void cancel();
 	bool convert();
 	bool convert();
+	void forwardError(QString error);
+	void forwardWarning(QString warning);
 };
 };
 
 
 #endif //__TEXTUALFEEDBACK_P_HH__
 #endif //__TEXTUALFEEDBACK_P_HH__

+ 1 - 3
src/wkhtmltopdf.cc

@@ -151,10 +151,8 @@ int main(int argc, char * argv[]) {
 // 			}
 // 			}
 // 			exit(0);
 // 			exit(0);
 // 		}
 // 		}
-	if (!converter.convert()) {
-		qDebug() << "Here";
+	if (!converter.convert())
 		exit(EXIT_FAILURE);
 		exit(EXIT_FAILURE);
-	}
 	switch(converter.httpErrorCode()) {
 	switch(converter.httpErrorCode()) {
 	case 401:
 	case 401:
 		exit(3);
 		exit(3);