forked from qt-creator/qt-creator
Squish: Add test for renaming macros
Change-Id: I9c9bc9556234ec321c6e3723f5276a0b66f6c90a Reviewed-by: Robert Loehning <robert.loehning@digia.com>
This commit is contained in:
@@ -295,3 +295,14 @@ def invokeFindUsage(editor, line, typeOperation, n=1):
|
|||||||
type(editor, typeOperation)
|
type(editor, typeOperation)
|
||||||
invokeContextMenuItem(editor, "Find Usages")
|
invokeContextMenuItem(editor, "Find Usages")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def openDocument(treeElement):
|
||||||
|
try:
|
||||||
|
navigator = waitForObject(":Qt Creator_Utils::NavigationTreeView")
|
||||||
|
fileName = waitForObjectItem(navigator, treeElement).text
|
||||||
|
doubleClickItem(navigator, treeElement, 5, 5, 0, Qt.LeftButton)
|
||||||
|
mainWindow = waitForObject(":Qt Creator_Core::Internal::MainWindow")
|
||||||
|
waitFor("fileName in str(mainWindow.windowTitle)")
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
@@ -452,7 +452,11 @@ def __getSupportedPlatforms__(text, getAsStrings=False):
|
|||||||
# copy example project (sourceExample is path to project) to temporary directory inside repository
|
# copy example project (sourceExample is path to project) to temporary directory inside repository
|
||||||
def prepareTemplate(sourceExample):
|
def prepareTemplate(sourceExample):
|
||||||
templateDir = os.path.abspath(tempDir() + "/template")
|
templateDir = os.path.abspath(tempDir() + "/template")
|
||||||
shutil.copytree(sourceExample, templateDir)
|
try:
|
||||||
|
shutil.copytree(sourceExample, templateDir)
|
||||||
|
except:
|
||||||
|
test.fatal("Error while copying '%s' to '%s'" % (sourceExample, templateDir))
|
||||||
|
return None
|
||||||
return templateDir
|
return templateDir
|
||||||
|
|
||||||
def __sortFilenamesOSDependent__(filenames):
|
def __sortFilenamesOSDependent__(filenames):
|
||||||
@@ -498,3 +502,26 @@ def compareProjectTree(rootObject, dataset):
|
|||||||
'Line %s in dataset' % str(i + 1))
|
'Line %s in dataset' % str(i + 1))
|
||||||
return
|
return
|
||||||
test.passes("No errors found in project tree")
|
test.passes("No errors found in project tree")
|
||||||
|
|
||||||
|
def addCPlusPlusFileToCurrentProject(name, template, forceOverwrite=False):
|
||||||
|
if name == None:
|
||||||
|
test.fatal("File must have a name - got None.")
|
||||||
|
return
|
||||||
|
__createProjectOrFileSelectType__(" C++", template, isProject=False)
|
||||||
|
window = "{type='Utils::FileWizardDialog' unnamed='1' visible='1'}"
|
||||||
|
basePath = str(waitForObject("{type='Utils::BaseValidatingLineEdit' unnamed='1' visible='1' "
|
||||||
|
"window=%s}" % window).text)
|
||||||
|
lineEdit = waitForObject("{name='nameLineEdit' type='Utils::FileNameValidatingLineEdit' "
|
||||||
|
"visible='1' window=%s}" % window)
|
||||||
|
replaceEditorContent(lineEdit, name)
|
||||||
|
clickButton(waitForObject(":Next_QPushButton"))
|
||||||
|
__createProjectHandleLastPage__()
|
||||||
|
if (os.path.exists(os.path.join(basePath, name))):
|
||||||
|
overwriteDialog = "{type='Core::Internal::PromptOverwriteDialog' unnamed='1' visible='1'}"
|
||||||
|
waitForObject(overwriteDialog)
|
||||||
|
if forceOverwrite:
|
||||||
|
buttonToClick = 'OK'
|
||||||
|
else:
|
||||||
|
buttonToClick = 'Cancel'
|
||||||
|
clickButton("{text='%s' type='QPushButton' unnamed='1' visible='1' window=%s}"
|
||||||
|
% (buttonToClick, overwriteDialog))
|
||||||
|
11
tests/system/suite_editors/shared/simplePlainCPP/main.cpp
Normal file
11
tests/system/suite_editors/shared/simplePlainCPP/main.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include "testfile.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
cout << "Hello World!" << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,14 @@
|
|||||||
|
#include "testfile.h"
|
||||||
|
|
||||||
|
class SomeClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SomeClass() {}
|
||||||
|
void function1(int a);
|
||||||
|
};
|
||||||
|
|
||||||
|
bool function1(int a) {
|
||||||
|
SOME_MACRO_NAME(a)
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
11
tests/system/suite_editors/shared/simplePlainCPP/testfile.h
Normal file
11
tests/system/suite_editors/shared/simplePlainCPP/testfile.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class AnyClass
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AnyClass() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SOME_MACRO_NAME( X )\
|
||||||
|
{\
|
||||||
|
(X) = 1;\
|
||||||
|
}\
|
||||||
|
|
@@ -0,0 +1,11 @@
|
|||||||
|
TEMPLATE = app
|
||||||
|
CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
CONFIG -= qt
|
||||||
|
|
||||||
|
SOURCES += main.cpp \
|
||||||
|
testfile.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
testfile.h
|
||||||
|
|
@@ -7,6 +7,6 @@ HOOK_SUB_PROCESSES=false
|
|||||||
IMPLICITAUTSTART=0
|
IMPLICITAUTSTART=0
|
||||||
LANGUAGE=Python
|
LANGUAGE=Python
|
||||||
OBJECTMAP=../objects.map
|
OBJECTMAP=../objects.map
|
||||||
TEST_CASES=tst_memberoperator
|
TEST_CASES=tst_memberoperator tst_rename_macros
|
||||||
VERSION=2
|
VERSION=2
|
||||||
WRAPPERS=Qt
|
WRAPPERS=Qt
|
||||||
|
153
tests/system/suite_editors/tst_rename_macros/test.py
Normal file
153
tests/system/suite_editors/tst_rename_macros/test.py
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
source("../../shared/qtcreator.py")
|
||||||
|
|
||||||
|
cppEditorStr = ":Qt Creator_CppEditor::Internal::CPPEditorWidget"
|
||||||
|
|
||||||
|
def main():
|
||||||
|
global cppEditorStr
|
||||||
|
folder = prepareTemplate(os.path.abspath(os.path.join(os.getcwd(), "..", "shared",
|
||||||
|
"simplePlainCPP")))
|
||||||
|
if folder == None:
|
||||||
|
test.fatal("Could not prepare test files - leaving test")
|
||||||
|
return
|
||||||
|
proFile = os.path.join(folder, "testfiles.pro")
|
||||||
|
startApplication("qtcreator" + SettingsPath)
|
||||||
|
openQmakeProject(proFile)
|
||||||
|
if not testRenameMacroAfterSourceModification():
|
||||||
|
return
|
||||||
|
addCPlusPlusFileToCurrentProject("anothertestfile.h", "C++ Header File")
|
||||||
|
if not testRenameMacroAfterSourceMoving():
|
||||||
|
return
|
||||||
|
invokeMenuItem("File", "Save All")
|
||||||
|
invokeMenuItem("File", "Exit")
|
||||||
|
|
||||||
|
def testRenameMacroAfterSourceModification():
|
||||||
|
def __deleteAnyClass__():
|
||||||
|
global cppEditorStr
|
||||||
|
if platform.system() == 'Darwin':
|
||||||
|
type(cppEditorStr, "<Command+Left>")
|
||||||
|
else:
|
||||||
|
type(cppEditorStr, "<Home>")
|
||||||
|
for i in range(5):
|
||||||
|
type(cppEditorStr, "<Shift+Down>")
|
||||||
|
type(cppEditorStr, "<Delete>")
|
||||||
|
|
||||||
|
test.log("Testing rename macro after modifying source.")
|
||||||
|
formerTexts = {}
|
||||||
|
content = openDocumentPlaceCursor("testfiles.Headers.testfile\\.h",
|
||||||
|
"class AnyClass", __deleteAnyClass__)
|
||||||
|
if not content:
|
||||||
|
return False
|
||||||
|
formerTexts["testfiles.Headers.testfile\\.h"] = content
|
||||||
|
content = openDocumentPlaceCursor("testfiles.Sources.testfile\\.cpp", "SOME_MACRO_NAME(a)")
|
||||||
|
if not content:
|
||||||
|
return False
|
||||||
|
formerTexts["testfiles.Sources.testfile\\.cpp"] = content
|
||||||
|
performMacroRenaming('SOME_OTHER_MACRO_NAME')
|
||||||
|
verifyChangedContent(formerTexts, "SOME_MACRO_NAME", "SOME_OTHER_MACRO_NAME")
|
||||||
|
revertChanges(formerTexts)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def testRenameMacroAfterSourceMoving():
|
||||||
|
def __cut__():
|
||||||
|
global cppEditorStr
|
||||||
|
if platform.system() == 'Darwin':
|
||||||
|
type(cppEditorStr, "<Command+Left>")
|
||||||
|
else:
|
||||||
|
type(cppEditorStr, "<Home>")
|
||||||
|
for i in range(4):
|
||||||
|
type(cppEditorStr, "<Shift+Down>")
|
||||||
|
invokeMenuItem("Edit", "Cut")
|
||||||
|
|
||||||
|
def __paste__():
|
||||||
|
global cppEditorStr
|
||||||
|
type(cppEditorStr, "<Return>")
|
||||||
|
invokeMenuItem("Edit", "Paste")
|
||||||
|
|
||||||
|
def __insertInclude__():
|
||||||
|
global cppEditorStr
|
||||||
|
typeLines(cppEditorStr, ['', '#include "anothertestfile.h"'])
|
||||||
|
|
||||||
|
test.log("Testing rename macro after moving source.")
|
||||||
|
formerTexts = {}
|
||||||
|
content = openDocumentPlaceCursor("testfiles.Headers.testfile\\.h",
|
||||||
|
"#define SOME_MACRO_NAME( X )\\", __cut__)
|
||||||
|
if not content:
|
||||||
|
return False
|
||||||
|
formerTexts["testfiles.Headers.testfile\\.h"] = content
|
||||||
|
content = openDocumentPlaceCursor("testfiles.Headers.anothertestfile\\.h",
|
||||||
|
"#define ANOTHERTESTFILE_H", __paste__)
|
||||||
|
if not content:
|
||||||
|
return False
|
||||||
|
formerTexts["testfiles.Headers.anothertestfile\\.h"] = content
|
||||||
|
content = openDocumentPlaceCursor('testfiles.Sources.testfile\\.cpp',
|
||||||
|
'#include "testfile.h"', __insertInclude__)
|
||||||
|
if not content:
|
||||||
|
return False
|
||||||
|
formerTexts["testfiles.Sources.testfile\\.cpp"] = content
|
||||||
|
placeCursorToLine(cppEditorStr, "SOME_MACRO_NAME(a)")
|
||||||
|
performMacroRenaming("COMPLETELY_DIFFERENT_MACRO_NAME")
|
||||||
|
verifyChangedContent(formerTexts, "SOME_MACRO_NAME", "COMPLETELY_DIFFERENT_MACRO_NAME")
|
||||||
|
revertChanges(formerTexts)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def openDocumentPlaceCursor(doc, line, additionalFunction=None):
|
||||||
|
global cppEditorStr
|
||||||
|
if openDocument(doc) and placeCursorToLine(cppEditorStr, line):
|
||||||
|
if additionalFunction:
|
||||||
|
additionalFunction()
|
||||||
|
return str(waitForObject(cppEditorStr).plainText)
|
||||||
|
else:
|
||||||
|
earlyExit("Open %s or placing cursor to line (%s) failed." % (simpleFileName(doc), line))
|
||||||
|
return None
|
||||||
|
|
||||||
|
def performMacroRenaming(newMacroName):
|
||||||
|
for i in range(10):
|
||||||
|
type(cppEditorStr, "<Left>")
|
||||||
|
invokeContextMenuItem(waitForObject(cppEditorStr), "Refactor",
|
||||||
|
"Rename Symbol Under Cursor")
|
||||||
|
validateSearchResult(2)
|
||||||
|
replaceLineEdit = waitForObject("{leftWidget={text='Replace with:' type='QLabel' "
|
||||||
|
"unnamed='1' visible='1'} "
|
||||||
|
"type='Find::Internal::WideEnoughLineEdit' unnamed='1' "
|
||||||
|
"visible='1' "
|
||||||
|
"window=':Qt Creator_Core::Internal::MainWindow'}")
|
||||||
|
replaceEditorContent(replaceLineEdit, newMacroName)
|
||||||
|
clickButton(waitForObject("{text='Replace' type='QToolButton' unnamed='1' visible='1' "
|
||||||
|
"window=':Qt Creator_Core::Internal::MainWindow'}"))
|
||||||
|
|
||||||
|
def verifyChangedContent(origTexts, replacedSymbol, replacement):
|
||||||
|
global cppEditorStr
|
||||||
|
successfullyCompared = []
|
||||||
|
for fileName,text in origTexts.iteritems():
|
||||||
|
if openDocument(fileName):
|
||||||
|
successfullyCompared.append(test.compare(waitForObject(cppEditorStr).plainText,
|
||||||
|
text.replace(replacedSymbol, replacement),
|
||||||
|
"Verifying content of %s" %
|
||||||
|
simpleFileName(fileName)))
|
||||||
|
else:
|
||||||
|
successfullyCompared.append(False)
|
||||||
|
test.fail("Failed to open document %s" % simpleFileName(fileName))
|
||||||
|
if successfullyCompared.count(True) == len(origTexts):
|
||||||
|
test.passes("Successfully compared %d changed files" % len(origTexts))
|
||||||
|
else:
|
||||||
|
test.fail("Verifyied %d files - %d have been successfully changed and %d failed to "
|
||||||
|
"change correctly." % (len(origTexts), successfullyCompared.count(True),
|
||||||
|
successfullyCompared.count(False)))
|
||||||
|
|
||||||
|
def revertChanges(files):
|
||||||
|
for f in files:
|
||||||
|
simpleName = simpleFileName(f)
|
||||||
|
if openDocument(f):
|
||||||
|
invokeMenuItem('File', 'Revert "%s" to Saved' % simpleName)
|
||||||
|
clickButton(waitForObject(":Revert to Saved.Proceed_QPushButton"))
|
||||||
|
test.log("Reverted changes inside %s" % simpleName)
|
||||||
|
else:
|
||||||
|
test.fail("Could not open %s for reverting changes" % simpleName)
|
||||||
|
|
||||||
|
def simpleFileName(navigatorFileName):
|
||||||
|
return ".".join(navigatorFileName.split(".")[-2:]).replace("\\","")
|
||||||
|
|
||||||
|
def earlyExit(details="No additional information"):
|
||||||
|
test.fail("Something went wrong running this test", details)
|
||||||
|
invokeMenuItem("File", "Save All")
|
||||||
|
invokeMenuItem("File", "Exit")
|
Reference in New Issue
Block a user