2014-07-31 08:25:23 -04:00
|
|
|
package go;
|
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
import android.test.suitebuilder.annotation.Suppress;
|
|
|
|
|
2014-07-31 08:25:23 -04:00
|
|
|
import go.testpkg.Testpkg;
|
|
|
|
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
|
|
|
|
public class SeqTest extends TestCase {
|
2014-11-11 09:55:39 -05:00
|
|
|
static {
|
|
|
|
Go.init(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testAdd() {
|
|
|
|
long res = Testpkg.Add(3, 4);
|
|
|
|
assertEquals("Unexpected arithmetic failure", 7, res);
|
|
|
|
}
|
2014-07-31 08:25:23 -04:00
|
|
|
|
2014-12-11 12:11:02 -05:00
|
|
|
public void testShortString() {
|
|
|
|
String want = "a short string";
|
|
|
|
String got = Testpkg.StrDup(want);
|
|
|
|
assertEquals("Strings should match", want, got);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testLongString() {
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
for (int i = 0; i < 128*1024; i++) {
|
|
|
|
b.append("0123456789");
|
|
|
|
}
|
|
|
|
String want = b.toString();
|
|
|
|
String got = Testpkg.StrDup(want);
|
|
|
|
assertEquals("Strings should match", want, got);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testUnicode() {
|
|
|
|
String want = "Hello, 世界";
|
|
|
|
String got = Testpkg.StrDup(want);
|
|
|
|
assertEquals("Strings should match", want, got);
|
|
|
|
}
|
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
public void testGoRefGC() {
|
|
|
|
Testpkg.S s = Testpkg.New();
|
|
|
|
runGC();
|
|
|
|
long collected = Testpkg.NumSCollected();
|
|
|
|
assertEquals("Only S should be pinned", 0, collected);
|
2014-07-31 08:25:23 -04:00
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
s = null;
|
|
|
|
runGC();
|
|
|
|
collected = Testpkg.NumSCollected();
|
|
|
|
assertEquals("S should be collected", 1, collected);
|
|
|
|
}
|
2014-07-31 08:25:23 -04:00
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
boolean finalizedAnI;
|
2014-07-31 08:25:23 -04:00
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
private class AnI extends Testpkg.I.Stub {
|
|
|
|
boolean called;
|
|
|
|
public void F() {
|
|
|
|
called = true;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void finalize() throws Throwable {
|
|
|
|
finalizedAnI = true;
|
|
|
|
super.finalize();
|
|
|
|
}
|
|
|
|
}
|
2014-07-31 08:25:23 -04:00
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
/* Suppress this test for now; it's flaky or broken. */
|
|
|
|
@Suppress
|
|
|
|
public void testJavaRefGC() {
|
|
|
|
finalizedAnI = false;
|
|
|
|
AnI obj = new AnI();
|
|
|
|
runGC();
|
|
|
|
Testpkg.Call(obj);
|
|
|
|
assertTrue("want F to be called", obj.called);
|
|
|
|
obj = null;
|
|
|
|
runGC();
|
|
|
|
assertTrue("want obj to be collected", finalizedAnI);
|
|
|
|
}
|
2014-07-31 08:25:23 -04:00
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
public void testJavaRefKeep() {
|
|
|
|
finalizedAnI = false;
|
|
|
|
AnI obj = new AnI();
|
|
|
|
Testpkg.Keep(obj);
|
|
|
|
obj = null;
|
|
|
|
runGC();
|
|
|
|
assertFalse("want obj to be kept live by Go", finalizedAnI);
|
|
|
|
}
|
2014-07-31 08:25:23 -04:00
|
|
|
|
2014-11-11 09:55:39 -05:00
|
|
|
private void runGC() {
|
|
|
|
System.gc();
|
|
|
|
System.runFinalization();
|
|
|
|
Testpkg.GC();
|
|
|
|
System.gc();
|
|
|
|
System.runFinalization();
|
|
|
|
}
|
2014-07-31 08:25:23 -04:00
|
|
|
}
|
2014-11-11 09:55:39 -05:00
|
|
|
|