pp_token.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 pp_token.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/equality.hh>
00036 #include <lestes/std/source_location.hh>
00037 #include <lestes/std/file_info.hh>
00038 #include <lestes/lang/cplus/lex/pp_token.hh>
00039 #include <lestes/lang/cplus/lex/token_value.hh>
00040 
00041 package(lestes);
00042 package(lang);
00043 package(cplus);
00044 package(lex);
00045 
00046 using namespace ::std;
00047 
00048 /*!
00049   \brief Tests pp_token class.
00050 
00051   Performs testing of pp_token class.
00052 */
00053 void pp_token_test(void)
00054 {
00055         ptr<file_info> fi = file_info::create("foobar.h",NULL);
00056         ptr<source_location> loc = source_location::create(fi,2,3);
00057         ptr<token_value> s = token_value::create("123");
00058         ptr<token_value> t = token_value::create("123");
00059         ptr<token_value> u = token_value::create("abc");
00060         ptr<token_value> v = token_value::create("abc");
00061         
00062         ptr<pp_token> a = pp_token::create(loc,pp_token::TOK_NUMBER_LIT,s);
00063 
00064         lassert(is_equal(a,a));
00065         lassert(is_equal(a->type_get(),pp_token::TOK_NUMBER_LIT));
00066         lassert(is_equal(a->value_get(),t));
00067         lassert(is_equal(a->location_get()->file_get(),fi));
00068         lassert(is_equal(a->location_get()->line_get(),2U));
00069         lassert(is_equal(a->location_get()->column_get(),3U));
00070         lassert(is_equal(a->flags_get(),pp_token::FLG_LITERAL));
00071                 
00072         a->type_set(pp_token::TOK_STRING_LIT);
00073         a->value_set(u);
00074         a->location_set(source_location::create(fi,0,0));
00075         a->flags_set(pp_token::FLG_ERROR);
00076 
00077         lassert(is_equal(a->type_get(),pp_token::TOK_STRING_LIT));
00078         lassert(is_equal(a->value_get(),v));
00079         lassert(is_equal(a->location_get()->file_get(),fi));
00080         lassert(is_equal(a->location_get()->line_get(),0U));
00081         lassert(is_equal(a->location_get()->column_get(),0U));
00082         lassert(is_equal(a->flags_get(),(pp_token::FLG_LITERAL | pp_token::FLG_ERROR)));
00083                 
00084         ptr<pp_token> b = a->clone();
00085 
00086         lassert(is_equal(b,a));
00087         lassert(is_equal(a,b));
00088         lassert(is_equal(b->type_get(),pp_token::TOK_STRING_LIT));
00089         lassert(is_equal(b->value_get(),v));
00090         lassert(is_equal(b->location_get()->file_get(),fi));
00091         lassert(is_equal(b->location_get()->line_get(),0U));
00092         lassert(is_equal(b->location_get()->column_get(),0U));
00093         lassert(is_equal(b->flags_get(),(pp_token::FLG_LITERAL | pp_token::FLG_ERROR)));
00094                 
00095         ptr<pp_token> c;
00096 
00097         c = a;
00098         lassert(is_equal(c,a));
00099         lassert(is_equal(a,c));
00100         lassert(is_equal(c->type_get(),pp_token::TOK_STRING_LIT));
00101         lassert(is_equal(c->value_get(),v));
00102         lassert(is_equal(c->location_get()->file_get(),fi));
00103         lassert(is_equal(c->location_get()->line_get(),0U));
00104         lassert(is_equal(c->location_get()->column_get(),0U));
00105         lassert(is_equal(c->flags_get(),(pp_token::FLG_LITERAL | pp_token::FLG_ERROR)));
00106 }
00107 
00108 end_package(lex);
00109 end_package(cplus);
00110 end_package(lang);
00111 end_package(lestes);
00112 
00113 int main(void)
00114 {
00115         lestes::lang::cplus::lex::pp_token_test();
00116         return 0;
00117 }
00118 
00119 /* vim: set ft=lestes : */

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