Mercurial > vim
annotate src/testdir/test_netbeans.py @ 20696:5e91479ba748
Added tag v8.2.0901 for changeset cea8ae407452b59d31fdabf4f7fea34ed4359b0a
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 04 Jun 2020 18:30:05 +0200 |
parents | 116c7bd5e980 |
children | c8a4ad051d23 |
rev | line source |
---|---|
9517
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 # |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 # Server that will communicate with Vim through the netbeans interface. |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 # Used by test_netbeans.vim. |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 # |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 # This requires Python 2.6 or later. |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 from __future__ import print_function |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 import socket |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 import sys |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 import time |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 import threading |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
13 import re |
9517
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 try: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 # Python 3 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 import socketserver |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 except ImportError: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
19 # Python 2 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 import SocketServer as socketserver |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler): |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
24 def process_msgs(self, msgbuf): |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
25 # Process all the received netbeans commands/responses/events from Vim. |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
26 # Each one is separated by a newline character. If a partial command |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
27 # is received, process it later after the rest of it is received. |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
28 while True: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
29 (line, sep, rest) = msgbuf.partition('\n') |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
30 if sep == '': |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
31 # received partial line |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
32 return line |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
33 msgbuf = rest |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
34 |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
35 # Process a command only after receiving a newline. |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
36 response = '' |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
37 if line.find('Xcmdbuf') > 0: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
38 name = line.split('"')[1] |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
39 response = '1:putBufferNumber!15 "' + name + '"\n' |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
40 response += '1:startDocumentListen!16\n' |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
41 elif re.match('1:insert=.* "\\\\n"', line): |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
42 # extract the command from the previous line |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
43 cmd = re.search('.*"(.*)"', self.prev_line).group(1) |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
44 testmap = { |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
45 'getCursor_Test' : '0:getCursor/30\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
46 'E627_Test' : '0 setReadOnly!31\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
47 'E628_Test' : '0:setReadOnly 32\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
48 'E632_Test' : '0:getLength/33\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
49 'E633_Test' : '0:getText/34\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
50 'E634_Test' : '0:remove/35 1 1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
51 'E635_Test' : '0:insert/36 0 "line1\\n"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
52 'E636_Test' : '0:create!37\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
53 'E637_Test' : '0:startDocumentListen!38\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
54 'E638_Test' : '0:stopDocumentListen!39\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
55 'E639_Test' : '0:setTitle!40 "Title"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
56 'E640_Test' : '0:initDone!41\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
57 'E641_Test' : '0:putBufferNumber!42 "XSomeBuf"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
58 'E642_Test' : '9:putBufferNumber!43 "XInvalidBuf"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
59 'E643_Test' : '0:setFullName!44 "XSomeBuf"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
60 'E644_Test' : '0:editFile!45 "Xfile3"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
61 'E645_Test' : '0:setVisible!46 T\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
62 'E646_Test' : '0:setModified!47 T\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
63 'E647_Test' : '0:setDot!48 1/1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
64 'E648_Test' : '0:close!49\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
65 'E650_Test' : '0:defineAnnoType!50 1 "abc" "a" "a" 1 1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
66 'E651_Test' : '0:addAnno!51 1 1 1 1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
67 'E652_Test' : '0:getAnno/52 8\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
68 'editFile_Test' : '2:editFile!53 "Xfile3"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
69 'getLength_Test' : '2:getLength/54\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
70 'getModified_Test' : '2:getModified/55\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
71 'getText_Test' : '2:getText/56\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
72 'setDot_Test' : '2:setDot!57 3/6\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
73 'startDocumentListen_Test' : '2:startDocumentListen!58\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
74 'stopDocumentListen_Test' : '2:stopDocumentListen!59\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
75 'define_anno_Test' : '2:defineAnnoType!60 1 "s1" "x" "=>" blue none\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
76 'E532_Test' : '2:defineAnnoType!61 1 "s1" "x" "=>" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa none\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
77 'add_anno_Test' : '2:addAnno!62 1 1 2/1 0\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
78 'get_anno_Test' : '2:getAnno/63 1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
79 'remove_anno_Test' : '2:removeAnno!64 1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
80 'getModifiedAll_Test' : '0:getModified/65\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
81 'create_Test' : '3:create!66\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
82 'setTitle_Test' : '3:setTitle!67 "Xfile4"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
83 'setFullName_Test' : '3:setFullName!68 "Xfile4"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
84 'initDone_Test' : '3:initDone!69\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
85 'setVisible_Test' : '3:setVisible!70 T\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
86 'setModtime_Test' : '3:setModtime!71 6\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
87 'insert_Test' : '3:insert/72 0 "line1\\nline2\\n"\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
88 'remove_Test' : '3:remove/73 3 4\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
89 'remove_invalid_offset_Test' : '3:remove/74 900 4\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
90 'remove_invalid_count_Test' : '3:remove/75 1 800\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
91 'guard_Test' : '3:guard!76 8 7\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
92 'setModified_Test' : '3:setModified!77 T\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
93 'insertDone_Test' : '3:insertDone!78 T F\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
94 'saveDone_Test' : '3:saveDone!79\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
95 'invalidcmd_Test' : '3:invalidcmd!80\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
96 'invalidfunc_Test' : '3:invalidfunc/81\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
97 'removeAnno_fail_Test' : '0:removeAnno/82 1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
98 'guard_fail_Test' : '0:guard/83 1 1\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
99 'save_fail_Test' : '0:save/84\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
100 'netbeansBuffer_fail_Test' : '0:netbeansBuffer/85 T\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
101 'setExitDelay_Test' : '0:setExitDelay!86 2\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
102 'setReadOnly_Test' : '3:setReadOnly!87\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
103 'close_Test' : '3:close!88\n', |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
104 'specialKeys_Test' : '0:specialKeys!89 "F12 F13"\n', |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
105 'nbbufwrite_Test' : '4:editFile!90 "XnbBuffer"\n4:netbeansBuffer!91 T\n', |
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
106 'detach_Test' : '2:close!92\n1:close!93\nDETACH\n' |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
107 } |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
108 # execute the specified test |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
109 if cmd not in testmap: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
110 print("=== invalid command %s ===" % (cmd)) |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
111 else: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
112 response = testmap[cmd] |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
113 elif line.find('disconnect') > 0: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
114 # we're done |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
115 self.server.shutdown() |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
116 return |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
117 |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
118 # save the current line, this is used as the test to run after |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
119 # receiving a newline only line. |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
120 self.prev_line = line |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
121 |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
122 if len(response) > 0: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
123 self.request.sendall(response.encode('utf-8')) |
20625
116c7bd5e980
patch 8.2.0866: not enough tests for buffer writing
Bram Moolenaar <Bram@vim.org>
parents:
20087
diff
changeset
|
124 # Write the response into the file, so that the test can knows |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
125 # the command was sent. |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
126 with open("Xnetbeans", "a") as myfile: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
127 myfile.write('send: ' + response) |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
128 if self.debug: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
129 with open("save_Xnetbeans", "a") as myfile: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
130 myfile.write('send: ' + response) |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
131 |
9517
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
132 def handle(self): |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
133 print("=== socket opened ===") |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
134 # To preserve the Xnetbeans file as save_Xnetbeans, set debug to 1 |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
135 self.debug = 0 |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
136 self.prev_line = '' |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
137 msgbuf = '' |
9517
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
138 while True: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
139 try: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
140 received = self.request.recv(4096).decode('utf-8') |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
141 except socket.error: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
142 print("=== socket error ===") |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
143 break |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
144 except IOError: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
145 print("=== socket closed ===") |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
146 break |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
147 if received == '': |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
148 print("=== socket closed ===") |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
149 break |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
150 print("received: {0}".format(received)) |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
151 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
152 # Write the received line into the file, so that the test can check |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
153 # what happened. |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
154 with open("Xnetbeans", "a") as myfile: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
155 myfile.write(received) |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
156 if self.debug: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
157 with open("save_Xnetbeans", "a") as myfile: |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
158 myfile.write(received) |
9517
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
159 |
20087
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
160 # Can receive more than one line in a response or a partial line. |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
161 # Accumulate all the received characters and process one line at |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
162 # a time. |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
163 msgbuf += received |
b378f860d4ab
patch 8.2.0599: Netbeans interface insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents:
15077
diff
changeset
|
164 msgbuf = self.process_msgs(msgbuf) |
9517
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
165 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
167 pass |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
168 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
169 def writePortInFile(port): |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
170 # Write the port number in Xportnr, so that the test knows it. |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
171 f = open("Xportnr", "w") |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
172 f.write("{0}".format(port)) |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
173 f.close() |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
174 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
175 if __name__ == "__main__": |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
176 HOST, PORT = "localhost", 0 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
177 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
178 server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler) |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
179 ip, port = server.server_address |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
180 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
181 # Start a thread with the server. That thread will then start a new thread |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
182 # for each connection. |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
183 server_thread = threading.Thread(target=server.serve_forever) |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
184 server_thread.start() |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
185 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
186 writePortInFile(port) |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
187 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
188 print("Listening on port {0}".format(port)) |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
189 |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
190 # Main thread terminates, but the server continues running |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
191 # until server.shutdown() is called. |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
192 try: |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
193 while server_thread.isAlive(): |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
194 server_thread.join(1) |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
195 except (KeyboardInterrupt, SystemExit): |
9f8f03a44886
commit https://github.com/vim/vim/commit/321efdd77a7b9ac11ade90dd7634b5d37f4820fe
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
196 server.shutdown() |