condition_stack.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 condition_stack.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/equality.hh>
00036 #include <lestes/lang/cplus/lex/condition_stack.hh>
00037 #include <lestes/std/file_info.hh>
00038 #include <lestes/std/source_location.hh>
00039 
00040 package(lestes);
00041 package(lang);
00042 package(cplus);
00043 package(lex);
00044 
00045 using namespace ::std;
00046 
00047 /*!
00048   \brief Tests condition class.
00049 
00050   Performs testing of condition_stack class.
00051 */
00052 void condition_stack_test(void)
00053 {
00054         ptr<source_location> loc = source_location::create(file_info::create("abc",NULL),1,1);
00055         ptr<condition_stack> cs = condition_stack::create();
00056 
00057         lassert(is_equal(cs->active_get(),true));
00058         lassert(is_equal(cs->depth(),0U));
00059 
00060         // error: #else without #if
00061         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),false));
00062         lassert(is_equal(cs->active_get(),true));
00063         lassert(is_equal(cs->depth(),0U));
00064 
00065         // error: #elif without #if
00066         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,false,loc),false));
00067         lassert(is_equal(cs->active_get(),true));
00068         lassert(is_equal(cs->depth(),0U));
00069 
00070         // error: #endif without #if
00071         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),false));
00072         lassert(is_equal(cs->active_get(),true));
00073         lassert(is_equal(cs->depth(),0U));
00074 
00075 
00076         // #if false
00077         lassert(is_equal(cs->process(condition_stack::DIR_IF,false,loc),true));
00078         lassert(is_equal(cs->active_get(),false));
00079         lassert(is_equal(cs->depth(),1U));
00080 
00081         // #endif
00082         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00083         lassert(is_equal(cs->active_get(),true));
00084         lassert(is_equal(cs->depth(),0U));
00085 
00086 
00087         // #if true
00088         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00089         lassert(is_equal(cs->active_get(),true));
00090         lassert(is_equal(cs->depth(),1U));
00091 
00092         // #endif
00093         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00094         lassert(is_equal(cs->active_get(),true));
00095         lassert(is_equal(cs->depth(),0U));
00096 
00097 
00098         // #if false
00099         lassert(is_equal(cs->process(condition_stack::DIR_IF,false,loc),true));
00100         lassert(is_equal(cs->active_get(),false));
00101         lassert(is_equal(cs->depth(),1U));
00102 
00103         // #else
00104         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00105         lassert(is_equal(cs->active_get(),true));
00106         lassert(is_equal(cs->depth(),1U));
00107         
00108         // #endif
00109         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00110         lassert(is_equal(cs->active_get(),true));
00111         lassert(is_equal(cs->depth(),0U));
00112 
00113 
00114         // #if true
00115         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00116         lassert(is_equal(cs->active_get(),true));
00117         lassert(is_equal(cs->depth(),1U));
00118 
00119         // #else
00120         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00121         lassert(is_equal(cs->active_get(),false));
00122         lassert(is_equal(cs->depth(),1U));
00123         
00124         // #endif
00125         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00126         lassert(is_equal(cs->active_get(),true));
00127         lassert(is_equal(cs->depth(),0U));
00128 
00129 
00130         // #if false
00131         lassert(is_equal(cs->process(condition_stack::DIR_IF,false,loc),true));
00132         lassert(is_equal(cs->active_get(),false));
00133         lassert(is_equal(cs->depth(),1U));
00134 
00135         // #elif true
00136         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,true,loc),true));
00137         lassert(is_equal(cs->active_get(),true));
00138         lassert(is_equal(cs->depth(),1U));
00139         
00140         // #elif false
00141         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,false,loc),true));
00142         lassert(is_equal(cs->active_get(),false));
00143         lassert(is_equal(cs->depth(),1U));
00144         
00145         // #endif
00146         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00147         lassert(is_equal(cs->active_get(),true));
00148         lassert(is_equal(cs->depth(),0U));
00149 
00150 
00151         // #if false
00152         lassert(is_equal(cs->process(condition_stack::DIR_IF,false,loc),true));
00153         lassert(is_equal(cs->active_get(),false));
00154         lassert(is_equal(cs->depth(),1U));
00155 
00156         // #elif false
00157         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,false,loc),true));
00158         lassert(is_equal(cs->active_get(),false));
00159         lassert(is_equal(cs->depth(),1U));
00160         
00161         // #elif true
00162         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,true,loc),true));
00163         lassert(is_equal(cs->active_get(),true));
00164         lassert(is_equal(cs->depth(),1U));
00165         
00166         // #endif
00167         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00168         lassert(is_equal(cs->active_get(),true));
00169         lassert(is_equal(cs->depth(),0U));
00170 
00171 
00172         // #if true
00173         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00174         lassert(is_equal(cs->active_get(),true));
00175         lassert(is_equal(cs->depth(),1U));
00176 
00177         // #elif true
00178         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,true,loc),true));
00179         lassert(is_equal(cs->active_get(),false));
00180         lassert(is_equal(cs->depth(),1U));
00181         
00182         // #elif false
00183         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,false,loc),true));
00184         lassert(is_equal(cs->active_get(),false));
00185         lassert(is_equal(cs->depth(),1U));
00186         
00187         // #endif
00188         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00189         lassert(is_equal(cs->active_get(),true));
00190         lassert(is_equal(cs->depth(),0U));
00191 
00192 
00193         // #if true
00194         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00195         lassert(is_equal(cs->active_get(),true));
00196         lassert(is_equal(cs->depth(),1U));
00197 
00198         // #elif false
00199         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,false,loc),true));
00200         lassert(is_equal(cs->active_get(),false));
00201         lassert(is_equal(cs->depth(),1U));
00202         
00203         // #elif true
00204         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,true,loc),true));
00205         lassert(is_equal(cs->active_get(),false));
00206         lassert(is_equal(cs->depth(),1U));
00207         
00208         // #endif
00209         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00210         lassert(is_equal(cs->active_get(),true));
00211         lassert(is_equal(cs->depth(),0U));
00212 
00213 
00214         // #if false
00215         lassert(is_equal(cs->process(condition_stack::DIR_IF,false,loc),true));
00216         lassert(is_equal(cs->active_get(),false));
00217         lassert(is_equal(cs->depth(),1U));
00218 
00219         // #elif false
00220         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,false,loc),true));
00221         lassert(is_equal(cs->active_get(),false));
00222         lassert(is_equal(cs->depth(),1U));
00223         
00224         // #else
00225         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00226         lassert(is_equal(cs->active_get(),true));
00227         lassert(is_equal(cs->depth(),1U));
00228         
00229         // #endif
00230         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00231         lassert(is_equal(cs->active_get(),true));
00232         lassert(is_equal(cs->depth(),0U));
00233 
00234 
00235         // #if false
00236         lassert(is_equal(cs->process(condition_stack::DIR_IF,false,loc),true));
00237         lassert(is_equal(cs->active_get(),false));
00238         lassert(is_equal(cs->depth(),1U));
00239 
00240         // #elif true
00241         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,true,loc),true));
00242         lassert(is_equal(cs->active_get(),true));
00243         lassert(is_equal(cs->depth(),1U));
00244         
00245         // #else
00246         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00247         lassert(is_equal(cs->active_get(),false));
00248         lassert(is_equal(cs->depth(),1U));
00249         
00250         // #endif
00251         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00252         lassert(is_equal(cs->active_get(),true));
00253         lassert(is_equal(cs->depth(),0U));
00254 
00255 
00256         // #if true
00257         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00258         lassert(is_equal(cs->active_get(),true));
00259         lassert(is_equal(cs->depth(),1U));
00260 
00261         // error: eof in #if
00262         lassert(is_equal(cs->process(condition_stack::DIR_EOF,false,loc),false));
00263         lassert(is_equal(cs->active_get(),true));
00264         lassert(is_equal(cs->depth(),1U));
00265         
00266         // #else
00267         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00268         lassert(is_equal(cs->active_get(),false));
00269         lassert(is_equal(cs->depth(),1U));
00270         
00271         // error: #else after #else
00272         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),false));
00273         lassert(is_equal(cs->active_get(),false));
00274         lassert(is_equal(cs->depth(),1U));
00275         
00276         // error: #elif after #else
00277         lassert(is_equal(cs->process(condition_stack::DIR_ELIF,false,loc),false));
00278         lassert(is_equal(cs->active_get(),false));
00279         lassert(is_equal(cs->depth(),1U));
00280         
00281         // clear the #if with #endif
00282         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00283         lassert(is_equal(cs->active_get(),true));
00284         lassert(is_equal(cs->depth(),0U));
00285 
00286 
00287         // #if true
00288         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00289         lassert(is_equal(cs->active_get(),true));
00290         lassert(is_equal(cs->depth(),1U));
00291 
00292         // nested #if true
00293         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00294         lassert(is_equal(cs->active_get(),true));
00295         lassert(is_equal(cs->depth(),2U));
00296 
00297         // nested #else
00298         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00299         lassert(is_equal(cs->active_get(),false));
00300         lassert(is_equal(cs->depth(),2U));
00301         
00302         // nested #endif
00303         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00304         lassert(is_equal(cs->active_get(),true));
00305         lassert(is_equal(cs->depth(),1U));
00306 
00307         // nested #if false
00308         lassert(is_equal(cs->process(condition_stack::DIR_IF,false,loc),true));
00309         lassert(is_equal(cs->active_get(),false));
00310         lassert(is_equal(cs->depth(),2U));
00311 
00312         // nested #else
00313         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00314         lassert(is_equal(cs->active_get(),true));
00315         lassert(is_equal(cs->depth(),2U));
00316         
00317         // nested #endif
00318         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00319         lassert(is_equal(cs->active_get(),true));
00320         lassert(is_equal(cs->depth(),1U));
00321 
00322         // #else
00323         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00324         lassert(is_equal(cs->active_get(),false));
00325         lassert(is_equal(cs->depth(),1U));
00326 
00327         // nested #if true
00328         lassert(is_equal(cs->process(condition_stack::DIR_IF,true,loc),true));
00329         lassert(is_equal(cs->active_get(),false));
00330         lassert(is_equal(cs->depth(),2U));
00331 
00332         // nested #else
00333         lassert(is_equal(cs->process(condition_stack::DIR_ELSE,false,loc),true));
00334         lassert(is_equal(cs->active_get(),false));
00335         lassert(is_equal(cs->depth(),2U));
00336         
00337         // nested #endif
00338         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00339         lassert(is_equal(cs->active_get(),false));
00340         lassert(is_equal(cs->depth(),1U));
00341 
00342         // #endif
00343         lassert(is_equal(cs->process(condition_stack::DIR_ENDIF,false,loc),true));
00344         lassert(is_equal(cs->active_get(),true));
00345         lassert(is_equal(cs->depth(),0U));
00346 
00347 }
00348 
00349 end_package(lex);
00350 end_package(cplus);
00351 end_package(lang);
00352 end_package(lestes);
00353 
00354 /*!
00355   \brief Main function.
00356 
00357   Runs the unit test in different namespace.
00358 */
00359 int main(void)
00360 {
00361 	::lestes::lang::cplus::lex::condition_stack_test();
00362         return 0;
00363 }
00364 /* vim: set ft=lestes : */

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