| 
									
										
										
										
											2012-01-17 13:47:47 +01:00
										 |  |  | import re; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  | # dictionary to hold a list of all installed handler functions for all object-signalSignature pairs | 
					
						
							|  |  |  | installedSignalHandlers = {} | 
					
						
							|  |  |  | # flag to indicate whether overrideInstallLazySignalHandler() has been called already | 
					
						
							|  |  |  | overridenInstallLazySignalHandlers = False | 
					
						
							|  |  |  | # flag to indicate whether a tasks file should be created when building ends with errors | 
					
						
							|  |  |  | createTasksFileOnError = True | 
					
						
							|  |  |  | # currently used directory for tasks files | 
					
						
							|  |  |  | tasksFileDir = None | 
					
						
							|  |  |  | # counter for written tasks files | 
					
						
							|  |  |  | tasksFileCount = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # call this function to override installLazySignalHandler() | 
					
						
							|  |  |  | def overrideInstallLazySignalHandler(): | 
					
						
							|  |  |  |     global overridenInstallLazySignalHandlers | 
					
						
							|  |  |  |     if overridenInstallLazySignalHandlers: | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     overridenInstallLazySignalHandlers = True | 
					
						
							|  |  |  |     global installLazySignalHandler | 
					
						
							| 
									
										
										
										
											2011-09-21 17:29:18 +02:00
										 |  |  |     installLazySignalHandler = __addSignalHandlerDict__(installLazySignalHandler) | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # avoids adding a handler to a signal twice or more often | 
					
						
							|  |  |  | # do not call this function directly - use overrideInstallLazySignalHandler() instead | 
					
						
							| 
									
										
										
										
											2011-09-21 17:29:18 +02:00
										 |  |  | def __addSignalHandlerDict__(lazySignalHandlerFunction): | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |     global installedSignalHandlers | 
					
						
							|  |  |  |     def wrappedFunction(name, signalSignature, handlerFunctionName): | 
					
						
							|  |  |  |         handlers = installedSignalHandlers.get("%s____%s" % (name,signalSignature)) | 
					
						
							|  |  |  |         if handlers == None: | 
					
						
							|  |  |  |             lazySignalHandlerFunction(name, signalSignature, handlerFunctionName) | 
					
						
							|  |  |  |             installedSignalHandlers.setdefault("%s____%s" % (name,signalSignature), [handlerFunctionName]) | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2012-02-22 15:43:05 +01:00
										 |  |  |             if not handlerFunctionName in handlers: | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |                 lazySignalHandlerFunction(name, signalSignature, handlerFunctionName) | 
					
						
							|  |  |  |                 handlers.append(handlerFunctionName) | 
					
						
							|  |  |  |                 installedSignalHandlers.setdefault("%s____%s" % (name,signalSignature), handlers) | 
					
						
							|  |  |  |     return wrappedFunction | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # returns the currently assigned handler functions for a given object and signal | 
					
						
							|  |  |  | def getInstalledSignalHandlers(name, signalSignature): | 
					
						
							|  |  |  |     return installedSignalHandlers.get("%s____%s" % (name,signalSignature)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # this method checks the last build (if there's one) and logs the number of errors, warnings and | 
					
						
							| 
									
										
										
										
											2011-10-06 13:55:05 +02:00
										 |  |  | # lines within the Issues output | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  | # optional parameter can be used to tell this function if the build was expected to fail or not | 
					
						
							|  |  |  | def checkLastBuild(expectedToFail=False): | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         # can't use waitForObject() 'cause visible is always 0 | 
					
						
							|  |  |  |         buildProg = findObject("{type='ProjectExplorer::Internal::BuildProgress' unnamed='1' }") | 
					
						
							|  |  |  |     except LookupError: | 
					
						
							|  |  |  |         test.log("checkLastBuild called without a build") | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     # get labels for errors and warnings | 
					
						
							|  |  |  |     children = object.children(buildProg) | 
					
						
							|  |  |  |     if len(children)<4: | 
					
						
							|  |  |  |         test.fatal("Leaving checkLastBuild()", "Referred code seems to have changed - method has to get adjusted") | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |     errors = children[2].text | 
					
						
							|  |  |  |     if errors == "": | 
					
						
							|  |  |  |         errors = "none" | 
					
						
							|  |  |  |     warnings = children[4].text | 
					
						
							|  |  |  |     if warnings == "": | 
					
						
							|  |  |  |         warnings = "none" | 
					
						
							|  |  |  |     gotErrors = errors != "none" and errors != "0" | 
					
						
							| 
									
										
										
										
											2011-09-26 15:24:49 +02:00
										 |  |  |     if not (gotErrors ^ expectedToFail): | 
					
						
							|  |  |  |         test.passes("Errors: %s | Warnings: %s" % (errors, warnings)) | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2011-09-26 15:24:49 +02:00
										 |  |  |         test.fail("Errors: %s | Warnings: %s" % (errors, warnings)) | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |     # additional stuff - could be removed... or improved :) | 
					
						
							| 
									
										
										
										
											2011-11-08 13:20:24 +01:00
										 |  |  |     ensureChecked("{type='Core::Internal::OutputPaneToggleButton' unnamed='1' " | 
					
						
							|  |  |  |                   "visible='1' window=':Qt Creator_Core::Internal::MainWindow'}") | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |     list=waitForObject("{type='QListView' unnamed='1' visible='1' " | 
					
						
							| 
									
										
										
										
											2011-10-06 13:55:05 +02:00
										 |  |  |                        "window=':Qt Creator_Core::Internal::MainWindow' windowTitle='Issues'}", 20000) | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |     model = list.model() | 
					
						
							| 
									
										
										
										
											2011-10-06 13:55:05 +02:00
										 |  |  |     test.log("Rows inside issues: %d" % model.rowCount()) | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |     if gotErrors and createTasksFileOnError: | 
					
						
							|  |  |  |         createTasksFile(list) | 
					
						
							|  |  |  |     return not gotErrors | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-05 11:00:32 +02:00
										 |  |  | # helper function to check the compilation when build wasn't successful | 
					
						
							|  |  |  | def checkCompile(): | 
					
						
							| 
									
										
										
										
											2011-11-08 13:20:24 +01:00
										 |  |  |     ensureChecked("{type='Core::Internal::OutputPaneToggleButton' unnamed='1' visible='1' " | 
					
						
							|  |  |  |                   "window=':Qt Creator_Core::Internal::MainWindow' occurrence='4'}") | 
					
						
							| 
									
										
										
										
											2011-09-05 11:00:32 +02:00
										 |  |  |     output = waitForObject("{type='Core::OutputWindow' unnamed='1' visible='1' windowTitle='Compile Output'" | 
					
						
							|  |  |  |                                  " window=':Qt Creator_Core::Internal::MainWindow'}", 20000) | 
					
						
							|  |  |  |     waitFor("len(str(output.plainText))>0",5000) | 
					
						
							| 
									
										
										
										
											2011-12-08 18:45:31 +01:00
										 |  |  |     success = str(output.plainText).endswith("exited normally.") | 
					
						
							| 
									
										
										
										
											2011-10-06 16:46:03 +02:00
										 |  |  |     if success: | 
					
						
							| 
									
										
										
										
											2012-01-10 16:55:57 +01:00
										 |  |  |         if os.getenv("SYSTEST_DEBUG") == "1": | 
					
						
							|  |  |  |             test.log("Compile Output:\n%s" % output.plainText) | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             test.passes("Compile successful") | 
					
						
							| 
									
										
										
										
											2011-09-05 11:00:32 +02:00
										 |  |  |     else: | 
					
						
							| 
									
										
										
										
											2011-10-06 16:46:03 +02:00
										 |  |  |         test.fail("Compile Output:\n%s" % output.plainText) | 
					
						
							|  |  |  |     return success | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-06 13:55:05 +02:00
										 |  |  | # helper method that parses the Issues output and writes a tasks file | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  | def createTasksFile(list): | 
					
						
							|  |  |  |     global tasksFileDir, tasksFileCount | 
					
						
							|  |  |  |     model = list.model() | 
					
						
							|  |  |  |     if tasksFileDir == None: | 
					
						
							| 
									
										
										
										
											2011-09-05 15:00:01 +02:00
										 |  |  |             tasksFileDir = os.getcwd() + "/tasks" | 
					
						
							|  |  |  |             tasksFileDir = os.path.abspath(tasksFileDir) | 
					
						
							|  |  |  |     if not os.path.exists(tasksFileDir): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             os.makedirs(tasksFileDir) | 
					
						
							|  |  |  |         except OSError: | 
					
						
							|  |  |  |             test.log("Could not create %s - falling back to a temporary directory" % tasksFileDir) | 
					
						
							|  |  |  |             tasksFileDir = tempDir() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |     tasksFileCount += 1 | 
					
						
							|  |  |  |     outfile = os.path.join(tasksFileDir, os.path.basename(squishinfo.testCase)+"_%d.tasks" % tasksFileCount) | 
					
						
							|  |  |  |     file = codecs.open(outfile, "w", "utf-8") | 
					
						
							|  |  |  |     test.log("Writing tasks file - can take some time (according to number of issues)") | 
					
						
							| 
									
										
										
										
											2012-02-03 14:19:01 +01:00
										 |  |  |     rows = model.rowCount() | 
					
						
							|  |  |  |     if os.environ.get("SYSTEST_DEBUG") == "1": | 
					
						
							|  |  |  |         firstrow = 0 | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         firstrow = max(0, rows - 100) | 
					
						
							|  |  |  |     for row in range(firstrow, rows): | 
					
						
							| 
									
										
										
										
											2011-09-01 14:09:25 +02:00
										 |  |  |         index = model.index(row,0) | 
					
						
							|  |  |  |         # the following is currently a bad work-around | 
					
						
							|  |  |  |         fData = index.data(Qt.UserRole).toString() # file | 
					
						
							|  |  |  |         lData = index.data(Qt.UserRole + 1).toString() # line -> linenumber or empty | 
					
						
							|  |  |  |         tData = index.data(Qt.UserRole + 4).toString() # type -> 1==error 2==warning | 
					
						
							|  |  |  |         dData = index.data(Qt.UserRole + 2).toString() # description | 
					
						
							|  |  |  |         if lData == "": | 
					
						
							|  |  |  |             lData = "-1" | 
					
						
							|  |  |  |         if tData == "1": | 
					
						
							|  |  |  |             tData = "error" | 
					
						
							|  |  |  |         elif tData == "2": | 
					
						
							|  |  |  |             tData = "warning" | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             tData = "unknown" | 
					
						
							|  |  |  |         file.write("%s\t%s\t%s\t%s\n" % (fData, lData, tData, dData)) | 
					
						
							|  |  |  |     file.close() | 
					
						
							|  |  |  |     test.log("Written tasks file %s" % outfile) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-17 13:47:47 +01:00
										 |  |  | # returns a list of the build configurations for a target | 
					
						
							|  |  |  | # param targetCount specifies the number of targets currently defined (must be correct!) | 
					
						
							|  |  |  | # param currentTarget specifies the target for which to switch into the specified settings (zero based index) | 
					
						
							|  |  |  | # param filter is a regular expression to filter the configuration by their name | 
					
						
							|  |  |  | def iterateBuildConfigs(targetCount, currentTarget, filter = ""): | 
					
						
							|  |  |  |     switchViewTo(ViewConstants.PROJECTS) | 
					
						
							|  |  |  |     switchToBuildOrRunSettingsFor(targetCount, currentTarget, ProjectSettings.BUILD) | 
					
						
							|  |  |  |     model = waitForObject(":scrollArea.Edit build configuration:_QComboBox", 20000).model() | 
					
						
							|  |  |  |     prog = re.compile(filter) | 
					
						
							| 
									
										
										
										
											2012-02-22 15:43:05 +01:00
										 |  |  |     # for each row in the model, write its data to a list | 
					
						
							|  |  |  |     configNames = [str(model.index(row, 0).data()) for row in range(model.rowCount())] | 
					
						
							|  |  |  |     # pick only those configuration names which pass the filter | 
					
						
							|  |  |  |     configs = [config for config in configNames if prog.match(config)] | 
					
						
							| 
									
										
										
										
											2012-01-17 13:47:47 +01:00
										 |  |  |     switchViewTo(ViewConstants.EDIT) | 
					
						
							|  |  |  |     return configs | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # selects a build configuration for building the current project | 
					
						
							|  |  |  | # param targetCount specifies the number of targets currently defined (must be correct!) | 
					
						
							|  |  |  | # param currentTarget specifies the target for which to switch into the specified settings (zero based index) | 
					
						
							|  |  |  | # param configName is the name of the configuration that should be selected | 
					
						
							|  |  |  | def selectBuildConfig(targetCount, currentTarget, configName): | 
					
						
							|  |  |  |     switchViewTo(ViewConstants.PROJECTS) | 
					
						
							|  |  |  |     switchToBuildOrRunSettingsFor(targetCount, currentTarget, ProjectSettings.BUILD) | 
					
						
							|  |  |  |     if selectFromCombo(":scrollArea.Edit build configuration:_QComboBox", configName): | 
					
						
							|  |  |  |         waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", | 
					
						
							|  |  |  |                       "sourceFilesRefreshed(QStringList)") | 
					
						
							|  |  |  |     switchViewTo(ViewConstants.EDIT) |