diff options
Diffstat (limited to 'libcontextprovider/customer-tests/multiprovider/multiprovider.py')
-rw-r--r-- | libcontextprovider/customer-tests/multiprovider/multiprovider.py | 239 |
1 files changed, 223 insertions, 16 deletions
diff --git a/libcontextprovider/customer-tests/multiprovider/multiprovider.py b/libcontextprovider/customer-tests/multiprovider/multiprovider.py index 71472a75..e1f094de 100644 --- a/libcontextprovider/customer-tests/multiprovider/multiprovider.py +++ b/libcontextprovider/customer-tests/multiprovider/multiprovider.py @@ -28,29 +28,236 @@ import sys import unittest import os from ContextKit.cltool import CLTool +from time import sleep class MultiProvider(unittest.TestCase): def tearDown(self): - #os.unlink('./context-provide.context') - #os.unlink('./context-provide2.context') - pass - + os.unlink('./context-provide_a.context') + os.unlink('./context-provide_b.context') + def testPingPong(self): """ + Description + This test verifies that valueChanged signals are emitted + when two providers continuously set new values to the same + property. + + Pre-conditions + + Steps + 1. starts two providers (A and B) providing the same property + the property is respectively initialised to V1 and V2 + 2. starts a client + 3. provider A sets the property to V2, a signal is emitted + since V2 is different than previous value V1 + 4. provider B sets the property to V1, a signal is emitted + since V1 is different than previous value V2 + 5. provider A sets the property to V1, a signal is emitted + since V1 is different than previous value V2 + 6. provider B sets the property to V2, a signal is emitted + since V2 is different than previous value V1 + + Post-conditions + + References + None + """ + provider_a = CLTool("context-provide", "--v2", "--session", "com.nokia.test.a", + "int","test.int","1") + provider_a.send("dump context-provide_a.context") + + provider_b = CLTool("context-provide", "--v2", "--session", "com.nokia.test.b", + "int","test.int","2") + provider_b.send("dump context-provide_b.context") + + client = CLTool("client") + + client.send("assign session com.nokia.test.a providerA") + client.expect(CLTool.STDOUT, + "Assigned providerA",3) + + client.send("assign session com.nokia.test.b providerB") + client.expect(CLTool.STDOUT, + "Assigned providerB",3) + + sleep(2) + + client.send("subscribe providerA test.int") + self.assert_(client.expect(CLTool.STDOUT, + "Subscribe returned: int:1",3)) + + client.send("subscribe providerB test.int") + self.assert_(client.expect(CLTool.STDOUT, + "Subscribe returned: int:2",3)) + + provider_a.send("test.int = 2") + client.send("waitforchanged 1000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.a /org/maemo/contextkit/test/int int:2",3) + + provider_b.send("test.int = 1") + client.send("waitforchanged 1000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.b /org/maemo/contextkit/test/int int:1",3) + + provider_a.send("test.int = 1") + client.send("waitforchanged 1000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.a /org/maemo/contextkit/test/int int:1",3) + + provider_b.send("test.int = 2") + client.send("waitforchanged 1000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.b /org/maemo/contextkit/test/int int:2",3) + + client.close() + provider_a.close() + provider_b.close() + + def testOverheardValues(self): + """ + Description + This test verifies that valueChanged signals are emitted + when a provider overhears the value from another provider. + + Pre-conditions + Steps + 1. starts two providers (A and B) providing the same property + the property is respectively initialised to V1 and V2 + 2. starts a client + 3. provider A sets the property to V3, a signal is emitted + since V3 is different than previous value V1 + 4. provider B sets the property to V4, a signal is emitted + since V4 is different than previous value V2 + 5. provider A sets the property to V3, a signal is emitted + because A has overheard V4 from provider B + + Post-conditions + + References + None """ - provider = CLTool("context-provide", "--v2", "--system", "com.nokia.test", - "int","test.int","1", - "string","test.string","foobar", - "double","test.double","2.5", - "truth","test.truth","True") - provider.send("dump") - provider2 = CLTool("context-provide", "--v2", "--session", "com.nokia.test2", - "int","test.int","1", - "string","test.string","foobar", - "double","test.double","2.5", - "truth","test.truth","True") - provider2.send("dump context-provide2.context") + + + provider_a = CLTool("context-provide", "--v2", "--session", "com.nokia.test.a", + "double","test.double","1.5") + provider_a.send("dump context-provide_a.context") + + provider_b = CLTool("context-provide", "--v2", "--session", "com.nokia.test.b", + "double","test.double","2.5") + provider_b.send("dump context-provide_b.context") + + client = CLTool("client") + + client.send("assign session com.nokia.test.a providerA") + client.expect(CLTool.STDOUT, + "Assigned providerA",3) + + client.send("assign session com.nokia.test.b providerB") + client.expect(CLTool.STDOUT, + "Assigned providerB",3) + + sleep(2) + + client.send("subscribe providerA test.double") + self.assert_(client.expect(CLTool.STDOUT, + "Subscribe returned: double:1.5",3)) + + client.send("subscribe providerB test.double") + self.assert_(client.expect(CLTool.STDOUT, + "Subscribe returned: double:2.5",3)) + + provider_a.send("test.double = 3.5") + client.send("waitforchanged 3000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.a /org/maemo/contextkit/test/double double:3.5",3) + + provider_b.send("test.double = 4.5") + client.send("waitforchanged 3000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.b /org/maemo/contextkit/test/double double:4.5",3) + + provider_a.send("test.double = 3.5") + client.send("waitforchanged 3000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.a /org/maemo/contextkit/test/double double:3.5",3) + + client.close() + provider_a.close() + provider_b.close() + + + def testBothProvidersSameValue(self): + """ + Description + This test verifies that no signals are emitted when + both providers are setting the same value to the same property. + + Pre-conditions + + Steps + 1. starts two providers (A and B) providing the same property + the property is respectively initialised to V1 and V2 + 2. starts a client + 3. provider A sets the property to V2, a signal is emitted + since V2 is different than previous value V1 + 4. provider B sets the property to V2, no signal is emitted + since V2 is identical to previous value V2 and V2 from Provider A + 5. provider A sets the property to V2, no signal is emitted + since V2 is identical to previous value V2 and V2 from Provider B + + Post-conditions + + References + None + """ + provider_a = CLTool("context-provide", "--v2", "--session", "com.nokia.test.a", + "truth","test.truth","true") + provider_a.send("dump context-provide_a.context") + + provider_b = CLTool("context-provide", "--v2", "--session", "com.nokia.test.b", + "truth","test.truth","false") + provider_b.send("dump context-provide_b.context") + + client = CLTool("client") + + client.send("assign session com.nokia.test.a providerA") + client.expect(CLTool.STDOUT, + "Assigned providerA",3) + + client.send("assign session com.nokia.test.b providerB") + client.expect(CLTool.STDOUT, + "Assigned providerB",3) + + sleep(2) + + client.send("subscribe providerA test.truth") + self.assert_(client.expect(CLTool.STDOUT, + "Subscribe returned: bool:true",3)) + + client.send("subscribe providerB test.truth") + self.assert_(client.expect(CLTool.STDOUT, + "Subscribe returned: bool:false",3)) + + provider_a.send("test.truth = false") + client.send("waitforchanged 3000") + client.expect(CLTool.STDOUT, + "ValueChanged: com.nokia.test.a /org/maemo/contextkit/test/truth bool:false",3) + + provider_b.send("test.truth = false") + client.send("waitforchanged 5000") + client.expect(CLTool.STDOUT, + "Timeout",6) + + provider_a.send("test.truth = false") + client.send("waitforchanged 5000") + client.expect(CLTool.STDOUT, + "Timeout",6) + + client.close() + provider_a.close() + provider_b.close() if __name__ == "__main__": |