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

test-streamable_dfa.cc

00001 /*
00002 *  Name:      test-streamable_dfa.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for 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/streamable_dfa.hh>
00028 #include <mpcl/io/output_streamable.hh>
00029 #include <mpcl/test.h>
00030 #include <sstream>
00031 
00032 
00033 using mpcl::automaton::TStreamableDfa;
00034 using mpcl::event::TEventHandler;
00035 using mpcl::io::IOutputStreamable;
00036 using std::basic_ostringstream;
00037 using std::basic_ifstream;
00038 using std::basic_ostream;
00039 
00040 
00041 //
00042 //  L O C A L   T Y P E S
00043 //
00044 
00045 class TTestEvent : public IOutputStreamable<>
00046 {
00047 
00048   private:
00049 
00050     char   cValue;
00051 
00052 
00053   protected:
00054 
00055     void write (basic_ostream<char_type, traits_type>& rtTARGET_OSTREAM) const
00056     {
00057       rtTARGET_OSTREAM << cValue;
00058     }
00059 
00060 
00061   public:
00062 
00063     TTestEvent (void)            :
00064       IOutputStreamable<> ()     ,
00065       cValue              ('\0') {}
00066 
00067     TTestEvent (char cSOURCE)       :
00068       IOutputStreamable<> ()        ,
00069       cValue              (cSOURCE) {}
00070 
00071     bool operator < (const TTestEvent&) const
00072     {
00073       return false;
00074     }
00075 
00076     bool operator == (const TTestEvent& rktSOURCE_EVENT) const
00077     {
00078       return ( cValue == rktSOURCE_EVENT.cValue );
00079     }
00080 
00081 };  // class TTestEvent
00082 
00083 
00084 class TTestStreamableDfa : public TStreamableDfa<int, TTestEvent>
00085 {
00086 
00087   public:
00088     
00089     TTestStreamableDfa (TEventHandler<TTestEvent>& rtSOURCE_EVENT_HANDLER) :
00090       TStreamableDfa<int, TTestEvent> (rtSOURCE_EVENT_HANDLER)
00091     {
00092       tStringToEventMap.bind ("event_zero",  TTestEvent ('0'));
00093       tStringToEventMap.bind ("event_one",   TTestEvent ('1'));
00094       tStringToEventMap.bind ("event_two",   TTestEvent ('2'));
00095       tStringToEventMap.bind ("event_three", TTestEvent ('3'));
00096     }
00097 
00098 };  // class TTestStreamableDfa
00099 
00100 
00102 int main (void)
00103 {
00104 
00105   TEST_INIT ("tests for class 'TStreamableDfa'");
00106 
00107   try
00108   {
00109     TEventHandler<TTestEvent>   tEventHandler;
00110     basic_ostringstream<char>   tOutputOstringstream;
00111     basic_ifstream<char>        tInputIfstream ("test-streamable_dfa.dfaml");
00112     TTestStreamableDfa          tTestSDFA (tEventHandler);
00113 
00114     //
00115     //  This is the path to the final state.
00116     //
00117     tEventHandler.push (TTestEvent ('0'));
00118     tEventHandler.push (TTestEvent ('1'));
00119     tEventHandler.push (TTestEvent ('2'));
00120     tEventHandler.push (TTestEvent ('3'));
00121     tInputIfstream >> tTestSDFA;
00122     if ( TEST_IN_SILENT_MODE )
00123     {
00124       tOutputOstringstream << tTestSDFA;
00125     }
00126     else
00127     {
00128       std::cerr << tTestSDFA;
00129     }
00130     tTestSDFA.start();
00131     TEST_PASS;
00132   }
00133   catch (const mpcl::TException& rktEXCEPTION)
00134   {
00135     if ( !TEST_IN_SILENT_MODE )
00136     {
00137       fprintf ( hptTestTargetFile                          ,
00138                 "#ERROR: %s:%d:%s; %s\n"                   ,
00139                 rktEXCEPTION.fileName().c_str()            ,
00140                 rktEXCEPTION.lineNumber()                  ,
00141                 rktEXCEPTION.generalDescription().c_str()  ,
00142                 rktEXCEPTION.specificDescription().c_str() );
00143     }
00144     TEST_FAIL;
00145   }
00146   TEST_MEMORY_STATUS;
00147   TEST_RETURN_CODE;
00148 
00149 }  // main()

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