Beispiel #1
0
    def testCopyClipboardWord(self):
        """test the copying of the clipboard word documents
        """
        ## open the txtFiles (are closed in tearDown)
        for docxFile in docxFiles:
            hndle = self.openTestFile(os.path.join(thisDir,
                                                   'test_clipboardfiles',
                                                   docxFile),
                                      waitingTime=0.5)
            if hndle:
                self.allWindows[hndle] = docxFile
            else:
                print 'could not open test file %s' % docxFile

        cb = natlinkclipboard.Clipboard(save_clear=True)

        ## empty file:
        expTextPrev = ""
        nCycles = 2  # make it 10 or 50 to do a longer test
        for i in range(nCycles):
            for hndle, docxFile in self.allWindows.iteritems():
                print 'trying %s (%s) (cycle %s)' % (hndle, docxFile, i + 1)
                natlinkutilsqh.SetForegroundWindow(hndle)
                time.sleep(
                    0.2
                )  # word needs a little time before keystrokes are accepted...
                natlink.playString(
                    "{ctrl+home}{shift+end}{shift+down 3}{ctrl+c}")
                # cb.copy_from_system(waiting_interval=0.005)
                # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
                gotall = cb.get_text(waiting_interval=0.05)
                lengotall = len(gotall)
                got = gotall
                expText = u"A small word document.\n\nWith only a few lines\n\n"
                if not got:
                    print 'no text, file: %s' % docxFile
                self.assert_equal(
                    expText, got,
                    "testing docx file %s, result not as expected" % docxFile)

                # also test the class method (direct call)
                got = natlinkclipboard.Clipboard.get_system_text()
                self.assert_equal(
                    expText, got,
                    "testing docx file %s, with class method, result not as expected"
                    % docxFile)

        pass
Beispiel #2
0
    def tttestCopyClipboardCautious(self):
        """test the copying of the clipboard, with waiting times
        """
        ## open the txtFiles (are closed in tearDown)
        for txtFile in txtFiles:
            hndle = self.openTestFile(
                os.path.join(thisDir, 'test_clipboardfiles', txtFile))
            if hndle:
                self.allWindows[hndle] = txtFile
            else:
                print 'could not open %s' % txtFile

        cb = natlinkclipboard.Clipboard(save_clear=True)

        ## empty file:
        expTextPrev = ""
        for hndle, txtFile in self.allWindows.iteritems():
            filePath = os.path.join(thisDir, 'test_clipboardfiles', txtFile)
            encoding, bom, expText = readwritefile.readAnything(filePath)
            if txtFile == "emptytest.txt":
                # now the clipboard remains unchanged...
                expText = expTextPrev
            else:
                # now save for empty file:
                expTextPrev = expText
            natlinkutilsqh.SetForegroundWindow(hndle)
            time.sleep(0.5)
            if txtFile == "emptytest.txt":
                time.sleep(3)
            natlink.playString("{ctrl+a}{ctrl+c}")

            # cb.copy_from_system(waiting_interval=0.05)
            # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
            # print 'cb text: %s'% cb
            got = cb.get_text(waiting_interval=0.05)
            if txtFile == "emptytest.txt":
                self.assert_equal(
                    expTextPrev, got,
                    "testing empty txt file %s, result not as expected" %
                    txtFile)
            else:
                self.assert_equal(
                    expPrev, got,
                    "testing txt file %s, result not as expected" % txtFile)
Beispiel #3
0
    def tttestCopyClipboardQuick(self):
        """test the copying of the clipboard, without waiting times
        """
        ## open the txtFiles (are closed in tearDown)
        for txtFile in txtFiles:
            hndle = self.openTestFile(
                os.path.join(thisDir, 'test_clipboardfiles', txtFile))
            if hndle:
                self.allWindows[hndle] = txtFile
            else:
                print 'did not open testfile: %s' % txtFile

        cb = natlinkclipboard.Clipboard(save_clear=True)

        ## empty file:
        expTextPrev = ""
        for hndle, txtFile in self.allWindows.iteritems():
            filePath = os.path.join(thisDir, 'test_clipboardfiles', txtFile)
            encoding, bom, expText = readwritefile.readAnything(filePath)
            if txtFile == "emptytest.txt":
                expText = expTextPrev
            else:
                expTextPrev = expText
            natlinkutilsqh.SetForegroundWindow(hndle)
            natlink.playString("{ctrl+a}{ctrl+c}")
            cb.copy_from_system()
            # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
            # print 'cb text: %s'% cb
            got = cb.get_text()
            self.assert_equal(
                expText, got,
                "testing txt file %s, result not as expected" % txtFile)

            # also test the class method (direct call)
            got = natlinkclipboard.Clipboard.get_system_text()
            self.assert_equal(
                expText, got,
                "testing txt file %s, with class method, result not as expected"
                % txtFile)

        cb.restore()
Beispiel #4
0
    def tttestCopyingFromExplorerWindows(self):
        """test the getting of explorer items
        
        dialog windows #32770 now also work.
        een
        The testing is not stable. But probably these are only testing issues.
        """
        cb = natlinkclipboard.Clipboard()
        ## open the txtFiles (are closed in tearDown)
        for explDir in explDirectories:
            hndle = self.openTestFile(explDir)
            if hndle:
                self.allWindows[hndle] = explDir
            else:
                raise IOError('could not open test directory %s'%  explDir)
        # for txtFile in txtFiles:
        #     hndle = self.openTestFile(os.path.join(thisDir, 'test_clipboardfiles', txtFile))
        #     if hndle:
        #         self.allWindows[hndle] = txtFile
        #     else:
        #         print 'did not open testfile: %s'% txtFile

        nCycles = 2
        for i in range(nCycles):
            for hndle in list(self.allWindows.keys()):
                steps = (i % 4) + 2
                expDir = self.allWindows[hndle]
                print('try to get %s (%s) (cycle %s)'% (hndle, expDir, i+1))
                result = natlinkutilsqh.SetForegroundWindow(hndle, debug=True)
                if not result:
                    print('could not get %s in the foreground after SetForegroundWindow %s'% (expDir, hndle))
                    continue
                curMod = natlinkutilsqh.getCurrentModuleSafe()
                print('doing %s lines of directory'% (steps+1,))
                expDNr = self.allWindows[hndle]
                if hndle != curMod[2]:
                    pass
                self.assert_equal(hndle, curMod[2], "hndle not as expected after SetForegroundWindow %s (%s)"% (hndle, expDir))
                testChild = (curMod[0].find("notepad") > 0)
                if testChild:
                    natlink.playString("{ctrl+o}")
                    time.sleep(0.2)
                    natlink.playString("{alt+d}%s{enter}"% testFilesDir)
                    time.sleep(0.2)

                actions.do_RMP(1, 0.5, 0.5) # click on middle of window

                time.sleep(1)

                natlink.playString("{home}{shift+down %s}"% steps, 0x200)
                
                time.sleep(1)
                
                natlink.playString("{ctrl+c}", 0x200)

                time.sleep(1)


                if testChild:
                    time.sleep(0.1)
                    natlink.playString("{esc}")
                    time.sleep(0.1)
                
                time.sleep(0.5)
                if testChild:
                    pass
                got = cb.get_folderinfo(waiting_interval=0.1)
                
                exp = ()
                lenexp = steps
                if testChild:
                    lenexp = steps + 1
                    
                gotclassmethod = natlinkclipboard.Clipboard.Get_folderinfo()


                print('got: %s'% repr(got))
                print('gotclassmethod: %s'% repr(gotclassmethod))
                if got is None:
                    pass
                self.assert_equal(got, gotclassmethod, "getting folderinfo should be the same from class method and instance method")
                self.assert_equal(type(exp), type(got), "result should be at least a tupl, testChild is: %s"% testChild)
                self.assert_equal(lenexp, len(got), "expect length of 2, but: %s, testChild is: %s"% (repr(got), testChild))

                formats = natlinkclipboard.Clipboard.Get_clipboard_formats()
                self.assertTrue(type(formats) == list, "list of formats should be a list, not: %s"% repr(formats))
                gotclassmethod = natlinkclipboard.Clipboard.Get_folderinfo()
                self.assert_equal(got, gotclassmethod, "getting folderinfo should be the same from class method and instance method")

        time.sleep(1)
        # cb.restore()
        pass
Beispiel #5
0
    def tttestCopyClipboardSwitching(self):
        """test the copying of the clipboard
        
        with empty, small and larger .txt file.
        
        .docx does not run smooth
        
        
        """
        print("testCopyClipboardSwitching")
        # self.setupDocxFile()
        # self.setupWindows()
        # self.setupThunderbirdNewWindow()
        self.setupFrescobaldiNewPane()
        self.setupTextFiles()

        cb = natlinkclipboard.Clipboard(save_clear=True, debug=2)   # debug flag can be set or omitted (or set to 0)
        return

        ## longer test:
        for i in range(1, 10, 5):
            waitTime = 0.001/i
            print('---- round: %s, waitTime %.4f '% (i, waitTime))
            
            ## first clear the clipboard:
            cb.clear_clipboard()
            got = cb.get_text(waitTime)
            print('after clear_clipboard, text: %s (cb: %s)'% (got, cb))
            self.assert_equal("", got, "should have no text now, waitTime: %s (times 4)"% waitTime)

            print("now testempty.txt -----------------")
            # empty file: 
            natlinkutilsqh.SetForegroundWindow(self.text0Hndle)
            natlinkutils.playString("{ctrl+a}{ctrl+c}")
            got = cb.get_text(waitTime)
            print('after select all copy of empty file, no change should have happened:')
            # print('got: %s, (cb: %s)'% (got, cb))
            self.assert_equal("", got, "should have no text now, waitTime: %s"% waitTime)
            
            natlinkutilsqh.SetForegroundWindow(self.thisHndle)

            print("now testsmall.txt -----------------")
            natlinkutilsqh.SetForegroundWindow(self.text1Hndle)
            natlinkutils.playString("{ctrl+a}{ctrl+c}")
            got = cb.get_text(waitTime)
            print('after select all copy of testsmall.txt')
            # print('got: %s, (cb: %s)'% (got, cb))
            exp = self.text1Txt
            self.assert_equal(exp, got, "testsmall should have two lines of text, waitTime: %s"% waitTime)
            
            
            # test large.txt
            print("now testlarge.txt -----------------")
            natlinkutilsqh.SetForegroundWindow(self.text2Hndle)
            natlinkutils.playString("{ctrl+a}{ctrl+c}")
            cb.get_text(waiting_interval=waitTime)
            got = cb.get_text()
            if got:
                lengot = len(got)
            else:
                print('testlarge, no result from get_text: %s'% cb)
            exp = len(self.text2Txt)
            self.assert_equal(exp, lengot, "should have long text now, waitTime: %s"% waitTime)
            # empty for the next round:
            # cb.set_text("")
            time.sleep(waitTime)

            natlinkutilsqh.SetForegroundWindow(self.thisHndle)

            # test natlink.docx
            print("now natlink.docx (%s)-----------------"% self.docx2Hndle)
            if not self.docx2Hndle:
                print("word document not available: %s"% (self.docx2Hndle))
                continue
            natlinkutilsqh.SetForegroundWindow(self.docx2Hndle)
            natlinkutils.playString("{ctrl+a}{ctrl+c}")
            cb.get_text(waiting_interval=waitTime)
            got = cb.get_text()
            if got:
                lengot = len(got)
            else:
                print('testlarge, no result from get_text: %s'% cb)
            exp = len(self.text2Txt)
            self.assert_equal(exp, lengot, "should have long text now, waitTime: %s"% waitTime)
            # empty for the next round:
            # cb.set_text("")
            time.sleep(waitTime)
            
        del cb
        got_org_text = natlinkclipboard.Clipboard.get_system_text()
        self.assert_equal(self.org_text, got_org_text, "restored text from clipboard not as expected")
Beispiel #6
0
    def getTextViaClipboard(self, waitTime):
        """get text of window and selection or cursor via copy paste actions
        
        pass waitTime for testing response time.
        
        waiting_iterations is default 10, but changed to 3 if an empty clipboard is expected
        
        return: text, selStart, selEnd, cursorPos
               
        """
        cb = natlinkclipboard.Clipboard(save_clear=True, debug=1)
        waitTime = 0.001
      
        # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
        # natlinkutilsqh.SetForegroundWindow(self.testHndle)
        
        ## first try if there is a selection:
        action("{ctrl+c}")
        selection = cb.get_text(waitTime, waiting_iterations=3)
        if selection:
            print('selection: %s'% selection)
            action("{left}")
            cb.clear_clipboard()

           
        # now try text left of selection:
        action("{ctrl+shift+home}{ctrl+c}")
     
        # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
        # natlinkutilsqh.SetForegroundWindow(self.testHndle)
     
     
        before = cb.get_text(waitTime)
        if before:
            action("{right}")
            cb.clear_clipboard()
        else:
            print("at start of document")

        # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
        # natlinkutilsqh.SetForegroundWindow(self.testHndle)

        text = before + selection
        selStart = len(before)
        selEnd = len(text)
    
        # skip to end of selection:       
        if selection:
            action("{right %s}"% len(selection))

        # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
        # natlinkutilsqh.SetForegroundWindow(self.testHndle)
        
        if text:
            # now select to end:
            action("{shift+ctrl+end}{ctrl+c}")
            after = cb.get_text(waitTime)
            print("after: %s"% repr(after))
            
            if not after:
                if self.testHndle == self.thundHndle:
                    ## after an empty selection, go one to the left!!
                    action("{left}")
                    pass
                after = ""
            else:
                # undo selection
                action("{left}")
            if after.endswith('\0'):
                after = after.replace('\0', '')
                print("removed null char at end of selection (1): %s"% after)
                # after = afterplusone[1:]
        else:
            # presumably at start of buffer
            action("{shift+ctrl+end}{ctrl+c}")
            after = cb.get_text(waitTime, waiting_iterations=3)
            if after:
                # undo selection 
                action("{left}")
            else:
                pass
            if after.endswith('\0'):
                after = after.replace('\0', '')
                print("removed null char at end of selection (2): %s"% after)
                # after = afterplusone[1:]
                cb.clear_clipboard()

        if selection:
            lensel = len(selection)
            # select from left to right;
            
            # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
            # natlinkutilsqh.SetForegroundWindow(self.testHndle)
            
            action("{left %s}{shift+right %s}"% (lensel, lensel))

        text = text + after
        cursorPos = selEnd            

        # natlinkutilsqh.SetForegroundWindow(self.thisHndle)
        # natlinkutilsqh.SetForegroundWindow(self.testHndle)


        return text, selStart, selEnd, cursorPos