message_stencil.test.cc

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
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    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 /*! \file
00029   \brief Unit test.
00030   
00031   Unit test for class message_stencil.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/equality.hh>
00036 #include <lestes/msg/message_stencil.hh>
00037 
00038 #include <iostream>
00039 
00040 package(lestes);
00041 package(msg);
00042 
00043 using namespace ::std;
00044 
00045 /*!
00046   \brief Tests message_stencil class.
00047 
00048   Performs testing of message_stencil class.
00049 */
00050 void message_stencil_test(void)
00051 {
00052         ptr< message_stencil0<bool> > ms0 = message_stencil0<bool>::create("%%message_stencil0%%",message::FLG_ERROR);
00053         lassert(is_equal(ms0,ms0));
00054         lassert(is_equal(ms0->nparams_get(),0U));
00055         
00056         ptr<message> m0 = ms0->format();
00057         lassert(is_equal(m0->kind_get(),ms0->kind_get()));
00058         //::std::cerr << "`" << m0->text_get() << "'" << ::std::endl;
00059         lassert(is_equal(m0->text_get(),"%message_stencil0%"));
00060         lassert(is_equal(m0->flags_get(),message::FLG_ERROR));
00061         
00062         ptr< message_stencil1<ulint> > ms1 = 
00063                 message_stencil1<ulint>::create("%0 message_stencil1 %0",message::FLG_ERROR,formatter<ulint>::instance());
00064         lassert(!is_equal(ms1,ms0));
00065         lassert(is_equal(ms1,ms1));
00066         lassert(is_equal(ms1->nparams_get(),1U));
00067 
00068         ptr<message> m1 = ms1->format(9);
00069         lassert(is_equal(m1->kind_get(),ms1->kind_get()));
00070         lassert(is_equal(m1->text_get(),"9 message_stencil1 9"));
00071         lassert(is_equal(m1->flags_get(),message::FLG_ERROR));
00072         
00073         ptr< message_stencil2<ulint,ulint> > ms2 = 
00074                 message_stencil2<ulint,ulint>::create("%0%1 message_stencil2 %1%0",message::FLG_ERROR,
00075                                 formatter<ulint>::instance(),formatter<ulint>::instance());
00076         lassert(!is_equal(ms2,ms0));
00077         lassert(!is_equal(ms2,ms1));
00078         lassert(is_equal(ms2,ms2));
00079         lassert(is_equal(ms2->nparams_get(),2U));
00080         
00081         ptr<message> m2 = ms2->format(6,7);
00082         lassert(is_equal(m2->kind_get(),ms2->kind_get()));
00083         lassert(is_equal(m2->text_get(),"67 message_stencil2 76"));
00084         lassert(is_equal(m2->flags_get(),message::FLG_ERROR));
00085         
00086         ptr< message_stencil3<ulint,ulint,lstring> > ms3 = 
00087                 message_stencil3<ulint,ulint,lstring>::create("%0%1%2 message_stencil3 %2%1%0",message::FLG_ERROR,
00088                                 formatter<ulint>::instance(),formatter<ulint>::instance(),formatter<lstring>::instance());
00089         lassert(!is_equal(ms3,ms0));
00090         lassert(!is_equal(ms3,ms1));
00091         lassert(!is_equal(ms3,ms2));
00092         lassert(is_equal(ms3,ms3));
00093         lassert(is_equal(ms3->nparams_get(),3U));
00094         
00095         ptr<message> m3 = ms3->format(1,2,"xyz");
00096         lassert(is_equal(m3->kind_get(),ms3->kind_get()));
00097         lassert(is_equal(m3->text_get(),"12xyz message_stencil3 xyz21"));
00098         lassert(is_equal(m3->flags_get(),message::FLG_ERROR));
00099         
00100 }
00101 
00102 end_package(msg);
00103 end_package(lestes);
00104 
00105 /*!
00106   \brief Main function.
00107 
00108   Runs the unit test in different namespace.
00109 */
00110 int main(void)
00111 {
00112 	::lestes::msg::message_stencil_test();
00113         return 0;
00114 }
00115 /* vim: set ft=lestes : */
00116 

Generated on Mon Feb 12 18:22:41 2007 for lestes by doxygen 1.5.1-20070107