Example #1
0
	def test_send_one_frame(self):
		def read_func():
			pass

		def write_func(data):
			write_func.data = data

		write_func.data = None

		hdlc_c = HDLController(read_func, write_func)
		hdlc_c.send('test')
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test', FRAME_DATA, 0))
		self.assertEqual(hdlc_c.get_senders_number(), 1)
		hdlc_c.stop()
Example #2
0
	def test_send_frame_and_receive_nack(self):
		def read_func():
			return frame_data('', FRAME_NACK, 0)

		def write_func(data):
			write_func.data = data

		write_func.data = None

		hdlc_c = HDLController(read_func, write_func)
		hdlc_c.send('test')
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test', FRAME_DATA, 0))
		self.assertEqual(hdlc_c.get_senders_number(), 1)
		hdlc_c.start()
		sleep(1)
		self.assertEqual(hdlc_c.get_senders_number(), 1)
		hdlc_c.stop()
Example #3
0
	def test_send_three_frames_and_wait_timeout(self):
		def read_func():
			pass

		def write_func(data):
			write_func.data = data

		write_func.data = None

		hdlc_c = HDLController(read_func, write_func, sending_timeout=5)
		hdlc_c.send('test1')
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test1', FRAME_DATA, 0))
		self.assertEqual(hdlc_c.get_senders_number(), 1)
		write_func.data = None
		sleep(1)
		hdlc_c.send('test2')
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test2', FRAME_DATA, 1))
		self.assertEqual(hdlc_c.get_senders_number(), 2)
		write_func.data = None
		sleep(1)
		hdlc_c.send('test3')
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test3', FRAME_DATA, 2))
		self.assertEqual(hdlc_c.get_senders_number(), 3)
		write_func.data = None
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test1', FRAME_DATA, 0))
		self.assertEqual(hdlc_c.get_senders_number(), 3)
		write_func.data = None
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test2', FRAME_DATA, 1))
		self.assertEqual(hdlc_c.get_senders_number(), 3)
		write_func.data = None
		while write_func.data == None: pass
		self.assertEqual(write_func.data, frame_data('test3', FRAME_DATA, 2))
		self.assertEqual(hdlc_c.get_senders_number(), 3)
		hdlc_c.stop()