annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/impl/AccessorTest.java @ 22533:1f7fe9f4207a

Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 07 Jan 2016 11:07:28 +0100
parents 5692953272eb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 *
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * accompanied this code).
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 *
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 *
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * questions.
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 */
22429
5692953272eb Replacing reflection in AccessorTest by package private access
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22425
diff changeset
23 package com.oracle.truffle.api.impl;
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24
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
25 import java.util.concurrent.Executors;
22424
fec62e298245 Rename package truffle.api.test to truffle.api to enable package-protected API access for testing.
Christian Humer <christian.humer@oracle.com>
parents: 22335
diff changeset
26
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
27 import org.junit.BeforeClass;
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
28 import org.junit.Test;
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
29
22425
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
30 import com.oracle.truffle.api.source.Source;
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
31 import com.oracle.truffle.api.vm.ImplicitExplicitExportTest.ExportImportLanguage1;
22429
5692953272eb Replacing reflection in AccessorTest by package private access
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22425
diff changeset
32 import static com.oracle.truffle.api.vm.ImplicitExplicitExportTest.L1;
5692953272eb Replacing reflection in AccessorTest by package private access
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22425
diff changeset
33 import com.oracle.truffle.api.vm.PolyglotEngine;
22533
1f7fe9f4207a Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22429
diff changeset
34 import java.lang.reflect.Method;
1f7fe9f4207a Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22429
diff changeset
35 import static org.junit.Assert.assertNotNull;
1f7fe9f4207a Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22429
diff changeset
36 import static org.junit.Assert.assertNull;
22425
b39b603e2a1e Organize imports after rename.
Christian Humer <christian.humer@oracle.com>
parents: 22424
diff changeset
37
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
38 public class AccessorTest {
22533
1f7fe9f4207a Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22429
diff changeset
39 public static Method find;
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
40
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
41 @BeforeClass
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
42 public static void initAccessors() throws Exception {
22533
1f7fe9f4207a Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22429
diff changeset
43 find = Accessor.class.getDeclaredMethod("findLanguageByClass", Object.class, Class.class);
1f7fe9f4207a Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22429
diff changeset
44 find.setAccessible(true);
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
45 }
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
46
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
47 @Test
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
48 public void canGetAccessToOwnLanguageInstance() throws Exception {
22335
906a5f6e07cc Giving the PolyglotEngine builder factory method more sensible name.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22278
diff changeset
49 PolyglotEngine vm = PolyglotEngine.newBuilder().executor(Executors.newSingleThreadExecutor()).build();
22170
796f0fef110e Renaming to PolyglotEngine
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22168
diff changeset
50 PolyglotEngine.Language language = vm.getLanguages().get(L1);
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
51 assertNotNull("L1 language is defined", language);
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
52
22278
85a6db6624ab Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
53 Source s = Source.fromText("return nothing", "nothing");
85a6db6624ab Simplifying the way to obtain Language.globalObject
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22173
diff changeset
54 Object ret = language.eval(s).get();
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
55 assertNull("nothing is returned", ret);
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
56
22533
1f7fe9f4207a Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22429
diff changeset
57 ExportImportLanguage1 afterInitialization = (ExportImportLanguage1) find.invoke(null, vm, ExportImportLanguage1.class);
22012
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
58 assertNotNull("Language found", afterInitialization);
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
59 }
09531c471176 Making sure the accessor can really find the TruffleLanguage instance by its class
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
60 }