Debian Codegraph @

rhino/testsrc/tests/lc3/JSNumber/ToChar-004.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'ToChar-004.js';
7
8 /* -*- Mode: java; tab-width: 8 -*-
9 * Copyright (C) 1997, 1998 Netscape Communications Corporation,
10 * All Rights Reserved.
11 */
12
13 /**
14 * JavaScript to Java type conversion.
15 *
16 * This test passes JavaScript number values to several Java methods
17 * that expect arguments of various types, and verifies that the value is
18 * converted to the correct value and type.
19 *
20 * This tests instance methods, and not static methods.
21 *
22 * Running these tests successfully requires you to have
23 * com.netscape.javascript.qa.liveconnect.DataTypeClass on your classpath.
24 *
25 * Specification: Method Overloading Proposal for Liveconnect 3.0
26 *
27 * @author: [email protected]
28 *
29 */
30 var SECTION = "number conversion to char";
31 var VERSION = "1_4";
32 var TITLE = "LiveConnect 3.0 JavaScript to Java Data Type Conversion " +
33 SECTION;
34 startTest();
35
36 var dt = new DT();
37
38 var a = new Array();
39 var i = 0;
40
41 // passing a JS number to a method that expects a char:
42 // round JS number to integral value using round-to-negative-infinity mode
43 // numbers with a magnitude too large to be represented in the target integral
44 // type result in a runtime error.
45 // Nan converts to 0.
46
47 // Special cases: 0, -0, Infinity, -Infinity, and NaN
48
49 a[i++] = new TestObject(
50 "dt.setChar(java.lang.Character.MAX_VALUE - 0.5)",
51 "dt.PUB_CHAR",
52 "dt.getChar()",
53 "typeof dt.getChar()",
54 java.lang.Character.MAX_VALUE - 1,
55 "number" );
56
57 a[i++] = new TestObject(
58 "dt.setChar(java.lang.Character.MAX_VALUE - 0.5)",
59 "dt.PUB_CHAR",
60 "dt.getChar()",
61 "typeof dt.getChar()",
62 java.lang.Character.MAX_VALUE - 1,
63 "number" );
64
65 a[i++] = new TestObject(
66 "dt.setChar(java.lang.Character.MAX_VALUE - 0.4)",
67 "dt.PUB_CHAR",
68 "dt.getChar()",
69 "typeof dt.getChar()",
70 java.lang.Character.MAX_VALUE - 1,
71 "number" );
72
73 a[i++] = new TestObject(
74 "dt.setChar(java.lang.Character.MIN_VALUE + 0.6)",
75 "dt.PUB_CHAR",
76 "dt.getChar()",
77 "typeof dt.getChar()",
78 java.lang.Character.MIN_VALUE,
79 "number" );
80
81 a[i++] = new TestObject(
82 "dt.setChar(java.lang.Character.MIN_VALUE + 0.4)",
83 "dt.PUB_CHAR",
84 "dt.getChar()",
85 "typeof dt.getChar()",
86 java.lang.Character.MIN_VALUE,
87 "number" );
88 a[i++] = new TestObject(
89 "dt.setChar(java.lang.Character.MIN_VALUE + 0.6)",
90 "dt.PUB_CHAR",
91 "dt.getChar()",
92 "typeof dt.getChar()",
93 java.lang.Character.MIN_VALUE,
94 "number" );
95
96 for ( i = 0; i < a.length; i++ ) {
97 new TestCase(
98 a[i].description +"; "+ a[i].javaFieldName,
99 a[i].jsValue,
100 a[i].javaFieldValue );
101
102 new TestCase(
103 a[i].description +"; " + a[i].javaMethodName,
104 a[i].jsValue,
105 a[i].javaMethodValue );
106
107 new TestCase(
108 a[i].javaTypeName,
109 a[i].jsType,
110 a[i].javaTypeValue );
111 }
112
113 test();
114
115 function TestObject( description, javaField, javaMethod, javaType,
116 jsValue, jsType )
117 {
118 eval (description );
119
120 this.description = description;
121 this.javaFieldName = javaField;
122 this.javaFieldValue = eval( javaField );
123 this.javaMethodName = javaMethod;
124 this.javaMethodValue = eval( javaMethod );
125 this.javaTypeName = javaType,
126 this.javaTypeValue = eval( javaType );
127
128 this.jsValue = jsValue;
129 this.jsType = jsType;
130 }