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

test-all.cc

00001 /*
00002 *  Name:      test-all.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   HTML library test
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 <fstream>
00027 #include <iostream>
00028 #include <mpcl/test.h>
00029 #include <mpcl/text/codegen/pattern_based_code_generator.hh>
00030 #include <mpcl/text/html/anchor.hh>
00031 #include <mpcl/text/html/body.hh>
00032 #include <mpcl/text/html/checkbox.hh>
00033 #include <mpcl/text/html/checkbox_group.hh>
00034 #include <mpcl/text/html/form.hh>
00035 #include <mpcl/text/html/horiz_rule.hh>
00036 #include <mpcl/text/html/hidden.hh>
00037 #include <mpcl/text/html/image_submit_group.hh>
00038 #include <mpcl/text/html/input_image.hh>
00039 #include <mpcl/text/html/layout_table.hh>
00040 #include <mpcl/text/html/option.hh>
00041 #include <mpcl/text/html/page.hh>
00042 #include <mpcl/text/html/password.hh>
00043 #include <mpcl/text/html/pattern_page.hh>
00044 #include <mpcl/text/html/radio.hh>
00045 #include <mpcl/text/html/radio_group.hh>
00046 #include <mpcl/text/html/reset.hh>
00047 #include <mpcl/text/html/select.hh>
00048 #include <mpcl/text/html/submit.hh>
00049 #include <mpcl/text/html/table.hh>
00050 #include <mpcl/text/html/table_cell.hh>
00051 #include <mpcl/text/html/table_row.hh>
00052 #include <mpcl/text/html/text.hh>
00053 #include <mpcl/text/html/text_entry.hh>
00054 
00055 
00056 using mpcl::text::codegen::TPatternBasedCodeGenerator;
00057 using mpcl::text::html::QTTag;
00058 using mpcl::text::html::TAnchor;
00059 using mpcl::text::html::TBody;
00060 using mpcl::text::html::TCheckbox;
00061 using mpcl::text::html::TCheckboxGroup;
00062 using mpcl::text::html::TForm;
00063 using mpcl::text::html::THorizRule;
00064 using mpcl::text::html::THidden;
00065 using mpcl::text::html::TImageSubmitGroup;
00066 using mpcl::text::html::TInputImage;
00067 using mpcl::text::html::TLayoutTable;
00068 using mpcl::text::html::TOption;
00069 using mpcl::text::html::TPage;
00070 using mpcl::text::html::TPatternPage;
00071 using mpcl::text::html::TPassword;
00072 using mpcl::text::html::TRadio;
00073 using mpcl::text::html::TRadioGroup;
00074 using mpcl::text::html::TReset;
00075 using mpcl::text::html::TSelect;
00076 using mpcl::text::html::TSubmit;
00077 using mpcl::text::html::TTable;
00078 using mpcl::text::html::TTableCell;
00079 using mpcl::text::html::TTableRow;
00080 using mpcl::text::html::TTag;
00081 using mpcl::text::html::TText;
00082 using mpcl::text::html::TTextEntry;
00083 
00084 
00085 //
00086 //  L O C A L   F U N C T I O N S
00087 //
00088 
00089 static int _TestPatternPage (void)
00090 {
00091 
00092   using std::cout;
00093 
00094   TAnchor*       ptAnchor1;
00095   TAnchor*       ptAnchor2;
00096   TAnchor*       ptAnchor3;
00097   TPatternPage   tPatternPage ("PatternPage-1", "test-pattern_page.html");
00098 
00099   TEST_INIT ("tests for class 'TPatternPage'");
00100   ptAnchor1 = new TAnchor ("", "anchor-1", "title", QTTag (new TText ("One")));
00101   ptAnchor2 = new TAnchor ("", "anchor-2", "title", QTTag (new TText ("Two")));
00102   ptAnchor3 = new TAnchor ("", "anchor-3", "title", QTTag (new TText ("Three")));
00103   tPatternPage.insert (QTTag (ptAnchor2));
00104   tPatternPage.insert (QTTag (ptAnchor3));
00105   tPatternPage.insert (QTTag (ptAnchor1), tPatternPage.begin());
00106   TEST_NUMBERS (3,    tPatternPage.size());
00107   TEST_NUMBERS (true, ( tPatternPage.begin() != tPatternPage.end() ));
00108   TEST_NUMBERS (true, ( (*tPatternPage.begin())->identifier() == "anchor-1" ));
00109   if ( !TEST_IN_SILENT_MODE )
00110   {
00111     std::cout << tPatternPage;
00112   }
00113   TEST_MEMORY_STATUS;
00114   TEST_RETURN_CODE;
00115 
00116 }  // _TestPatternPage()
00117 
00118 
00119 static int _TestOutput (void)
00120 {
00121 
00122   TEST_INIT ("tests for classes 'html::*'");
00123 
00124   TBody*               ptBody;
00125   TForm*               ptForm;
00126   TCheckboxGroup*      ptCheckboxGroup;
00127   TImageSubmitGroup*   ptImageSubmitGroup;
00128   TLayoutTable*        ptLayoutTable;
00129   TRadioGroup*         ptRadioGroup;
00130   TSelect*             ptSelect;
00131   TTable*              ptTable;
00132   TTableRow*           ptTableRow1;
00133   TTableRow*           ptTableRow2;
00134   TPage                tPage ("page-1");
00135 
00136   ptForm             = new TForm ("form-1", "cgi-bin/test-cgi", "get");
00137   ptCheckboxGroup    = new TCheckboxGroup ("cbg1", "vertical");
00138   ptImageSubmitGroup = new TImageSubmitGroup ("isg1");
00139   ptLayoutTable      = new TLayoutTable ("layout-table", "Table Sample");
00140   ptRadioGroup       = new TRadioGroup ("rg1", "value1", "horizontal");
00141   ptSelect           = new TSelect ("s1", 2, true);
00142   ptTable            = new TTable ("table", "Table Sample");
00143   ptTableRow1        = new TTableRow();
00144   ptTableRow2        = new TTableRow();
00145 
00146   ptForm->insert (QTTag (new THorizRule()));
00147   ptForm->insert (QTTag (new TTextEntry ("te1", "root", "Nombre: ", 10, 20)));
00148   ptForm->insert (QTTag (new TPassword ("te2", "Password: ", 20, 30)));
00149 
00150   ptCheckboxGroup->insert (QTTag (new TCheckbox ("cb1", "Checkbox 1", "value1", true)));
00151   ptCheckboxGroup->insert (QTTag (new TCheckbox ("cb2", "Checkbox 2", "value2", true)));
00152   ptCheckboxGroup->insert (QTTag (new TCheckbox ("cb3", "Checkbox 3", "value3")));
00153   ptCheckboxGroup->insert (QTTag (new TCheckbox ("cb4", "Checkbox 4", "value4")));
00154   ptForm->insert (QTTag (ptCheckboxGroup));
00155 
00156   ptRadioGroup->insert (QTTag (new TRadio ("rb1", "Radio 1", "value1")));
00157   ptRadioGroup->insert (QTTag (new TRadio ("rb2", "Radio 2", "value2")));
00158   ptRadioGroup->insert (QTTag (new TRadio ("rb3", "Radio 3", "value3")));
00159   ptRadioGroup->insert (QTTag (new TRadio ("rb4", "Radio 4", "value4")));
00160   ptForm->insert (QTTag (ptRadioGroup));
00161 
00162   ptImageSubmitGroup->insert (QTTag (new TInputImage ("ii1", "src")));
00163   ptImageSubmitGroup->insert (QTTag (new TInputImage ("ii2", "src")));
00164   ptImageSubmitGroup->insert (QTTag (new TInputImage ("ii3", "src")));
00165   ptImageSubmitGroup->insert (QTTag (new TInputImage ("ii4", "src")));
00166   ptForm->insert (QTTag (ptImageSubmitGroup));
00167 
00168   ptSelect->insert (QTTag (new TOption ("o1", "Option 1", "value1", true)));
00169   ptSelect->insert (QTTag (new TOption ("o2", "Option 2", "value2")));
00170   ptSelect->insert (QTTag (new TOption ("o3", "Option 3", "value3", true)));
00171   ptSelect->insert (QTTag (new TOption ("o4", "Option 4", "value4")));
00172   ptForm->insert (QTTag (ptSelect));
00173 
00174   ptTableRow1->insert (QTTag (new TTableCell (QTTag (new TText ("1-1")))));
00175   ptTableRow1->insert (QTTag (new TTableCell (QTTag (new TTextEntry ("te1", "1-2", "root", 10, 20)))));
00176   ptTableRow2->insert (QTTag (new TTableCell (QTTag (new TText ("2-1")))));
00177   ptTableRow2->insert (QTTag (new TTableCell (QTTag (new TAnchor ("my-ref.html", "Name", "Title", QTTag (new TText ("2-2")))))));
00178   ptTable->insert (QTTag (ptTableRow1));
00179   ptTable->insert (QTTag (ptTableRow2));
00180   ptForm->insert (QTTag (ptTable));
00181 
00182   ptTableRow1 = new TTableRow();
00183   ptTableRow2 = new TTableRow();
00184   ptTableRow1->insert (QTTag (new TTableCell (QTTag (new TText ("text-1-1", "1-1")))));
00185   ptTableRow1->insert (QTTag (new TTableCell (QTTag (new TTextEntry ("te1", "1-2", "root", 10, 20)))));
00186   ptTableRow2->insert (QTTag (new TTableCell (QTTag (new TText ("text-2-1", "2-1")))));
00187   ptTableRow2->insert (QTTag (new TTableCell (QTTag (new TAnchor ("my-ref.html", "Name", "Title", QTTag (new TText ("2-2")))))));
00188   ptLayoutTable->insert (QTTag (ptTableRow1));
00189   ptLayoutTable->insert (QTTag (ptTableRow2));
00190   ptForm->insert (QTTag (ptLayoutTable));
00191 
00192   ptForm->insert (QTTag (new THorizRule()));
00193   ptForm->insert (QTTag (new TSubmit ("s1", "Submit-1")));
00194   ptForm->insert (QTTag (new TReset ("r1", "Reset-1")));
00195   ptForm->insert (QTTag (new THidden ("h1", "Hidden-1")));
00196 
00197   ptBody = tPage.tag ("body").dynamicCast<TBody*>();
00198   ptBody->insert (QTTag (ptForm));
00199   ptBody->insert (QTTag (new TAnchor ("", "Alt-message", "Title-message", QTTag (new TText ("Ejemplo de enlace")))));
00200   if ( !TEST_IN_SILENT_MODE )
00201   {
00202     std::cout << tPage;
00203   }
00204 
00205   //
00206   //  Checks TLayoutTable.
00207   //
00208   ptLayoutTable->setDynamiclyLoadable (true);
00209   TEST_STRINGS ("1-2", tPage ["body"]["form-1"]["layout-table"]["te1"].getValue().c_str());
00210   TEST_STRINGS ("1-1", tPage ["body"]["form-1"]["layout-table"]["text-1-1"].getValue().c_str());
00211   TEST_STRINGS ("2-1", tPage ["body"]["form-1"]["layout-table"]["text-2-1"].getValue().c_str());
00212   TEST_STRINGS ("text-3-1", (tPage.findOrInsertTag ("body/form-1/layout-table/text-3-1"))->identifier().c_str());
00213 
00214   TEST_MEMORY_STATUS;
00215   TEST_RETURN_CODE;
00216 
00217 }  // _TestOutput()
00218 
00219 
00221 int main (void)
00222 {
00223 
00224   TEST_INIT ("tests for HTML");
00225   try
00226   {
00227     TPatternBasedCodeGenerator   tPbcg1 ("html-2.0.cdml",           "../../../../../data/cdml");
00228     TPatternBasedCodeGenerator   tPbcg2 ("html-3.2.cdml",           "../../../../../data/cdml");
00229     TPatternBasedCodeGenerator   tPbcg3 ("html-3.2-netscape.cdml",  "../../../../../data/cdml");
00230     TPatternBasedCodeGenerator   tPbcg4 ("html-4.01.cdml",          "../../../../../data/cdml");
00231     TPatternBasedCodeGenerator   tPbcg5 ("html-4.01-netscape.cdml", "../../../../../data/cdml");
00232     
00233     TTag::_setCodeGenerator (tPbcg1); TEST_FUNCTION (_TestOutput());
00234     TTag::_setCodeGenerator (tPbcg2); TEST_FUNCTION (_TestOutput());
00235     TTag::_setCodeGenerator (tPbcg3); TEST_FUNCTION (_TestOutput());
00236     TTag::_setCodeGenerator (tPbcg4); TEST_FUNCTION (_TestOutput());
00237     TEST_FUNCTION (_TestPatternPage());
00238   }
00239   catch (const mpcl::TException& rktEXCEPTION)
00240   {
00241     std::cerr << rktEXCEPTION;
00242     TEST_FAIL;
00243   }
00244   catch (std::exception& rktEXCEPTION)
00245   {
00246     std::cerr << rktEXCEPTION.what();
00247     TEST_FAIL;
00248   }
00249   TEST_MEMORY_STATUS;
00250   TEST_RETURN_CODE;
00251 
00252 }  // main()

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