Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 22495:aeba89e1d8da
Add ComplexNumber sequence tests
author | Matthias Grimmer <grimmer@ssw.jku.at> |
---|---|
date | Fri, 11 Dec 2015 15:20:27 +0100 |
parents | fa7b15454c66 |
children | b3569a53c24c |
rev | line source |
---|---|
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1 /* |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
4 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
10 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
16 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
20 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
23 * questions. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
24 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.tck; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
26 |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
27 import static org.junit.Assert.assertEquals; |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
28 import static org.junit.Assert.assertNotNull; |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
29 import static org.junit.Assert.assertNotSame; |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
30 import static org.junit.Assert.assertNull; |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
31 import static org.junit.Assert.assertSame; |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
32 import static org.junit.Assert.assertTrue; |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
33 import static org.junit.Assert.fail; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
34 |
22495
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
35 import java.io.IOException; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
36 import java.lang.reflect.Field; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
37 import java.nio.ByteBuffer; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
38 import java.util.Arrays; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
39 import java.util.Random; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
40 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
41 import org.junit.Assert; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
42 import org.junit.Test; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
43 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
44 import com.oracle.truffle.api.TruffleLanguage; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
45 import com.oracle.truffle.api.interop.TruffleObject; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
46 import com.oracle.truffle.api.interop.java.JavaInterop; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
47 import com.oracle.truffle.api.source.Source; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
48 import com.oracle.truffle.api.vm.PolyglotEngine; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
49 import com.oracle.truffle.api.vm.PolyglotEngine.Language; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
50 import com.oracle.truffle.tck.Schema.Type; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
51 |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
52 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
53 * A collection of tests that can certify language implementation to be compliant with most recent |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
54 * requirements of the Truffle infrastructure and tooling. Subclass, implement abstract methods and |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
55 * include in your test suite. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
56 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
57 public abstract class TruffleTCK { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
58 private static final Random RANDOM = new Random(); |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
59 private PolyglotEngine tckVM; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
60 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
61 protected TruffleTCK() { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
62 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
63 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
64 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
65 * This methods is called before first test is executed. It's purpose is to set a |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
66 * {@link PolyglotEngine} with your language up, so it is ready for testing. |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
67 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source) Execute} any scripts you |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
68 * need, and prepare global symbols with proper names. The symbols will then be looked up by the |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
69 * infrastructure (using the names provided by you from methods like {@link #plusInt()}) and |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
70 * used for internal testing. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
71 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
72 * @return initialized Truffle virtual machine |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
73 * @throws java.lang.Exception thrown when the VM preparation fails |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
74 */ |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
75 protected abstract PolyglotEngine prepareVM() throws Exception; |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
76 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
77 /** |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
78 * MIME type associated with your language. The MIME type will be passed to |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
79 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source)} method of the |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
80 * {@link #prepareVM() created engine}. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
81 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
82 * @return mime type of the tested language |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
83 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
84 protected abstract String mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
85 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
86 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
87 * Name of function which will return value 42 as a number. The return value of the method |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
88 * should be instance of {@link Number} and its {@link Number#intValue()} should return |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
89 * <code>42</code>. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
90 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
91 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
92 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
93 protected abstract String fourtyTwo(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
94 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
95 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
96 * Name of a function that returns <code>null</code>. Truffle languages are encouraged to have |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
97 * their own type representing <code>null</code>, but when such value is returned from |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
98 * {@link PolyglotEngine#eval}, it needs to be converted to real Java <code>null</code> by |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
99 * sending a foreign access <em>isNull</em> message. There is a test to verify it is really |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
100 * true. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
101 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
102 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
103 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
104 protected abstract String returnsNull(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
105 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
106 /** |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
107 * Name of function to add two integer values together. The symbol will be invoked with two |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
108 * parameters of type {@link Integer} and expects result of type {@link Number} which's |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
109 * {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
110 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
111 * @return name of globally exported symbol |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
112 */ |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
113 protected String plusInt() { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
114 throw new UnsupportedOperationException("Override plus(Class,Class) method!"); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
115 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
116 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
117 /** |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
118 * Name of function to add two numbers together. The symbol will be invoked with two parameters |
22437 | 119 * of <code>type1</code> and <code>type2</code> and expects result of type {@link Number} |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
120 * which's {@link Number#intValue()} is equivalent of <code>param1 + param2</code>. As some |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
121 * languages may have different operations for different types of numbers, the actual types are |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
122 * passed to the method and the implementation can decide to return different symbol based on |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
123 * the parameters. |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
124 * |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
125 * @param type1 one of byte, short, int, long, float, double class |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
126 * @param type2 one of byte, short, int, long, float, double class |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
127 * @return name of globally exported symbol |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
128 */ |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
129 protected String plus(Class<?> type1, Class<?> type2) { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
130 return plusInt(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
131 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
132 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
133 /** |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
134 * Name of a function in your language to perform a callback to foreign function. Your function |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
135 * should prepare two numbers (18 and 32) and apply them to the function passed in as an |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
136 * argument of your function. It should then add 10 to the returned value and return the result |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
137 * back to its caller. |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
138 * |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
139 * @return name of globally exported symbol |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
140 */ |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
141 protected abstract String applyNumbers(); |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
142 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
143 /** |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
144 * Name of identity function. The identity function accepts one argument and returns it. The |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
145 * argument should go through without any modification, e.g. the input should result in |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
146 * identical output. |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
147 * |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
148 * @return name of globally exported symbol |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
149 */ |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
150 protected String identity() { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
151 throw new UnsupportedOperationException("identity() method not implemented"); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
152 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
153 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
154 /** |
22488
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
155 * Name of a function that adds up two complex numbers. The function accepts two arguments and |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
156 * provides no return value. The arguments are complex numbers with members called real and |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
157 * imaginary. The first argument contains the result of the addition. |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
158 * |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
159 * @return name of globally exported symbol |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
160 */ |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
161 protected String complexAdd() { |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
162 throw new UnsupportedOperationException("complexAdd() method not implemented"); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
163 } |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
164 |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
165 /** |
22495
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
166 * Name of a function that adds up the real part of complex numbers. The function accepts one |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
167 * argument and provides the sum of all real parts. The argument is an array/buffer of complex |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
168 * numbers. |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
169 * |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
170 * @return name of globally exported symbol |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
171 */ |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
172 protected String complexSumReal() { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
173 throw new UnsupportedOperationException("complexSumReal() method not implemented"); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
174 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
175 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
176 /** |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
177 * Name of a function that copies a list of complex numbers. The function accepts two arguments |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
178 * and provides no return value. The arguments are two lists of complex numbers with members |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
179 * called real and imaginary. The first argument is the destination, the second argument is the |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
180 * source. |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
181 * |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
182 * @return name of globally exported symbol |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
183 */ |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
184 protected String complexCopy() { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
185 throw new UnsupportedOperationException("complexCopy() method not implemented"); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
186 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
187 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
188 /** |
22278
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
189 * Name of a function to return global object. The function can be executed without providing |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
190 * any arguments and should return global object of the language, if the language supports it. |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
191 * Global object is the one accessible via |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
192 * {@link TruffleLanguage#getLanguageGlobal(java.lang.Object)}. |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
193 * |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
194 * @return name of globally exported symbol, return <code>null</code> if the language doesn't |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
195 * support the concept of global object |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
196 */ |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
197 protected String globalObject() { |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
198 throw new UnsupportedOperationException("globalObject() method not implemented"); |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
199 } |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
200 |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
201 /** |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
202 * Name of a function to parse source written in some other language. When the function is |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
203 * executed, it expects two arguments. First one is MIME type identifying |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
204 * {@link TruffleLanguage} and the second one is the source code to parse in that language and |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
205 * execute it. The result of the execution is then returned back to the caller. |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
206 * |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
207 * @return name of globally exported symbol to invoke when one wants to execute some code |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
208 */ |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
209 protected String evaluateSource() { |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
210 throw new UnsupportedOperationException("evaluateSource() method not implemented"); |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
211 } |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
212 |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
213 /** |
22382
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
214 * Code snippet to multiplyCode two two variables. The test uses the snippet as a parameter to |
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
215 * your language's |
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
216 * {@link TruffleLanguage#parse(com.oracle.truffle.api.source.Source, com.oracle.truffle.api.nodes.Node, java.lang.String...)} |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
217 * method. |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
218 * |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
219 * @param firstName name of the first variable to multiplyCode |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
220 * @param secondName name of the second variable to multiplyCode |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
221 * @return code snippet that multiplies the two variables in your language |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
222 */ |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
223 protected String multiplyCode(String firstName, String secondName) { |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
224 throw new UnsupportedOperationException("multiply(String,String) method not implemeted!"); |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
225 } |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
226 |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
227 /** |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
228 * Name of a function that counts number of its invocations in current {@link PolyglotEngine} |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
229 * context. Your function should somehow keep a counter to remember number of its invocations |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
230 * and always increment it. The first invocation should return <code>1</code>, the second |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
231 * <code>2</code> and so on. The returned values are expected to be instances of {@link Number}. |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
232 * <p> |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
233 * The function will be used to test that two instances of your language can co-exist next to |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
234 * each other. Without being mutually influenced. |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
235 * |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
236 * @return name of globally expected symbol |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
237 */ |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
238 protected abstract String countInvocations(); |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
239 |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
240 /** |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
241 * Return a code snippet that is invalid in your language. Its |
22172
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
242 * {@link PolyglotEngine#eval(com.oracle.truffle.api.source.Source) evaluation} should fail and |
b31dcacfc8ff
Replacing more TruffleVM references in comments with the new PolyglotEngine name
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22170
diff
changeset
|
243 * yield an exception. |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
244 * |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
245 * @return code snippet invalid in the tested language |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
246 */ |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
247 protected abstract String invalidCode(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
248 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
249 /** |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
250 * Name of a function that returns a compound object with members representing certain |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
251 * operations. In the JavaScript the object should look like: |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
252 * |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
253 * <pre> |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
254 * <b>var</b> obj = { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
255 * 'fourtyTwo': function {@link #fourtyTwo()}, |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
256 * 'plus': function {@link #plusInt()}, |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
257 * 'returnsNull': function {@link #returnsNull()}, |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
258 * 'returnsThis': function() { return obj; } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
259 * }; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
260 * <b>return</b> obj; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
261 * </pre> |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
262 * |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
263 * The returned object shall have three functions that will be obtained and used exactly as |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
264 * described in their Javadoc - e.g. {@link #fourtyTwo()}, {@link #plusInt()} and |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
265 * {@link #returnsNull()}. In addition to that there should be one more function |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
266 * <b>returnsThis</b> that will return the object itself again. |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
267 * |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
268 * @return name of a function that returns such compound object |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
269 */ |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
270 protected String compoundObject() { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
271 throw new UnsupportedOperationException("compoundObject() method not implemented"); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
272 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
273 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
274 private PolyglotEngine vm() throws Exception { |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
275 if (tckVM == null) { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
276 tckVM = prepareVM(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
277 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
278 return tckVM; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
279 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
280 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
281 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
282 // The tests |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
283 // |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
284 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
285 @Test |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
286 public void testFortyTwo() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
287 PolyglotEngine.Value fourtyTwo = findGlobalSymbol(fourtyTwo()); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
288 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
289 Object res = fourtyTwo.execute().get(); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
290 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
291 assert res instanceof Number : "should yield a number, but was: " + res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
292 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
293 Number n = (Number) res; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
294 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
295 assert 42 == n.intValue() : "The value is 42 = " + n.intValue(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
296 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
297 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
298 @Test |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
299 public void testFortyTwoWithCompoundObject() throws Exception { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
300 CompoundObject obj = findCompoundSymbol(); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
301 if (obj == null) { |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
302 return; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
303 } |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
304 Number res = obj.fourtyTwo(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
305 assertEquals("Should be 42", 42, res.intValue()); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
306 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
307 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
308 @Test |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
309 public void testNull() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
310 PolyglotEngine.Value retNull = findGlobalSymbol(returnsNull()); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
311 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
312 Object res = retNull.execute().get(); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
313 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
314 assertNull("Should yield real Java null", res); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
315 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
316 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
317 @Test |
22279
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
318 public void testNullCanBeCastToAnything() throws Exception { |
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
319 PolyglotEngine.Value retNull = findGlobalSymbol(returnsNull()); |
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
320 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
321 Object res = retNull.execute().as(CompoundObject.class); |
22279
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
322 |
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
323 assertNull("Should yield real Java null", res); |
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
324 } |
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
325 |
0fc995134ff3
asJavaObject can work with null value
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22278
diff
changeset
|
326 @Test |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
327 public void testNullInCompoundObject() throws Exception { |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
328 CompoundObject obj = findCompoundSymbol(); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
329 if (obj == null) { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
330 return; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
331 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
332 Object res = obj.returnsNull(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
333 assertNull("Should yield real Java null", res); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
334 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
335 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
336 @Test |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
337 public void testPlusWithInts() throws Exception { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
338 int a = RANDOM.nextInt(100); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
339 int b = RANDOM.nextInt(100); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
340 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
341 PolyglotEngine.Value plus = findGlobalSymbol(plus(int.class, int.class)); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
342 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
343 Number n = plus.execute(a, b).as(Number.class); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
344 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
345 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
346 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
347 @Test |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
348 public void testPlusWithBytes() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
349 int a = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
350 int b = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
351 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
352 PolyglotEngine.Value plus = findGlobalSymbol(plus(byte.class, byte.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
353 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
354 Number n = plus.execute((byte) a, (byte) b).as(Number.class); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
355 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
356 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
357 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
358 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
359 public void testPlusWithShort() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
360 int a = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
361 int b = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
362 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
363 PolyglotEngine.Value plus = findGlobalSymbol(plus(short.class, short.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
364 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
365 Number n = plus.execute((short) a, (short) b).as(Number.class); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
366 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
367 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
368 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
369 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
370 public void testPlusWithLong() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
371 long a = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
372 long b = RANDOM.nextInt(100); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
373 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
374 PolyglotEngine.Value plus = findGlobalSymbol(plus(long.class, long.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
375 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
376 Number n = plus.execute(a, b).as(Number.class); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
377 assert a + b == n.longValue() : "The value is correct: (" + a + " + " + b + ") = " + n.longValue(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
378 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
379 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
380 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
381 public void testPlusWithFloat() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
382 float a = RANDOM.nextFloat(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
383 float b = RANDOM.nextFloat(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
384 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
385 PolyglotEngine.Value plus = findGlobalSymbol(plus(float.class, float.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
386 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
387 Number n = plus.execute(a, b).as(Number.class); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
388 assertEquals("Correct value computed", a + b, n.floatValue(), 0.01f); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
389 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
390 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
391 @Test |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
392 public void testPlusWithDouble() throws Exception { |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
393 double a = RANDOM.nextDouble(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
394 double b = RANDOM.nextDouble(); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
395 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
396 PolyglotEngine.Value plus = findGlobalSymbol(plus(float.class, float.class)); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
397 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
398 Number n = plus.execute(a, b).as(Number.class); |
22138
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
399 assertEquals("Correct value computed", a + b, n.doubleValue(), 0.01); |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
400 } |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
401 |
a583d7ffd285
Enhancing TCK to pass in all Java number types and see whether they result in something meaningful.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22135
diff
changeset
|
402 @Test |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
403 public void testPlusWithIntsOnCompoundObject() throws Exception { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
404 int a = RANDOM.nextInt(100); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
405 int b = RANDOM.nextInt(100); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
406 |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
407 CompoundObject obj = findCompoundSymbol(); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
408 if (obj == null) { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
409 return; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
410 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
411 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
412 Number n = obj.plus(a, b); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
413 assert a + b == n.intValue() : "The value is correct: (" + a + " + " + b + ") = " + n.intValue(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
414 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
415 |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
416 @Test(expected = IOException.class) |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
417 public void testInvalidTestMethod() throws Exception { |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
418 String mime = mimeType(); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
419 String code = invalidCode(); |
22121
d045a505c2b3
Asynchronous TruffleVM can be created by providing own Executor when configuring the TruffleVM.Builder
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22104
diff
changeset
|
420 Object ret = vm().eval(Source.fromText(code, "Invalid code").withMimeType(mime)).get(); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
421 fail("Should yield IOException, but returned " + ret); |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
422 } |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
423 |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
424 @Test |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
425 public void testMaxOrMinValue() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
426 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
427 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
428 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
429 Object res = apply.execute(fn).get(); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
430 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
431 assert res instanceof Number : "result should be a number: " + res; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
432 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
433 Number n = (Number) res; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
434 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
435 assert 42 == n.intValue() : "32 > 18 and plus 10"; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
436 } |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
437 |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
438 @Test |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
439 public void testMaxOrMinValue2() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
440 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
441 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
442 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(false)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
443 final PolyglotEngine.Value result = apply.execute(fn); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
444 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
445 try { |
22284
33d49924a921
PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22279
diff
changeset
|
446 Boolean res = result.as(Boolean.class); |
33d49924a921
PolyglotEngine.Value.as(String.class) gives the language that produced the value a chance to do its conversion to appropriate textual representation.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22279
diff
changeset
|
447 fail("Cannot be converted to Boolean: " + res); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
448 } catch (ClassCastException ex) { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
449 // correct |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
450 } |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
451 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
452 Number n = result.as(Number.class); |
21960
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
453 assert 28 == n.intValue() : "18 < 32 and plus 10"; |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
454 } |
a88981c5ce8b
Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
455 |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
456 @Test |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
457 public void testPrimitiveReturnTypeByte() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
458 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
459 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
460 byte value = (byte) RANDOM.nextInt(100); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
461 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
462 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
463 Number n = apply.execute(fn).as(Number.class); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
464 assertEquals("The same value returned", value + 10, n.byteValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
465 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
466 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
467 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
468 public void testPrimitiveReturnTypeShort() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
469 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
470 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
471 short value = (short) RANDOM.nextInt(100); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
472 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
473 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
474 Number n = apply.execute(fn).as(Number.class); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
475 assertEquals("The same value returned", value + 10, n.shortValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
476 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
477 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
478 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
479 public void testPrimitiveReturnTypeInt() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
480 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
481 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
482 int value = RANDOM.nextInt(100); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
483 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
484 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
485 Number n = apply.execute(fn).as(Number.class); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
486 assertEquals("The same value returned", value + 10, n.intValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
487 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
488 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
489 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
490 public void testPrimitiveReturnTypeLong() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
491 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
492 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
493 long value = RANDOM.nextInt(1000); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
494 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
495 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
496 Number n = apply.execute(fn).as(Number.class); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
497 assertEquals("The same value returned", value + 10, n.longValue()); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
498 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
499 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
500 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
501 public void testPrimitiveReturnTypeFloat() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
502 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
503 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
504 float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
505 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
506 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
507 Number n = apply.execute(fn).as(Number.class); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
508 assertEquals("The same value returned", value + 10, n.floatValue(), 0.01); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
509 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
510 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
511 @Test |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
512 public void testPrimitiveReturnTypeDouble() throws Exception { |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
513 PolyglotEngine.Value apply = findGlobalSymbol(applyNumbers()); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
514 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
515 double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
516 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
517 TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
518 Number n = apply.execute(fn).as(Number.class); |
22139
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
519 assertEquals("The same value returned", value + 10, n.doubleValue(), 0.01); |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
520 } |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
521 |
597953a8e6f0
Testing behavior of primitive types returned from an interop method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22138
diff
changeset
|
522 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
523 public void testPrimitiveidentityByte() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
524 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
525 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
526 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
527 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
528 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
529 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
530 byte value = (byte) RANDOM.nextInt(100); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
531 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
532 Number n = (Number) apply.execute(value).get(); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
533 assertEquals("The same value returned", value, n.byteValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
534 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
535 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
536 @Test |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
537 public void testPrimitiveidentityBoxedByte() throws Exception { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
538 String id = identity(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
539 if (id == null) { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
540 return; |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
541 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
542 PolyglotEngine.Value apply = findGlobalSymbol(id); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
543 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
544 byte value = (byte) RANDOM.nextInt(100); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
545 BoxedValue boxed = new BoxedValue(value); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
546 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
547 Number n = (Number) apply.execute(boxed).get(); |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
548 assertEquals("The same value returned", value, n.byteValue()); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
549 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
550 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
551 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
552 public void testPrimitiveidentityShort() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
553 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
554 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
555 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
556 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
557 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
558 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
559 short value = (short) RANDOM.nextInt(100); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
560 Number n = (Number) apply.execute(value).get(); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
561 assertEquals("The same value returned", value, n.shortValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
562 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
563 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
564 @Test |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
565 public void testPrimitiveidentityBoxedShort() throws Exception { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
566 String id = identity(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
567 if (id == null) { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
568 return; |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
569 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
570 PolyglotEngine.Value apply = findGlobalSymbol(id); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
571 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
572 short value = (short) RANDOM.nextInt(100); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
573 BoxedValue boxed = new BoxedValue(value); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
574 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
575 Number n = (Number) apply.execute(boxed).get(); |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
576 assertEquals("The same value returned", value, n.shortValue()); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
577 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
578 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
579 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
580 public void testPrimitiveidentityInt() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
581 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
582 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
583 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
584 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
585 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
586 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
587 int value = RANDOM.nextInt(100); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
588 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
589 Number n = (Number) apply.execute(value).get(); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
590 assertEquals("The same value returned", value, n.intValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
591 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
592 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
593 @Test |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
594 public void testPrimitiveidentityBoxedInt() throws Exception { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
595 String id = identity(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
596 if (id == null) { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
597 return; |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
598 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
599 PolyglotEngine.Value apply = findGlobalSymbol(id); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
600 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
601 int value = RANDOM.nextInt(100); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
602 BoxedValue boxed = new BoxedValue(value); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
603 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
604 Number n = (Number) apply.execute(boxed).get(); |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
605 assertEquals("The same value returned", value, n.intValue()); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
606 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
607 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
608 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
609 public void testPrimitiveidentityLong() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
610 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
611 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
612 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
613 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
614 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
615 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
616 long value = RANDOM.nextInt(1000); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
617 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
618 Number n = (Number) apply.execute(value).get(); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
619 assertEquals("The same value returned", value, n.longValue()); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
620 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
621 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
622 @Test |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
623 public void testPrimitiveidentityBoxedLong() throws Exception { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
624 String id = identity(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
625 if (id == null) { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
626 return; |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
627 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
628 PolyglotEngine.Value apply = findGlobalSymbol(id); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
629 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
630 long value = RANDOM.nextInt(1000); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
631 BoxedValue boxed = new BoxedValue(value); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
632 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
633 Number n = (Number) apply.execute(boxed).get(); |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
634 assertEquals("The same value returned", value, n.longValue()); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
635 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
636 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
637 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
638 public void testPrimitiveidentityFloat() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
639 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
640 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
641 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
642 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
643 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
644 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
645 float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
646 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
647 Number n = (Number) apply.execute(value).get(); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
648 assertEquals("The same value returned", value, n.floatValue(), 0.01); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
649 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
650 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
651 @Test |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
652 public void testPrimitiveidentityBoxedFloat() throws Exception { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
653 String id = identity(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
654 if (id == null) { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
655 return; |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
656 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
657 PolyglotEngine.Value apply = findGlobalSymbol(id); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
658 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
659 float value = RANDOM.nextInt(1000) + RANDOM.nextFloat(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
660 BoxedValue boxed = new BoxedValue(value); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
661 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
662 Number n = (Number) apply.execute(boxed).get(); |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
663 assertEquals("The same value returned", value, n.floatValue(), 0.01); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
664 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
665 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
666 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
667 public void testPrimitiveidentityDouble() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
668 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
669 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
670 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
671 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
672 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
673 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
674 double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
675 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
676 Number n = (Number) apply.execute(value).get(); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
677 assertEquals("The same value returned", value, n.doubleValue(), 0.01); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
678 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
679 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
680 @Test |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
681 public void testPrimitiveidentityBoxedDouble() throws Exception { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
682 String id = identity(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
683 if (id == null) { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
684 return; |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
685 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
686 PolyglotEngine.Value apply = findGlobalSymbol(id); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
687 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
688 double value = RANDOM.nextInt(1000) + RANDOM.nextDouble(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
689 BoxedValue boxed = new BoxedValue(value); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
690 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
691 Number n = (Number) apply.execute(boxed).get(); |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
692 assertEquals("The same value returned", value, n.doubleValue(), 0.01); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
693 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
694 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
695 @Test |
22422
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
696 public void testPrimitiveidentityString() throws Exception { |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
697 String id = identity(); |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
698 if (id == null) { |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
699 return; |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
700 } |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
701 PolyglotEngine.Value apply = findGlobalSymbol(id); |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
702 |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
703 String value = "Value" + RANDOM.nextInt(1000) + RANDOM.nextDouble(); |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
704 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
705 String ret = (String) apply.execute(value).get(); |
22422
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
706 assertEquals("The same value returned", value, ret); |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
707 } |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
708 |
30644770899d
Testing identity behavior for String values
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22382
diff
changeset
|
709 @Test |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
710 public void testPrimitiveidentityBoxedString() throws Exception { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
711 String id = identity(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
712 if (id == null) { |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
713 return; |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
714 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
715 PolyglotEngine.Value apply = findGlobalSymbol(id); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
716 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
717 String value = "Value" + RANDOM.nextInt(1000) + RANDOM.nextDouble(); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
718 BoxedValue boxed = new BoxedValue(value); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
719 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
720 String ret = (String) apply.execute(boxed).get(); |
22423
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
721 assertEquals("The same value returned", value, ret); |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
722 } |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
723 |
70a10a9f28ad
Verify that primitive data (numbers as well as String) can be passed into a language as boxed TruffleObject instances
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22422
diff
changeset
|
724 @Test |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
725 public void testPrimitiveIdentityForeignObject() throws Exception { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
726 String id = identity(); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
727 if (id == null) { |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
728 return; |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
729 } |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
730 PolyglotEngine.Value apply = findGlobalSymbol(id); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
731 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
732 TruffleObject fn = JavaInterop.asTruffleFunction(LongBinaryOperation.class, new MaxMinObject(true)); |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
733 |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
734 Object ret = apply.execute(fn).get(); |
22200
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
735 assertSameTruffleObject("The same value returned", fn, ret); |
22140
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
736 } |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
737 |
92906003d607
Adding check of behavior of identity function into the TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22139
diff
changeset
|
738 @Test |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
739 public void testCoExistanceOfMultipleLanguageInstances() throws Exception { |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
740 final String countMethod = countInvocations(); |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
741 PolyglotEngine.Value count1 = findGlobalSymbol(countMethod); |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
742 PolyglotEngine vm1 = tckVM; |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
743 tckVM = null; // clean-up |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
744 PolyglotEngine.Value count2 = findGlobalSymbol(countMethod); |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
745 PolyglotEngine vm2 = tckVM; |
22076
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
746 |
f54d7e045a37
Verify the two TruffleVM instances are different - otherwise the isolation cannot work
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22046
diff
changeset
|
747 assertNotSame("Two virtual machines allocated", vm1, vm2); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
748 |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
749 int prev1 = 0; |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
750 int prev2 = 0; |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
751 for (int i = 0; i < 10; i++) { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
752 int quantum = RANDOM.nextInt(10); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
753 for (int j = 0; j < quantum; j++) { |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
754 Object res = count1.execute().get(); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
755 assert res instanceof Number : "expecting number: " + res; |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
756 ++prev1; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
757 assert ((Number) res).intValue() == prev1 : "expecting " + prev1 + " but was " + res; |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
758 } |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
759 for (int j = 0; j < quantum; j++) { |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
760 Object res = count2.execute().get(); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
761 assert res instanceof Number : "expecting number: " + res; |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
762 ++prev2; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
763 assert ((Number) res).intValue() == prev2 : "expecting " + prev2 + " but was " + res; |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
764 } |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
765 assert prev1 == prev2 : "At round " + i + " the same number of invocations " + prev1 + " vs. " + prev2; |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
766 } |
22278
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
767 } |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
768 |
22278
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
769 @Test |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
770 public void testGlobalObjectIsAccessible() throws Exception { |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
771 String globalObjectFunction = globalObject(); |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
772 if (globalObjectFunction == null) { |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
773 return; |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
774 } |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
775 |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
776 Language language = vm().getLanguages().get(mimeType()); |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
777 assertNotNull("Langugage for " + mimeType() + " found", language); |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
778 |
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
779 PolyglotEngine.Value function = vm().findGlobalSymbol(globalObjectFunction); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
780 Object global = function.execute().get(); |
22278
85a6db6624ab
Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22200
diff
changeset
|
781 assertEquals("Global from the language same with Java obtained one", language.getGlobalObject().get(), global); |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
782 } |
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21960
diff
changeset
|
783 |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
784 @Test |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
785 public void testEvaluateSource() throws Exception { |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
786 Language language = vm().getLanguages().get(mimeType()); |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
787 assertNotNull("Langugage for " + mimeType() + " found", language); |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
788 |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
789 PolyglotEngine.Value function = vm().findGlobalSymbol(evaluateSource()); |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
790 assertNotNull(evaluateSource() + " found", function); |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
791 |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
792 double expect = Math.floor(RANDOM.nextDouble() * 100000.0) / 10.0; |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
793 Object parsed = function.execute("application/x-tck", "" + expect).get(); |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
794 assertTrue("Expecting numeric result, was:" + expect, parsed instanceof Number); |
22382
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
795 double value = ((Number) parsed).doubleValue(); |
22375
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
796 assertEquals("Gets the double", expect, value, 0.01); |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
797 } |
78594d342228
Give Truffle languages access to evaluation functions of other languages.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22284
diff
changeset
|
798 |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
799 @Test |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
800 public void multiplyTwoVariables() throws Exception { |
22382
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
801 final String firstVar = "var" + (char) ('A' + RANDOM.nextInt(24)); |
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
802 final String secondVar = "var" + (char) ('0' + RANDOM.nextInt(10)); |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
803 String mulCode = multiplyCode(firstVar, secondVar); |
22382
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
804 Source source = Source.fromText("TCK42:" + mimeType() + ":" + mulCode, "evaluate " + firstVar + " * " + secondVar).withMimeType("application/x-tck"); |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
805 final PolyglotEngine.Value evalSource = vm().eval(source); |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
806 final PolyglotEngine.Value invokeMul = evalSource.execute(firstVar, secondVar); |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
807 Object result = invokeMul.get(); |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
808 assertTrue("Expecting numeric result, was:" + result, result instanceof Number); |
22382
fb607f23d1eb
Apply formating rules
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22381
diff
changeset
|
809 assertEquals("Right value", 42, ((Number) result).intValue()); |
22378
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
810 } |
06bdf4a43126
Adding parse with argument names into the API and TCK
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22375
diff
changeset
|
811 |
22488
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
812 @Test |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
813 public void testAddComplexNumbers() throws Exception { |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
814 String id = complexAdd(); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
815 if (id == null) { |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
816 return; |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
817 } |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
818 PolyglotEngine.Value apply = findGlobalSymbol(id); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
819 |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
820 ComplexNumber a = new ComplexNumber(32, 10); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
821 ComplexNumber b = new ComplexNumber(10, 32); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
822 |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
823 apply.execute(a, b); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
824 |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
825 assertEquals(42.0, a.get(ComplexNumber.REAL_IDENTIFIER), 0.1); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
826 assertEquals(42.0, a.get(ComplexNumber.IMAGINARY_IDENTIFIER), 0.1); |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
827 } |
fa7b15454c66
Add ComplexNumber test to TCK
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22437
diff
changeset
|
828 |
22495
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
829 @Test |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
830 public void testSumRealOfComplexNumbersA() throws Exception { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
831 String id = complexSumReal(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
832 if (id == null) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
833 return; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
834 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
835 PolyglotEngine.Value apply = findGlobalSymbol(id); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
836 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
837 ComplexNumbersA numbers = new ComplexNumbersA(new double[]{2, -1, 30, -1, 10, -1}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
838 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
839 Number n = (Number) apply.execute(numbers).get(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
840 assertEquals("The same value returned", 42.0, n.doubleValue(), 0.01); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
841 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
842 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
843 @Test |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
844 public void testSumRealOfComplexNumbersB() throws Exception { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
845 String id = complexSumReal(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
846 if (id == null) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
847 return; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
848 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
849 PolyglotEngine.Value apply = findGlobalSymbol(id); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
850 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
851 ComplexNumbersB numbers = new ComplexNumbersB(new double[]{2, 30, 10}, new double[]{-1, -1, -1}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
852 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
853 Number n = (Number) apply.execute(numbers).get(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
854 assertEquals("The same value returned", 42.0, n.doubleValue(), 0.01); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
855 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
856 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
857 @Test |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
858 public void testSumRealOfComplexNumbersAsStructuredDataRowBased() throws Exception { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
859 String id = complexSumReal(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
860 if (id == null) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
861 return; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
862 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
863 PolyglotEngine.Value apply = findGlobalSymbol(id); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
864 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
865 Schema schema = new Schema(3, true, Arrays.asList(ComplexNumber.REAL_IDENTIFIER, ComplexNumber.IMAGINARY_IDENTIFIER), Arrays.asList(Type.DOUBLE, Type.DOUBLE)); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
866 byte[] buffer = new byte[(6 * Double.SIZE / Byte.SIZE)]; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
867 putDoubles(buffer, new double[]{2, -1, 30, -1, 10, -1}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
868 StructuredData numbers = new StructuredData(buffer, schema); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
869 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
870 Number n = (Number) apply.execute(numbers).get(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
871 assertEquals("The same value returned", 42.0, n.doubleValue(), 0.01); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
872 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
873 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
874 @Test |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
875 public void testSumRealOfComplexNumbersAsStructuredDataColumnBased() throws Exception { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
876 String id = complexSumReal(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
877 if (id == null) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
878 return; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
879 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
880 PolyglotEngine.Value apply = findGlobalSymbol(id); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
881 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
882 Schema schema = new Schema(3, false, Arrays.asList(ComplexNumber.REAL_IDENTIFIER, ComplexNumber.IMAGINARY_IDENTIFIER), Arrays.asList(Type.DOUBLE, Type.DOUBLE)); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
883 byte[] buffer = new byte[6 * Double.SIZE / Byte.SIZE]; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
884 putDoubles(buffer, new double[]{2, 30, 10, -1, -1, -1}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
885 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
886 StructuredData numbers = new StructuredData(buffer, schema); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
887 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
888 Number n = (Number) apply.execute(numbers).get(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
889 assertEquals("The same value returned", 42.0, n.doubleValue(), 0.01); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
890 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
891 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
892 @Test |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
893 public void testCopyComplexNumbersA() throws Exception { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
894 String id = complexCopy(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
895 if (id == null) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
896 return; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
897 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
898 PolyglotEngine.Value apply = findGlobalSymbol(id); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
899 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
900 ComplexNumbersA a = new ComplexNumbersA(new double[]{-1, -1, -1, -1, -1, -1}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
901 ComplexNumbersA b = new ComplexNumbersA(new double[]{41, 42, 43, 44, 45, 46}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
902 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
903 apply.execute(a, b); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
904 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
905 Assert.assertArrayEquals(new double[]{41, 42, 43, 44, 45, 46}, a.getData(), 0.1); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
906 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
907 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
908 @Test |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
909 public void testCopyComplexNumbersB() throws Exception { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
910 String id = complexCopy(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
911 if (id == null) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
912 return; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
913 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
914 PolyglotEngine.Value apply = findGlobalSymbol(id); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
915 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
916 ComplexNumbersB a = new ComplexNumbersB(new double[]{-1, -1, -1}, new double[]{-1, -1, -1}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
917 ComplexNumbersB b = new ComplexNumbersB(new double[]{41, 43, 45}, new double[]{42, 44, 46}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
918 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
919 apply.execute(a, b); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
920 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
921 Assert.assertArrayEquals(new double[]{41, 42, 43, 44, 45, 46}, a.getData(), 0.1); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
922 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
923 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
924 @Test |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
925 public void testCopyStructuredComplexToComplexNumbersA() throws Exception { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
926 String id = complexCopy(); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
927 if (id == null) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
928 return; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
929 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
930 PolyglotEngine.Value apply = findGlobalSymbol(id); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
931 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
932 ComplexNumbersA a = new ComplexNumbersA(new double[]{-1, -1, -1, -1, -1, -1}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
933 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
934 Schema schema = new Schema(3, true, Arrays.asList(ComplexNumber.REAL_IDENTIFIER, ComplexNumber.IMAGINARY_IDENTIFIER), Arrays.asList(Type.DOUBLE, Type.DOUBLE)); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
935 byte[] buffer = new byte[6 * Double.SIZE / Byte.SIZE]; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
936 putDoubles(buffer, new double[]{41, 42, 43, 44, 45, 46}); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
937 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
938 StructuredData b = new StructuredData(buffer, schema); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
939 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
940 apply.execute(a, b); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
941 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
942 Assert.assertArrayEquals(new double[]{41, 42, 43, 44, 45, 46}, a.getData(), 0.1); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
943 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
944 |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
945 private static void putDoubles(byte[] buffer, double[] values) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
946 for (int index = 0; index < values.length; index++) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
947 int doubleSize = Double.SIZE / Byte.SIZE; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
948 byte[] bytes = new byte[doubleSize]; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
949 ByteBuffer.wrap(bytes).putDouble(values[index]); |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
950 for (int i = 0; i < doubleSize; i++) { |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
951 buffer[index * doubleSize + i] = bytes[i]; |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
952 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
953 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
954 } |
aeba89e1d8da
Add ComplexNumber sequence tests
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22488
diff
changeset
|
955 |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
956 private PolyglotEngine.Value findGlobalSymbol(String name) throws Exception { |
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
957 PolyglotEngine.Value s = vm().findGlobalSymbol(name); |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
958 assert s != null : "Symbol " + name + " is not found!"; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
959 return s; |
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
960 } |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
961 |
22156
50056a161d7f
Replacing time out associated warnings by UnsupportedOperationException. Meaning of exception is probably more straightforward than a soft hint attempted before. Shouldn't influence the way things are build, if tests are skipped.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22142
diff
changeset
|
962 private CompoundObject findCompoundSymbol() throws Exception { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
963 final String compoundObjectName = compoundObject(); |
22170
796f0fef110e
Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22168
diff
changeset
|
964 PolyglotEngine.Value s = vm().findGlobalSymbol(compoundObjectName); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
965 assert s != null : "Symbol " + compoundObjectName + " is not found!"; |
22436
46a6d3eb790c
Adopt TCK and Polyglot after changes to execute and invoke message
Matthias Grimmer <grimmer@ssw.jku.at>
parents:
22382
diff
changeset
|
966 final PolyglotEngine.Value value = s.execute(); |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
967 CompoundObject obj = value.as(CompoundObject.class); |
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
968 assertNotNull("Compound object for " + value + " found", obj); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
969 int traverse = RANDOM.nextInt(10); |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
970 for (int i = 1; i <= traverse; i++) { |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
971 obj = obj.returnsThis(); |
22141
46384e637592
Make sure the proper TruffleVM execution context is re-set before invoking an operation on a JavaInterop wrapper obtained via Symbol.as method.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22140
diff
changeset
|
972 assertNotNull("Remains non-null even after " + i + " iteration", obj); |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
973 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
974 return obj; |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
975 } |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
976 |
22200
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
977 private static void assertSameTruffleObject(String msg, Object expected, Object actual) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
978 Object unExpected = unwrapTruffleObject(expected); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
979 Object unAction = unwrapTruffleObject(actual); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
980 assertSame(msg, unExpected, unAction); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
981 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
982 |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
983 private static Object unwrapTruffleObject(Object obj) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
984 try { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
985 if (obj instanceof TruffleObject) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
986 Class<?> eto = Class.forName("com.oracle.truffle.api.vm.EngineTruffleObject"); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
987 if (eto.isInstance(obj)) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
988 final Field field = eto.getDeclaredField("delegate"); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
989 field.setAccessible(true); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
990 return field.get(obj); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
991 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
992 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
993 return obj; |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
994 } catch (Exception ex) { |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
995 throw new IllegalStateException(ex); |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
996 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
997 } |
7abcbeb12d08
Creating a TruffleObject that knows its PolyglotEngine and wrapping all values returned from the engine by it, so it is always clear into which engine context an object belongs.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22173
diff
changeset
|
998 |
22135
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
999 interface CompoundObject { |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1000 Number fourtyTwo(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1001 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1002 Number plus(int x, int y); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1003 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1004 Object returnsNull(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1005 |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1006 CompoundObject returnsThis(); |
e70b20f4bb00
Implementing API for Java/Truffle interop. Based around JavaInterop.asJavaObject and JavaInterop.asTruffleObject methods. Connected to TruffleVM via Symbol.as(Class) wrapper. Verified by extended TCK.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22121
diff
changeset
|
1007 } |
21938
0a6e10379b9b
Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff
changeset
|
1008 } |