encoder_host.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 encoder_host.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/lang/cplus/lex/string_source.hh>
00036 #include <lestes/lang/cplus/lex/encoder_host.hh>
00037 #include <lestes/std/set.hh>
00038 
00039 package(lestes);
00040 package(lang);
00041 package(cplus);
00042 package(lex);
00043 
00044 using namespace ::std;
00045 
00046 #define TEST_CNT 2
00047 
00048 /*!
00049   \brief Tests encoder_host class.
00050 
00051   Performs testing of encoder_host class.
00052 */
00053 void encoder_host_test(void)
00054 {
00055    char *supported =
00056          "\a\b\t\n\v\f\r !\"#$%&'()*+,-./0123456789:;<=>?@"
00057          "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
00058 
00059    // search for char value not expressable
00060    // TODO pt ugly 
00061    ptr< set<ulint> > sch = set<ulint>::create();
00062    for (char *s = supported; *s; s++) {
00063       sch->insert(static_cast<ulint>(*s));
00064    }
00065 
00066    set<ulint>::iterator it = sch->begin();
00067    char c = static_cast<char>(*it);
00068    if (c > CHAR_MIN) {
00069       c--;
00070    } else {
00071       set<ulint>::reverse_iterator rit = sch->rbegin();
00072       c = static_cast<char>(*rit);
00073       lassert(c < CHAR_MAX);
00074       c++;
00075    }
00076    
00077    char unsupported[] = { c, '\0' };
00078 
00079    char *in[TEST_CNT] = {
00080          /* allowed */
00081          supported
00082       ,
00083          /* disallowed */
00084          unsupported
00085    };
00086 
00087    ucn_token_type out[] = {
00088       ucn_token::TOK_NOT_EOF,
00089       ucn_token::TOK_NOT_EOF,
00090       ucn_token::TOK_NOT_EOF,
00091       ucn_token::TOK_NOT_EOF,
00092       ucn_token::TOK_NOT_EOF,
00093       ucn_token::TOK_NOT_EOF,
00094       ucn_token::TOK_NOT_EOF,
00095       ucn_token::TOK_NOT_EOF,
00096       ucn_token::TOK_NOT_EOF,
00097       ucn_token::TOK_NOT_EOF,
00098       ucn_token::TOK_NOT_EOF,
00099       ucn_token::TOK_NOT_EOF,
00100       ucn_token::TOK_NOT_EOF,
00101       ucn_token::TOK_NOT_EOF,
00102       ucn_token::TOK_NOT_EOF,
00103       ucn_token::TOK_NOT_EOF,
00104       ucn_token::TOK_NOT_EOF,
00105       ucn_token::TOK_NOT_EOF,
00106       ucn_token::TOK_NOT_EOF,
00107       ucn_token::TOK_NOT_EOF,
00108       ucn_token::TOK_NOT_EOF,
00109       ucn_token::TOK_NOT_EOF,
00110       ucn_token::TOK_NOT_EOF,
00111       ucn_token::TOK_NOT_EOF,
00112       ucn_token::TOK_NOT_EOF,
00113       ucn_token::TOK_NOT_EOF,
00114       ucn_token::TOK_NOT_EOF,
00115       ucn_token::TOK_NOT_EOF,
00116       ucn_token::TOK_NOT_EOF,
00117       ucn_token::TOK_NOT_EOF,
00118       ucn_token::TOK_NOT_EOF,
00119       ucn_token::TOK_NOT_EOF,
00120       ucn_token::TOK_NOT_EOF,
00121       ucn_token::TOK_NOT_EOF,
00122       ucn_token::TOK_NOT_EOF,
00123       ucn_token::TOK_NOT_EOF,
00124       ucn_token::TOK_NOT_EOF,
00125       ucn_token::TOK_NOT_EOF,
00126       ucn_token::TOK_NOT_EOF,
00127       ucn_token::TOK_NOT_EOF,
00128       ucn_token::TOK_NOT_EOF,
00129       ucn_token::TOK_NOT_EOF,
00130       ucn_token::TOK_NOT_EOF,
00131       ucn_token::TOK_NOT_EOF,
00132       ucn_token::TOK_NOT_EOF,
00133       ucn_token::TOK_NOT_EOF,
00134       ucn_token::TOK_NOT_EOF,
00135       ucn_token::TOK_NOT_EOF,
00136       ucn_token::TOK_NOT_EOF,
00137       ucn_token::TOK_NOT_EOF,
00138       ucn_token::TOK_NOT_EOF,
00139       ucn_token::TOK_NOT_EOF,
00140       ucn_token::TOK_NOT_EOF,
00141       ucn_token::TOK_NOT_EOF,
00142       ucn_token::TOK_NOT_EOF,
00143       ucn_token::TOK_NOT_EOF,
00144       ucn_token::TOK_NOT_EOF,
00145       ucn_token::TOK_NOT_EOF,
00146       ucn_token::TOK_NOT_EOF,
00147       ucn_token::TOK_NOT_EOF,
00148       ucn_token::TOK_NOT_EOF,
00149       ucn_token::TOK_NOT_EOF,
00150       ucn_token::TOK_NOT_EOF,
00151       ucn_token::TOK_NOT_EOF,
00152       ucn_token::TOK_NOT_EOF,
00153       ucn_token::TOK_NOT_EOF,
00154       ucn_token::TOK_NOT_EOF,
00155       ucn_token::TOK_NOT_EOF,
00156       ucn_token::TOK_NOT_EOF,
00157       ucn_token::TOK_NOT_EOF,
00158       ucn_token::TOK_NOT_EOF,
00159       ucn_token::TOK_NOT_EOF,
00160       ucn_token::TOK_NOT_EOF,
00161       ucn_token::TOK_NOT_EOF,
00162       ucn_token::TOK_NOT_EOF,
00163       ucn_token::TOK_NOT_EOF,
00164       ucn_token::TOK_NOT_EOF,
00165       ucn_token::TOK_NOT_EOF,
00166       ucn_token::TOK_NOT_EOF,
00167       ucn_token::TOK_NOT_EOF,
00168       ucn_token::TOK_NOT_EOF,
00169       ucn_token::TOK_NOT_EOF,
00170       ucn_token::TOK_NOT_EOF,
00171       ucn_token::TOK_NOT_EOF,
00172       ucn_token::TOK_NOT_EOF,
00173       ucn_token::TOK_NOT_EOF,
00174       ucn_token::TOK_NOT_EOF,
00175       ucn_token::TOK_NOT_EOF,
00176       ucn_token::TOK_NOT_EOF,
00177       ucn_token::TOK_NOT_EOF,
00178       ucn_token::TOK_NOT_EOF,
00179       ucn_token::TOK_NOT_EOF,
00180       ucn_token::TOK_NOT_EOF,
00181       ucn_token::TOK_NOT_EOF,
00182       ucn_token::TOK_NOT_EOF,
00183       ucn_token::TOK_NOT_EOF,
00184       ucn_token::TOK_NOT_EOF,
00185       ucn_token::TOK_NOT_EOF,
00186       ucn_token::TOK_NOT_EOF,
00187       ucn_token::TOK_NOT_EOF,
00188       ucn_token::TOK_NOT_EOF,
00189       ucn_token::TOK_NOT_EOF,
00190       ucn_token::TOK_EOF,
00191       ucn_token::TOK_ERROR,
00192    };
00193 
00194    ptr<ucn_token> tok;
00195    ucn_token_type utt;
00196    ulint test, i;
00197 
00198    for (i = test = 0; test < TEST_CNT; test++) {
00199       ptr<data_source> ds = string_source::create(string_source::string_type(in[test]));
00200       ptr<encoder_host> enc = encoder_host::create();
00201 
00202       enc->input_set(ds);
00203 
00204       while (true) {
00205          tok = enc->read();
00206          utt = tok->type_get();
00207          lassert(utt == out[i]);
00208          i++;
00209          if (utt == ucn_token::TOK_EOF || utt == ucn_token::TOK_ERROR) break;
00210       }
00211    }
00212 }
00213 
00214 end_package(lex);
00215 end_package(cplus);
00216 end_package(lang);
00217 end_package(lestes);
00218 
00219 /*!
00220   \brief Main function.
00221 
00222   Runs the unit test in different namespace.
00223 */
00224 int main(void)
00225 {
00226    ::lestes::lang::cplus::lex::encoder_host_test();
00227    return 0;
00228 }
00229 /* vim: set ft=lestes : */

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