Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

test-executable_streamable_dfa.cc

00001 /*
00002 *  Name:      test-executable_streamable_dfa.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for Executable Streamable Deterministic Finite Automaton
00005 *  Date:      $Date: 2003/10/06 12:45:11 $
00006 *  Revision:  $Revision: 1.2 $
00007 *
00008 *  Copyright (C) 1999-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <fstream>
00027 #include <mpcl/automaton/executable_streamable_dfa.hh>
00028 #include <mpcl/test.h>
00029 #include <sstream>
00030 
00031 
00032 using mpcl::automaton::TActionHandler;
00033 using mpcl::automaton::TExecutableStreamableDfa;
00034 using mpcl::event::IAction;
00035 using mpcl::event::TEventHandler;
00036 using mpcl::text::TString;
00037 
00038 
00039 //
00040 //  L O C A L   T Y P E S
00041 //
00042 
00043 class TTestAction : public IAction
00044 {
00045 
00046   public:
00047 
00048     TTestAction (const TString& rkySOURCE_NAME) :
00049       IAction (rkySOURCE_NAME)                  {}
00050 
00051     bool execute (void)
00052     {
00053       if ( !TEST_IN_SILENT_MODE )
00054       {
00055         fprintf (hptTestTargetFile, "#ACTION:   %s\n", getName().c_str());
00056       }
00057       return true;
00058     }
00059     
00060     int react (void)
00061     {
00062       if ( !TEST_IN_SILENT_MODE )
00063       {
00064         fprintf (hptTestTargetFile, "#REACTION: %s\n", getName().c_str());
00065       }
00066       return 0;
00067     }
00068     
00069 };  // class TTestAction
00070 
00071 
00072 class TTestActionHandler : public TActionHandler<int>
00073 {
00074 
00075   public:
00076 
00077     TTestActionHandler (void) : TActionHandler<int>()
00078     {
00079       tActionList.push_back (new TTestAction ("run"));
00080       tActionList.push_back (new TTestAction ("eat"));
00081       tActionList.push_back (new TTestAction ("die"));
00082     }
00083 
00084 };  // class TTestActionHandler
00085 
00086 
00088 int main (void)
00089 {
00090 
00091   TEST_INIT ("tests for class 'TExecutableStreamableDfa'");
00092 
00093   TTestActionHandler                   tActionHandler;
00094   TEventHandler<int>                   tEventHandler;
00095   std::basic_ostringstream<char>       tOutputOstringstream;
00096   std::ifstream                        tInputIfstream ("test-executable_streamable_dfa.dfaml");
00097   TExecutableStreamableDfa<int, int>   tTestESDFA (tEventHandler, tActionHandler);
00098 
00099   tInputIfstream >> tTestESDFA;
00100   if ( TEST_IN_SILENT_MODE )
00101   {
00102     tOutputOstringstream << tTestESDFA;
00103   }
00104   else
00105   {
00106     std::cerr << tTestESDFA;
00107   }
00108   
00109   TEST_MEMORY_STATUS;
00110   TEST_RETURN_CODE;
00111 
00112 }  // main()

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18