Skip to content

Commit e08083b

Browse files
committed
New Source files for test
1 parent b4d232b commit e08083b

11 files changed

Lines changed: 131 additions & 17 deletions

File tree

sources/net.sf.j2s.core/test/src/test/Test_.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package test;
22

3-
class Test_ {
3+
class Testx {
4+
// example of a second independent top-level class
5+
}
6+
7+
abstract class Test_ {
48

9+
private static int i_ = 0;
510
private int t = 0;
611

712
public void showt() {
@@ -64,4 +69,5 @@ public static void main(String[] args) {
6469

6570

6671

67-
}
72+
}
73+

sources/net.sf.j2s.core/test/src/test/Test_Anon.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,29 @@
77

88
class Test_Anon extends Test_ {
99

10-
private static int x = 3;
10+
private static boolean b = !(true);
11+
private static int x = -(3);
1112
private static final Enumeration<?> EMPTY_ENUMERATION = new Enumeration<Object>() {
1213
public boolean hasMoreElements() {
13-
return false;
14+
return isAnonymous();
1415
}
1516

1617
public Object nextElement() {
1718
throw new NoSuchElementException();
1819
}
1920

21+
public boolean isAnonymous() {
22+
return this.getClass().isAnonymousClass();
23+
}
24+
2025
};
2126

2227

2328
public static void main(String[] args) {
2429
int z = 3;
25-
assert(!EMPTY_ENUMERATION.hasMoreElements());
30+
boolean a = !(Test_Class.Test_Class_Inner.i == 3);
31+
System.out.println(EMPTY_ENUMERATION.hasMoreElements());
32+
assert(EMPTY_ENUMERATION.hasMoreElements());
2633
Object xx = new MouseListener() {
2734

2835
int y = 0;

sources/net.sf.j2s.core/test/src/test/Test_Array.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Test_Array extends Test_ {
88
static {
99
int x = 3;
1010
y = x;
11+
Test_Array[] a = new Test_Array[3];
1112
}
1213

1314
static Object tType3__ = Array.newInstance(Test_Array[][].class, 3);

sources/net.sf.j2s.core/test/src/test/Test_Byte.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static void main(String[] args) {
1010
d /= 'c';
1111
System.out.println(d);
1212
assert(d == 3.0/99);
13+
System.out.println("Hello, Trai");
1314

1415
// integer division must be turned back into an integer in JavaScript
1516

sources/net.sf.j2s.core/test/src/test/Test_Bytecode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void setX(double x) {
2121

2222
void setX(Double x) {
2323
System.out.println("BC_setX(Number) " + x);
24-
assert(false);
24+
assert(x == 33);
2525
// note that in JavaScript, the above construction uses "valueOf" not "toString" for x.
2626
// this results in reporting "3" for new Double(3.0) instead of "3.0"
2727
}

sources/net.sf.j2s.core/test/src/test/Test_Bytecode2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ public static void main(String[] args) {
7575
// t0.setX (( new Integer (3)).intValue ());
7676
// BC_setX(int) 3
7777

78-
t1.setX(new Double(3));
78+
t1.setX(new Double(33));
7979
// 119 invokevirtual test.Test_Bytecode.setX(java.lang.Double) : void [80]
8080
// t0.setX ( new Double (3));
8181
// BC_setX(Double) 3.0
8282

83-
83+
System.out.println("Bytecode2 OK");
8484

8585
}
8686

sources/net.sf.j2s.core/test/src/test/Test_Class.java

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
@SuppressWarnings("rawtypes")
44
class Test_Class extends Test_ {
55

6+
static class Test_Class_Inner {
7+
static Integer i = 5;
8+
static int i2 = new Integer(3);
9+
static int ic = 'c';
10+
static char c = 'c';
11+
static Character c2 = 'c';
12+
static char c3 = new Character('c');
13+
}
14+
615
public Test_Class() {
716
System.out.println(true);
817
}
@@ -33,8 +42,30 @@ public static Test_Class newInstance(Object... objects) {
3342
return null;
3443
}
3544

45+
String test = "testing";
46+
class B {
47+
String test = "testingB";
48+
void testB() {
49+
System.out.println(test);
50+
assert(test.equals("testingB"));
51+
System.out.println(Test_Class.this.test);
52+
assert(Test_Class.this.test.equals("testing"));
53+
test = "testc";
54+
assert(test.equals("testc"));
55+
test += "test";
56+
assert(test.equals("testctest"));
57+
test += Test_Class.this.test;
58+
assert(test.equals("testctesttesting"));
59+
Test_Class.this.test += test;
60+
assert(Test_Class.this.test.equals("testingtestctesttesting"));
61+
62+
63+
}
64+
65+
}
66+
3667
Class B() {
37-
return null;
68+
return B.class;
3869
}
3970

4071
static class C extends Test_Class {
@@ -47,7 +78,22 @@ Class C() {
4778

4879
public static void main(String[] args) {
4980

81+
class LocalClass {
82+
83+
String hello() {
84+
return "hello";
85+
}
86+
}
87+
88+
5089
try {
90+
91+
String s = new LocalClass().hello();
92+
System.out.println(s);
93+
assert(s.equals("hello"));
94+
95+
96+
new Test_Class().new B().testB();
5197
Class<?> cl;
5298
cl = Class.forName("test.Test_Class");
5399
cl.getConstructor(String.class, String.class).newInstance(
@@ -58,7 +104,35 @@ public static void main(String[] args) {
58104
"test2");
59105
Test_Class c = (Test_Class) cl.getConstructor().newInstance();
60106
cl = c.C();
61-
cl.newInstance(); // fails in JavaScript - runs the static method instead
107+
cl.newInstance();
108+
109+
String o = "" + java.util.concurrent.DelayQueue.class;
110+
System.out.println(o);
111+
assert(("" + o).equals("class java.util.concurrent.DelayQueue"));
112+
o = "" + java.awt.geom.Point2D.Double.class;
113+
System.out.println(o);
114+
assert(("" + o).equals("class java.awt.geom.Point2D$Double"));
115+
116+
o = "" + test.Test_Class.B.class;
117+
System.out.println(o);
118+
assert(("" + o).equals("class test.Test_Class$B"));
119+
120+
System.out.println(test.Test_Class.B.class.getSimpleName());
121+
assert(test.Test_Class.B.class.getSimpleName().equals("B"));
122+
123+
o = "" + test.Test_Class.C.class;
124+
System.out.println(o);
125+
assert(("" + o).equals("class test.Test_Class$C"));
126+
127+
System.out.println(test.Test_Class.C.class.getSimpleName());
128+
assert(test.Test_Class.C.class.getSimpleName().equals("C"));
129+
130+
System.out.println(LocalClass.class.isLocalClass());
131+
assert(LocalClass.class.isLocalClass());
132+
133+
134+
assert(("" + test.Test_Interface.class).equals("interface test.Test_Interface"));
135+
62136
System.out.println("Test_Class OK");
63137
} catch (Exception e) {
64138
// TODO Auto-generated catch block

sources/net.sf.j2s.core/test/src/test/Test_Interface.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ public interface Test_Interface {
77
String[] s = new String[3];
88

99

10+
public interface Test_Interface_inner {
11+
// This mus be wrapped, or C$ changes definitions
12+
}
13+
1014
public static void main(String[] args) {
1115
ClassLoader.getSystemClassLoader().setClassAssertionStatus("test.Test_Interface", true);
1216
System.out.println("in the interface " + x + " " + y);

sources/net.sf.j2s.core/test/src/test/Test_Resource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package test;
22

3-
import java.io.IOException;
43
import java.util.Properties;
54

65
public class Test_Resource extends Test_ {
@@ -12,14 +11,16 @@ static int getInt() {
1211
public static void main(String[] args) {
1312
Properties p = new Properties();
1413
try {
15-
Class<?> c = test.Test_Resource.class;
14+
// check for proper referencing of an interface
15+
Class<?> c = Test_Resource.class;
1616
p.load(c.getResourceAsStream("test.properties"));
1717
String test = p.getProperty("test");
1818
System.out.println(test);
1919
assert("OK".equals(test));
2020
System.out.println("Test_Resource OK");
21-
} catch (IOException e) {
21+
} catch (Exception e) {
2222
System.out.println(e);
23+
assert(false);
2324
}
2425
}
2526

sources/net.sf.j2s.core/test/src/test/Test_Static.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package test;
22

3-
class Test_Static extends Test_ {
3+
import test.Test_Class.Test_Class_Inner;
4+
5+
class Test_Static extends Test_ implements Test_int3, Test_int2, Test_int1 {
46

57
private static boolean b = false;
68
private final static char c0 = new Character('c');
79
private final static char c2 = '2';
810
private static int y;
911
private static char c = 'c';
12+
private static int innerI = Test_Class_Inner.i;
1013
static String s;
1114
static {
15+
16+
17+
System.out.println(Test_int1.int1);
18+
System.out.println(Test_int2.int2);
19+
System.out.println(Test_int3.int3);
20+
21+
System.out.println(innerI);
22+
assert(innerI == 5);
1223
char cc = c2;
1324
int x = 3;
1425
y = Test_Boolean.i_;

0 commit comments

Comments
 (0)