00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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
00095
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
00110
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 }