encoder_ascii7.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_ascii7.
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_ascii7.hh>
00037 
00038 package(lestes);
00039 package(lang);
00040 package(cplus);
00041 package(lex);
00042 
00043 using namespace ::std;
00044 
00045 #define TEST_CNT 9
00046 
00047 /*!
00048   \brief Tests encoder_ascii7 class.
00049 
00050   Performs testing of encoder_ascii7 class.
00051 */
00052 void encoder_ascii7_test(void)
00053 {
00054         char *in[TEST_CNT] = {
00055                         /* allowed */
00056                         "\x01"
00057                 ,
00058                         /* allowed */
00059                         "\x4D"
00060                 ,
00061                         /* allowed */
00062                         "\x7E"
00063                 ,
00064                         /* allowed */
00065                         "\x7F"
00066                 ,
00067                         /* disallowed */
00068                         "\x80"
00069                 ,
00070                         /* disallowed */
00071                         "\x81"
00072                 ,
00073                         /* disallowed */
00074                         "\x90"
00075                 ,
00076                         /* disallowed */
00077                         "\xAF"
00078                 ,
00079                         /* disallowed */
00080                         "\xFF"
00081         };
00082 
00083         ucn_token_type out[] = {
00084                 ucn_token::TOK_NOT_EOF,
00085                 ucn_token::TOK_EOF,
00086                 ucn_token::TOK_NOT_EOF,
00087                 ucn_token::TOK_EOF,
00088                 ucn_token::TOK_NOT_EOF,
00089                 ucn_token::TOK_EOF,
00090                 ucn_token::TOK_NOT_EOF,
00091                 ucn_token::TOK_EOF,
00092                 ucn_token::TOK_ERROR,
00093                 ucn_token::TOK_ERROR,
00094                 ucn_token::TOK_ERROR,
00095                 ucn_token::TOK_ERROR,
00096                 ucn_token::TOK_ERROR,
00097         };
00098 
00099         ptr<ucn_token> tok;
00100         ucn_token_type utt;
00101         ulint test, i;
00102 
00103         for (i = test = 0; test < TEST_CNT; test++) {
00104                 ptr<data_source> ds = string_source::create(string_source::string_type(in[test]));
00105                 ptr<encoder_ascii7> enc = encoder_ascii7::create();
00106 
00107                 enc->input_set(ds);
00108 
00109                 while (true) {
00110                         tok = enc->read();
00111                         utt = tok->type_get();
00112                         lassert(utt == out[i]);
00113                         i++;
00114                         if (utt == ucn_token::TOK_EOF || utt == ucn_token::TOK_ERROR) break;
00115                 }
00116         }
00117 }
00118 
00119 end_package(lex);
00120 end_package(cplus);
00121 end_package(lang);
00122 end_package(lestes);
00123 
00124 /*!
00125   \brief Main function.
00126 
00127   Runs the unit test in different namespace.
00128 */
00129 int main(void)
00130 {
00131 	::lestes::lang::cplus::lex::encoder_ascii7_test();
00132         return 0;
00133 }
00134 /* vim: set ft=lestes : */

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