~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/js/src/xpconnect/tests/js/multiple-2.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
5
 *
 
6
 * The contents of this file are subject to the Mozilla Public License Version
 
7
 * 1.1 (the "License"); you may not use this file except in compliance with
 
8
 * the License. You may obtain a copy of the License at
 
9
 * http://www.mozilla.org/MPL/
 
10
 *
 
11
 * Software distributed under the License is distributed on an "AS IS" basis,
 
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
13
 * for the specific language governing rights and limitations under the
 
14
 * License.
 
15
 *
 
16
 * The Original Code is Mozilla Communicator client code, released
 
17
 * March 31, 1998.
 
18
 *
 
19
 * The Initial Developer of the Original Code is
 
20
 * Netscape Communications Corporation.
 
21
 * Portions created by the Initial Developer are Copyright (C) 1998
 
22
 * the Initial Developer. All Rights Reserved.
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
26
 * Alternatively, the contents of this file may be used under the terms of
 
27
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 
28
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
30
 * of those above. If you wish to allow use of your version of this file only
 
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
32
 * use your version of this file under the terms of the MPL, indicate your
 
33
 * decision by deleting the provisions above and replace them with the notice
 
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
35
 * the provisions above, a recipient may use your version of this file under
 
36
 * the terms of any one of the MPL, the GPL or the LGPL.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
/**
 
41
 * Test classes that inherit from multiple interfaces.  This differs
 
42
 * from classes that inherit from interfaces other than nsISupports,
 
43
 * in that you can't have an object with all the 
 
44
 *
 
45
 *  See xpctest_multiple.idl and xpctest_multiple.cpp.
 
46
 */
 
47
 
 
48
StartTest( "Classes that inherit from multiple interfaces" );
 
49
SetupTest();
 
50
AddTestData();
 
51
StopTest();
 
52
 
 
53
function SetupTest() {
 
54
try {           
 
55
        // xpcTestChild2 inherits from nsIXPCTestChild2 nsIXPCTestParentOne, 
 
56
        // and nsIXPCTestParentTwo but implements all the interfaces itself
 
57
 
 
58
        iChild = Components.interfaces.nsIXPCTestChild2;
 
59
        iParentOne = Components.interfaces.nsIXPCTestParentOne;
 
60
        iParentTwo = Components.interfaces.nsIXPCTestParentTwo;
 
61
 
 
62
 
 
63
        CONTRACTID = "@mozilla.org/js/xpc/test/Child2;1";
 
64
        cChild = Components.classes[CONTRACTID].createInstance();
 
65
        CONTRACTID = "@mozilla.org/js/xpc/test/ParentOne;1";
 
66
        cParentOne = Components.classes[CONTRACTID].createInstance();
 
67
        CONTRACTID = "@mozilla.org/js/xpc/test/ParentTwo;1";
 
68
        cParentTwo = Components.classes[CONTRACTID].createInstance();
 
69
 
 
70
        c_c2 = cChild.QueryInterface(iChild);
 
71
        c_p1 = cChild.QueryInterface(iParentOne);
 
72
        c_p2 = cChild.QueryInterface(iParentTwo);
 
73
 
 
74
        parentOne = cParentOne.QueryInterface(iParentOne);
 
75
        parentTwo = cParentTwo.QueryInterface(iParentTwo);
 
76
 
 
77
} catch (e) {
 
78
        WriteLine(e);
 
79
        AddTestCase(
 
80
                "Setting up the test",
 
81
                "PASSED",
 
82
                "FAILED: " + e.message  +" "+ e.location +". ");
 
83
}
 
84
}
 
85
 
 
86
function AddTestData() {
 
87
        Check( cChild,    "@mozilla.org/js/xpc/test/Child2;1", c_c2);
 
88
        Check( parentOne, "@mozilla.org/js/xpc/test/Child2;1", c_p1);
 
89
        Check( parentTwo, "@mozilla.org/js/xpc/test/Child2;1", c_p2);
 
90
}
 
91
 
 
92
function Check( parent, parentName, child) {
 
93
        // child should have all the properties and methods of parentOne
 
94
 
 
95
        parentProps = {};
 
96
        for ( p in parent ) parentProps[p] = true;
 
97
        for ( p in child ) if ( parentProps[p] ) parentProps[p] = false;
 
98
 
 
99
        for ( p in parentProps ) {
 
100
                AddTestCase(
 
101
                        "child has property " + p,
 
102
                        true,
 
103
                        (parentProps[p] ? false : true ) 
 
104
                );
 
105
 
 
106
                if ( p.match(/Method/) ) {
 
107
                        AddTestCase(
 
108
                                "child."+p+"()",
 
109
                                parentName +" method",
 
110
                                child[p]() );
 
111
 
 
112
                } else if (p.match(/Attribute/)) {
 
113
                        AddTestCase(
 
114
                                "child." +p,
 
115
                                parentName+" attribute",
 
116
                                child[p] );
 
117
                }
 
118
        }
 
119
 
 
120
        var result = true;
 
121
        for ( p in parentProps ) {
 
122
                if ( parentProps[p] == true )
 
123
                        result == false;
 
124
        }
 
125
 
 
126
        AddTestCase(
 
127
                "child has all parent properties?",
 
128
                true,
 
129
                result );
 
130
 
 
131
        for ( p in child ) {
 
132
                AddTestCase(
 
133
                        "child has property " + p,
 
134
                        true,
 
135
                        (child[p] ? true : false ) 
 
136
                );
 
137
 
 
138
                if ( p.match(/Method/) ) {
 
139
                        AddTestCase(
 
140
                                "child."+p+"()",
 
141
                                parentName +" method",
 
142
                                child[p]() );
 
143
 
 
144
                } else if (p.match(/Attribute/)) {
 
145
                        AddTestCase(
 
146
                                "child." +p,
 
147
                                parentName +" attribute",
 
148
                                child[p] );
 
149
                }
 
150
        }               
 
151
}