Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / e4x / Statements / 12.1.js
1 /* -*- Mode: java; 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 Rhino code, released
17  * May 6, 1999.
18  *
19  * The Initial Developer of the Original Code is
20  * Netscape Communications Corporation.
21  * Portions created by the Initial Developer are Copyright (C) 1997-2000
22  * the Initial Developer. All Rights Reserved.
23  *
24  * Contributor(s):
25  *   Igor Bukanov
26  *   Ethan Hugg
27  *   Milen Nankov
28  *
29  * Alternatively, the contents of this file may be used under the terms of
30  * either the GNU General Public License Version 2 or later (the "GPL"), or
31  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32  * in which case the provisions of the GPL or the LGPL are applicable instead
33  * of those above. If you wish to allow use of your version of this file only
34  * under the terms of either the GPL or the LGPL, and not to allow others to
35  * use your version of this file under the terms of the MPL, indicate your
36  * decision by deleting the provisions above and replace them with the notice
37  * and other provisions required by the GPL or the LGPL. If you do not delete
38  * the provisions above, a recipient may use your version of this file under
39  * the terms of any one of the MPL, the GPL or the LGPL.
40  *
41  * ***** END LICENSE BLOCK ***** */
42
43
44 START("12.1 - Default XML Namespace");
45
46
47 // Declare some namespaces ad a default namespace for the current block
48 var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
49 var stock = new Namespace("http://mycompany.com/stocks");
50 default xml namespace = soap;
51
52 // Create an XML initializer in the default (i.e., soap) namespace
53 message =
54 <Envelope
55     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
56     soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
57     <Body>
58         <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
59             <stock:symbol>DIS</stock:symbol>
60         </stock:GetLastTradePrice>
61     </Body>
62 </Envelope>;
63
64 // Extract the soap encoding style using a QualifiedIdentifier
65 encodingStyle = message.@soap::encodingStyle;
66 TEST_XML(1, "http://schemas.xmlsoap.org/soap/encoding/", encodingStyle);
67
68 // Extract the body from the soap message using the default namespace
69 correct =
70 <Body
71     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
72     <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
73         <stock:symbol>DIS</stock:symbol>
74     </stock:GetLastTradePrice>
75 </Body>;
76
77 body = message.Body;
78 TEST_XML(2, correct.toXMLString(), body);
79
80 // Change the stock symbol using the default namespace and qualified names
81 correct =
82 <Envelope
83     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
84     soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
85     <Body>
86         <stock:GetLastTradePrice xmlns:stock="http://mycompany.com/stocks">
87             <stock:symbol>MYCO</stock:symbol>
88         </stock:GetLastTradePrice>
89     </Body>
90 </Envelope>;
91
92 message.Body.stock::GetLastTradePrice.stock::symbol = "MYCO";
93
94 TEST(3, correct, message);
95
96 function scopeTest()
97 {
98     var x = <a/>;
99     TEST(4, soap.uri, x.namespace().uri);
100
101     default xml namespace = "http://" + "someuri.org";
102     x = <a/>;
103     TEST(5, "http://someuri.org", x.namespace().uri);
104 }
105
106 scopeTest();
107
108 x = <a><b><c xmlns="">foo</c></b></a>;
109 TEST(6, soap.uri, x.namespace().uri);
110 TEST(7, soap.uri, x.b.namespace().uri);
111
112 ns = new Namespace("");
113 TEST(8, "foo", x.b.ns::c.toString());
114
115 x = <a foo="bar"/>;
116 TEST(9, soap.uri, x.namespace().uri);
117 TEST(10, "", x.@foo.namespace().uri);
118 TEST_XML(11, "bar", x.@foo);
119
120 default xml namespace = "";
121 x = <x/>;
122 ns = new Namespace("http://someuri");
123 default xml namespace = ns;
124 x.a = "foo";
125 TEST(12, "foo", x["a"].toString());
126 q = new QName("a");
127 TEST(13, "foo", x[q].toString());
128
129 default xml namespace = "";
130 x[q] = "bar";
131 TEST(14, "bar", x.ns::a.toString());
132
133 END();