From 3368c34aad8a85016543dd885b004dff3660d208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pertti=20Kellom=C3=A4ki?= Date: Wed, 13 Jul 2011 10:30:46 +0300 Subject: [PATCH] Changes: Added test cases for argument passing to cached [QM]Application. RevBy: Nimika Keshri --- debian/changelog | 1 + .../testapps/fala_qml_helloworld/main.cpp | 31 ++++++++++- tests/common/testapps/testapp/main.cpp | 31 ++++++++++- .../testscripts/test-func-launcher.py | 54 +++++++++++++++++++ 4 files changed, 113 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index 958cbce..3ee8034 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ applauncherd (0.30.6) unstable; urgency=low + * Changes: Added test cases for argument passing to cached [QM]Application. * Changes: Performance test modified. Tracking pixel co-ordinates changed. * Changes: Language corrections into documentation. diff --git a/tests/common/testapps/fala_qml_helloworld/main.cpp b/tests/common/testapps/fala_qml_helloworld/main.cpp index f06782a..89cef91 100644 --- a/tests/common/testapps/fala_qml_helloworld/main.cpp +++ b/tests/common/testapps/fala_qml_helloworld/main.cpp @@ -24,15 +24,25 @@ QString log_file = "/tmp/fala_qml_helloworld.log"; -void FANGORNLOG(const char* s) +void FANGORNLOG(const char* s, bool eol = true) { QFile f(log_file); f.open(QIODevice::Append); f.write(s, qstrlen(s)); - f.write("\n", 1); + if (eol) { + f.write("\n", 1); + } f.close(); } +void FANGORNLOG(const QString& s, bool eol = true) +{ + QByteArray ba = s.toLocal8Bit(); + char *p = new char[ba.size() + 1]; + strcpy(p, ba.data()); + FANGORNLOG(p, eol); +} + void timestamp(const char *s) { timeval tim; @@ -74,6 +84,23 @@ Q_DECL_EXPORT int main(int argc, char **argv) timestamp(QString("applicationDirPath: ").append(QApplication::applicationDirPath())); timestamp(QString("applicationFilePath: ").append(QApplication::applicationFilePath())); + if (argc > 2 && QString(argv[1]) == QString("--log-args")) { + FANGORNLOG("argv:", false); + for (int i = 0; i < argc; i++) { + FANGORNLOG(" ", false); + FANGORNLOG(argv[i], false); + } + FANGORNLOG(""); + + FANGORNLOG("argv:", false); + QStringList args = QCoreApplication::arguments(); + for (int i = 0; i < args.size(); i++) { + FANGORNLOG(" ", false); + FANGORNLOG(args.at(i), false); + } + FANGORNLOG(""); + } + window->setWindowTitle("Applauncherd QML testapp"); window->setResizeMode(QDeclarativeView::SizeRootObjectToView); diff --git a/tests/common/testapps/testapp/main.cpp b/tests/common/testapps/testapp/main.cpp index 8605955..d0672f5 100644 --- a/tests/common/testapps/testapp/main.cpp +++ b/tests/common/testapps/testapp/main.cpp @@ -31,15 +31,25 @@ QString log_file = "/tmp/fala_testapp.log"; -void FANGORNLOG(const char* s) +void FANGORNLOG(const char* s, bool eol = true) { QFile f(log_file); f.open(QIODevice::Append); f.write(s, qstrlen(s)); - f.write("\n", 1); + if (eol) { + f.write("\n", 1); + } f.close(); } +void FANGORNLOG(const QString& s, bool eol = true) +{ + QByteArray ba = s.toLocal8Bit(); + char *p = new char[ba.size() + 1]; + strcpy(p, ba.data()); + FANGORNLOG(p, eol); +} + void timestamp(const char *s) { timeval tim; @@ -87,6 +97,23 @@ int main(int argc, char **argv) { timestamp("win created without cache"); #endif + if (argc > 2 && QString(argv[1]) == QString("--log-args")) { + FANGORNLOG("argv:", false); + for (int i = 0; i < argc; i++) { + FANGORNLOG(" ", false); + FANGORNLOG(argv[i], false); + } + FANGORNLOG(""); + + FANGORNLOG("argv:", false); + QStringList args = QCoreApplication::arguments(); + for (int i = 0; i < args.size(); i++) { + FANGORNLOG(" ", false); + FANGORNLOG(args.at(i), false); + } + FANGORNLOG(""); + } + MyApplicationPage p; timestamp("page created"); diff --git a/tests/harmattan/testscripts/test-func-launcher.py b/tests/harmattan/testscripts/test-func-launcher.py index 3901269..26f30d8 100644 --- a/tests/harmattan/testscripts/test-func-launcher.py +++ b/tests/harmattan/testscripts/test-func-launcher.py @@ -1163,6 +1163,60 @@ class launcher_tests (unittest.TestCase): self.assert_(int(launch_count) == int(init_count) +1, "The file descriptors was not changed") self.assert_(close_count == init_count, "The file descriptors was changed") + def test_argv_mbooster_limit(self): + self._test_argv_booster_limit("m", "fala_wl") + + def test_argv_dbooster_limit(self): + self._test_argv_booster_limit("d", "fala_qml_helloworld") + + def _test_argv_booster_limit(self, btype, testapp): + """ + Test that ARGV_LIMIT (32) arguments are successfully passed to cached [QM]Application. + """ + if os.path.isfile("/tmp/%s.log" % testapp): + os.system("rm /tmp/%s.log" % testapp) + if get_pid(testapp)!= None: + kill_process(testapp) + p = run_cmd_as_user('invoker --type=%s /usr/bin/%s --log-args 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t' % (btype, testapp)) + time.sleep(4) + pid = get_pid(testapp) + self.assert_(pid != None, "The application was not launched") + debug("get arguments from log file") + st, op = commands.getstatusoutput("grep argv: /tmp/%s.log | tail -2" % testapp) + original_argv = op.split("\n")[0] + cache_argv = op.split("\n")[1] + self.assert_(original_argv == cache_argv, "Wrong arguments passed.\nOriginal: %s\nCached: %s" % (original_argv, cache_argv)) + kill_process(apppid=pid) + + def test_argv_mbooster_over_limit(self): + self._test_argv_booster_over_limit("m", "fala_wl") + + def test_argv_dbooster_over_limit(self): + self._test_argv_booster_over_limit("d", "fala_qml_helloworld") + + def _test_argv_booster_over_limit(self, btype, testapp): + """ + Test that if more than ARGV_LIMIT (32) arguments are passed to cached [QM]Application, + the application is still launched and ARGV_LIMIT arguments are successfully passed. + """ + ARGV_LIMIT = 32 + if os.path.isfile("/tmp/%s.log" % testapp): + os.system("rm /tmp/%s.log" % testapp) + if get_pid(testapp)!= None: + kill_process(testapp) + p = run_cmd_as_user('invoker --type=%s /usr/bin/%s --log-args 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z' % (btype, testapp)) + time.sleep(4) + pid = get_pid(testapp) + self.assert_(pid != None, "The application was not launched") + debug("get arguments from log file") + st, op = commands.getstatusoutput("grep argv: /tmp/%s.log | tail -2" % testapp) + original_argv = op.split("\n")[0].split(" ")[1:] + cache_argv = op.split("\n")[1].split(" ")[1:] + self.assert_(len(cache_argv) == ARGV_LIMIT, "Wrong number of arguments passed.\nOriginal: %s\nCached: %s" % (original_argv, cache_argv)) + for i in range(ARGV_LIMIT): + self.assert_(original_argv[i] == cache_argv[i], "Wrong arguments passed.\nOriginal: %s\nCached: %s" % (original_argv, cache_argv)) + kill_process(apppid=pid) + # main if __name__ == '__main__':