From 0c4b9455b67c5882697280a65b3c042f4eebe552 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Tue, 22 Apr 2014 16:02:37 +0200 Subject: [PATCH] Squish: Add test for external modification Additionally moved common code of tst_*_externally to project.py. Change-Id: I056e0dc6749cf92e1416ce313a8f058639981609 Reviewed-by: Robert Loehning --- tests/system/shared/project.py | 19 ++++ tests/system/suite_editors/suite.conf | 2 +- .../tst_delete_externally/test.py | 20 +--- .../suite_editors/tst_edit_externally/test.py | 101 ++++++++++++++++++ 4 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 tests/system/suite_editors/tst_edit_externally/test.py diff --git a/tests/system/shared/project.py b/tests/system/shared/project.py index 816bf286ed3..8c11cd00241 100644 --- a/tests/system/shared/project.py +++ b/tests/system/shared/project.py @@ -665,6 +665,25 @@ def prepareTemplate(sourceExample): return None return templateDir +# check and copy files of given dataset to an existing templateDir +def checkAndCopyFiles(dataSet, fieldName, templateDir): + files = map(lambda record: + os.path.normpath(os.path.join(srcPath, testData.field(record, fieldName))), + dataSet) + for currentFile in files: + if not neededFilePresent(currentFile): + return [] + return copyFilesToDir(files, templateDir) + +# copy a list of files to an existing targetDir +def copyFilesToDir(files, targetDir): + result = [] + for filepath in files: + dst = os.path.join(targetDir, os.path.basename(filepath)) + shutil.copyfile(filepath, dst) + result.append(dst) + return result + def __sortFilenamesOSDependent__(filenames): if platform.system() in ('Windows', 'Microsoft'): filenames.sort(key=str.lower) diff --git a/tests/system/suite_editors/suite.conf b/tests/system/suite_editors/suite.conf index e7a043be624..cbb4aed9812 100644 --- a/tests/system/suite_editors/suite.conf +++ b/tests/system/suite_editors/suite.conf @@ -7,6 +7,6 @@ HOOK_SUB_PROCESSES=false IMPLICITAUTSTART=0 LANGUAGE=Python OBJECTMAP=../objects.map -TEST_CASES=tst_basic_cpp_support tst_delete_externally tst_memberoperator tst_modify_readonly tst_qml_editor tst_qml_indent tst_rename_macros tst_revert_changes tst_select_all +TEST_CASES=tst_basic_cpp_support tst_delete_externally tst_edit_externally tst_memberoperator tst_modify_readonly tst_qml_editor tst_qml_indent tst_rename_macros tst_revert_changes tst_select_all VERSION=2 WRAPPERS=Qt diff --git a/tests/system/suite_editors/tst_delete_externally/test.py b/tests/system/suite_editors/tst_delete_externally/test.py index 5e9393ee9d1..95d7329ceca 100644 --- a/tests/system/suite_editors/tst_delete_externally/test.py +++ b/tests/system/suite_editors/tst_delete_externally/test.py @@ -29,24 +29,10 @@ source("../../shared/qtcreator.py") -global templateDir - -def copyToTemplateDir(filepath): - global templateDir - dst = os.path.join(templateDir, os.path.basename(filepath)) - shutil.copyfile(filepath, dst) - return dst - def main(): - global templateDir - files = map(lambda record: os.path.normpath(os.path.join(srcPath, testData.field(record, "filename"))), - testData.dataset("files.tsv")) - for currentFile in files: - if not neededFilePresent(currentFile): - return - templateDir = tempDir() - files = map(copyToTemplateDir, files) - + files = checkAndCopyFiles(testData.dataset("files.tsv"), "filename", tempDir()) + if not files: + return startApplication("qtcreator" + SettingsPath) if not startedWithoutPluginError(): return diff --git a/tests/system/suite_editors/tst_edit_externally/test.py b/tests/system/suite_editors/tst_edit_externally/test.py new file mode 100644 index 00000000000..6fd8bb8a061 --- /dev/null +++ b/tests/system/suite_editors/tst_edit_externally/test.py @@ -0,0 +1,101 @@ +############################################################################# +## +## Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +## Contact: http://www.qt-project.org/legal +## +## This file is part of Qt Creator. +## +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and Digia. For licensing terms and +## conditions see http://qt.digia.com/licensing. For further information +## use the contact form at http://qt.digia.com/contact-us. +## +## GNU Lesser General Public License Usage +## Alternatively, this file may be used under the terms of the GNU Lesser +## General Public License version 2.1 as published by the Free Software +## Foundation and appearing in the file LICENSE.LGPL included in the +## packaging of this file. Please review the following information to +## ensure the GNU Lesser General Public License version 2.1 requirements +## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +## +## In addition, as a special exception, Digia gives you certain additional +## rights. These rights are described in the Digia Qt LGPL Exception +## version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +## +############################################################################# + +source("../../shared/qtcreator.py") + + +def modifyExternally(filePath): + fileToModify = open(filePath, "a") + fileToModify.write("addedLine\n") + fileToModify.close() + +def switchOpenDocsTo(filename): + selectFromCombo(":Qt Creator_Core::Internal::NavComboBox", "Open Documents") + docs = waitForObject(":OpenDocuments_Widget") + clickItem(docs, filename.replace(".", "\\.").replace("_", "\\_"), 5, 5, 0, Qt.LeftButton) + return getEditorForFileSuffix(filename) + +def main(): + files = checkAndCopyFiles(testData.dataset("files.tsv"), "filename", tempDir()) + if not files: + return + startApplication("qtcreator" + SettingsPath) + if not startedWithoutPluginError(): + return + + mBox = ("{text?='The file * has changed outside Qt Creator. Do you want to reload it?' " + "type='QMessageBox' unnamed='1' visible='1'}") + popupText = "The file %s has changed outside Qt Creator. Do you want to reload it?" + formerContent = None + + for i, currentFile in enumerate(files): + test.log("Opening file %s" % currentFile) + invokeMenuItem("File", "Open File or Project...") + selectFromFileDialog(currentFile) + editor = getEditorForFileSuffix(currentFile) + if editor == None: + test.fatal("Could not get the editor for '%s'" % currentFile, + "Skipping this file for now.") + continue + contentBefore = readFile(currentFile) + if i % 2 == 0: + # modify current file and store content for next modification + formerContent = contentBefore + modifyExternally(currentFile) + test.compare(waitForObject(mBox).text, popupText % os.path.basename(currentFile)) + clickButton(waitForObject("{text='Yes' type='QPushButton' window=%s}" % mBox)) + else: + # modify the current and the former file after AUT had lost focus and use 'Yes to All' + invokeMenuItem("File", "New File or Project...") + modifyExternally(currentFile) + modifyExternally(files[i - 1]) + # clicking Cancel does not work when running inside Squish - mBox would not come up + sendEvent("QCloseEvent", waitForObject(":New_Core::Internal::NewDialog")) + test.verify(str(waitForObject(mBox).text) + in (popupText % os.path.basename(currentFile), + popupText % os.path.basename(files[i - 1])), + "Verifying: One of the modified files is offered as changed.") + clickButton(waitForObject("{text='Yes to All' type='QPushButton' window=%s}" % mBox)) + # verify former file + editor = switchOpenDocsTo(os.path.basename(files[i - 1])) + if not editor: + test.fatal("Failed to get editor - continuing...") + continue + waitFor("str(editor.plainText).count('addedLine') == 2", 2500) + test.compare(editor.plainText, formerContent + "addedLine\naddedLine\n", + "Verifying: file '%s' was reloaded modified (Yes to All)." % files[i - 1]) + editor = switchOpenDocsTo(os.path.basename(currentFile)) + if not editor: + test.fatal("Failed to get editor - continuing...") + continue + # verify currentFile + waitFor("'addedLine' in str(editor.plainText)", 2500) + test.compare(editor.plainText, contentBefore + "addedLine\n", + "Verifying: file '%s' was reloaded modified." % currentFile) + invokeMenuItem("File", "Exit")