Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.interop.java.test/src/com/oracle/truffle/api/interop/java/test/BoxedStringTest.java @ 22529:2643b968c0c6
Send UNBOX message when a primitive type is requested for a TruffleObject value
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 06 Jan 2016 10:59:58 +0100 |
parents | truffle/com.oracle.truffle.api.interop.java.test/src/com/oracle/truffle/api/interop/java/test/PrimitiveArrayInteropTest.java@0d36601f233e |
children |
comparison
equal
deleted
inserted
replaced
22528:d725323deb6c | 22529:2643b968c0c6 |
---|---|
1 /* | |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. Oracle designates this | |
8 * particular file as subject to the "Classpath" exception as provided | |
9 * by Oracle in the LICENSE file that accompanied this code. | |
10 * | |
11 * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 * version 2 for more details (a copy is included in the LICENSE file that | |
15 * accompanied this code). | |
16 * | |
17 * You should have received a copy of the GNU General Public License version | |
18 * 2 along with this work; if not, write to the Free Software Foundation, | |
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 * | |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
22 * or visit www.oracle.com if you need additional information or have any | |
23 * questions. | |
24 */ | |
25 package com.oracle.truffle.api.interop.java.test; | |
26 | |
27 import com.oracle.truffle.api.CallTarget; | |
28 import com.oracle.truffle.api.Truffle; | |
29 import com.oracle.truffle.api.interop.ForeignAccess; | |
30 import com.oracle.truffle.api.interop.Message; | |
31 import com.oracle.truffle.api.interop.TruffleObject; | |
32 import com.oracle.truffle.api.interop.java.JavaInterop; | |
33 import com.oracle.truffle.api.nodes.RootNode; | |
34 | |
35 import static org.junit.Assert.assertEquals; | |
36 import org.junit.Before; | |
37 import org.junit.Test; | |
38 | |
39 public class BoxedStringTest implements TruffleObject, ForeignAccess.Factory10 { | |
40 public interface ExactMatchInterop { | |
41 String stringValue(); | |
42 | |
43 char charValue(); | |
44 } | |
45 | |
46 private String value; | |
47 private ExactMatchInterop interop; | |
48 | |
49 @Before | |
50 public void initObjects() { | |
51 interop = JavaInterop.asJavaObject(ExactMatchInterop.class, this); | |
52 } | |
53 | |
54 @Test | |
55 public void convertToString() { | |
56 value = "Hello"; | |
57 assertEquals("Hello", interop.stringValue()); | |
58 } | |
59 | |
60 @Test | |
61 public void convertToChar() { | |
62 value = "W"; | |
63 assertEquals('W', interop.charValue()); | |
64 } | |
65 | |
66 @Override | |
67 public ForeignAccess getForeignAccess() { | |
68 return ForeignAccess.create(BoxedStringTest.class, this); | |
69 } | |
70 | |
71 @Override | |
72 public CallTarget accessIsNull() { | |
73 return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false)); | |
74 } | |
75 | |
76 @Override | |
77 public CallTarget accessIsExecutable() { | |
78 return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(false)); | |
79 } | |
80 | |
81 @Override | |
82 public CallTarget accessIsBoxed() { | |
83 return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(true)); | |
84 } | |
85 | |
86 @Override | |
87 public CallTarget accessHasSize() { | |
88 return null; | |
89 } | |
90 | |
91 @Override | |
92 public CallTarget accessGetSize() { | |
93 return null; | |
94 } | |
95 | |
96 @Override | |
97 public CallTarget accessUnbox() { | |
98 return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(value)); | |
99 } | |
100 | |
101 @Override | |
102 public CallTarget accessRead() { | |
103 return Truffle.getRuntime().createCallTarget(RootNode.createConstantNode(this)); | |
104 } | |
105 | |
106 @Override | |
107 public CallTarget accessWrite() { | |
108 return null; | |
109 } | |
110 | |
111 @Override | |
112 public CallTarget accessExecute(int argumentsLength) { | |
113 return null; | |
114 } | |
115 | |
116 @Override | |
117 public CallTarget accessInvoke(int argumentsLength) { | |
118 return null; | |
119 } | |
120 | |
121 @Override | |
122 public CallTarget accessNew(int argumentsLength) { | |
123 return null; | |
124 } | |
125 | |
126 @Override | |
127 public CallTarget accessMessage(Message unknown) { | |
128 return null; | |
129 } | |
130 | |
131 } |