summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_netbeans.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:44:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 02:44:24 +0000
commit8baab3c8d7a6f22888bd581cd5c6098fd2e4b5a8 (patch)
tree3537e168b860f2742f6029d70501b5ed7d15d345 /src/testdir/test_netbeans.py
parentInitial commit. (diff)
downloadvim-8baab3c8d7a6f22888bd581cd5c6098fd2e4b5a8.tar.xz
vim-8baab3c8d7a6f22888bd581cd5c6098fd2e4b5a8.zip
Adding upstream version 2:8.1.0875.upstream/2%8.1.0875upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/testdir/test_netbeans.py')
-rw-r--r--src/testdir/test_netbeans.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/testdir/test_netbeans.py b/src/testdir/test_netbeans.py
new file mode 100644
index 0000000..bdebb54
--- /dev/null
+++ b/src/testdir/test_netbeans.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+#
+# Server that will communicate with Vim through the netbeans interface.
+# Used by test_netbeans.vim.
+#
+# This requires Python 2.6 or later.
+
+from __future__ import print_function
+import socket
+import sys
+import time
+import threading
+
+try:
+ # Python 3
+ import socketserver
+except ImportError:
+ # Python 2
+ import SocketServer as socketserver
+
+class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
+
+ def handle(self):
+ print("=== socket opened ===")
+ while True:
+ try:
+ received = self.request.recv(4096).decode('utf-8')
+ except socket.error:
+ print("=== socket error ===")
+ break
+ except IOError:
+ print("=== socket closed ===")
+ break
+ if received == '':
+ print("=== socket closed ===")
+ break
+ print("received: {0}".format(received))
+
+ # Write the received line into the file, so that the test can check
+ # what happened.
+ with open("Xnetbeans", "a") as myfile:
+ myfile.write(received)
+
+ response = ''
+ if received.find('XREADME.txt') > 0:
+ name = received.split('"')[1]
+ response = '5:putBufferNumber!33 "' + name + '"\n'
+ response += '5:setDot!1 3/19\n'
+ elif received.find('disconnect') > 0:
+ # we're done
+ self.server.shutdown()
+ return
+
+ if len(response) > 0:
+ self.request.sendall(response.encode('utf-8'))
+ # Write the respoinse into the file, so that the test can knows
+ # the command was sent.
+ with open("Xnetbeans", "a") as myfile:
+ myfile.write('send: ' + response)
+
+class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
+ pass
+
+def writePortInFile(port):
+ # Write the port number in Xportnr, so that the test knows it.
+ f = open("Xportnr", "w")
+ f.write("{0}".format(port))
+ f.close()
+
+if __name__ == "__main__":
+ HOST, PORT = "localhost", 0
+
+ server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
+ ip, port = server.server_address
+
+ # Start a thread with the server. That thread will then start a new thread
+ # for each connection.
+ server_thread = threading.Thread(target=server.serve_forever)
+ server_thread.start()
+
+ writePortInFile(port)
+
+ print("Listening on port {0}".format(port))
+
+ # Main thread terminates, but the server continues running
+ # until server.shutdown() is called.
+ try:
+ while server_thread.isAlive():
+ server_thread.join(1)
+ except (KeyboardInterrupt, SystemExit):
+ server.shutdown()