sa_decl_spec.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 sa_decl_spec.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/std/file_info.hh>
00036 #include <lestes/std/source_location.hh>
00037 #include <lestes/lang/cplus/sem/sa_decl_spec.g.hh>
00038 #include <lestes/lang/cplus/sem/as_decl.g.hh>
00039 #include <lestes/lang/cplus/sem/as_other.g.hh>
00040 #include <lestes/lang/cplus/sem/ss_type.g.hh>
00041 #include <lestes/lang/cplus/sem/ss_enums.g.hh>
00042 #include <lestes/lang/cplus/sem/ss_type_builtin.g.hh>
00043 
00044 package(lestes);
00045 package(lang);
00046 package(cplus);
00047 package(sem);
00048 
00049 using namespace ::std;
00050 
00051 #define lassert_no_specifiers(x) \
00052         lassert(sads->explicit_flag_get() == false); \
00053         lassert(sads->inline_flag_get() == false); \
00054         lassert(sads->friend_flag_get() == false); \
00055         lassert(sads->virtual_flag_get() == false); \
00056         lassert(sads->storage_get() == ss_storage_class::ST_NONE);
00057 
00058 /*!
00059   \brief Tests sa_decl_spec class.
00060 
00061   Performs testing of sa_decl_spec class.
00062 */
00063 void sa_decl_spec_test(void)
00064 {
00065         ptr<file_info> fi = file_info::create("abc",NULL);
00066         ptr<source_location> loc = source_location::create(fi,1,1);
00067         typedef sa_decl_spec::as_decl_spec_list_type ds_list_type;
00068         
00069         ptr<ds_list_type> dsl = ds_list_type::create();
00070         ptr<sa_decl_spec_context> ctx =
00071                 sa_decl_spec_context::create(declaration_context::CTX_NAMESPACE);
00072         ptr<sa_decl_spec> sads = sa_decl_spec::create(ctx);
00073                 
00074         dsl->push_back(as_int_simple_type_specifier::create(loc));
00075         sads->process(dsl);
00076         lassert(sads->type_get() == ss_type_sint::instance());
00077         lassert_no_specifiers(sads);
00078         dsl->clear();
00079 
00080         dsl->push_back(as_unsigned_simple_type_specifier::create(loc));
00081         sads->process(dsl);
00082         lassert(sads->type_get() == ss_type_uint::instance());
00083         lassert_no_specifiers(sads);
00084         dsl->clear();
00085 
00086         dsl->push_back(as_short_simple_type_specifier::create(loc));
00087         sads->process(dsl);
00088         lassert(sads->type_get() == ss_type_sshort::instance());
00089         lassert_no_specifiers(sads);
00090         dsl->clear();
00091 
00092         dsl->push_back(as_int_simple_type_specifier::create(loc));
00093         dsl->push_back(as_long_simple_type_specifier::create(loc));
00094         dsl->push_back(as_unsigned_simple_type_specifier::create(loc));
00095         sads->process(dsl);
00096         lassert(sads->type_get() == ss_type_ulong::instance());
00097         lassert_no_specifiers(sads);
00098         dsl->clear();
00099         
00100         dsl->push_back(as_char_simple_type_specifier::create(loc));
00101         dsl->push_back(as_unsigned_simple_type_specifier::create(loc));
00102         sads->process(dsl);
00103         lassert(sads->type_get() == ss_type_uchar::instance());
00104         lassert_no_specifiers(sads);
00105         dsl->clear();
00106         
00107         dsl->push_back(as_char_simple_type_specifier::create(loc));
00108         dsl->push_back(as_signed_simple_type_specifier::create(loc));
00109         sads->process(dsl);
00110         lassert(sads->type_get() == ss_type_schar::instance());
00111         lassert_no_specifiers(sads);
00112         dsl->clear();
00113         
00114         dsl->push_back(as_char_simple_type_specifier::create(loc));
00115         sads->process(dsl);
00116         lassert(sads->type_get() == ss_type_pchar::instance());
00117         lassert_no_specifiers(sads);
00118         dsl->clear();
00119 
00120         dsl->push_back(as_int_simple_type_specifier::create(loc));
00121         dsl->push_back(as_cv_qualifier_const::create(loc));
00122         sads->process(dsl);
00123         lassert(sads->type_get() == ss_const::instance(ss_type_sint::instance()));
00124         lassert_no_specifiers(sads);
00125         dsl->clear();
00126 
00127         lassert(ss_const::instance(ss_volatile::instance(ss_type_sint::instance())) ==
00128                 ss_const::instance(ss_volatile::instance(ss_type_sint::instance())));
00129                 
00130         lassert(ss_const::instance(ss_volatile::instance(ss_type_sint::instance())) ==
00131                 ss_volatile::instance(ss_const::instance(ss_type_sint::instance())));
00132                 
00133         dsl->push_back(as_int_simple_type_specifier::create(loc));
00134         dsl->push_back(as_cv_qualifier_const::create(loc));
00135         dsl->push_back(as_cv_qualifier_volatile::create(loc));
00136         sads->process(dsl);
00137         lassert(sads->type_get() ==
00138                 ss_const::instance(ss_volatile::instance(ss_type_sint::instance())));
00139         lassert_no_specifiers(sads);
00140         dsl->clear();
00141 
00142 }
00143 
00144 end_package(sem);
00145 end_package(cplus);
00146 end_package(lang);
00147 end_package(lestes);
00148 
00149 /*!
00150   \brief Main function.
00151 
00152   Runs the unit test in different namespace.
00153 */
00154 int main(void)
00155 {
00156 	::lestes::lang::cplus::sem::sa_decl_spec_test();
00157         return 0;
00158 }
00159 /* vim: set ft=lestes : */

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