author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Mon, 07 Jan 2013 17:22:59 +0100 | |
changeset 412 | 777b9b841f15 |
parent 394 | 31ca8ea998a9 |
child 413 | c91483c86597 |
permissions | -rw-r--r-- |
jaroslav@355 | 1 |
/** |
jaroslav@355 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@355 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@355 | 4 |
* |
jaroslav@355 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@355 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@355 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@355 | 8 |
* |
jaroslav@355 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@355 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@355 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@355 | 12 |
* GNU General Public License for more details. |
jaroslav@355 | 13 |
* |
jaroslav@355 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@355 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@355 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@355 | 17 |
*/ |
jaroslav@355 | 18 |
package org.apidesign.bck2brwsr.tck; |
jaroslav@355 | 19 |
|
jaroslav@392 | 20 |
import java.lang.reflect.Method; |
jaroslav@392 | 21 |
import java.util.Arrays; |
jaroslav@392 | 22 |
import java.util.Collections; |
jaroslav@392 | 23 |
import java.util.List; |
jaroslav@392 | 24 |
import org.apidesign.bck2brwsr.core.JavaScriptBody; |
jaroslav@355 | 25 |
import org.apidesign.bck2brwsr.vmtest.Compare; |
jaroslav@355 | 26 |
import org.apidesign.bck2brwsr.vmtest.VMTest; |
jaroslav@355 | 27 |
import org.testng.annotations.Factory; |
jaroslav@355 | 28 |
|
jaroslav@355 | 29 |
/** |
jaroslav@355 | 30 |
* |
jaroslav@355 | 31 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@355 | 32 |
*/ |
jaroslav@355 | 33 |
public class ReflectionTest { |
jaroslav@412 | 34 |
@Compare public boolean nonNullThis() { |
jaroslav@412 | 35 |
return this == null; |
jaroslav@412 | 36 |
} |
jaroslav@412 | 37 |
|
jaroslav@355 | 38 |
@Compare public String intType() { |
jaroslav@355 | 39 |
return Integer.TYPE.toString(); |
jaroslav@355 | 40 |
} |
jaroslav@355 | 41 |
|
jaroslav@355 | 42 |
@Compare public String longClass() { |
jaroslav@355 | 43 |
return long.class.toString(); |
jaroslav@355 | 44 |
} |
jaroslav@355 | 45 |
|
jaroslav@392 | 46 |
@Compare public String namesOfMethods() { |
jaroslav@392 | 47 |
StringBuilder sb = new StringBuilder(); |
jaroslav@392 | 48 |
String[] arr = new String[20]; |
jaroslav@392 | 49 |
int i = 0; |
jaroslav@392 | 50 |
for (Method m : StaticUse.class.getMethods()) { |
jaroslav@392 | 51 |
arr[i++] = m.getName(); |
jaroslav@392 | 52 |
} |
jaroslav@392 | 53 |
for (String s : sort(arr, i)) { |
jaroslav@392 | 54 |
sb.append(s).append("\n"); |
jaroslav@392 | 55 |
} |
jaroslav@392 | 56 |
return sb.toString(); |
jaroslav@392 | 57 |
} |
jaroslav@392 | 58 |
|
jaroslav@394 | 59 |
@Compare public String newInstanceFails() throws InstantiationException { |
jaroslav@394 | 60 |
try { |
jaroslav@394 | 61 |
return "success: " + StaticUse.class.newInstance(); |
jaroslav@394 | 62 |
} catch (IllegalAccessException ex) { |
jaroslav@394 | 63 |
return ex.getClass().getName(); |
jaroslav@394 | 64 |
} |
jaroslav@394 | 65 |
} |
jaroslav@394 | 66 |
|
jaroslav@392 | 67 |
@JavaScriptBody(args = { "arr", "len" }, body="var a = arr.slice(0, len); a.sort(); return a;") |
jaroslav@392 | 68 |
private static String[] sort(String[] arr, int len) { |
jaroslav@392 | 69 |
List<String> list = Arrays.asList(arr).subList(0, len); |
jaroslav@392 | 70 |
Collections.sort(list); |
jaroslav@392 | 71 |
return list.toArray(new String[0]); |
jaroslav@392 | 72 |
} |
jaroslav@355 | 73 |
|
jaroslav@355 | 74 |
@Factory |
jaroslav@355 | 75 |
public static Object[] create() { |
jaroslav@355 | 76 |
return VMTest.create(ReflectionTest.class); |
jaroslav@355 | 77 |
} |
jaroslav@355 | 78 |
|
jaroslav@355 | 79 |
} |