diff options
author | Jean-Luc Lamadon <jean-luc.lamadon@nokia.com> | 2009-10-29 11:45:14 +0200 |
---|---|---|
committer | Jean-Luc Lamadon <jean-luc.lamadon@nokia.com> | 2009-10-29 11:45:14 +0200 |
commit | c9d3ead208802fbc0f2b1a5d143b57492b4c1462 (patch) | |
tree | cd978233fcfc69e9e07e46f8b83bb755b07be2f1 | |
parent | ef9c847b1f0b654c3f9315fae25149dd961fcab8 (diff) |
libcontextprovider, protocol change: new customer tests for multiprovider scenarios
added service name in valuechanged message print of test client
7 files changed, 256 insertions, 30 deletions
diff --git a/libcontextprovider/customer-tests/c-api/cprovidertests.c b/libcontextprovider/customer-tests/c-api/cprovidertests.c index b5f96f64..99958526 100644 --- a/libcontextprovider/customer-tests/c-api/cprovidertests.c +++ b/libcontextprovider/customer-tests/c-api/cprovidertests.c @@ -289,8 +289,9 @@ int test_value_changes() /* Expected result: the client got the signal */ int mismatch = compare_output("ValueChanged: " + "org.freedesktop.ContextKit.testProvider " "/org/maemo/contextkit/Group1/Double " - "double:-41.987\n"); + "double:-41.987 \n"); if (mismatch) return 1; write_to_client("resetsignalstatus\n"); @@ -301,7 +302,8 @@ int test_value_changes() /* Expected result: the client got the signal */ mismatch = compare_output("ValueChanged: " - "/org/maemo/contextkit/Group1/String Unknown\n"); + "org.freedesktop.ContextKit.testProvider " + "/org/maemo/contextkit/Group1/String Unknown \n"); if (mismatch) return 1; write_to_client("resetsignalstatus\n"); diff --git a/libcontextprovider/customer-tests/client/commandwatcher.cpp b/libcontextprovider/customer-tests/client/commandwatcher.cpp index b5bb05b9..736c6139 100644 --- a/libcontextprovider/customer-tests/client/commandwatcher.cpp +++ b/libcontextprovider/customer-tests/client/commandwatcher.cpp @@ -227,18 +227,30 @@ void CommandWatcher::waitForChanged(int timeout) while (changedSignalReceived == false && t.elapsed() < timeout) { QCoreApplication::processEvents(QEventLoop::AllEvents); } + if (changedSignalReceived) { - out << "ValueChanged: " << changedSignalParameters.at(0) << endl; + out << "ValueChanged: "; + foreach (QString param, changedSignalParameters) + out << param << " "; + out << endl; } else { out << "Timeout" << endl; } + changedSignalReceived = false; + changedSignalParameters.clear(); } void CommandWatcher::onValueChanged(QList<QVariant> value, quint64 timestamp, QDBusMessage msg) { changedSignalReceived = true; - changedSignalParameters.append(msg.path() + " " + describeValue(value, timestamp)); + QPair<QString, QString> connData; + foreach (connData, connectionMap) + { + QDBusReply<QString> reply = QDBusConnection::sessionBus().interface()->serviceOwner(connData.second); + if (reply.value() == msg.service()) + changedSignalParameters.append(connData.second + " " + msg.path() + " " + describeValue(value, timestamp)); + } } QString CommandWatcher::describeValue(QList<QVariant> value, quint64 timestamp) diff --git a/libcontextprovider/customer-tests/multiprovider/env.sh b/libcontextprovider/customer-tests/multiprovider/env.sh index df63b533..41ee3f8e 100755 --- a/libcontextprovider/customer-tests/multiprovider/env.sh +++ b/libcontextprovider/customer-tests/multiprovider/env.sh @@ -3,4 +3,4 @@ export PYTHONPATH=$PYTHONPATH:../../../python export CONTEXT_PROVIDERS=. export LD_LIBRARY_PATH=../../src/.libs:../../../libcontextprovider/src/.libs -export PATH=../../../python:../../libcontextprovider/context-provide:../../../libcontextsubscriber/cli:../../../libcontextsubscriber/cls:$PATH +export PATH=../../../python:../../libcontextprovider/context-provide:../../../libcontextsubscriber/cli:../../../libcontextsubscriber/cls:../client:$PATH 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__": diff --git a/libcontextprovider/customer-tests/tests.xml b/libcontextprovider/customer-tests/tests.xml index ce7b766d..93cc6528 100644 --- a/libcontextprovider/customer-tests/tests.xml +++ b/libcontextprovider/customer-tests/tests.xml @@ -19,6 +19,11 @@ <case name="service" description="Operations on the Service class" requirement="" timeout="50"> <step expected_result="0">. /tmp/session_bus_address.user;export PATH=$PATH:.;cd /usr/lib/libcontextprovider-tests/;./servicetest</step> </case> + <case name="multiprovider" description="Scenarios involving + several providers" requirement="" timeout="50"> + <step expected_result="0">. /tmp/session_bus_address.user;export + PATH=$PATH:.;cd /usr/share/libcontextprovider-tests/multiprovider;python /usr/share/libcontextprovider-tests/multiprovider.py</step> + </case> <environments> <scratchbox>false</scratchbox> <hardware>true</hardware> diff --git a/libcontextprovider/customer-tests/types/typestests.cpp b/libcontextprovider/customer-tests/types/typestests.cpp index aad31142..56be8d0a 100644 --- a/libcontextprovider/customer-tests/types/typestests.cpp +++ b/libcontextprovider/customer-tests/types/typestests.cpp @@ -193,28 +193,28 @@ void TypesTests::typesInChangeSignal() intItem->setValue(-11); QString actual = writeToClient("waitforchanged 3000\n"); - QString expected = "ValueChanged: /org/maemo/contextkit/Test/Int int:-11"; + QString expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/Int int:-11"; QCOMPARE(actual.simplified(), expected.simplified()); writeToClient("resetsignalstatus\n"); doubleItem->setValue(4.88); actual = writeToClient("waitforchanged 3000\n"); - expected = "ValueChanged: /org/maemo/contextkit/Test/Double double:4.88"; + expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/Double double:4.88"; QCOMPARE(actual.simplified(), expected.simplified()); writeToClient("resetsignalstatus\n"); stringItem->setValue("anotherstring"); actual = writeToClient("waitforchanged 3000\n"); - expected = "ValueChanged: /org/maemo/contextkit/Test/String QString:anotherstring"; + expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/String QString:anotherstring"; QCOMPARE(actual.simplified(), expected.simplified()); writeToClient("resetsignalstatus\n"); boolItem->setValue(true); actual = writeToClient("waitforchanged 3000\n"); - expected = "ValueChanged: /org/maemo/contextkit/Test/Bool bool:true"; + expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/Bool bool:true"; QCOMPARE(actual.simplified(), expected.simplified()); writeToClient("resetsignalstatus\n"); @@ -225,7 +225,7 @@ void TypesTests::typesInChangeSignal() actual = writeToClient("waitforchanged 3000\n"); // Expected result: The client got the Changed signal with correct values - expected = "ValueChanged: /org/maemo/contextkit/Test/StringList QStringList:something/else/here"; + expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/StringList QStringList:something/else/here"; QCOMPARE(actual.simplified(), expected.simplified()); } diff --git a/libcontextprovider/customer-tests/value-changes/valuechangestests.cpp b/libcontextprovider/customer-tests/value-changes/valuechangestests.cpp index f5da63e6..10a38dc3 100644 --- a/libcontextprovider/customer-tests/value-changes/valuechangestests.cpp +++ b/libcontextprovider/customer-tests/value-changes/valuechangestests.cpp @@ -106,7 +106,7 @@ void ValueChangesTests::subscribedPropertyChanges() QString actual = writeToClient("waitforchanged 3000\n"); // Expected result: the client got the Changed signal - QString expected = "ValueChanged: /org/maemo/contextkit/Test/Double double:51.987"; + QString expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/Double double:51.987"; QCOMPARE(actual.simplified(), expected.simplified()); @@ -119,7 +119,7 @@ void ValueChangesTests::subscribedPropertyChanges() actual = writeToClient("waitforchanged 3000\n"); // Expected result: the client got the Changed signal - expected = "ValueChanged: /org/maemo/contextkit/Test/Double Unknown"; + expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/Double Unknown"; QCOMPARE(actual.simplified(), expected.simplified()); } @@ -256,7 +256,7 @@ void ValueChangesTests::changesBetweenZeroAndUnknown() actual = writeToClient("waitforchanged 3000\n"); // Expected result: the client got the Changed signal - expected = "ValueChanged: /org/maemo/contextkit/Test/Int int:0"; + expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/Int int:0"; QCOMPARE(actual.simplified(), expected.simplified()); @@ -269,7 +269,7 @@ void ValueChangesTests::changesBetweenZeroAndUnknown() actual = writeToClient("waitforchanged 3000\n"); // Expected result: the client got the Changed signal - expected = "ValueChanged: /org/maemo/contextkit/Test/Int Unknown"; + expected = "ValueChanged: org.maemo.contextkit.testProvider1 /org/maemo/contextkit/Test/Int Unknown"; QCOMPARE(actual.simplified(), expected.simplified()); } |