comparison truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleTCK.java @ 21960:a88981c5ce8b

Initial test for Java Interop: Perform callback to Math.min and Math.max via TruffleObject and Message.createExecute(2).
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 18 Jun 2015 16:09:38 +0200
parents 9c8c0937da41
children e7c2d36daf72
comparison
equal deleted inserted replaced
21959:3e7fc5f743ed 21960:a88981c5ce8b
90 * @return name of globally exported symbol 90 * @return name of globally exported symbol
91 */ 91 */
92 protected abstract String plusInt(); 92 protected abstract String plusInt();
93 93
94 /** 94 /**
95 * Name of a function in your language to perform a callback to foreign function. Your function
96 * should prepare two numbers (18 and 32) and apply them to the function passed in as an
97 * argument of your function. It should then add 10 to the returned value and return the result
98 * back to its caller.
99 *
100 * @return name of globally exported symbol
101 */
102 protected abstract String applyNumbers();
103
104 /**
95 * Return a code snippet that is invalid in your language. Its 105 * Return a code snippet that is invalid in your language. Its
96 * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield 106 * {@link TruffleVM#eval(java.lang.String, java.lang.String) evaluation} should fail and yield
97 * an exception. 107 * an exception.
98 * 108 *
99 * @return code snippet invalid in the tested language 109 * @return code snippet invalid in the tested language
159 String code = invalidCode(); 169 String code = invalidCode();
160 Object ret = vm().eval(mime, code); 170 Object ret = vm().eval(mime, code);
161 fail("Should yield IOException, but returned " + ret); 171 fail("Should yield IOException, but returned " + ret);
162 } 172 }
163 173
174 @Test
175 public void testMaxOrMinValue() throws Exception {
176 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
177
178 Object res = apply.invoke(null, new MaxMinObject(true));
179
180 assert res instanceof Number : "result should be a number: " + res;
181
182 Number n = (Number) res;
183
184 assert 42 == n.intValue() : "32 > 18 and plus 10";
185 }
186
187 @Test
188 public void testMaxOrMinValue2() throws Exception {
189 TruffleVM.Symbol apply = findGlobalSymbol(applyNumbers());
190
191 Object res = apply.invoke(null, new MaxMinObject(false));
192
193 assert res instanceof Number : "result should be a number: " + res;
194
195 Number n = (Number) res;
196
197 assert 28 == n.intValue() : "18 < 32 and plus 10";
198 }
199
164 private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception { 200 private TruffleVM.Symbol findGlobalSymbol(String name) throws Exception {
165 TruffleVM.Symbol s = vm().findGlobalSymbol(name); 201 TruffleVM.Symbol s = vm().findGlobalSymbol(name);
166 assert s != null : "Symbol " + name + " is not found!"; 202 assert s != null : "Symbol " + name + " is not found!";
167 return s; 203 return s;
168 } 204 }