001/* Copyright (C) 2013 TU Dortmund 002 * This file is part of LearnLib, http://www.learnlib.de/. 003 * 004 * LearnLib is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Lesser General Public 006 * License version 3.0 as published by the Free Software Foundation. 007 * 008 * LearnLib is distributed in the hope that it will be useful, 009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 011 * Lesser General Public License for more details. 012 * 013 * You should have received a copy of the GNU Lesser General Public 014 * License along with LearnLib; if not, see 015 * <http://www.gnu.de/documents/lgpl.en.html>. 016 */ 017package de.learnlib.drivers.api; 018 019import de.learnlib.api.SUL; 020 021/** 022 * A test driver executes 023 * 024 * 025 * @author falkhowar 026 * 027 * @param <AI> abstract input type 028 * @param <CI> concrete input type 029 * @param <AO> abstract output type 030 * @param <CO> concrete output type 031 */ 032public class TestDriver<AI, AO, CI extends ExecutableInput<CO>, CO> implements SUL<AI, AO> { 033 034 private final DataMapper<AI, AO, CI, CO> mapper; 035 036 public TestDriver(DataMapper<AI, AO, CI, CO> mapper) { 037 this.mapper = mapper; 038 } 039 040 @Override 041 public AO step(AI i) { 042 ExecutableInput<CO> ci = this.mapper.input(i); 043 try { 044 CO out = ci.execute(); 045 return this.mapper.output(out); 046 } 047 catch (SULException e) { 048 return this.mapper.exception(e); 049 } 050 } 051 052 @Override 053 public void pre() { 054 mapper.pre(); 055 } 056 057 @Override 058 public void post() { 059 mapper.post(); 060 } 061 062}