From 4e0ac1d3f661efe589b6b24e3bdf6362ddb08323 Mon Sep 17 00:00:00 2001
From: Ramin Yaghoubzadeh <ryaghoub@techfak.uni-bielefeld.de>
Date: Wed, 8 Feb 2012 16:08:35 +0100
Subject: [PATCH] Added first test case. Found approx 10 bugs.

---
 python/src/ipaaca.py     |  4 ++--
 python/src/testipaaca.py | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100755 python/src/testipaaca.py

diff --git a/python/src/ipaaca.py b/python/src/ipaaca.py
index 834fed8..38f0d5a 100755
--- a/python/src/ipaaca.py
+++ b/python/src/ipaaca.py
@@ -215,7 +215,7 @@ class IUInterface(object): #{{{
 	def _replace_links(self, links):
 		'''Just wipe and replace our links set, do not send an update here'''
 		'''Note: Also used for remotely enforced links updates.'''
-		self._links = {}
+		self._links = collections.defaultdict(set)
 		for type in links.keys(): self._links[type] |= set(links[type])
 		
 	def add_links(self, type, targets, writer_name=None):
@@ -239,7 +239,7 @@ class IUInterface(object): #{{{
 		'''Attempt to set (replace) links if the conditions are met
 		and send an update message. Then call the local setter.'''
 		self._modify_links(links=self, is_delta=False, new_links=links, links_to_remove={}, writer_name=writer_name)
-		self._replace_links( links=new_links )
+		self._replace_links( links=links )
 	def get_links(self, type):
 		return set(self._links[type])
 	def get_all_links(self):
diff --git a/python/src/testipaaca.py b/python/src/testipaaca.py
new file mode 100755
index 0000000..4156281
--- /dev/null
+++ b/python/src/testipaaca.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+
+import time
+import ipaaca
+import sys
+
+import unittest
+
+class IpaacaLinksTestCase(unittest.TestCase):
+	def setUp(self):
+		self.ib = ipaaca.InputBuffer('TestIn', ['sensorcategory'])
+		self.ob = ipaaca.OutputBuffer('TestOut')
+		self.sensor_iu = ipaaca.IU('sensorcategory')
+		self.sensor_iu.payload = {'data': 'sensordata'}
+		self.ob.add(self.sensor_iu)
+	def tearDown(self):
+		pass
+	def testSetLink(self):
+		time.sleep(0.1)
+		self.decision_iu = ipaaca.IU('decisioncategory')
+		self.decision_iu.payload = {'data':'decision'}
+		self.decision_iu.set_links( { 'grin': [self.sensor_iu.uid] } )
+		self.ob.add(self.decision_iu)
+		time.sleep(0.1)
+		grinlinks = self.decision_iu.get_links('grin')
+		self.assertIn(self.sensor_iu.uid, grinlinks)
+		self.assertEqual(len(grinlinks), 1)
+
+if __name__ == '__main__':
+	unittest.main()
+
-- 
GitLab