# HG changeset patch # User Jaroslav Tulach # Date 1456982240 -3600 # Node ID bf9cd8ee73d69c96f9b522bb11e96f89cb1384da # Parent fe13a2b0fd243af2dc6f155a525bfc62f62b3a17 Tests for interfaces with default methods implemented by lamda functions diff -r fe13a2b0fd24 -r bf9cd8ee73d6 rt/vm8/src/main/java/org/apidesign/bck2brwsr/vm8/Functions.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/vm8/src/main/java/org/apidesign/bck2brwsr/vm8/Functions.java Thu Mar 03 06:17:20 2016 +0100 @@ -0,0 +1,62 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.vm8; + +public class Functions { + public interface SimpleOne extends BaseOne { + public R invoke(P1 p1, P2 p2, P3 p3, P4 p4); + + @Override + public default R invoke(P1 p1, P2 p2, P3 p3, P4 p4, java.lang.Object ignore) { + return invoke(p1, p2, p3, p4); + } + } + + public interface BaseOne { + public R invoke(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5); + } + + public static BaseOne inner5() { + return new BaseOne() { + @Override + public Integer invoke(Void p1, Void p2, Void p3, Void p4, Object p5) { + return 42; + } + }; + } + + public static BaseOne inner4() { + return new SimpleOne() { + @Override + public Integer invoke(Void p1, Void p2, Void p3, Void p4) { + return 42; + } + }; + } + public static BaseOne function5() { + return (Void p1, Void p2, Void p3, Void p4, Object p5) -> 42; + } + + public static BaseOne function4() { + return function4impl(); + } + + private static SimpleOne function4impl() { + return null; + } +} diff -r fe13a2b0fd24 -r bf9cd8ee73d6 rt/vm8/src/test/java/org/apidesign/bck2brwsr/vm8/FunctionsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/vm8/src/test/java/org/apidesign/bck2brwsr/vm8/FunctionsTest.java Thu Mar 03 06:17:20 2016 +0100 @@ -0,0 +1,49 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012-2015 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.vm8; + +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +public class FunctionsTest { + @Compare + public int inner5() throws Exception { + return Functions.inner5().invoke(null, null, null, null, null); + } + @Compare + public int function5() throws Exception { + return Functions.function5().invoke(null, null, null, null, null); + } + @Compare + public int inner4() throws Exception { + return Functions.inner4().invoke(null, null, null, null, null); + } + @Compare + public int function4() throws Exception { + final Functions.BaseOne fn = Functions.function4(); + if (fn == null) { + return -1; + } + return fn.invoke(null, null, null, null, null); + } + + @Factory public static Object[] create() { + return VMTest.create(FunctionsTest.class); + } +}