Exemplo n.º 1
0
def main(clientBug):
	server = Server()
	server.setExperimentErrorDataTransferConfirmation(True)
	commandNet = TestNetwork(server, False)
	dataNet = TestNetwork(server, True)
	host = "foo"
	client = Client(commandNet, dataNet)
	client.setDataTransferConfirmationBug(clientBug)
	client.setPasvResponseReadingBug(clientBug)
	suc = client.connect(host, 21)
	print "C:Test connected:", suc
	client.login("anonymous", "*****@*****.**")
	
	f = client.retrieveFile("xx")
	if f is not None:
		print "C:File is:\r\n", f
	else:
		print "C:File transfer failed."

	print "C:##Second shot..."
	
	f = client.retrieveFile("xx")
	if f is not None:
		print "C:File is(2):\r\n", f
	else:
		print "C:File transfer failed.(2)"
	
	print "C:##Third shot..."
	
	f = client.retrieveFile("xx")
	if f is not None:
		print "C:File is(3):\r\n", f
	else:
		print "C:File transfer failed.(3)"
	
	print "C:##Stream shot..."	
	
	stream = client.retrieveFileStream("xx")
	counter = 0
	while True:
		c = stream.read()
		if c == -1:
			stream.close()
			break
		else:
			counter += 1

	print "Stream contained %d bytes" % counter
	
	client.logout()
	
	print "C:TestDone."
def main(dataTransferConfirmationBug, pasvResponseReadingBug, cuttingServer):
	""" 
		Mainly for counting states of JPF and for comparison with simulation 
	"""
	assert not (dataTransferConfirmationBug and pasvResponseReadingBug)
	
	config = None
	if cuttingServer:
		config = RandServerConfig()
		config.setSERVER_LEVEL(0)
		config.setREADLINE_LEVEL(2)
		
	server = RandServer(config)

	commandNet = TestNetwork(server, False, config)
	dataNet = TestNetwork(server, True)
	host = "foo"
	client = Client(commandNet, dataNet)
	# This sets the artificial clien bug:
	client.setDataTransferConfirmationBug(dataTransferConfirmationBug)
	client.setPasvResponseReadingBug(pasvResponseReadingBug)
	suc = client.connect(host, 21)
	print "C:Test connected:", suc
	if not suc:
		return
	
	suc = client.login("anonymous", "*****@*****.**")
	if not suc:
		return
	
	f = client.retrieveFile("xx")
	if f is None:
		pass
	else:
		print f
		
	f = client.retrieveFile("xx2")
	if f is None:
		pass
	else:
		print f
	
	suc = client.logout()
	if not suc:
		pass

	print "C:TestDone."