[26] | 1 | /*
|
---|
| 2 | * TOPPERS/JSP Kernel
|
---|
| 3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
| 4 | * Just Standard Profile Kernel
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
|
---|
| 7 | * Toyohashi Univ. of Technology, JAPAN
|
---|
| 8 | *
|
---|
| 9 | * ä¸è¨èä½æ¨©è
|
---|
| 10 | ã¯ï¼ä»¥ä¸ã® (1)ã(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
| 11 | * ã«ãã£ã¦å
|
---|
| 12 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
| 13 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
| 14 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
| 15 | å¸ï¼ä»¥ä¸ï¼
|
---|
| 16 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 17 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 18 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 19 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 20 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 21 | * ç¨ã§ããå½¢ã§åé
|
---|
| 22 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 23 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 24 | * è
|
---|
| 25 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 26 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 27 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 28 | * ç¨ã§ããªãå½¢ã§åé
|
---|
| 29 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 30 | * ã¨ï¼
|
---|
| 31 | * (a) åé
|
---|
| 32 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 33 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 34 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 35 | * (b) åé
|
---|
| 36 | å¸ã®å½¢æ
|
---|
| 37 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 38 | * å ±åãããã¨ï¼
|
---|
| 39 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 40 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 42 | 責ãããã¨ï¼
|
---|
| 43 | *
|
---|
| 44 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 45 | ã
|
---|
| 46 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
| 47 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
| 48 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
| 49 | *
|
---|
| 50 | * @(#) $Id: clause.cpp,v 1.3 2003/12/15 07:32:13 takayuki Exp $
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | // $Header: /home/CVS/configurator/base/clause.cpp,v 1.3 2003/12/15 07:32:13 takayuki Exp $
|
---|
| 54 |
|
---|
| 55 | #include "base/clause.h"
|
---|
| 56 | #include "base/message.h"
|
---|
| 57 |
|
---|
| 58 | using namespace std;
|
---|
| 59 |
|
---|
| 60 | /*
|
---|
| 61 | * æ§æä¸ã®ä¸ç¯ãå¦çããã¯ã©ã¹
|
---|
| 62 | */
|
---|
| 63 |
|
---|
| 64 | //æå®ããåå空éã®ç¯ããããåå¾
|
---|
| 65 | Clause::map_type * Clause::getClauseMap(string name) throw()
|
---|
| 66 | {
|
---|
| 67 | map_type * result = NULL;
|
---|
| 68 | Namespace::iterator scope;
|
---|
| 69 |
|
---|
| 70 | Namespace * const ns = Singleton<Namespace>::getInstance(nothrow);
|
---|
| 71 | if(ns!= 0) {
|
---|
| 72 | scope = ns->find(name);
|
---|
| 73 | if(scope != ns->end())
|
---|
| 74 | result = &(scope->second);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | return result;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | //ç¯ã®ç»é²
|
---|
| 81 | void Clause::addClause(string _namespace, string _identifier) throw()
|
---|
| 82 | {
|
---|
| 83 | if(isValid()) {
|
---|
| 84 | Namespace * const ns = Singleton<Namespace>::getInstance(nothrow);
|
---|
| 85 | if(ns != 0)
|
---|
| 86 | (*ns)[_namespace][_identifier] = this;
|
---|
| 87 | // ns->operator [](_namespace).insert(map_type::value_type(_identifier, this)); //ä¸æ¸ããããªãå ´å
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | //ãã¼ã¯ã³ã«å¯¾ãã¦ç¯èå¥åãçæãã
|
---|
| 92 | string Clause::getClauseIdentifier(Token token) throw()
|
---|
| 93 | {
|
---|
| 94 | string result;
|
---|
| 95 |
|
---|
| 96 | switch(token.getType()) {
|
---|
| 97 | case Token::IDENTIFIER:
|
---|
| 98 | case Token::PUNCTUATOR:
|
---|
| 99 | result = token.getLiteral();
|
---|
| 100 | break;
|
---|
| 101 | case Token::INTEGER:
|
---|
| 102 | result.assign(INTEGER_CLAUSE_IDENTIFIER);
|
---|
| 103 | break;
|
---|
| 104 | case Token::LITERAL:
|
---|
| 105 | result.assign(LITERAL_CLAUSE_IDENTIFIER);
|
---|
| 106 | break;
|
---|
| 107 | case Token::OPERATOR:
|
---|
| 108 | result.assign(OPERATOR_CLAUSE_IDENTIFIER);
|
---|
| 109 | break;
|
---|
| 110 | default:
|
---|
| 111 | result = string();
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | return result;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | //ç¯ã®è§£æ
|
---|
| 118 | bool Clause::parseClause(string ns, Parser & p)
|
---|
| 119 | {
|
---|
| 120 | bool result = false;
|
---|
| 121 | map_type::iterator scope;
|
---|
| 122 | map_type * clause = getClauseMap(ns);
|
---|
| 123 |
|
---|
| 124 | //ã¬ã¼ãç¯
|
---|
| 125 | if(clause == 0 || p.eof())
|
---|
| 126 | return false;
|
---|
| 127 |
|
---|
| 128 | //ãã¼ã¯ã³ããèå¥åãåãåºã
|
---|
| 129 | Token token;
|
---|
| 130 | string identifier;
|
---|
| 131 |
|
---|
| 132 | token = p.getToken();
|
---|
| 133 | identifier = getClauseIdentifier(token);
|
---|
| 134 |
|
---|
| 135 | //ç¯å¦çé¨ã®å®è¡
|
---|
| 136 | scope = clause->find(identifier);
|
---|
| 137 | if(scope != clause->end()) {
|
---|
| 138 |
|
---|
| 139 | //ãããã°ç¨ã¡ãã»ã¼ã¸åºå
|
---|
| 140 | DebugMessage("Clause::parseClause(%) - %\n") << ns << identifier;
|
---|
| 141 |
|
---|
| 142 | try {
|
---|
| 143 | scope->second->before(token, p);
|
---|
| 144 | scope->second->body(token, p); //ããããããã®ãå®è¡
|
---|
| 145 | scope->second->after(token, p);
|
---|
| 146 | result = true;
|
---|
| 147 | }
|
---|
| 148 | catch(...) {
|
---|
| 149 | scope->second->onFail(token, p); //失æããã¨ãã®å¾å§æ«ããé¡ããã
|
---|
| 150 | throw;
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 | else
|
---|
| 154 | p.putback(token); //èå¥åã«ããããããã®ãç»é²ããã¦ããªã
|
---|
| 155 |
|
---|
| 156 | return result;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | //firstã§å§ã¾ãç¯ãããã
|
---|
| 160 | bool Clause::hasClause(string ns, string first) throw()
|
---|
| 161 | {
|
---|
| 162 | map_type * clause = getClauseMap(ns);
|
---|
| 163 | if(clause == 0)
|
---|
| 164 | return false;
|
---|
| 165 |
|
---|
| 166 | return clause->find(first) != clause->end();
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | //ãã¼ã¹åå¦ç
|
---|
| 170 | void Clause::before(const Token &, Parser &)
|
---|
| 171 | {}
|
---|
| 172 |
|
---|
| 173 | //ãã¼ã¹å¾å¦ç
|
---|
| 174 | void Clause::after(const Token &, Parser &)
|
---|
| 175 | {}
|
---|
| 176 |
|
---|
| 177 | //æ¨æºã®ä¾å¤çºçæã®å¾å§æ«ã«ã¼ãã³
|
---|
| 178 | void Clause::onFail(const Token &, Parser & p) throw()
|
---|
| 179 | {
|
---|
| 180 | Token token;
|
---|
| 181 |
|
---|
| 182 | //æå¾ã¾ã§èªã¿ãã
|
---|
| 183 | while(!p.eof())
|
---|
| 184 | token = p.getToken();
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | //ç¯ãè¤æ°ã®èå¥åã«å¯¾å¿ä»ãã
|
---|
| 188 | void Clause::addMultipleClauses(string ns, string id_list) throw()
|
---|
| 189 | {
|
---|
| 190 | string id;
|
---|
| 191 | string::size_type pos;
|
---|
| 192 | string::size_type prev;
|
---|
| 193 |
|
---|
| 194 | //ã«ã³ãã§åºåãããè¦ç´ æ¯ã«addClauseãçºè¡
|
---|
| 195 | if(isValid()) {
|
---|
| 196 | prev = 0;
|
---|
| 197 | do {
|
---|
| 198 | pos = id_list.find_first_of(',', prev);
|
---|
| 199 | id = id_list.substr(prev, pos - prev);
|
---|
| 200 |
|
---|
| 201 | addClause(ns, id);
|
---|
| 202 |
|
---|
| 203 | prev = pos + 1;
|
---|
| 204 | } while(pos != string::npos);
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | //[ãã«ãç¨] ç»é²ããã¦ããç¯ã®ä¸è¦§ãä½æãã
|
---|
| 209 | std::string Clause::makeClauseList(string ns, int width) throw()
|
---|
| 210 | {
|
---|
| 211 | string result;
|
---|
| 212 | map_type::iterator scope;
|
---|
| 213 | map_type * clause = getClauseMap(ns);
|
---|
| 214 | size_t max_length = 0;
|
---|
| 215 |
|
---|
| 216 | //æ大ã®æååé·ãæ±ãã
|
---|
| 217 | scope = clause->begin();
|
---|
| 218 | while(scope != clause->end()) {
|
---|
| 219 | size_t i = scope->first.size();
|
---|
| 220 | if(i > max_length)
|
---|
| 221 | max_length = i;
|
---|
| 222 | ++ scope;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | //ä¸è¦§ãä½æ
|
---|
| 226 | size_t max_column = width/(max_length+1);
|
---|
| 227 | size_t column = 0;
|
---|
| 228 | scope = clause->begin();
|
---|
| 229 | while(scope != clause->end()) {
|
---|
| 230 | size_t i = scope->first.size();
|
---|
| 231 |
|
---|
| 232 | result += scope->first;
|
---|
| 233 |
|
---|
| 234 | ++ column;
|
---|
| 235 | ++ scope;
|
---|
| 236 |
|
---|
| 237 | //æ«å°¾å¦ç
|
---|
| 238 | if(column == max_column || scope == clause->end())
|
---|
| 239 | result += '\n';
|
---|
| 240 | else {
|
---|
| 241 | result += ',';
|
---|
| 242 | result += string(max_length - i, ' ');
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | return result;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 |
|
---|
| 250 | /*
|
---|
| 251 | * éçAPI
|
---|
| 252 | */
|
---|
| 253 |
|
---|
| 254 | //ãã¼ã¹åå¦ç
|
---|
| 255 | void StaticAPI::before(const Token & first, Parser & p)
|
---|
| 256 | {
|
---|
| 257 | Token token = p.getToken();
|
---|
| 258 | if(token != Token::LPAREN) {
|
---|
| 259 | ExceptionMessage("StaticAPI [%] lacks left-parenthesis '('.","éçAPI[%]ã«ã¯æ¬å¼§'('ãæ¬ ãã¦ãã") << first.getLiteral() << throwException;
|
---|
| 260 | }
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | //ãã¼ã¹å¾å¦ç
|
---|
| 264 | void StaticAPI::after(const Token & first, Parser & p)
|
---|
| 265 | {
|
---|
| 266 | Token token = p.getToken();
|
---|
| 267 | if(token != Token::RPAREN) {
|
---|
| 268 | ExceptionMessage("StaticAPI [%] lacks right-parenthesis ')'.","éçAPI[%]ã«ã¯æ¬å¼§')'ãæ¬ ãã¦ãã") << first.getLiteral() << throwException;
|
---|
| 269 | }
|
---|
| 270 | else {
|
---|
| 271 | token = p.getToken();
|
---|
| 272 | if(token != ";")
|
---|
| 273 | ExceptionMessage("StaticAPI [%] lacks ';' at the end of declaration.","éçAPI[%]ã®æ«å°¾ã«';'ãæ¬ ãã¦ãã") << first.getLiteral() << throwException;
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | //失ææã®å復å¦ç
|
---|
| 278 | void StaticAPI::onFail(const Token & , Parser & p) throw()
|
---|
| 279 | { skip(p, false); }
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 | //ã¹ããã
|
---|
| 283 | // invalid_api : 次ã«æåã«èªã¿åºãããAPIã¯ç¡å¹
|
---|
| 284 | void StaticAPI::skip(Parser & p, bool invalid_api) throw()
|
---|
| 285 | {
|
---|
| 286 | //ã»ãã³ãã³ or 次ã®éçAPIã®åºç¾ã¾ã§
|
---|
| 287 | Token token;
|
---|
| 288 | bool condition; //ã¢ã¬å¯¾ç
|
---|
| 289 |
|
---|
| 290 | if(invalid_api)
|
---|
| 291 | token = p.getToken(); //次ã®APIåã¯èªã¿é£ã°ã
|
---|
| 292 |
|
---|
| 293 | do {
|
---|
| 294 | token = p.getToken(true);
|
---|
| 295 |
|
---|
| 296 | condition = (!token.isValid()) || //ç¡å¹ãªãã¼ã¯ã³ã
|
---|
| 297 | (token == Token::PUNCTUATOR && token == ";") || //ã»ãã³ãã³ã
|
---|
| 298 | (token == Token::IDENTIFIER && hasStaticAPI(token.getLiteral())); //éçAPIã
|
---|
| 299 |
|
---|
| 300 | } while(!condition);
|
---|
| 301 |
|
---|
| 302 | if(token == Token::IDENTIFIER)
|
---|
| 303 | p.putback(token);
|
---|
| 304 | }
|
---|
| 305 |
|
---|
| 306 | /*
|
---|
| 307 | * ããªããã»ã¹ãã£ã¬ã¯ãã£ã
|
---|
| 308 | */
|
---|
| 309 |
|
---|
| 310 | //ãã¼ã¹å¾å¦ç
|
---|
| 311 | void Directives::after(const Token & first, Parser & p) throw(Exception)
|
---|
| 312 | {
|
---|
| 313 | Token token = p.getToken(true);
|
---|
| 314 | if(!token.isValid() || !p.isLocatedonHeadofLine())
|
---|
| 315 | ExceptionMessage("Directive [%] has a wrong parameter or misses a new-line.","ãã£ã¬ã¯ãã£ã[%]ã«ä¸æ£ãªå¼æ°ãããããæ¹è¡ããªã") << first.getLiteral() << throwException;
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | //ãã¼ã¹å¤±ææã®å復å¦ç
|
---|
| 319 | void Directives::onFail(const Token & , Parser & p) throw()
|
---|
| 320 | {
|
---|
| 321 | //次ã®æ¹è¡ã¾ã§èªã¿é£ã°ã
|
---|
| 322 | Token token;
|
---|
| 323 |
|
---|
| 324 | do {
|
---|
| 325 | token = p.getToken(true);
|
---|
| 326 | } while(token.isValid() && !p.isLocatedonHeadofLine());
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | /************************************************* ãã¹ãã¹ã£ã¼ã *************************************************/
|
---|
| 330 |
|
---|
| 331 | #ifdef TESTSUITE
|
---|
| 332 |
|
---|
| 333 | #include "coverage_undefs.h"
|
---|
| 334 | #include <sstream>
|
---|
| 335 |
|
---|
| 336 | namespace {
|
---|
| 337 | class Clause_test : public Clause
|
---|
| 338 | {
|
---|
| 339 | public:
|
---|
| 340 | Token first;
|
---|
| 341 | Token second;
|
---|
| 342 | bool throw_exception;
|
---|
| 343 |
|
---|
| 344 | Clause_test(void) throw() : first(Token::ERROR), throw_exception(false) {}
|
---|
| 345 |
|
---|
| 346 | void body(const Token & _first, Parser & _p)
|
---|
| 347 | {
|
---|
| 348 | TestSuite::check("Clause_test::body");
|
---|
| 349 | first = _first;
|
---|
| 350 | second = _p.getToken();
|
---|
| 351 | if(throw_exception)
|
---|
| 352 | throw 0;
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | void before(const Token & , Parser & )
|
---|
| 356 | {
|
---|
| 357 | TestSuite::check("Clause_test::before");
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | void after(const Token &, Parser &)
|
---|
| 361 | {
|
---|
| 362 | TestSuite::check("Clause_test::after");
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | void onFail(const Token & _first, Parser & p) throw()
|
---|
| 366 | {
|
---|
| 367 | TestSuite::check("Clause_test::onFail");
|
---|
| 368 | first = _first;
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | void onFail_super(const Token & _first, Parser & p) throw()
|
---|
| 372 | { Clause::onFail(_first, p); }
|
---|
| 373 | };
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | TESTSUITE(main, Clause)
|
---|
| 377 | {
|
---|
| 378 | SingletonBase::ContextChain chain;
|
---|
| 379 | chain.saveContext<Namespace>();
|
---|
| 380 |
|
---|
| 381 | BEGIN_CASE("getClauseIdentifier","getClauseIdentifier") {
|
---|
| 382 | BEGIN_CASE("1","æ®éã®èå¥åã¯ãã®ã¾ã¾ãä¸èº«ã«ãªã") {
|
---|
| 383 | Token token(Token::IDENTIFIER, "test");
|
---|
| 384 |
|
---|
| 385 | if(getClauseIdentifier(token).compare("test") != 0)
|
---|
| 386 | TEST_FAIL;
|
---|
| 387 | } END_CASE;
|
---|
| 388 |
|
---|
| 389 | BEGIN_CASE("2","æ°å¤ã¯ä¸èº«ã«é¢ä¿ãªã" INTEGER_CLAUSE_IDENTIFIER "ãè¿ã") {
|
---|
| 390 | Token token(Token::INTEGER, "", "", 0);
|
---|
| 391 |
|
---|
| 392 | if(getClauseIdentifier(token).compare(INTEGER_CLAUSE_IDENTIFIER) != 0)
|
---|
| 393 | TEST_FAIL;
|
---|
| 394 | } END_CASE;
|
---|
| 395 |
|
---|
| 396 | BEGIN_CASE("3","ãªãã©ã«ã¯ä¸èº«ã«é¢ä¿ãªã" LITERAL_CLAUSE_IDENTIFIER "ãè¿ã") {
|
---|
| 397 | Token token(Token::LITERAL, "");
|
---|
| 398 |
|
---|
| 399 | if(getClauseIdentifier(token).compare(LITERAL_CLAUSE_IDENTIFIER) != 0)
|
---|
| 400 | TEST_FAIL;
|
---|
| 401 | } END_CASE;
|
---|
| 402 |
|
---|
| 403 | BEGIN_CASE("4","æ¼ç®åã¯ä¸èº«ã«é¢ä¿ãªã" OPERATOR_CLAUSE_IDENTIFIER "ãè¿ã") {
|
---|
| 404 | Token token(Token::OPERATOR);
|
---|
| 405 |
|
---|
| 406 | if(getClauseIdentifier(token).compare(OPERATOR_CLAUSE_IDENTIFIER) != 0)
|
---|
| 407 | TEST_FAIL;
|
---|
| 408 | } END_CASE;
|
---|
| 409 |
|
---|
| 410 | BEGIN_CASE("5","空ç½ã®ãã¼ã¯ã³ã«ã¯ç©ºæå(==éåç)ãè¿ã") {
|
---|
| 411 | Token token(Token::SPACE);
|
---|
| 412 |
|
---|
| 413 | if(!getClauseIdentifier(token).empty())
|
---|
| 414 | TEST_FAIL;
|
---|
| 415 | } END_CASE;
|
---|
| 416 |
|
---|
| 417 | TEST_CASE("6","ã¨ã©ã¼ãã¼ã¯ã³ã«ã¯ç©ºæå(==éåç)ãè¿ã", getClauseIdentifier(Token(Token::ERROR)).empty());
|
---|
| 418 | TEST_CASE("7","EOSãã¼ã¯ã³ã«ã¯ç©ºæå(==éåç)ãè¿ã", getClauseIdentifier(Token(Token::END_OF_STREAM)).empty());
|
---|
| 419 |
|
---|
| 420 | } END_CASE;
|
---|
| 421 |
|
---|
| 422 | BEGIN_CASE("getClauseMap","getClauseMap") {
|
---|
| 423 | BEGIN_CASE("1","ä½ãç»é²ãã¦ããªã空éã«ã¯NULLãè¿ã") {
|
---|
| 424 | chain.renewInstance();
|
---|
| 425 | if(Clause::getClauseMap("unknown") != 0)
|
---|
| 426 | TEST_FAIL;
|
---|
| 427 | } END_CASE;
|
---|
| 428 |
|
---|
| 429 | BEGIN_CASE("2","è¦ç´ ãããã°é0ãè¿ã") {
|
---|
| 430 | chain.renewInstance();
|
---|
| 431 | Singleton<Namespace>::getInstance()->operator []("test");
|
---|
| 432 |
|
---|
| 433 | if(Clause::getClauseMap("test") == 0)
|
---|
| 434 | TEST_FAIL;
|
---|
| 435 | } END_CASE;
|
---|
| 436 | } END_CASE;
|
---|
| 437 |
|
---|
| 438 | BEGIN_CASE("addClause","addClause") {
|
---|
| 439 | BEGIN_CASE("1","ãªãã¸ã§ã¯ããç»é²ã§ãã") {
|
---|
| 440 | chain.renewInstance();
|
---|
| 441 | Clause_test ct;
|
---|
| 442 | Clause_test ct2;
|
---|
| 443 |
|
---|
| 444 | BEGIN_CASE("1","æ®éã«ç»é²ãã") {
|
---|
| 445 | ct.addClause("test","first_literal");
|
---|
| 446 |
|
---|
| 447 | TEST_CASE("1","åå空éãå¢ãã¦ãã", Singleton<Namespace>::getInstance()->size() == 1);
|
---|
| 448 | TEST_CASE("2","\"test\"ã¨ãã空éããã", Singleton<Namespace>::getInstance()->find("test") != Singleton<Namespace>::getInstance()->end());
|
---|
| 449 | TEST_CASE("3","getClauseã§ã¢ãã¬ã¹ãåãã", Clause::getClauseMap("test") != 0);
|
---|
| 450 | TEST_CASE("4","åå空éã®ç¯ã®æ°ã¯1", Clause::getClauseMap("test")->size() == 1);
|
---|
| 451 | TEST_CASE("5","\"first_literal\"ã®ãã¼ãããã", Clause::getClauseMap("test")->find("first_literal") != Clause::getClauseMap("test")->end());
|
---|
| 452 | TEST_CASE("6","é¢é£ä»ããããå¤ãæ£ãã", (*Clause::getClauseMap("test"))["first_literal"] == &ct);
|
---|
| 453 | } END_CASE;
|
---|
| 454 |
|
---|
| 455 | BEGIN_CASE("2","2åç®ãç»é²ãã") {
|
---|
| 456 | ct2.addClause("test","second_literal");
|
---|
| 457 |
|
---|
| 458 | TEST_CASE("1","åå空éãå¢ãã¦ããªã", Singleton<Namespace>::getInstance()->size() == 1);
|
---|
| 459 | TEST_CASE("2","\"test\"ã¨ãã空éããã", Singleton<Namespace>::getInstance()->find("test") != Singleton<Namespace>::getInstance()->end());
|
---|
| 460 | TEST_CASE("3","åå空éã®ç¯ã®æ°ã¯2", Clause::getClauseMap("test")->size() == 2);
|
---|
| 461 | TEST_CASE("4","\"second_literal\"ã®ãã¼ãããã", Clause::getClauseMap("test")->find("second_literal") != Clause::getClauseMap("test")->end());
|
---|
| 462 | TEST_CASE("5","é¢é£ä»ããããå¤ãæ£ãã", (*Clause::getClauseMap("test"))["second_literal"] == &ct2);
|
---|
| 463 | } END_CASE;
|
---|
| 464 |
|
---|
| 465 | BEGIN_CASE("3","2åç®ã1åç®ã§ä¸æ¸ãç»é²ãã") {
|
---|
| 466 | ct.addClause("test","second_literal");
|
---|
| 467 | TEST_CASE("1","ä¸æ¸ãããã¦ãã", (*Clause::getClauseMap("test"))["second_literal"] == &ct);
|
---|
| 468 | } END_CASE;
|
---|
| 469 |
|
---|
| 470 | BEGIN_CASE("4","éãåå空éã«ç»é²ãã") {
|
---|
| 471 | ct.addClause("TEST","first_literal");
|
---|
| 472 |
|
---|
| 473 | TEST_CASE("1","åå空éãå¢ãã¦ãã", Singleton<Namespace>::getInstance()->size() == 2);
|
---|
| 474 | TEST_CASE("2","\"TEST\"ã¨ãã空éããã", Singleton<Namespace>::getInstance()->find("TEST") != Singleton<Namespace>::getInstance()->end());
|
---|
| 475 | TEST_CASE("3","getClauseã§ã¢ãã¬ã¹ãåãã", Clause::getClauseMap("TEST") != 0);
|
---|
| 476 | TEST_CASE("4","åå空éã®ç¯ã®æ°ã¯1", Clause::getClauseMap("TEST")->size() == 1);
|
---|
| 477 | TEST_CASE("5","\"first_literal\"ã®ãã¼ãããã", Clause::getClauseMap("TEST")->find("first_literal") != Clause::getClauseMap("TEST")->end());
|
---|
| 478 | TEST_CASE("6","é¢é£ä»ããããå¤ãæ£ãã", (*Clause::getClauseMap("TEST"))["first_literal"] == &ct);
|
---|
| 479 | } END_CASE;
|
---|
| 480 |
|
---|
| 481 | } END_CASE;
|
---|
| 482 |
|
---|
| 483 | BEGIN_CASE("2","ç¡å¹ãªãªãã¸ã§ã¯ãã¯ç»é²ãããªã") {
|
---|
| 484 | chain.renewInstance();
|
---|
| 485 |
|
---|
| 486 | ((Clause_test *)0)->addClause("test","first_literal");
|
---|
| 487 |
|
---|
| 488 | TEST_CASE("1","åå空éãå¢ãã¦ããªã", Singleton<Namespace>::getInstance()->size() == 0);
|
---|
| 489 | } END_CASE;
|
---|
| 490 |
|
---|
| 491 | } END_CASE;
|
---|
| 492 |
|
---|
| 493 | BEGIN_CASE("hasClause","hasClause") {
|
---|
| 494 | Clause_test ct;
|
---|
| 495 | chain.renewInstance();
|
---|
| 496 |
|
---|
| 497 | TEST_CASE("1","ä½ãè¦ç´ ããªãã¨ãã«ãæ£å¸¸ã«åä½ãã", !Clause::hasClause("dummy","null"));
|
---|
| 498 |
|
---|
| 499 | ct.addClause("test","first_literal");
|
---|
| 500 |
|
---|
| 501 | TEST_CASE("2","ç»é²ããè¦ç´ ãæ¢ããtrueãè¿ã", Clause::hasClause("test","first_literal"));
|
---|
| 502 | TEST_CASE("3","åå¨ããªãè¦ç´ ã«falseãè¿ã", !Clause::hasClause("dummy","null"));
|
---|
| 503 | } END_CASE;
|
---|
| 504 |
|
---|
| 505 | BEGIN_CASE("addMultipleClauses","addMultipleClauses") {
|
---|
| 506 | BEGIN_CASE("1","åä¸ã®ç¯ãç»é²ã§ãã") {
|
---|
| 507 | chain.renewInstance();
|
---|
| 508 | Clause_test ct;
|
---|
| 509 |
|
---|
| 510 | ct.addMultipleClauses("test","first");
|
---|
| 511 |
|
---|
| 512 | TEST_CASE("1","ç»é²ããç¯ããã", Clause::hasClause("test","first"));
|
---|
| 513 | } END_CASE;
|
---|
| 514 |
|
---|
| 515 | BEGIN_CASE("2","è¤æ°ã®ç¯ãç»é²ãã") {
|
---|
| 516 | chain.renewInstance();
|
---|
| 517 | Clause_test ct;
|
---|
| 518 |
|
---|
| 519 | ct.addMultipleClauses("test","first,second,third");
|
---|
| 520 |
|
---|
| 521 | TEST_CASE("1","ç»é²ããç¯ããã", Clause::hasClause("test","first"));
|
---|
| 522 | TEST_CASE("2","ç»é²ããç¯ããã", Clause::hasClause("test","second"));
|
---|
| 523 | TEST_CASE("3","ç»é²ããç¯ããã", Clause::hasClause("test","third"));
|
---|
| 524 | } END_CASE;
|
---|
| 525 |
|
---|
| 526 | } END_CASE;
|
---|
| 527 |
|
---|
| 528 | BEGIN_CASE("Clause::onFail","Clause::onFail") {
|
---|
| 529 | stringstream buf;
|
---|
| 530 | Parser p(&buf, "test");
|
---|
| 531 | Token token;
|
---|
| 532 | Clause_test ct;
|
---|
| 533 |
|
---|
| 534 | buf.str("first second third 4 5 6 siebt acht neunt 0xa");
|
---|
| 535 |
|
---|
| 536 | ct.onFail_super(token, p);
|
---|
| 537 | TEST_CASE("1","ã¹ããªã¼ã ã¯æå¾ã¾ã§é²ãã§ãã", p.eof());
|
---|
| 538 | } END_CASE;
|
---|
| 539 |
|
---|
| 540 | BEGIN_CASE("parseClause","parseClause") {
|
---|
| 541 | chain.renewInstance();
|
---|
| 542 | Clause_test ct;
|
---|
| 543 |
|
---|
| 544 | ct.addClause("test","first");
|
---|
| 545 |
|
---|
| 546 | BEGIN_CASE("1","åå空éãé¸æãã¦æ£ããç¯ãå®è¡ã§ãã") {
|
---|
| 547 | stringstream buf;
|
---|
| 548 | Parser p(&buf, "test");
|
---|
| 549 | buf.str("first second");
|
---|
| 550 |
|
---|
| 551 | TestSuite::clearCheckpoints();
|
---|
| 552 | TEST_CASE("1","é¢æ°ã¯æåãã", Clause::parseClause("test", p));
|
---|
| 553 | TEST_CASE("2","Clause::beforeãå®è¡ããã¦ãã", TestSuite::isReached("Clause_test::before"));
|
---|
| 554 | TEST_CASE("3","Clause::bodyãå®è¡ããã¦ãã", TestSuite::isReached("Clause_test::body"));
|
---|
| 555 | TEST_CASE("4","bodyã®firstãæ£ãã", ct.first == "first");
|
---|
| 556 | TEST_CASE("5","bodyã§èªã¿åºãããã¼ã¯ã³ãæ£ãã", ct.second == "second");
|
---|
| 557 | TEST_CASE("6","Clause::afterãå®è¡ããã¦ãã", TestSuite::isReached("Clause_test::after"));
|
---|
| 558 | } END_CASE;
|
---|
| 559 |
|
---|
| 560 | BEGIN_CASE("2","ç¯ã®å¦çä¸ã«ä¾å¤ãèµ·ããã¨onFailãå¼ã°ãã") {
|
---|
| 561 | stringstream buf;
|
---|
| 562 | Parser p(&buf, "test");
|
---|
| 563 | buf.str("first second");
|
---|
| 564 |
|
---|
| 565 | ct.throw_exception = true;
|
---|
| 566 | TestSuite::clearCheckpoints();
|
---|
| 567 |
|
---|
| 568 | bool result = false;
|
---|
| 569 | try { Clause::parseClause("test", p); }
|
---|
| 570 | catch(...){ result = true; }
|
---|
| 571 |
|
---|
| 572 | TEST_CASE("1","ä¾å¤ãèµ·ãã", result);
|
---|
| 573 | TEST_CASE("2","Clause::bodyãå®è¡ããã¦ãã", TestSuite::isReached("Clause_test::body"));
|
---|
| 574 | TEST_CASE("3","Clause::onFailãå®è¡ããã¦ãã", TestSuite::isReached("Clause_test::onFail"));
|
---|
| 575 | } END_CASE;
|
---|
| 576 |
|
---|
| 577 | BEGIN_CASE("3","åå¨ããªãåå空éãæå®ãã") {
|
---|
| 578 | stringstream buf;
|
---|
| 579 | Parser p(&buf, "test");
|
---|
| 580 | buf.str("first second");
|
---|
| 581 |
|
---|
| 582 | TEST_CASE("1","é¢æ°ã¯å¤±æãã", !Clause::parseClause("unknown", p));
|
---|
| 583 | } END_CASE;
|
---|
| 584 |
|
---|
| 585 | BEGIN_CASE("4","EOFã«éããã¹ããªã¼ã ãæå®ãã") {
|
---|
| 586 | stringstream buf;
|
---|
| 587 | Parser p(&buf, "test");
|
---|
| 588 | buf.str("");
|
---|
| 589 | buf.get();
|
---|
| 590 |
|
---|
| 591 | TEST_CASE("0","[åæ]ã¹ããªã¼ã ã¯çµç«¯ã«éãã¦ãã", buf.eof());
|
---|
| 592 | TEST_CASE("1","é¢æ°ã¯å¤±æãã", !Clause::parseClause("unknown", p));
|
---|
| 593 | } END_CASE;
|
---|
| 594 | } END_CASE;
|
---|
| 595 |
|
---|
| 596 | chain.restoreContext();
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 |
|
---|
| 600 |
|
---|
| 601 |
|
---|
| 602 | namespace {
|
---|
| 603 | class StaticAPI_test : public StaticAPI
|
---|
| 604 | {
|
---|
| 605 | public:
|
---|
| 606 | StaticAPI_test(void) throw() : StaticAPI() {}
|
---|
| 607 | StaticAPI_test(string src) throw() : StaticAPI(src) {}
|
---|
| 608 |
|
---|
| 609 | void body(const Token & , Parser &) { TestSuite::check("StaticAPI::body"); }
|
---|
| 610 | void onFail_super(const Token & first, Parser & p) throw() { StaticAPI::onFail(first, p); }
|
---|
| 611 | };
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | TESTSUITE(main, StaticAPI)
|
---|
| 615 | {
|
---|
| 616 | Singleton<Namespace>::Context context;
|
---|
| 617 | Singleton<Namespace>::saveContext(context);
|
---|
| 618 |
|
---|
| 619 | Exception::setThrowControl(true);
|
---|
| 620 |
|
---|
| 621 | BEGIN_CASE("regist","regist") {
|
---|
| 622 | BEGIN_CASE("1","åä¸ã®ååãæå®ãã¦ç»é²ã§ãã") {
|
---|
| 623 | Singleton<Namespace>::renewInstance();
|
---|
| 624 | StaticAPI_test api;
|
---|
| 625 |
|
---|
| 626 | api.regist("VTST_API");
|
---|
| 627 |
|
---|
| 628 | TEST_CASE("1","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("VTST_API"));
|
---|
| 629 | } END_CASE;
|
---|
| 630 |
|
---|
| 631 | BEGIN_CASE("2","è¤æ°ã®ååãæå®ãã¦ç»é²ãã") {
|
---|
| 632 | Singleton<Namespace>::renewInstance();
|
---|
| 633 | StaticAPI_test api;
|
---|
| 634 |
|
---|
| 635 | api.regist("API_1,API_2,API_3");
|
---|
| 636 |
|
---|
| 637 | TEST_CASE("1","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("API_1"));
|
---|
| 638 | TEST_CASE("2","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("API_2"));
|
---|
| 639 | TEST_CASE("3","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("API_3"));
|
---|
| 640 | } END_CASE;
|
---|
| 641 |
|
---|
| 642 | BEGIN_CASE("3","ä¸æ¸ããã") {
|
---|
| 643 | Singleton<Namespace>::renewInstance();
|
---|
| 644 | StaticAPI_test api;
|
---|
| 645 | StaticAPI_test api2;
|
---|
| 646 | StaticAPI_test api3;
|
---|
| 647 |
|
---|
| 648 | api.regist("test");
|
---|
| 649 | TEST_CASE("1","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("test"));
|
---|
| 650 | TEST_CASE("2","APIãã³ãã©ãæ£ãã", (*StaticAPI::getClauseMap(NAMESPACE_STATICAPI))["test"] == &api);
|
---|
| 651 |
|
---|
| 652 | api2.regist("test");
|
---|
| 653 | TEST_CASE("3","APIãã³ãã©ãä¸æ¸ãããã¦ãã", (*StaticAPI::getClauseMap(NAMESPACE_STATICAPI))["test"] == &api2);
|
---|
| 654 |
|
---|
| 655 | api3.regist("test");
|
---|
| 656 | TEST_CASE("4","APIãã³ãã©ãä¸æ¸ãããã¦ãã", (*StaticAPI::getClauseMap(NAMESPACE_STATICAPI))["test"] == &api3);
|
---|
| 657 | } END_CASE;
|
---|
| 658 |
|
---|
| 659 | BEGIN_CASE("4","ã³ã³ã¹ãã©ã¯ã¿ã§ç»é²") {
|
---|
| 660 | Singleton<Namespace>::renewInstance();
|
---|
| 661 | StaticAPI_test api("API1,API2,API3");
|
---|
| 662 |
|
---|
| 663 | TEST_CASE("1","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("API1"));
|
---|
| 664 | TEST_CASE("2","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("API2"));
|
---|
| 665 | TEST_CASE("3","APIã¯æ£ããç»é²ã§ãã¦ãã",StaticAPI::hasStaticAPI("API3"));
|
---|
| 666 | } END_CASE;
|
---|
| 667 | } END_CASE;
|
---|
| 668 |
|
---|
| 669 | BEGIN_CASE("parseStaticAPI","parseStaticAPI") {
|
---|
| 670 | BEGIN_CASE("1","éçAPIãæ£ããå¦çã§ãã") {
|
---|
| 671 | Singleton<Namespace>::renewInstance();
|
---|
| 672 | stringstream buf;
|
---|
| 673 | StaticAPI_test api("API");
|
---|
| 674 |
|
---|
| 675 | buf.str("API();");
|
---|
| 676 | Parser p(&buf, "test");
|
---|
| 677 |
|
---|
| 678 | TestSuite::clearCheckpoints();
|
---|
| 679 | bool result = true;
|
---|
| 680 | try { StaticAPI::parseStaticAPI(p); }
|
---|
| 681 | catch(...) { result = false; }
|
---|
| 682 |
|
---|
| 683 | TEST_CASE("1","ä¾å¤ã¯èµ·ããªã", result);
|
---|
| 684 | TEST_CASE("2","éçAPIã®æ¬ä½ãå¼ã°ãã¦ãã", TestSuite::isReached("StaticAPI::body"));
|
---|
| 685 | } END_CASE;
|
---|
| 686 |
|
---|
| 687 | BEGIN_CASE("2","'('å¿ãã§ä¾å¤") {
|
---|
| 688 | Singleton<Namespace>::renewInstance();
|
---|
| 689 | stringstream buf;
|
---|
| 690 | StaticAPI_test api("API");
|
---|
| 691 |
|
---|
| 692 | buf.str("API);");
|
---|
| 693 | Parser p(&buf, "test");
|
---|
| 694 |
|
---|
| 695 | TestSuite::clearCheckpoints();
|
---|
| 696 | bool result = false;
|
---|
| 697 | try { StaticAPI::parseStaticAPI(p); }
|
---|
| 698 | catch(...) { result = true; }
|
---|
| 699 |
|
---|
| 700 | TEST_CASE("1","ä¾å¤ãèµ·ã", result);
|
---|
| 701 | TEST_CASE("2","éçAPIã®æ¬ä½ãå¼ã°ããªã", !TestSuite::isReached("StaticAPI::body"));
|
---|
| 702 | } END_CASE;
|
---|
| 703 |
|
---|
| 704 | BEGIN_CASE("3","')'å¿ãã§ä¾å¤") {
|
---|
| 705 | Singleton<Namespace>::renewInstance();
|
---|
| 706 | stringstream buf;
|
---|
| 707 | StaticAPI_test api("API");
|
---|
| 708 |
|
---|
| 709 | buf.str("API(; NEXT");
|
---|
| 710 | Parser p(&buf, "test");
|
---|
| 711 |
|
---|
| 712 | TestSuite::clearCheckpoints();
|
---|
| 713 | bool result = false;
|
---|
| 714 | try { StaticAPI::parseStaticAPI(p); }
|
---|
| 715 | catch(...) { result = true; }
|
---|
| 716 |
|
---|
| 717 | TEST_CASE("1","ä¾å¤ãèµ·ã", result);
|
---|
| 718 | TEST_CASE("2","éçAPIã®æ¬ä½ãå¼ã°ãã¦ãã", TestSuite::isReached("StaticAPI::body"));
|
---|
| 719 | } END_CASE;
|
---|
| 720 |
|
---|
| 721 | BEGIN_CASE("4","';'å¿ãã§ä¾å¤") {
|
---|
| 722 | Singleton<Namespace>::renewInstance();
|
---|
| 723 | stringstream buf;
|
---|
| 724 | StaticAPI_test api("API");
|
---|
| 725 |
|
---|
| 726 | buf.str("API() NEXT");
|
---|
| 727 | Parser p(&buf, "test");
|
---|
| 728 |
|
---|
| 729 | TestSuite::clearCheckpoints();
|
---|
| 730 | bool result = false;
|
---|
| 731 | try { StaticAPI::parseStaticAPI(p); }
|
---|
| 732 | catch(...) { result = true; }
|
---|
| 733 |
|
---|
| 734 | TEST_CASE("1","ä¾å¤ãèµ·ã", result);
|
---|
| 735 | TEST_CASE("2","éçAPIã®æ¬ä½ãå¼ã°ãã¦ãã", TestSuite::isReached("StaticAPI::body"));
|
---|
| 736 | } END_CASE;
|
---|
| 737 | } END_CASE;
|
---|
| 738 |
|
---|
| 739 | BEGIN_CASE("onFail","onFail") {
|
---|
| 740 | BEGIN_CASE("1","ã»ãã³ãã³ã¾ã§èªã¿é£ã°ã") {
|
---|
| 741 | Singleton<Namespace>::renewInstance();
|
---|
| 742 | stringstream buf;
|
---|
| 743 | Parser p(&buf, "test");
|
---|
| 744 | StaticAPI_test api;
|
---|
| 745 | Token token;
|
---|
| 746 | buf.str("api parameter;next_api next_api_parameter;");
|
---|
| 747 |
|
---|
| 748 | api.onFail_super(Token(), p);
|
---|
| 749 |
|
---|
| 750 | TEST_CASE("1","ã»ãã³ãã³ã®æ¬¡ãèªãã", p.getToken() == "next_api");
|
---|
| 751 | } END_CASE;
|
---|
| 752 |
|
---|
| 753 | BEGIN_CASE("2","次ã®APIã¾ã§èªã¿é£ã°ã") {
|
---|
| 754 | Singleton<Namespace>::renewInstance();
|
---|
| 755 | stringstream buf;
|
---|
| 756 | Parser p(&buf, "test");
|
---|
| 757 | StaticAPI_test api("api,next_api");
|
---|
| 758 | buf.str("api parameter_1 parameter_2 next_api next_api_parameter;");
|
---|
| 759 |
|
---|
| 760 | api.onFail_super(p.getToken(), p);
|
---|
| 761 |
|
---|
| 762 | TEST_CASE("1","次ã®APIåãèªãã", p.getToken() == "next_api");
|
---|
| 763 | } END_CASE;
|
---|
| 764 | } END_CASE;
|
---|
| 765 |
|
---|
| 766 | BEGIN_CASE("skip","skip") {
|
---|
| 767 | BEGIN_CASE("1","ã»ãã³ãã³ã¾ã§èªã¿é£ã°ã") {
|
---|
| 768 | Singleton<Namespace>::renewInstance();
|
---|
| 769 | stringstream buf;
|
---|
| 770 | Parser p(&buf, "test");
|
---|
| 771 | StaticAPI_test api;
|
---|
| 772 | Token token;
|
---|
| 773 | buf.str("api parameter;next_api next_api_parameter;");
|
---|
| 774 |
|
---|
| 775 | StaticAPI::skip(p);
|
---|
| 776 |
|
---|
| 777 | TEST_CASE("1","ã»ãã³ãã³ã®æ¬¡ãèªãã", p.getToken() == "next_api");
|
---|
| 778 | } END_CASE;
|
---|
| 779 |
|
---|
| 780 | BEGIN_CASE("2","次ã®APIã¾ã§èªã¿é£ã°ã") {
|
---|
| 781 | Singleton<Namespace>::renewInstance();
|
---|
| 782 | stringstream buf;
|
---|
| 783 | Parser p(&buf, "test");
|
---|
| 784 | StaticAPI_test api("api,next_api");
|
---|
| 785 | buf.str("parameter_1 parameter_2 next_api next_api_parameter;");
|
---|
| 786 |
|
---|
| 787 | StaticAPI::skip(p);
|
---|
| 788 |
|
---|
| 789 | TEST_CASE("1","次ã®APIå次ãèªãã", p.getToken() == "next_api");
|
---|
| 790 | } END_CASE;
|
---|
| 791 |
|
---|
| 792 | BEGIN_CASE("3","å
|
---|
| 793 | é ãAPIåã§ãèªã¿é£ã°ãã§ãã") {
|
---|
| 794 | Singleton<Namespace>::renewInstance();
|
---|
| 795 | stringstream buf;
|
---|
| 796 | Parser p(&buf, "test");
|
---|
| 797 | StaticAPI_test api("api,next_api");
|
---|
| 798 | buf.str("api parameter_1 parameter_2 next_api next_api_parameter;");
|
---|
| 799 |
|
---|
| 800 | StaticAPI::skip(p);
|
---|
| 801 |
|
---|
| 802 | TEST_CASE("1","次ã®APIåãèªãã", p.getToken() == "next_api");
|
---|
| 803 | } END_CASE;
|
---|
| 804 | } END_CASE;
|
---|
| 805 |
|
---|
| 806 | Singleton<Namespace>::restoreContext(context);
|
---|
| 807 | }
|
---|
| 808 |
|
---|
| 809 |
|
---|
| 810 | namespace {
|
---|
| 811 | class Directives_test : public Directives
|
---|
| 812 | {
|
---|
| 813 | public:
|
---|
| 814 | bool throws;
|
---|
| 815 |
|
---|
| 816 | Directives_test(void) throw() : Directives(), throws(false) {}
|
---|
| 817 | Directives_test(string src) throw() : Directives(src), throws(false) {}
|
---|
| 818 |
|
---|
| 819 | void body(const Token & , Parser & ) throw(int)
|
---|
| 820 | {
|
---|
| 821 | TestSuite::check("Directives::body");
|
---|
| 822 | if(throws)
|
---|
| 823 | throw 0;
|
---|
| 824 | }
|
---|
| 825 | };
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | TESTSUITE(main, Directives)
|
---|
| 829 | {
|
---|
| 830 | Singleton<Namespace>::Context context;
|
---|
| 831 | Singleton<Namespace>::saveContext(context);
|
---|
| 832 |
|
---|
| 833 | Exception::setThrowControl(true);
|
---|
| 834 |
|
---|
| 835 | BEGIN_CASE("regist","regist") {
|
---|
| 836 | BEGIN_CASE("1","åä¸ã®ååãæå®ãã¦ç»é²ã§ãã") {
|
---|
| 837 | Singleton<Namespace>::renewInstance();
|
---|
| 838 | Directives_test api;
|
---|
| 839 |
|
---|
| 840 | api.regist("include");
|
---|
| 841 |
|
---|
| 842 | TEST_CASE("1","APIã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("include"));
|
---|
| 843 | } END_CASE;
|
---|
| 844 |
|
---|
| 845 | BEGIN_CASE("2","è¤æ°ã®ååãæå®ãã¦ç»é²ãã") {
|
---|
| 846 | Singleton<Namespace>::renewInstance();
|
---|
| 847 | Directives_test api;
|
---|
| 848 |
|
---|
| 849 | api.regist("pragma,define,endif");
|
---|
| 850 |
|
---|
| 851 | TEST_CASE("1","ãã£ã¬ã¯ãã£ãã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("pragma"));
|
---|
| 852 | TEST_CASE("2","ãã£ã¬ã¯ãã£ãã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("define"));
|
---|
| 853 | TEST_CASE("3","ãã£ã¬ã¯ãã£ãã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("endif"));
|
---|
| 854 | } END_CASE;
|
---|
| 855 |
|
---|
| 856 | BEGIN_CASE("3","ä¸æ¸ããã") {
|
---|
| 857 | Singleton<Namespace>::renewInstance();
|
---|
| 858 | Directives_test api;
|
---|
| 859 | Directives_test api2;
|
---|
| 860 | Directives_test api3;
|
---|
| 861 |
|
---|
| 862 | api.regist("test");
|
---|
| 863 | TEST_CASE("1","ãã£ã¬ã¯ãã£ãã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("test"));
|
---|
| 864 | TEST_CASE("2","ãã£ã¬ã¯ãã£ããã³ãã©ãæ£ãã", (*Directives::getClauseMap(NAMESPACE_DIRECTIVES))["test"] == &api);
|
---|
| 865 |
|
---|
| 866 | api2.regist("test");
|
---|
| 867 | TEST_CASE("3","ãã£ã¬ã¯ãã£ããã³ãã©ãä¸æ¸ãããã¦ãã", (*Directives::getClauseMap(NAMESPACE_DIRECTIVES))["test"] == &api2);
|
---|
| 868 |
|
---|
| 869 | api3.regist("test");
|
---|
| 870 | TEST_CASE("4","ãã£ã¬ã¯ãã£ããã³ãã©ãä¸æ¸ãããã¦ãã", (*Directives::getClauseMap(NAMESPACE_DIRECTIVES))["test"] == &api3);
|
---|
| 871 | } END_CASE;
|
---|
| 872 |
|
---|
| 873 | BEGIN_CASE("4","ã³ã³ã¹ãã©ã¯ã¿ã§ç»é²") {
|
---|
| 874 | Singleton<Namespace>::renewInstance();
|
---|
| 875 | Directives_test api("pragma,define,endif");
|
---|
| 876 |
|
---|
| 877 | TEST_CASE("1","ãã£ã¬ã¯ãã£ãã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("pragma"));
|
---|
| 878 | TEST_CASE("2","ãã£ã¬ã¯ãã£ãã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("define"));
|
---|
| 879 | TEST_CASE("3","ãã£ã¬ã¯ãã£ãã¯æ£ããç»é²ã§ãã¦ãã",Directives::hasDirectives("endif"));
|
---|
| 880 | } END_CASE;
|
---|
| 881 | } END_CASE;
|
---|
| 882 |
|
---|
| 883 | BEGIN_CASE("parseDirectives","parseDirectives") {
|
---|
| 884 | BEGIN_CASE("1","ãã£ã¬ã¯ãã£ããæ£ããå¦çã§ãã") {
|
---|
| 885 | Singleton<Namespace>::renewInstance();
|
---|
| 886 | stringstream buf;
|
---|
| 887 | Directives_test api("pragma");
|
---|
| 888 |
|
---|
| 889 | buf.str("pragma\nnext\n");
|
---|
| 890 | Parser p(&buf, "test");
|
---|
| 891 |
|
---|
| 892 | TestSuite::clearCheckpoints();
|
---|
| 893 | bool result = true;
|
---|
| 894 | try { Directives::parseDirectives(p); }
|
---|
| 895 | catch(...) { result = false; }
|
---|
| 896 |
|
---|
| 897 | TEST_CASE("1","ä¾å¤ã¯èµ·ããªã", result);
|
---|
| 898 | TEST_CASE("2","ãã£ã¬ã¯ãã£ãã®æ¬ä½ãå¼ã°ãã¦ãã", TestSuite::isReached("Directives::body"));
|
---|
| 899 | } END_CASE;
|
---|
| 900 |
|
---|
| 901 | BEGIN_CASE("2","æ¹è¡ãªã(ä¸æ£ãã©ã¡ã¼ã¿)ã§ä¾å¤") {
|
---|
| 902 | Singleton<Namespace>::renewInstance();
|
---|
| 903 | stringstream buf;
|
---|
| 904 | Directives_test api("pragma");
|
---|
| 905 |
|
---|
| 906 | buf.str("pragma next\n");
|
---|
| 907 | Parser p(&buf, "test");
|
---|
| 908 |
|
---|
| 909 | TestSuite::clearCheckpoints();
|
---|
| 910 | bool result = false;
|
---|
| 911 | try { Directives::parseDirectives(p); }
|
---|
| 912 | catch(...) { result = true; }
|
---|
| 913 |
|
---|
| 914 | TEST_CASE("1","ä¾å¤ãèµ·ã", result);
|
---|
| 915 | TEST_CASE("2","ãã£ã¬ã¯ãã£ãã®æ¬ä½ãå¼ã°ãã¦ãã", TestSuite::isReached("Directives::body"));
|
---|
| 916 | } END_CASE;
|
---|
| 917 |
|
---|
| 918 | BEGIN_CASE("3","æ¹è¡ãªã(EOF)ã§ä¾å¤") {
|
---|
| 919 | Singleton<Namespace>::renewInstance();
|
---|
| 920 | stringstream buf;
|
---|
| 921 | Directives_test api("pragma");
|
---|
| 922 |
|
---|
| 923 | buf.str("pragma");
|
---|
| 924 | Parser p(&buf, "test");
|
---|
| 925 |
|
---|
| 926 | TestSuite::clearCheckpoints();
|
---|
| 927 | bool result = false;
|
---|
| 928 | try { Directives::parseDirectives(p); }
|
---|
| 929 | catch(...) { result = true; }
|
---|
| 930 |
|
---|
| 931 | TEST_CASE("1","ä¾å¤ãèµ·ã", result);
|
---|
| 932 | TEST_CASE("2","ãã£ã¬ã¯ãã£ãã®æ¬ä½ãå¼ã°ãã¦ãã", TestSuite::isReached("Directives::body"));
|
---|
| 933 | } END_CASE;
|
---|
| 934 | } END_CASE;
|
---|
| 935 |
|
---|
| 936 | BEGIN_CASE("onFail","onFail") {
|
---|
| 937 | BEGIN_CASE("1","bodyã§ä¾å¤ãèµ·ãã¨onFailã次ã®æ¹è¡ã¾ã§èªã¿é£ã°ã") {
|
---|
| 938 | Singleton<Namespace>::renewInstance();
|
---|
| 939 | stringstream buf;
|
---|
| 940 | Directives_test api("pragma");
|
---|
| 941 | buf.str("pragma parameter\nnext\n");
|
---|
| 942 | Parser p(&buf, "test");
|
---|
| 943 |
|
---|
| 944 | api.throws = true;
|
---|
| 945 | bool result = false;
|
---|
| 946 | try { Directives::parseDirectives(p); }
|
---|
| 947 | catch(...) { result = true; }
|
---|
| 948 |
|
---|
| 949 | TEST_CASE("1","ä¾å¤ãèµ·ã", result);
|
---|
| 950 | TEST_CASE("2","æ®ã£ãå
|
---|
| 951 | 容ãæ£ãã", p.getToken() == "next");
|
---|
| 952 | TEST_CASE("3","ãã¼ã¯ã³ã¯è¡é ", p.isHeadofLine());
|
---|
| 953 | } END_CASE;
|
---|
| 954 | } END_CASE;
|
---|
| 955 |
|
---|
| 956 | Singleton<Namespace>::restoreContext(context);
|
---|
| 957 | }
|
---|
| 958 |
|
---|
| 959 | #endif
|
---|
| 960 |
|
---|
| 961 |
|
---|
| 962 |
|
---|