jaroslav@1407: /** jaroslav@1407: * Back 2 Browser Bytecode Translator jaroslav@1407: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1407: * jaroslav@1407: * This program is free software: you can redistribute it and/or modify jaroslav@1407: * it under the terms of the GNU General Public License as published by jaroslav@1407: * the Free Software Foundation, version 2 of the License. jaroslav@1407: * jaroslav@1407: * This program is distributed in the hope that it will be useful, jaroslav@1407: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1407: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1407: * GNU General Public License for more details. jaroslav@1407: * jaroslav@1407: * You should have received a copy of the GNU General Public License jaroslav@1407: * along with this program. Look for COPYING file in the top folder. jaroslav@1407: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1407: */ jaroslav@1407: package org.apidesign.bck2brwsr.tck; jaroslav@1407: jaroslav@1407: import java.util.Timer; jaroslav@1407: import java.util.TimerTask; jaroslav@1407: import org.apidesign.bck2brwsr.vmtest.BrwsrTest; jaroslav@1407: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@1407: import org.testng.annotations.Factory; jaroslav@1407: jaroslav@1407: /** jaroslav@1407: * jaroslav@1407: * @author Jaroslav Tulach jaroslav@1407: */ jaroslav@1407: public class TimerTest { jaroslav@1407: int miss; jaroslav@1407: int exec; jaroslav@1407: jaroslav@1407: public TimerTest() { jaroslav@1407: } jaroslav@1407: jaroslav@1407: @BrwsrTest public void scheduleTick() throws Exception { jaroslav@1407: Timer t = new Timer("MyTest"); jaroslav@1407: class TT extends TimerTask { jaroslav@1407: @Override jaroslav@1407: public void run() { jaroslav@1407: exec++; jaroslav@1407: } jaroslav@1407: } jaroslav@1407: TT task = new TT(); jaroslav@1407: t.schedule(task, 15); jaroslav@1407: jaroslav@1407: if (exec == 0) { jaroslav@1407: miss++; jaroslav@1407: throw new InterruptedException(); jaroslav@1407: } jaroslav@1407: jaroslav@1407: assert exec == 1 : "One exec: " + exec; jaroslav@1407: assert miss == 1 : "One miss: " + miss; jaroslav@1407: } jaroslav@1407: jaroslav@1407: @BrwsrTest public void repeatedTicks() throws Exception { jaroslav@1407: Timer t = new Timer("MyTest"); jaroslav@1407: class TT extends TimerTask { jaroslav@1407: @Override jaroslav@1407: public void run() { jaroslav@1407: exec++; jaroslav@1407: } jaroslav@1407: } jaroslav@1407: TT task = new TT(); jaroslav@1407: t.scheduleAtFixedRate(task, 15, 10); jaroslav@1407: jaroslav@1407: if (exec != 2) { jaroslav@1407: miss++; jaroslav@1407: throw new InterruptedException(); jaroslav@1407: } jaroslav@1407: jaroslav@1407: assert exec == 2 : "Two execs: " + exec; jaroslav@1407: assert miss == 2 : "Two misses: " + miss; jaroslav@1407: } jaroslav@1407: jaroslav@1407: @Factory public static Object[] create() { jaroslav@1407: return VMTest.create(TimerTest.class); jaroslav@1407: } jaroslav@1407: jaroslav@1407: }