VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/python/test/test_components.py@ 63668

最後變更 在這個檔案從63668是 11746,由 vboxsync 提交於 16 年 前

export python lib to OSE

  • 屬性 svn:eol-style 設為 native
檔案大小: 4.6 KB
 
1# ***** BEGIN LICENSE BLOCK *****
2# Version: MPL 1.1/GPL 2.0/LGPL 2.1
3#
4# The contents of this file are subject to the Mozilla Public License Version
5# 1.1 (the "License"); you may not use this file except in compliance with
6# the License. You may obtain a copy of the License at
7# http://www.mozilla.org/MPL/
8#
9# Software distributed under the License is distributed on an "AS IS" basis,
10# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11# for the specific language governing rights and limitations under the
12# License.
13#
14# The Original Code is the Python XPCOM language bindings.
15#
16# The Initial Developer of the Original Code is
17# ActiveState Tool Corp.
18# Portions created by the Initial Developer are Copyright (C) 2000, 2001
19# the Initial Developer. All Rights Reserved.
20#
21# Contributor(s):
22# Mark Hammond <[email protected]> (original author)
23#
24# Alternatively, the contents of this file may be used under the terms of
25# either the GNU General Public License Version 2 or later (the "GPL"), or
26# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27# in which case the provisions of the GPL or the LGPL are applicable instead
28# of those above. If you wish to allow use of your version of this file only
29# under the terms of either the GPL or the LGPL, and not to allow others to
30# use your version of this file under the terms of the MPL, indicate your
31# decision by deleting the provisions above and replace them with the notice
32# and other provisions required by the GPL or the LGPL. If you do not delete
33# the provisions above, a recipient may use your version of this file under
34# the terms of any one of the MPL, the GPL or the LGPL.
35#
36# ***** END LICENSE BLOCK *****
37
38"""Tests the "xpcom.components" object.
39"""
40
41import xpcom.components
42from pyxpcom_test_tools import suite_from_functions, testmain
43
44if not __debug__:
45 raise RuntimeError, "This test uses assert, so must be run in debug mode"
46
47def test_interfaces():
48 "Test the xpcom.components.interfaces object"
49
50 iid = xpcom.components.interfaces.nsISupports
51 assert iid == xpcom._xpcom.IID_nsISupports, "Got the wrong IID!"
52 iid = xpcom.components.interfaces['nsISupports']
53 assert iid == xpcom._xpcom.IID_nsISupports, "Got the wrong IID!"
54
55 # Test dictionary semantics
56 num_fetched = num_nsisupports = 0
57 for name, iid in xpcom.components.interfaces.items():
58 num_fetched = num_fetched + 1
59 if name == "nsISupports":
60 num_nsisupports = num_nsisupports + 1
61 assert iid == xpcom._xpcom.IID_nsISupports, "Got the wrong IID!"
62 assert xpcom.components.interfaces[name] == iid
63 # Check all the lengths match.
64 assert len(xpcom.components.interfaces.keys()) == len(xpcom.components.interfaces.values()) == \
65 len(xpcom.components.interfaces.items()) == len(xpcom.components.interfaces) == \
66 num_fetched, "The collection lengths were wrong"
67 assert num_nsisupports == 1, "Didnt find exactly 1 nsiSupports!"
68
69def test_classes():
70 # Need a well-known contractID here?
71 prog_id = "@mozilla.org/supports-array;1"
72 clsid = xpcom.components.ID("{bda17d50-0d6b-11d3-9331-00104ba0fd40}")
73
74 # Check we can create the instance (dont check we can do anything with it tho!)
75 klass = xpcom.components.classes[prog_id]
76 instance = klass.createInstance()
77
78 # Test dictionary semantics
79 num_fetched = num_mine = 0
80 for name, klass in xpcom.components.classes.items():
81 num_fetched = num_fetched + 1
82 if name == prog_id:
83 assert klass.clsid == clsid, "Eeek - didn't get the correct IID - got %s" %klass.clsid
84 num_mine = num_mine + 1
85
86# xpcom appears to add charset info to the contractid!?
87# assert xpcom.components.classes[name].contractid == prog_id, "Expected '%s', got '%s'" % (prog_id, xpcom.components.classes[name].contractid)
88 # Check all the lengths match.
89 if len(xpcom.components.classes.keys()) == len(xpcom.components.classes.values()) == \
90 len(xpcom.components.classes.items()) == len(xpcom.components.classes) == \
91 num_fetched:
92 pass
93 else:
94 raise RuntimeError, "The collection lengths were wrong"
95 if num_fetched <= 0:
96 raise RuntimeError, "Didnt get any classes!!!"
97 if num_mine != 1:
98 raise RuntimeError, "Didnt find exactly 1 of my contractid! (%d)" % (num_mine,)
99
100def test_id():
101 id = xpcom.components.ID(str(xpcom._xpcom.IID_nsISupports))
102 assert id == xpcom._xpcom.IID_nsISupports
103
104# Make this test run under our std test suite
105def suite():
106 return suite_from_functions(test_interfaces, test_classes, test_id)
107
108if __name__=='__main__':
109 testmain()
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette