aboutsummaryrefslogtreecommitdiff
path: root/libcontextsubscriber/customer-tests/pluginchanging/pluginchanging.py
blob: a1ee1fbee8060d8a493989c3f5a467f7c6908d42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
##
## This file is part of ContextKit.
##
## Copyright (C) 2009 Nokia. All rights reserved.
##
## Contact: Marius Vollmer <marius.vollmer@nokia.com>
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Lesser General Public License
## version 2.1 as published by the Free Software Foundation.
##
## This library is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
## 02110-1301 USA
##
##
## Requires python2.5-gobject and python2.5-dbus
##
import sys
import unittest
import os
from ContextKit.cltool import CLTool

class Subscription(unittest.TestCase):
        def tearDown(self):
                os.remove('time.context')

        def testChangingPlugin(self):
                os.environ["CONTEXT_PROVIDERS"] = "."
                if os.path.isdir("../testplugins"):
                        # for your local machine
                        os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] = "../testplugins"
                else:
                        # if libcontextsubscriber-tests is installed
                        os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] = "/usr/lib/contextkit/subscriber-test-plugins"

                if not os.path.exists(os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] + "/" + "contextsubscribertime1.so") \
                            or not os.path.exists(os.environ["CONTEXT_SUBSCRIBER_PLUGINS"] + "/" + "contextsubscribertime2.so"):
                        self.assert_(False, "Couldn't find the test time plugins")

                self.context_client = CLTool("context-listen", "Test.Time")
                self.context_client.expect("Available commands") # wait for it

                # Copy the declaration file, declaring libcontextsubscribertime1 plugin.
                os.system('cp time1.context.temp time.context.temp')
                os.system('mv time.context.temp time.context')
                #print "now reading"

                # Expect value coming from plugin libcontextsubscribertime1
                self.assert_(self.context_client.expect("Test.Time = QString:\"Time1:"))

                # Modify the registry so that the key is now provided by libcontextsubscribertime2
                os.system('cp time2.context.temp time.context.temp')
                os.system('mv time.context.temp time.context')

                # Expect value coming from plugin libcontextsubscribertime2
                self.assert_(self.context_client.expect("Test.Time = QString:\"Time2:"))
		self.context_client.wait()

if __name__ == "__main__":
        sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1)
        unittest.main()