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

test-verifier.cc

00001 /*
00002 *  Name:      test-verifier.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for base invariant verifier
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-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 <mpcl/invariant/verifier.hh>
00027 #include <mpcl/test.h>
00028 
00029 
00030 using mpcl::invariant::IVerifier;
00031 
00032 
00033 class TVerifier : public IVerifier<int>
00034 {
00035 
00036   public:
00037 
00038     enum { FIRST_LEVEL, SECOND_LEVEL, THIRD_LEVEL };
00039     enum { FIRST_RULE, SECOND_RULE, THIRD_RULE, FOURTH_RULE };
00040       
00041 
00042   public:
00043 
00044     //
00045     //  C O N S T R U C T O R S
00046     //
00047 
00049     TVerifier (void)               :
00050       IVerifier<int> (FIRST_LEVEL) {}
00051     
00052 
00053   public:
00054 
00055     //
00056     //  S E L E C T O R S
00057     //
00058     
00065     bool verify (long int liINVARIANT_IDENTIFIER) const;
00066 
00067 };  // class TVerifier
00068 
00069 
00070 bool TVerifier::verify (long int liINVARIANT_IDENTIFIER) const
00071 {
00072 
00073   bool   gSuccess = false;
00074 
00075   switch (liINVARIANT_IDENTIFIER)
00076   {
00077     case FIRST_RULE:
00078     {
00079       gSuccess = ( tArgumentArray [0] < 1000 );
00080       break;
00081     }
00082     case SECOND_RULE:
00083     {
00084       gSuccess = ( tArgumentArray [0] < 100 );
00085       break;
00086     }
00087     case THIRD_RULE:
00088     {
00089       gSuccess = ( tArgumentArray [0] < 10 );
00090       break;
00091     }
00092     case FOURTH_RULE:
00093     {
00094       gSuccess = ( tArgumentArray [0] < 1 );
00095       break;
00096     }
00097   }
00098   return gSuccess;
00099 
00100 }  // TVerifier::verify()
00101  
00102 
00104 int main (void)
00105 {
00106 
00107   TEST_INIT ("tests for class 'IVerifier'");
00108 
00109   TVerifier   tRV;
00110   
00111   tRV.tConformanceLevelSet.insert (TVerifier::FIRST_LEVEL);
00112   tRV.tConformanceLevelSet.insert (TVerifier::SECOND_LEVEL);
00113   tRV.tConformanceLevelSet.insert (TVerifier::THIRD_LEVEL);
00114 
00115   tRV.addInvariant (TVerifier::FIRST_RULE,  TVerifier::FIRST_LEVEL,  "Less than 1000");
00116   tRV.addInvariant (TVerifier::SECOND_RULE, TVerifier::FIRST_LEVEL,  "Less than 100");
00117   tRV.addInvariant (TVerifier::THIRD_RULE,  TVerifier::SECOND_LEVEL, "Less than 10");
00118   tRV.addInvariant (TVerifier::FOURTH_RULE, TVerifier::THIRD_LEVEL,  "Less than 1");
00119 
00120   tRV.require (TVerifier::FIRST_RULE, 999);
00121 
00122   tRV.tConformanceLevelSet.erase (TVerifier::FIRST_LEVEL);
00123   tRV.require (TVerifier::FIRST_RULE,  1000);
00124   tRV.require (TVerifier::SECOND_RULE, 1000);
00125   tRV.require (TVerifier::THIRD_RULE,     9);
00126 
00127   TEST_MEMORY_STATUS;
00128   TEST_RETURN_CODE;
00129 
00130 }  // main()

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