vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 28 Dec 2012 12:35:32 +0100
changeset 392 44a5802816be
parent 355 eea0065bcc1a
child 394 31ca8ea998a9
permissions -rw-r--r--
Class.getMethods returns only public methods
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@355
    34
    @Compare public String intType() {
jaroslav@355
    35
        return Integer.TYPE.toString();
jaroslav@355
    36
    }
jaroslav@355
    37
jaroslav@355
    38
    @Compare public String longClass() {
jaroslav@355
    39
        return long.class.toString();
jaroslav@355
    40
    }
jaroslav@355
    41
    
jaroslav@392
    42
    @Compare public String namesOfMethods() {
jaroslav@392
    43
        StringBuilder sb = new StringBuilder();
jaroslav@392
    44
        String[] arr = new String[20];
jaroslav@392
    45
        int i = 0;
jaroslav@392
    46
        for (Method m : StaticUse.class.getMethods()) {
jaroslav@392
    47
            arr[i++] = m.getName();
jaroslav@392
    48
        }
jaroslav@392
    49
        for (String s : sort(arr, i)) {
jaroslav@392
    50
            sb.append(s).append("\n");
jaroslav@392
    51
        }
jaroslav@392
    52
        return sb.toString();
jaroslav@392
    53
    }
jaroslav@392
    54
    
jaroslav@392
    55
    @JavaScriptBody(args = { "arr", "len" }, body="var a = arr.slice(0, len); a.sort(); return a;")
jaroslav@392
    56
    private static String[] sort(String[] arr, int len) {
jaroslav@392
    57
        List<String> list = Arrays.asList(arr).subList(0, len);
jaroslav@392
    58
        Collections.sort(list);
jaroslav@392
    59
        return list.toArray(new String[0]);
jaroslav@392
    60
    }
jaroslav@355
    61
    
jaroslav@355
    62
    @Factory
jaroslav@355
    63
    public static Object[] create() {
jaroslav@355
    64
        return VMTest.create(ReflectionTest.class);
jaroslav@355
    65
    }
jaroslav@355
    66
    
jaroslav@355
    67
}