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

test-pattern_based_code_generator.cc

00001 /*
00002 *  Name:      test-pattern_based_code_generator.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Test for CODEGEN
00005 *  Date:      $Date: 2003/10/06 12:45:11 $
00006 *  Revision:  $Revision: 1.2 $
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 <iostream>
00027 #include <mpcl/text/codegen/pattern_based_code_generator.hh>
00028 #include <mpcl/test.h>
00029 
00030 
00032 int main (void)
00033 {
00034 
00035   using mpcl::text::codegen::TBadInstantiateSyntaxException;
00036   using mpcl::text::codegen::TPatternBasedCodeGenerator;
00037   using mpcl::text::TString;
00038   using mpcl::util::collection::TStringToStringMap;
00039 
00040   TEST_INIT ("tests for class 'TPatternBasedCodeGenerator'");
00041 
00042   TString                      yCorrectInstance11;
00043   TString                      yCorrectInstance12;
00044   TString                      yInstance1;
00045   TString                      yInstance2;
00046   TString                      yInstance3;
00047   TString                      yInstance4;
00048   TString                      yInstance5;
00049   TPatternBasedCodeGenerator   tCG1;
00050   TPatternBasedCodeGenerator   tCG2 ("test-pattern_based_code_generator.cdml", ".");
00051   TStringToStringMap           tStringToStringMap;
00052   
00053   TEST_NUMBERS (true,  tCG2.existsClause ("instruction-1", "clause-1"));
00054   TEST_NUMBERS (true,  tCG2.existsClause ("instruction-1", "clause-2"));
00055   TEST_NUMBERS (false, tCG2.existsClause ("instruction-3", ""));
00056   TEST_NUMBERS (false, tCG2.existsClause ("instruction-1", "clause-3"));
00057 
00058   //
00059   //  Checks for instantiation.
00060   //
00061   tStringToStringMap.bind ("param_1", "1-1-value_1");
00062   tStringToStringMap.bind ("param_2", "1-1-value_2");
00063   yCorrectInstance11 = "          <1-1-value_1>\n0123456789<1-1-value_2>\n";
00064   yCorrectInstance12 = "";
00065   yInstance1 = tCG2 ["instruction-1"]["clause-1"].instantiate (tStringToStringMap);
00066   yInstance2 = tCG2 ["instruction-1"]["clause-1"].instantiate ( "param_1"     ,
00067                                                                 "1-1-value_1" ,
00068                                                                 "param_2"     ,
00069                                                                 "1-1-value_2" ,
00070                                                                 NULL          );
00071   try
00072   {
00073     yInstance3 = tCG2.codePatternFor ("instruction-1", "clause-2").instantiate ( "param_1"     ,
00074                                                                                  "1-2-value_1" ,
00075                                                                                  NULL          );
00076     TEST_FAIL;
00077   }
00078   catch (const TBadInstantiateSyntaxException& rktEXCEPTION)
00079   {
00080     //
00081     //  There is no 'param_1' in clause code.
00082     //
00083     TEST_PASS;
00084   }
00085   yInstance4 = tCG2.codePatternFor ("instruction-1", "clause-2").instantiate();
00086   yInstance5 = tCG2 ["instruction-1"]["clause-2"].instantiate();
00087   TEST_STRINGS (yCorrectInstance11.c_str(), yInstance1.c_str());
00088   TEST_STRINGS (yCorrectInstance11.c_str(), yInstance2.c_str());
00089   TEST_STRINGS (yCorrectInstance12.c_str(), yInstance3.c_str());
00090   TEST_STRINGS (yCorrectInstance12.c_str(), yInstance4.c_str());
00091   TEST_STRINGS (yCorrectInstance12.c_str(), yInstance5.c_str());
00092 
00093   //
00094   //  Sets an inexistent path and tries to load
00095   //  an inexistent CDML document.
00096   //
00097   tCG1.setCdmlPath ("/there/is/no/such/path/");
00098   try
00099   {
00100     tCG1.loadFrom ("inexistent file");
00101     TEST_FAIL;
00102   }
00103   catch (const mpcl::TException& rktEXCEPTION)
00104   {
00105     TEST_PASS;
00106   }
00107     
00108   //
00109   //  Set an existent path and tries to load
00110   //  an inexistent CDML document.
00111   //
00112   tCG1.setCdmlPath ("/");
00113   try
00114   {
00115     tCG1.loadFrom ("inexistent file");
00116     TEST_FAIL;
00117   }
00118   catch (const mpcl::TException& rktEXCEPTION)
00119   {
00120     TEST_PASS;
00121   }
00122 
00123   TEST_MEMORY_STATUS;
00124   TEST_RETURN_CODE;
00125 
00126 }  // main()

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