1 | /*
|
---|
2 | * TOPPERS/JSP Kernel
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems/
|
---|
4 | * Just Standard Profile Kernel
|
---|
5 | *
|
---|
6 | * Copyright (C) 2000-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: component.cpp,v 1.13 2003/12/15 07:32:13 takayuki Exp $
|
---|
51 | */
|
---|
52 |
|
---|
53 | // $Header: /home/CVS/configurator/base/component.cpp,v 1.13 2003/12/15 07:32:13 takayuki Exp $
|
---|
54 |
|
---|
55 | #include "base/component.h"
|
---|
56 |
|
---|
57 | #include <iostream>
|
---|
58 |
|
---|
59 | using namespace std;
|
---|
60 |
|
---|
61 | //ã³ã³ãã¼ãã³ãå
|
---|
62 | ¨ä½ã使ç¨ã§ãããªãtrue
|
---|
63 | bool Component::is_valid = true;
|
---|
64 |
|
---|
65 | //ã³ã³ãã¼ãã³ãã®ç»é²
|
---|
66 | bool Component::ComponentInfo::addComponent(Component * component, int order) throw()
|
---|
67 | {
|
---|
68 | bool result = false;
|
---|
69 |
|
---|
70 | if(this != 0 && component != 0) {
|
---|
71 | componentList.insert(multimap<int, Component *>::value_type(order, component));
|
---|
72 | result = true;
|
---|
73 | }
|
---|
74 |
|
---|
75 | return result;
|
---|
76 | }
|
---|
77 |
|
---|
78 | //ã³ã³ãã¼ãã³ãã®ç»é²è§£é¤
|
---|
79 | void Component::ComponentInfo::removeComponent(Component * component, int order) throw()
|
---|
80 | {
|
---|
81 | if(this != 0 && component != 0) {
|
---|
82 | multimap<int, Component *>::iterator scope;
|
---|
83 |
|
---|
84 | scope = componentList.lower_bound(order);
|
---|
85 | while(scope != componentList.end()) {
|
---|
86 | //ããæå®ãããåªå
|
---|
87 | 度ã¯ãã¹ã¦è¦ã
|
---|
88 | if(scope->first != order)
|
---|
89 | break;
|
---|
90 |
|
---|
91 | //æå®ãããã³ã³ãã¼ãã³ãã«ä¸è´ãããåé¤
|
---|
92 | if(scope->second == component) {
|
---|
93 | multimap<int, Component *>::iterator target = scope;
|
---|
94 | ++ scope;
|
---|
95 | componentList.erase(target);
|
---|
96 | }
|
---|
97 | else
|
---|
98 | ++ scope;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | //ã³ã³ãã¼ãã³ãã®ç»é²è§£é¤
|
---|
104 | void Component::ComponentInfo::removeComponent(Component * component) throw()
|
---|
105 | {
|
---|
106 | if(this != 0 && component != 0) {
|
---|
107 | multimap<int, Component *>::iterator scope;
|
---|
108 |
|
---|
109 | //æå®ãããã³ã³ãã¼ãã³ãã«ä¸è´ãããã®ãå
|
---|
110 | ¨ã¦åé¤
|
---|
111 | scope = componentList.begin();
|
---|
112 | while(scope != componentList.end()) {
|
---|
113 | if(scope->second == component) {
|
---|
114 | multimap<int, Component *>::iterator target = scope;
|
---|
115 | ++ scope;
|
---|
116 | componentList.erase(target);
|
---|
117 | }
|
---|
118 | else
|
---|
119 | ++ scope;
|
---|
120 | }
|
---|
121 |
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | //ã³ã³ãã¼ãã³ãã®èµ·åè¦æ±ã®çºè¡
|
---|
126 | bool Component::ComponentInfo::activateComponent(Component * component) throw()
|
---|
127 | {
|
---|
128 | bool result = false;
|
---|
129 |
|
---|
130 | if(this != 0 && component != 0) {
|
---|
131 | //èµ·åè¦æ±ã®æ«å°¾ã«å ãã
|
---|
132 | activatedComponentList.push_back(component);
|
---|
133 | result = true;
|
---|
134 | }
|
---|
135 |
|
---|
136 | return result;
|
---|
137 | }
|
---|
138 |
|
---|
139 | //ãªãã·ã§ã³ã®ãã¼ã¹
|
---|
140 | void Component::ComponentInfo::parseOption(OptionParameter & option)
|
---|
141 | {
|
---|
142 | if(this != 0) {
|
---|
143 | multimap<int, Component *>::iterator scope;
|
---|
144 |
|
---|
145 | //å
|
---|
146 | ¨ã¦ã®ã³ã³ãã¼ãã³ãã®parseOptionãå®è¡
|
---|
147 | scope = componentList.begin();
|
---|
148 | while(scope != componentList.end()) {
|
---|
149 | DebugMessage("Component::parseOption start - %\n") << typeid(*scope->second).name();
|
---|
150 | scope->second->parseOption(option);
|
---|
151 | DebugMessage("Component::parseOption finish - %\n") << typeid(*scope->second).name();
|
---|
152 | ++ scope;
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | //ã³ã³ãã¼ãã³ãã®èµ·å
|
---|
158 | void Component::ComponentInfo::activateComponent(void)
|
---|
159 | {
|
---|
160 | if(this != 0) {
|
---|
161 | list<Component *>::iterator scope;
|
---|
162 |
|
---|
163 | try {
|
---|
164 | //èµ·åè¦æ±ã®ãã£ãå
|
---|
165 | ¨ã¦ã®ã³ã³ãã¼ãã³ããèµ·å
|
---|
166 | scope = activatedComponentList.begin();
|
---|
167 | while(scope != activatedComponentList.end()) {
|
---|
168 | DebugMessage("Component::body start - %\n") << typeid(**scope).name();
|
---|
169 | (*scope)->body();
|
---|
170 | DebugMessage("Component::body finish - %\n") << typeid(**scope).name();
|
---|
171 | ++ scope;
|
---|
172 | }
|
---|
173 | //è¦æ±ãªã¹ããã¯ãªã¢
|
---|
174 | activatedComponentList.clear();
|
---|
175 | }
|
---|
176 | catch(...) {
|
---|
177 | //onFatalExitç¨ã«ãactivatedComponentListãèµ·åããããã³ã³ãã¼ãã³ãã ãã«çµã
|
---|
178 | ++ scope;
|
---|
179 | if(scope != activatedComponentList.end())
|
---|
180 | activatedComponentList.erase(scope, activatedComponentList.end());
|
---|
181 |
|
---|
182 | throw;
|
---|
183 | }
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | //ç°å¸¸å¦çãã³ãã©ã®èµ·å
|
---|
188 | void Component::ComponentInfo::onFatalExit(void)
|
---|
189 | {
|
---|
190 | if(this != 0) {
|
---|
191 | Component * handler;
|
---|
192 |
|
---|
193 | //èµ·åè¦æ±ã®ãã£ãå
|
---|
194 | ¨ã¦ã®ã³ã³ãã¼ãã³ããèµ·å
|
---|
195 | while(!activatedComponentList.empty()) {
|
---|
196 | handler = *activatedComponentList.begin();
|
---|
197 | activatedComponentList.pop_front();
|
---|
198 |
|
---|
199 | //ãã³ãã©ãèµ·å
|
---|
200 | DebugMessage("Component::onFatalExit start - %\n") << typeid(*handler).name();
|
---|
201 | handler->onFatalExit();
|
---|
202 | DebugMessage("Component::onFatalExit fihish - %\n") << typeid(*handler).name();
|
---|
203 | }
|
---|
204 | //è¦æ±ãªã¹ããã¯ãªã¢
|
---|
205 | activatedComponentList.clear();
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|
210 | /*
|
---|
211 | * Component : ã³ã³ãã¼ãã³ã
|
---|
212 | */
|
---|
213 |
|
---|
214 | //ã³ã³ã¹ãã©ã¯ã¿
|
---|
215 | Component::Component(int order) throw() : RuntimeObject()
|
---|
216 | {
|
---|
217 | //ããã§åãã¦ã·ã³ã°ã«ãã³ã¤ã³ã¹ã¿ã³ã¹ã«ã¢ã¯ã»ã¹ããã®ã§ãbad_allocãçºçããå¯è½æ§ããã
|
---|
218 | try {
|
---|
219 | Singleton<ComponentInfo>::getInstance()->addComponent(this, order);
|
---|
220 | }
|
---|
221 | catch(bad_alloc) {
|
---|
222 | is_valid = false;
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | //ãã¹ãã©ã¯ã¿
|
---|
227 | Component::~Component(void) throw()
|
---|
228 | { Singleton<ComponentInfo>::getInstance()->removeComponent(this); }
|
---|
229 |
|
---|
230 | //ã³ã³ãã¼ãã³ãã®å®è¡
|
---|
231 | void Component::executeComponents(int argc, char * argv [])
|
---|
232 | {
|
---|
233 | OptionParameter & option = getOptionParameter();
|
---|
234 |
|
---|
235 | option.parseOption(argc, argv);
|
---|
236 | executeComponents(option);
|
---|
237 | }
|
---|
238 |
|
---|
239 | //ã³ã³ãã¼ãã³ãã®å®è¡
|
---|
240 | void Component::executeComponents(OptionParameter & option)
|
---|
241 | {
|
---|
242 | if(isValid()) {
|
---|
243 |
|
---|
244 | _parseCommonOption(option);
|
---|
245 |
|
---|
246 | try {
|
---|
247 | //ãªãã·ã§ã³ã®ãã¼ã¹
|
---|
248 | Singleton<ComponentInfo>::getInstance()->parseOption(option);
|
---|
249 |
|
---|
250 | //å
|
---|
251 | ¨ã¦ã®ãªãã·ã§ã³ãä½¿ç¨æ¸ã¿ã§ãªããã°ã¨ã©ã¼
|
---|
252 | if(!option.validateOption()) {
|
---|
253 | CHECKPOINT("Exception_UnknownOption");
|
---|
254 | ExceptionMessage("Unknown option [%] found.","䏿ãªãªãã·ã§ã³ãæå®ããã : %") << option.getInvalidOptions() << throwException;
|
---|
255 | }
|
---|
256 | else {
|
---|
257 | //ã³ã³ãã¼ãã³ãã®å®è¡
|
---|
258 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
259 | }
|
---|
260 | }
|
---|
261 |
|
---|
262 | //ä¾å¤ã®çºç -> ç°å¸¸çµäºãã³ãã©ã®èµ·å
|
---|
263 | catch(...) {
|
---|
264 | bool continuation;
|
---|
265 | do {
|
---|
266 | try {
|
---|
267 | continuation = true;
|
---|
268 | Singleton<ComponentInfo>::getInstance()->onFatalExit();
|
---|
269 | continuation = false;
|
---|
270 | }
|
---|
271 | catch(Exception & e) {
|
---|
272 | CHECKPOINT("Exception_onFatalExit");
|
---|
273 | cerr << Message("[Internal error] onFatalExit threw an exception! : ","[å
|
---|
274 | é¨ã¨ã©ã¼] onFatalExitä¸ã®ä¾å¤! : ") << e.getDetails() << '\n';
|
---|
275 | }
|
---|
276 | } while(continuation);
|
---|
277 |
|
---|
278 | throw;
|
---|
279 | }
|
---|
280 | }
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | //ä¸è¬çãªãªãã·ã§ã³ã®å¦ç
|
---|
285 | void Component::_parseCommonOption(OptionParameter & option) throw()
|
---|
286 | {
|
---|
287 | //ãããã°å¦ç
|
---|
288 | if(option.find("debug")) {
|
---|
289 | DebugMessage::setStream(&cerr);
|
---|
290 | DebugMessage::setVerbose(true);
|
---|
291 | }
|
---|
292 |
|
---|
293 | //è¨èªé¸æ
|
---|
294 | if(option.find("lj") || option.find("-japanese"))
|
---|
295 | Message::selectLanguage(Message::JAPANESE);
|
---|
296 | if(option.find("le") || option.find("-english"))
|
---|
297 | Message::selectLanguage(Message::ENGLISH);
|
---|
298 |
|
---|
299 | //åé·ã¡ãã»ã¼ã¸
|
---|
300 | if(option.find("v") || option.find("-verbose")) {
|
---|
301 | VerboseMessage::setStream(&cout);
|
---|
302 | VerboseMessage::setVerbose(true);
|
---|
303 | }
|
---|
304 |
|
---|
305 | //ããã¼è¡¨ç¤º
|
---|
306 | if(!getBanner().empty() && option.find("v") || option.find("-verbose") || option.find("h") || option.find("-help"))
|
---|
307 | cout << getBanner() << endl;
|
---|
308 |
|
---|
309 | //ãã«ã表示
|
---|
310 | if(option.find("h") || option.find("-help"))
|
---|
311 | cout << '\n' << Message(
|
---|
312 | "Global option\n"
|
---|
313 | " -lj, --japanese : Use Japanese as default language\n"
|
---|
314 | " -le, --english : Use English as default language\n"
|
---|
315 | " -v, --verbose : Verbose Message\n",
|
---|
316 | "å
|
---|
317 | ¨ä½ã®ãªãã·ã§ã³\n"
|
---|
318 | " -lj, --japanese : æ¥æ¬èªã§è¡¨ç¤ºãã¾ã\n"
|
---|
319 | " -le, --english : è±èªã§è¡¨ç¤ºãã¾ã\n"
|
---|
320 | " -v, --verbose : åé·ã¡ãã»ã¼ã¸ãåºåãã¾ã\n");
|
---|
321 | }
|
---|
322 |
|
---|
323 | //ããã¼ã¢ã¯ã»ãµ
|
---|
324 | void Component::setBanner(string src) throw(bad_alloc)
|
---|
325 | {
|
---|
326 | ComponentInfo * info = Singleton<ComponentInfo>::getInstance();
|
---|
327 | info->setBanner(src);
|
---|
328 | }
|
---|
329 |
|
---|
330 | string Component::getBanner(void) throw(bad_alloc)
|
---|
331 | {
|
---|
332 | ComponentInfo * info = Singleton<ComponentInfo>::getInstance();
|
---|
333 | return info->getBanner();
|
---|
334 | }
|
---|
335 |
|
---|
336 | /*
|
---|
337 | * éå»ã¨ã®äºææ§ã®ããã®ãã©ã¡ã¼ã¿æä½API
|
---|
338 | */
|
---|
339 |
|
---|
340 | /* æå®ããããªãã·ã§ã³ã®åå¨ã確èªããå¿
|
---|
341 | è¦ã§ããã°ãã®ãã©ã¡ã¼ã¿ãåå¾ãã */
|
---|
342 | bool Component::findOption(const char * key1, const char * key2, std::string * element) throw()
|
---|
343 | {
|
---|
344 | OptionParameter::OptionItem item;
|
---|
345 |
|
---|
346 | item = getOption(key1, key2, true);
|
---|
347 | if(item.isValid() && element != 0 && item.hasParameter())
|
---|
348 | *element = item[0];
|
---|
349 |
|
---|
350 | return item.isValid();
|
---|
351 | }
|
---|
352 |
|
---|
353 | /* åå¨ç¢ºèª + ãã§ãã¯ãã¤ãã */
|
---|
354 | bool Component::checkOption(const char * key1, const char * key2) throw()
|
---|
355 | { return getOption(key1, key2, true).isValid(); }
|
---|
356 |
|
---|
357 | /* æå®ãããååã®ãªãã·ã§ã³ãã©ã¡ã¼ã¿ãåå¾ */
|
---|
358 | OptionParameter::OptionItem Component::getOption(const char * key1, const char * key2, bool dirty) throw()
|
---|
359 | {
|
---|
360 | OptionParameter::OptionItem item;
|
---|
361 |
|
---|
362 | if(key1 != 0)
|
---|
363 | item = getOptionParameter().get(key1, dirty);
|
---|
364 |
|
---|
365 | if(key2 != 0) {
|
---|
366 | if(item.isValid())
|
---|
367 | item.mergeItem(getOptionParameter().get(string("-") + key2, dirty));
|
---|
368 | else
|
---|
369 | item = getOptionParameter().get(string("-") + key2, dirty);
|
---|
370 | }
|
---|
371 |
|
---|
372 | return item;
|
---|
373 | }
|
---|
374 |
|
---|
375 | /* 2ã¤ã®ãªãã·ã§ã³é
|
---|
376 | ç®ããã¼ã¸ãã (æ¾ã£ã¦ããã¦ããã¼ã¸ãããã®ã§æ°ã«ããªã) */
|
---|
377 | OptionParameter::OptionItem Component::mergeOption(const char * key1, const char * key2) throw()
|
---|
378 | { return getOption(key1, key2); }
|
---|
379 |
|
---|
380 |
|
---|
381 |
|
---|
382 | /****************************************************** ãã¹ãã¹ã£ã¼ã ******************************************************/
|
---|
383 |
|
---|
384 | #ifdef TESTSUITE
|
---|
385 | #include "coverage_undefs.h"
|
---|
386 |
|
---|
387 | namespace {
|
---|
388 | int counter = 0;
|
---|
389 |
|
---|
390 | class TestComponent : public Component
|
---|
391 | {
|
---|
392 | public:
|
---|
393 | bool check_parseOption;
|
---|
394 | bool check_body;
|
---|
395 | bool check_onFatalExit;
|
---|
396 | bool activation;
|
---|
397 | bool throw_parseOption;
|
---|
398 | bool throw_body;
|
---|
399 | bool throw_onFatalExit;
|
---|
400 | int actcnt;
|
---|
401 |
|
---|
402 | TestComponent(int order = GENERAL_PURPOSE) : Component(order)
|
---|
403 | {
|
---|
404 | check_parseOption = false;
|
---|
405 | check_body = false;
|
---|
406 | check_onFatalExit = false;
|
---|
407 | activation = false;
|
---|
408 | throw_parseOption = false;
|
---|
409 | throw_body = false;
|
---|
410 | throw_onFatalExit = false;
|
---|
411 | }
|
---|
412 |
|
---|
413 | void parseOption(OptionParameter & option) throw(Exception)
|
---|
414 | {
|
---|
415 | actcnt = ++counter;
|
---|
416 | check_parseOption = true;
|
---|
417 | if(activation)
|
---|
418 | activateComponent();
|
---|
419 | if(throw_parseOption)
|
---|
420 | ExceptionMessage("exception","exception").throwException();
|
---|
421 | }
|
---|
422 |
|
---|
423 | void body(void) throw(Exception)
|
---|
424 | {
|
---|
425 | actcnt = ++counter;
|
---|
426 | check_body = true;
|
---|
427 | if(throw_body)
|
---|
428 | ExceptionMessage("exception","exception").throwException();
|
---|
429 | }
|
---|
430 |
|
---|
431 | void onFatalExit(void) throw(Exception)
|
---|
432 | {
|
---|
433 | actcnt = ++counter;
|
---|
434 | check_onFatalExit = true;
|
---|
435 | if(throw_onFatalExit)
|
---|
436 | ExceptionMessage("exception","exception").throwException();
|
---|
437 | }
|
---|
438 | };
|
---|
439 |
|
---|
440 | class DerivedTestComponent : public TestComponent
|
---|
441 | {};
|
---|
442 | }
|
---|
443 |
|
---|
444 |
|
---|
445 | TESTSUITE_(main,ComponentInfo,Component)
|
---|
446 | {
|
---|
447 | Singleton<ComponentInfo>::Context context;
|
---|
448 | Singleton<ComponentInfo>::saveContext(context);
|
---|
449 | Singleton<ComponentInfo>::renewInstance();
|
---|
450 |
|
---|
451 | BEGIN_CASE("addComponent","addComponent") {
|
---|
452 |
|
---|
453 | BEGIN_CASE("1","æ£ãã追å ã§ãã") {
|
---|
454 | ComponentInfo info;
|
---|
455 |
|
---|
456 | BEGIN_CASE("1","颿°ã¯æåãã") {
|
---|
457 | if(!info.addComponent((Component *)0x1234, 10))
|
---|
458 | TEST_FAIL;
|
---|
459 | } END_CASE;
|
---|
460 |
|
---|
461 | BEGIN_CASE("2","追å ããã¦ãã") {
|
---|
462 | if(info.componentList.size() != 1)
|
---|
463 | TEST_FAIL;
|
---|
464 | } END_CASE;
|
---|
465 |
|
---|
466 | BEGIN_CASE("3", "å
|
---|
467 | å®¹ãæ£ãã") {
|
---|
468 | if(info.componentList.begin()->first != 10 || info.componentList.begin()->second != (Component *)0x1234)
|
---|
469 | TEST_FAIL;
|
---|
470 | } END_CASE;
|
---|
471 | } END_CASE;
|
---|
472 |
|
---|
473 | BEGIN_CASE("2","NULLã¤ã³ã¹ã¿ã³ã¹ã¯ç»é²ã§ããªã") {
|
---|
474 | ComponentInfo info;
|
---|
475 |
|
---|
476 | BEGIN_CASE("1","颿°ã¯å¤±æãã") {
|
---|
477 | if(info.addComponent(0, 10))
|
---|
478 | TEST_FAIL;
|
---|
479 | } END_CASE;
|
---|
480 |
|
---|
481 | BEGIN_CASE("2","è¦ç´ ã¯è¿½å ããã¦ããªã") {
|
---|
482 | if(info.componentList.size() != 0)
|
---|
483 | TEST_FAIL;
|
---|
484 | } END_CASE;
|
---|
485 | } END_CASE;
|
---|
486 |
|
---|
487 | BEGIN_CASE("3","NULLã¤ã³ã¹ã¿ã³ã¹ã«æä½ããã¨falseãè¿ã") {
|
---|
488 | if(((ComponentInfo *)0)->addComponent((Component *)0x1234, 10))
|
---|
489 | TEST_FAIL;
|
---|
490 | } END_CASE;
|
---|
491 |
|
---|
492 | } END_CASE;
|
---|
493 |
|
---|
494 | BEGIN_CASE("removeComponent(Component *, int)","removeComponent(Component *, int)") {
|
---|
495 | BEGIN_CASE("1", "æ£ããè§£é¤ã§ãã") {
|
---|
496 | ComponentInfo info;
|
---|
497 |
|
---|
498 | info.addComponent((Component *)0x0123, 10); //38è¡ç®ã®ifã®elseãå®è¡ãããããã®ããã¼
|
---|
499 | info.addComponent((Component *)0x1234, 10);
|
---|
500 | info.addComponent((Component *)0x1234, 20);
|
---|
501 |
|
---|
502 | info.removeComponent((Component *)0x1234, 10);
|
---|
503 | info.removeComponent((Component *)0x0123, 10);
|
---|
504 |
|
---|
505 | BEGIN_CASE("1","è¦ç´ æ°ã1") {
|
---|
506 | if(info.componentList.size() != 1)
|
---|
507 | TEST_FAIL;
|
---|
508 | } END_CASE;
|
---|
509 |
|
---|
510 | BEGIN_CASE("2","æ®ã£ãè¦ç´ ã®orderã¯20") {
|
---|
511 | if(info.componentList.begin()->first != 20)
|
---|
512 | TEST_FAIL;
|
---|
513 | } END_CASE;
|
---|
514 | } END_CASE;
|
---|
515 |
|
---|
516 | BEGIN_CASE("2", "NULLãªãã¸ã§ã¯ãããå®è¡ãã¦ã大ä¸å¤«") {
|
---|
517 | ((ComponentInfo *)0)->removeComponent(0, 0);
|
---|
518 | } END_CASE;
|
---|
519 | } END_CASE;
|
---|
520 |
|
---|
521 | BEGIN_CASE("removeComponent(Component *)","removeComponent(Component *)") {
|
---|
522 | BEGIN_CASE("1", "æ£ããè§£é¤ã§ãã") {
|
---|
523 | ComponentInfo info;
|
---|
524 | multimap<int, Component *>::iterator scope;
|
---|
525 |
|
---|
526 | info.addComponent((Component *)0x1234, 10);
|
---|
527 | info.addComponent((Component *)0x1235, 10);
|
---|
528 | info.addComponent((Component *)0x1234, 20);
|
---|
529 | info.addComponent((Component *)0x1235, 20);
|
---|
530 |
|
---|
531 | info.removeComponent((Component *)0x1234);
|
---|
532 |
|
---|
533 | BEGIN_CASE("1","è¦ç´ æ°ã2") {
|
---|
534 | if(info.componentList.size() != 2)
|
---|
535 | TEST_FAIL;
|
---|
536 | } END_CASE;
|
---|
537 |
|
---|
538 | scope = info.componentList.begin();
|
---|
539 | BEGIN_CASE("2","æ®ã£ãè¦ç´ ã®å
|
---|
540 | å®¹ã¯æ£ãã") {
|
---|
541 | if(scope->first != 10 || scope->second != (Component *)0x1235)
|
---|
542 | TEST_FAIL;
|
---|
543 | ++ scope;
|
---|
544 | if(scope->first != 20 || scope->second != (Component *)0x1235)
|
---|
545 | TEST_FAIL;
|
---|
546 | } END_CASE;
|
---|
547 | } END_CASE;
|
---|
548 |
|
---|
549 | BEGIN_CASE("2", "NULLãªãã¸ã§ã¯ãããå®è¡ãã¦ã大ä¸å¤«") {
|
---|
550 | ((ComponentInfo *)0)->removeComponent(0);
|
---|
551 | } END_CASE;
|
---|
552 | } END_CASE;
|
---|
553 |
|
---|
554 | BEGIN_CASE("activateComponent","activateComponent") {
|
---|
555 | BEGIN_CASE("1","æ£å¸¸ã«è¿½å ã§ãã") {
|
---|
556 | ComponentInfo info;
|
---|
557 |
|
---|
558 | BEGIN_CASE("1","颿°ã¯æåãã") {
|
---|
559 | if(!info.activateComponent((Component *)0x1234))
|
---|
560 | TEST_FAIL;
|
---|
561 | } END_CASE;
|
---|
562 |
|
---|
563 | BEGIN_CASE("2","èµ·åè¦æ±ãªã¹ãã«æ£ãã追å ããã¦ãã") {
|
---|
564 | if(info.activatedComponentList.size() != 1)
|
---|
565 | TEST_FAIL;
|
---|
566 | if(*info.activatedComponentList.begin() != (Component *)0x1234)
|
---|
567 | TEST_FAIL;
|
---|
568 | } END_CASE;
|
---|
569 |
|
---|
570 | BEGIN_CASE("3","NULLãªãã¸ã§ã¯ãããçºè¡ãã¦ãæ´èµ°ããªã") {
|
---|
571 | ((ComponentInfo *)0)->activateComponent();
|
---|
572 | } END_CASE;
|
---|
573 | } END_CASE;
|
---|
574 |
|
---|
575 | BEGIN_CASE("1","NULLã¤ã³ã¹ã¿ã³ã¹ã¯è¿½å ãããªã") {
|
---|
576 | ComponentInfo info;
|
---|
577 |
|
---|
578 | BEGIN_CASE("1","颿°ã¯å¤±æãã") {
|
---|
579 | if(info.activateComponent((Component *)0))
|
---|
580 | TEST_FAIL;
|
---|
581 | } END_CASE;
|
---|
582 |
|
---|
583 | BEGIN_CASE("2","èµ·åè¦æ±ãªã¹ãã¯ç©ºã®ã¾ã¾") {
|
---|
584 | if(!info.activatedComponentList.empty())
|
---|
585 | TEST_FAIL;
|
---|
586 | } END_CASE;
|
---|
587 | } END_CASE;
|
---|
588 | } END_CASE;
|
---|
589 |
|
---|
590 | BEGIN_CASE("Component::Component","Component::Component") {
|
---|
591 | Singleton<ComponentInfo>::renewInstance();
|
---|
592 | TestComponent * test = 0;
|
---|
593 |
|
---|
594 | BEGIN_CASE("0","åææ¡ä»¶ãæºãã") {
|
---|
595 | if(Singleton<ComponentInfo>::getInstance()->componentList.size() != 0)
|
---|
596 | TEST_FAIL;
|
---|
597 | } END_CASE;
|
---|
598 |
|
---|
599 | BEGIN_CASE("1","Componentãã¤ã³ã¹ã¿ã³ã¹åããã¨ãåæã«ç»é²ããã") {
|
---|
600 | test = new TestComponent;
|
---|
601 | if(Singleton<ComponentInfo>::getInstance()->componentList.size() != 1)
|
---|
602 | TEST_FAIL;
|
---|
603 | } END_CASE;
|
---|
604 |
|
---|
605 | BEGIN_CASE("2","ç»é²ããã¦ããå
|
---|
606 | å®¹ã¯æ£ãã") {
|
---|
607 | if(Singleton<ComponentInfo>::getInstance()->componentList.begin()->second != test)
|
---|
608 | TEST_FAIL;
|
---|
609 | } END_CASE;
|
---|
610 |
|
---|
611 | BEGIN_CASE("3","ç ´æ£ããã¨ã¨ã³ããªãæ¶ãã") {
|
---|
612 | delete test;
|
---|
613 | if(Singleton<ComponentInfo>::getInstance()->componentList.size() != 0)
|
---|
614 | TEST_FAIL;
|
---|
615 | } END_CASE;
|
---|
616 | } END_CASE;
|
---|
617 |
|
---|
618 | BEGIN_CASE("parseOption","parseOption") {
|
---|
619 |
|
---|
620 | BEGIN_CASE("1","parseOptionãå®è¡ããã¨ç»é²ãããã³ã³ãã¼ãã³ãã®parseOptionãå®è¡ããã") {
|
---|
621 | Singleton<ComponentInfo>::renewInstance();
|
---|
622 |
|
---|
623 | TestComponent test;
|
---|
624 | TestComponent test2;
|
---|
625 |
|
---|
626 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
627 |
|
---|
628 | if(!test.check_parseOption || !test2.check_parseOption)
|
---|
629 | TEST_FAIL;
|
---|
630 | } END_CASE;
|
---|
631 |
|
---|
632 | BEGIN_CASE("2","èµ·åé åºãæ£ãã (åä¸ã¬ãã«ãªãç»é²é )") {
|
---|
633 | Singleton<ComponentInfo>::renewInstance();
|
---|
634 |
|
---|
635 | TestComponent test;
|
---|
636 | TestComponent test2;
|
---|
637 |
|
---|
638 | counter = 0;
|
---|
639 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
640 |
|
---|
641 | if(test.actcnt != 1 || test2.actcnt != 2 )
|
---|
642 | TEST_FAIL;
|
---|
643 | } END_CASE;
|
---|
644 |
|
---|
645 | BEGIN_CASE("3","èµ·åé åºãæ£ãã (åªå
|
---|
646 | 度é )") {
|
---|
647 | Singleton<ComponentInfo>::renewInstance();
|
---|
648 |
|
---|
649 | TestComponent test(10);
|
---|
650 | TestComponent test2(1);
|
---|
651 |
|
---|
652 | counter = 0;
|
---|
653 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
654 |
|
---|
655 | if(test.actcnt != 2 || test2.actcnt != 1 )
|
---|
656 | TEST_FAIL;
|
---|
657 | } END_CASE;
|
---|
658 |
|
---|
659 | BEGIN_CASE("4","activateããããã¨activateListã«ç»é²ããã") {
|
---|
660 | Singleton<ComponentInfo>::renewInstance();
|
---|
661 |
|
---|
662 | TestComponent test;
|
---|
663 | TestComponent test2;
|
---|
664 | list<Component *>::iterator scope;
|
---|
665 |
|
---|
666 | test.activation = true;
|
---|
667 | test2.activation = true;
|
---|
668 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
669 |
|
---|
670 | if(Singleton<ComponentInfo>::getInstance()->activatedComponentList.size() != 2)
|
---|
671 | TEST_FAIL;
|
---|
672 | scope = Singleton<ComponentInfo>::getInstance()->activatedComponentList.begin();
|
---|
673 | if(*scope != &test)
|
---|
674 | TEST_FAIL;
|
---|
675 | ++ scope;
|
---|
676 | if(*scope != &test2)
|
---|
677 | TEST_FAIL;
|
---|
678 | } END_CASE;
|
---|
679 |
|
---|
680 | BEGIN_CASE("5","ä¾å¤ã¯æãã¦ãã") {
|
---|
681 | Singleton<ComponentInfo>::renewInstance();
|
---|
682 |
|
---|
683 | TestComponent test;
|
---|
684 | TestComponent test2;
|
---|
685 | list<Component *>::iterator scope;
|
---|
686 | bool result = false;
|
---|
687 |
|
---|
688 | Exception::setThrowControl(true);
|
---|
689 | test.throw_parseOption = true;
|
---|
690 | try {
|
---|
691 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
692 | }
|
---|
693 | catch(...) {
|
---|
694 | result = true;
|
---|
695 | }
|
---|
696 |
|
---|
697 | if(!result)
|
---|
698 | TEST_FAIL;
|
---|
699 | } END_CASE;
|
---|
700 |
|
---|
701 | BEGIN_CASE("6","ä¾å¤åã«ç»é²ãããactivateã¯æ®ã") {
|
---|
702 | Singleton<ComponentInfo>::renewInstance();
|
---|
703 |
|
---|
704 | TestComponent test;
|
---|
705 | TestComponent test2;
|
---|
706 | list<Component *>::iterator scope;
|
---|
707 | bool result = false;
|
---|
708 |
|
---|
709 | Exception::setThrowControl(true);
|
---|
710 | test.activation = true;
|
---|
711 | test2.throw_parseOption = true;
|
---|
712 | try {
|
---|
713 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
714 | }
|
---|
715 | catch(...) {
|
---|
716 | result = true;
|
---|
717 | }
|
---|
718 |
|
---|
719 | if(!result)
|
---|
720 | TEST_FAIL;
|
---|
721 |
|
---|
722 | if(Singleton<ComponentInfo>::getInstance()->activatedComponentList.size() != 1)
|
---|
723 | TEST_FAIL;
|
---|
724 |
|
---|
725 | if(*Singleton<ComponentInfo>::getInstance()->activatedComponentList.begin() != &test)
|
---|
726 | TEST_FAIL;
|
---|
727 | } END_CASE;
|
---|
728 |
|
---|
729 | BEGIN_CASE("7","NULLã¤ã³ã¹ã¿ã³ã¹ããã®ã³ã¼ã«ã«èãã") {
|
---|
730 | ((ComponentInfo *)0)->parseOption(getOptionParameter());
|
---|
731 | } END_CASE;
|
---|
732 | }END_CASE;
|
---|
733 |
|
---|
734 | BEGIN_CASE("activateCompoent/Component::body","activateCompoent/Component::body") {
|
---|
735 | BEGIN_CASE("1","activateComponentãããã¨ãèµ·åè¦æ±ãåºããã³ã³ãã¼ãã³ããèµ·åããã") {
|
---|
736 | Singleton<ComponentInfo>::renewInstance();
|
---|
737 |
|
---|
738 | TestComponent test;
|
---|
739 | TestComponent test2;
|
---|
740 |
|
---|
741 | test.activation = true;
|
---|
742 | test2.activation = true;
|
---|
743 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
744 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
745 |
|
---|
746 | if(!test.check_body || !test2.check_body)
|
---|
747 | TEST_FAIL;
|
---|
748 | } END_CASE;
|
---|
749 |
|
---|
750 | BEGIN_CASE("2","èµ·åè¦æ±ãåºããªãã³ã³ãã¼ãã³ãã¯èµ·åãããªã") {
|
---|
751 | Singleton<ComponentInfo>::renewInstance();
|
---|
752 |
|
---|
753 | TestComponent test;
|
---|
754 | TestComponent test2;
|
---|
755 |
|
---|
756 | test.activation = false;
|
---|
757 | test2.activation = true;
|
---|
758 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
759 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
760 |
|
---|
761 | if(test.check_body || !test2.check_body)
|
---|
762 | TEST_FAIL;
|
---|
763 | } END_CASE;
|
---|
764 |
|
---|
765 | BEGIN_CASE("3","èµ·åé åºãæ£ãã (åä¸ã¬ãã«ãªãç»é²é )") {
|
---|
766 | Singleton<ComponentInfo>::renewInstance();
|
---|
767 |
|
---|
768 | TestComponent test;
|
---|
769 | TestComponent test2;
|
---|
770 | counter = 0;
|
---|
771 |
|
---|
772 | test.activation = test2.activation = true;
|
---|
773 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
774 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
775 |
|
---|
776 | if(test.actcnt != 3 || test2.actcnt != 4 )
|
---|
777 | TEST_FAIL;
|
---|
778 | } END_CASE;
|
---|
779 |
|
---|
780 | BEGIN_CASE("4","èµ·åé åºãæ£ãã (åªå
|
---|
781 | 度é )") {
|
---|
782 | Singleton<ComponentInfo>::renewInstance();
|
---|
783 |
|
---|
784 | TestComponent test(10);
|
---|
785 | TestComponent test2(4);
|
---|
786 | counter = 0;
|
---|
787 |
|
---|
788 | test.activation = test2.activation = true;
|
---|
789 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
790 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
791 |
|
---|
792 | if(test.actcnt != 4 || test2.actcnt != 3 )
|
---|
793 | TEST_FAIL;
|
---|
794 | } END_CASE;
|
---|
795 |
|
---|
796 | BEGIN_CASE("5","ä¾å¤ã¯æãã¦ãã") {
|
---|
797 | Singleton<ComponentInfo>::renewInstance();
|
---|
798 |
|
---|
799 | TestComponent test;
|
---|
800 | TestComponent test2;
|
---|
801 | list<Component *>::iterator scope;
|
---|
802 | bool result = false;
|
---|
803 |
|
---|
804 | Exception::setThrowControl(true);
|
---|
805 | test.activation = test2.activation = true;
|
---|
806 | test.throw_body = true;
|
---|
807 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
808 | try {
|
---|
809 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
810 | }
|
---|
811 | catch(...) {
|
---|
812 | result = true;
|
---|
813 | }
|
---|
814 |
|
---|
815 | if(!result)
|
---|
816 | TEST_FAIL;
|
---|
817 | } END_CASE;
|
---|
818 |
|
---|
819 | BEGIN_CASE("6","ä¾å¤ãèµ·ãããããããã¾ã§ã«èµ·åããã³ã³ãã¼ãã³ããactivatedComponentListã«æ®ã") {
|
---|
820 | Singleton<ComponentInfo>::renewInstance();
|
---|
821 |
|
---|
822 | TestComponent test;
|
---|
823 | TestComponent test2;
|
---|
824 | bool result = false;
|
---|
825 |
|
---|
826 | Exception::setThrowControl(true);
|
---|
827 | test.activation = test2.activation = true;
|
---|
828 | test.throw_body = true;
|
---|
829 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
830 | try {
|
---|
831 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
832 | }
|
---|
833 | catch(...) {
|
---|
834 | result = true;
|
---|
835 | }
|
---|
836 |
|
---|
837 | if(!result)
|
---|
838 | TEST_FAIL;
|
---|
839 |
|
---|
840 | if(Singleton<ComponentInfo>::getInstance()->activatedComponentList.size() != 1)
|
---|
841 | TEST_FAIL;
|
---|
842 |
|
---|
843 | if(*Singleton<ComponentInfo>::getInstance()->activatedComponentList.begin() != &test)
|
---|
844 | TEST_FAIL;
|
---|
845 | } END_CASE;
|
---|
846 |
|
---|
847 | BEGIN_CASE("8","ä¾å¤ãèµ·ãããããããã¾ã§ã«èµ·åããã³ã³ãã¼ãã³ããactivatedComponentListã«æ®ã(2åç®)") {
|
---|
848 | Singleton<ComponentInfo>::renewInstance();
|
---|
849 |
|
---|
850 | TestComponent test;
|
---|
851 | TestComponent test2;
|
---|
852 | list<Component *>::iterator scope;
|
---|
853 | bool result = false;
|
---|
854 |
|
---|
855 | Exception::setThrowControl(true);
|
---|
856 | test.activation = test2.activation = true;
|
---|
857 | test2.throw_body = true;
|
---|
858 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
859 | try {
|
---|
860 | Singleton<ComponentInfo>::getInstance()->activateComponent();
|
---|
861 | }
|
---|
862 | catch(...) {
|
---|
863 | result = true;
|
---|
864 | }
|
---|
865 |
|
---|
866 | if(!result)
|
---|
867 | TEST_FAIL;
|
---|
868 |
|
---|
869 | if(Singleton<ComponentInfo>::getInstance()->activatedComponentList.size() != 2)
|
---|
870 | TEST_FAIL;
|
---|
871 | scope = Singleton<ComponentInfo>::getInstance()->activatedComponentList.begin();
|
---|
872 | if(*scope != &test)
|
---|
873 | TEST_FAIL;
|
---|
874 | ++ scope;
|
---|
875 | if(*scope != &test2)
|
---|
876 | TEST_FAIL;
|
---|
877 | } END_CASE;
|
---|
878 | } END_CASE;
|
---|
879 |
|
---|
880 | BEGIN_CASE("onFatalExit","onFatalExit") {
|
---|
881 | BEGIN_CASE("1","OnFatalExitãããã¨èµ·åè¦æ±ãªã¹ãã«ããã³ã³ãã¼ãã³ããå¼ã°ãã") {
|
---|
882 | Singleton<ComponentInfo>::renewInstance();
|
---|
883 |
|
---|
884 | TestComponent test;
|
---|
885 | TestComponent test2;
|
---|
886 |
|
---|
887 | test.activation = test2.activation = true;
|
---|
888 | test2.throw_body = true;
|
---|
889 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
890 | try{ Singleton<ComponentInfo>::getInstance()->activateComponent(); } catch(...) {}
|
---|
891 | Singleton<ComponentInfo>::getInstance()->onFatalExit();
|
---|
892 |
|
---|
893 | if(!test.check_onFatalExit || !test2.check_onFatalExit)
|
---|
894 | TEST_FAIL;
|
---|
895 | } END_CASE;
|
---|
896 |
|
---|
897 | BEGIN_CASE("2","èµ·åè¦æ±ãåºããªãã³ã³ãã¼ãã³ãã¯èµ·åãããªã") {
|
---|
898 | Singleton<ComponentInfo>::renewInstance();
|
---|
899 |
|
---|
900 | TestComponent test;
|
---|
901 | TestComponent test2;
|
---|
902 |
|
---|
903 | test.activation = false;
|
---|
904 | test2.activation = true;
|
---|
905 | test2.throw_body = true;
|
---|
906 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
907 | try{ Singleton<ComponentInfo>::getInstance()->activateComponent(); } catch(...) {}
|
---|
908 | Singleton<ComponentInfo>::getInstance()->onFatalExit();
|
---|
909 |
|
---|
910 | if(test.check_onFatalExit || !test2.check_onFatalExit)
|
---|
911 | TEST_FAIL;
|
---|
912 | } END_CASE;
|
---|
913 |
|
---|
914 | BEGIN_CASE("4","èµ·åé åºãæ£ãã (åä¸ã¬ãã«ãªãç»é²é )") {
|
---|
915 | Singleton<ComponentInfo>::renewInstance();
|
---|
916 |
|
---|
917 | TestComponent test;
|
---|
918 | TestComponent test2;
|
---|
919 | counter = 0;
|
---|
920 |
|
---|
921 | test2.throw_body = true;
|
---|
922 | test.activation = test2.activation = true;
|
---|
923 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
924 | try{ Singleton<ComponentInfo>::getInstance()->activateComponent(); } catch(...) {}
|
---|
925 | Singleton<ComponentInfo>::getInstance()->onFatalExit();
|
---|
926 |
|
---|
927 | if(test.actcnt != 5 || test2.actcnt != 6 )
|
---|
928 | TEST_FAIL;
|
---|
929 | } END_CASE;
|
---|
930 |
|
---|
931 | BEGIN_CASE("5","èµ·åé åºãæ£ãã (åªå
|
---|
932 | 度é )") {
|
---|
933 | Singleton<ComponentInfo>::renewInstance();
|
---|
934 |
|
---|
935 | TestComponent test(10);
|
---|
936 | TestComponent test2(4);
|
---|
937 | counter = 0;
|
---|
938 |
|
---|
939 | test.activation = test2.activation = true;
|
---|
940 | test.throw_body = true;
|
---|
941 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
942 | try{ Singleton<ComponentInfo>::getInstance()->activateComponent(); } catch(...) {}
|
---|
943 | Singleton<ComponentInfo>::getInstance()->onFatalExit();
|
---|
944 |
|
---|
945 | if(test.actcnt != 6 || test2.actcnt != 5 )
|
---|
946 | TEST_FAIL;
|
---|
947 | } END_CASE;
|
---|
948 |
|
---|
949 | BEGIN_CASE("6","ä¾å¤ã¯æãã¦ãã") {
|
---|
950 | Singleton<ComponentInfo>::renewInstance();
|
---|
951 |
|
---|
952 | TestComponent test;
|
---|
953 | TestComponent test2;
|
---|
954 | list<Component *>::iterator scope;
|
---|
955 | bool result = false;
|
---|
956 |
|
---|
957 | Exception::setThrowControl(true);
|
---|
958 | test.activation = test2.activation = true;
|
---|
959 | test2.throw_body = true;
|
---|
960 | test.throw_onFatalExit = true;
|
---|
961 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
962 | try{ Singleton<ComponentInfo>::getInstance()->activateComponent(); } catch(...) {}
|
---|
963 | try {
|
---|
964 | Singleton<ComponentInfo>::getInstance()->onFatalExit();
|
---|
965 | }
|
---|
966 | catch(...) {
|
---|
967 | result = true;
|
---|
968 | }
|
---|
969 |
|
---|
970 | if(!result)
|
---|
971 | TEST_FAIL;
|
---|
972 | } END_CASE;
|
---|
973 |
|
---|
974 | BEGIN_CASE("7","ä¾å¤ãèµ·ããã¨ããã¾ã å®è¡ããã¦ããªãã³ã³ãã¼ãã³ãã®ãã³ãã©èµ·åè¦æ±ã¯æ®ã") {
|
---|
975 | Singleton<ComponentInfo>::renewInstance();
|
---|
976 |
|
---|
977 | TestComponent test;
|
---|
978 | TestComponent test2;
|
---|
979 | list<Component *>::iterator scope;
|
---|
980 | bool result = false;
|
---|
981 |
|
---|
982 | Exception::setThrowControl(true);
|
---|
983 | test.activation = test2.activation = true;
|
---|
984 | test2.throw_body = true;
|
---|
985 | test.throw_onFatalExit = true;
|
---|
986 | Singleton<ComponentInfo>::getInstance()->parseOption(getOptionParameter());
|
---|
987 | try{ Singleton<ComponentInfo>::getInstance()->activateComponent(); } catch(...) {}
|
---|
988 | try{
|
---|
989 | Singleton<ComponentInfo>::getInstance()->onFatalExit();
|
---|
990 | }
|
---|
991 | catch(...) {
|
---|
992 | result = true;
|
---|
993 | }
|
---|
994 |
|
---|
995 | if(!result)
|
---|
996 | TEST_FAIL;
|
---|
997 |
|
---|
998 | if(Singleton<ComponentInfo>::getInstance()->activatedComponentList.size() != 1)
|
---|
999 | TEST_FAIL;
|
---|
1000 |
|
---|
1001 | if(*Singleton<ComponentInfo>::getInstance()->activatedComponentList.begin() != &test2)
|
---|
1002 | TEST_FAIL;
|
---|
1003 |
|
---|
1004 | } END_CASE;
|
---|
1005 |
|
---|
1006 | BEGIN_CASE("8","NULLãªãã¸ã§ã¯ãããçºè¡ãã¦ã大ä¸å¤«") {
|
---|
1007 | ((ComponentInfo *)0)->onFatalExit();
|
---|
1008 | } END_CASE;
|
---|
1009 |
|
---|
1010 | } END_CASE;
|
---|
1011 |
|
---|
1012 | BEGIN_CASE("isActive","isActive") {
|
---|
1013 | BEGIN_CASE("1","èµ·åããã³ã³ãã¼ãã³ããå¤å®ã§ãã") {
|
---|
1014 | Singleton<ComponentInfo>::renewInstance();
|
---|
1015 |
|
---|
1016 | TestComponent test;
|
---|
1017 | Singleton<ComponentInfo>::getInstance()->activateComponent(&test);
|
---|
1018 |
|
---|
1019 | if(!Singleton<ComponentInfo>::getInstance()->isActive<TestComponent>())
|
---|
1020 | TEST_FAIL;
|
---|
1021 | } END_CASE;
|
---|
1022 |
|
---|
1023 | BEGIN_CASE("2","èµ·åãã¦ããªãã³ã³ãã¼ãã³ãã«ã¯åå¿ããªã") {
|
---|
1024 | Singleton<ComponentInfo>::renewInstance();
|
---|
1025 |
|
---|
1026 | TestComponent test;
|
---|
1027 |
|
---|
1028 | if(Singleton<ComponentInfo>::getInstance()->isActive<TestComponent>())
|
---|
1029 | TEST_FAIL;
|
---|
1030 | } END_CASE;
|
---|
1031 |
|
---|
1032 | BEGIN_CASE("3","æ´¾çããã³ã³ãã¼ãã³ãã®ã¤ã³ã¹ã¿ã³ã¹ã«ã¯åå¿ãã") {
|
---|
1033 | Singleton<ComponentInfo>::renewInstance();
|
---|
1034 |
|
---|
1035 | DerivedTestComponent test;
|
---|
1036 | Singleton<ComponentInfo>::getInstance()->activateComponent(&test);
|
---|
1037 |
|
---|
1038 | if(!Singleton<ComponentInfo>::getInstance()->isActive<TestComponent>())
|
---|
1039 | TEST_FAIL;
|
---|
1040 | } END_CASE;
|
---|
1041 |
|
---|
1042 | BEGIN_CASE("4","è¤æ°èµ·åãã¦ãã¦ãè¦æ±ã«åã£ããã®ãæ¢ãã") { //isActiveã®if(dynamic_cast<T *>(iterator->instance) != 0)ã®elseç¯ãå®è¡ãããã®ãç®ç
|
---|
1043 | Singleton<ComponentInfo>::renewInstance();
|
---|
1044 |
|
---|
1045 | TestComponent test;
|
---|
1046 | Singleton<ComponentInfo>::getInstance()->activateComponent(&test);
|
---|
1047 | DerivedTestComponent test2;
|
---|
1048 | Singleton<ComponentInfo>::getInstance()->activateComponent(&test2);
|
---|
1049 |
|
---|
1050 | if(!Singleton<ComponentInfo>::getInstance()->isActive<DerivedTestComponent>())
|
---|
1051 | TEST_FAIL;
|
---|
1052 | } END_CASE;
|
---|
1053 | } END_CASE;
|
---|
1054 |
|
---|
1055 |
|
---|
1056 | Singleton<ComponentInfo>::restoreContext(context);
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | //--------
|
---|
1060 |
|
---|
1061 |
|
---|
1062 | TESTSUITE(main,Component)
|
---|
1063 | {
|
---|
1064 | SingletonBase::ContextChain chain;
|
---|
1065 |
|
---|
1066 | chain.saveContext<ComponentInfo>();
|
---|
1067 | chain.saveContext<OptionParameter>();
|
---|
1068 | chain.saveContext<VerboseMessage::VerboseControl>();
|
---|
1069 | chain.saveContext<Message::MessageControl>();
|
---|
1070 | chain.saveContext<DebugMessage::DebugControl>();
|
---|
1071 |
|
---|
1072 | BEGIN_CASE("executeComponent","executeComponent") {
|
---|
1073 | BEGIN_CASE("1","ç¹ã«ä½ããªãã°parseOption/bodyãå®è¡ããã") {
|
---|
1074 | chain.renewInstance();
|
---|
1075 |
|
---|
1076 | bool result = true;
|
---|
1077 | TestComponent test;
|
---|
1078 | test.activation = true;
|
---|
1079 |
|
---|
1080 | Exception::setThrowControl(true);
|
---|
1081 | try { executeComponents(getOptionParameter()); }
|
---|
1082 | catch(...) { result = false; }
|
---|
1083 |
|
---|
1084 | BEGIN_CASE("1","ä¾å¤ã¯èµ·ãããªã") {
|
---|
1085 | if(!result)
|
---|
1086 | TEST_FAIL;
|
---|
1087 | } END_CASE;
|
---|
1088 |
|
---|
1089 | BEGIN_CASE("2","parseOption/bodyã¯å®è¡ããã") {
|
---|
1090 | if(!test.check_parseOption || !test.check_body || test.check_onFatalExit)
|
---|
1091 | TEST_FAIL;
|
---|
1092 | } END_CASE;
|
---|
1093 | } END_CASE;
|
---|
1094 |
|
---|
1095 | BEGIN_CASE("2","å¦çãã¦ãªããªãã·ã§ã³ããã") {
|
---|
1096 | TestSuite::clearCheckpoints();
|
---|
1097 | chain.renewInstance();
|
---|
1098 |
|
---|
1099 | char * argv[] = { "test.exe", "-test" };
|
---|
1100 | bool result = false;
|
---|
1101 | TestComponent test;
|
---|
1102 | test.activation = true;
|
---|
1103 |
|
---|
1104 | getOptionParameter().parseOption(2, argv);
|
---|
1105 | Exception::setThrowControl(true);
|
---|
1106 | try { executeComponents(getOptionParameter()); }
|
---|
1107 | catch(...) { result = true; }
|
---|
1108 |
|
---|
1109 | BEGIN_CASE("1","ä¾å¤ãèµ·ãã") {
|
---|
1110 | if(!result)
|
---|
1111 | TEST_FAIL;
|
---|
1112 | if(!TestSuite::isReached("Exception_UnknownOption"))
|
---|
1113 | TEST_FAIL;
|
---|
1114 | } END_CASE;
|
---|
1115 |
|
---|
1116 | BEGIN_CASE("2","parseOption/onFatalExitã¯å®è¡ããããbodyã¯å®è¡ãããªã") {
|
---|
1117 | if(!test.check_parseOption || test.check_body || !test.check_onFatalExit)
|
---|
1118 | TEST_FAIL;
|
---|
1119 | } END_CASE;
|
---|
1120 | } END_CASE;
|
---|
1121 |
|
---|
1122 | BEGIN_CASE("3","ãªãã·ã§ã³ãã¼ã¹ä¸ã«ä¾å¤ (activateãªã)") {
|
---|
1123 | chain.renewInstance();
|
---|
1124 |
|
---|
1125 | bool result = false;
|
---|
1126 | TestComponent test;
|
---|
1127 | test.throw_parseOption = true;
|
---|
1128 |
|
---|
1129 | Exception::setThrowControl(true);
|
---|
1130 | try { executeComponents(getOptionParameter()); }
|
---|
1131 | catch(...) { result = true; }
|
---|
1132 |
|
---|
1133 | BEGIN_CASE("1","ä¾å¤ãèµ·ãã") {
|
---|
1134 | if(!result)
|
---|
1135 | TEST_FAIL;
|
---|
1136 | } END_CASE;
|
---|
1137 |
|
---|
1138 | BEGIN_CASE("2","parseOptionã¯å®è¡ããããbody/onFatalExitã¯å®è¡ãããªã") {
|
---|
1139 | if(!test.check_parseOption || test.check_body || test.check_onFatalExit)
|
---|
1140 | TEST_FAIL;
|
---|
1141 | } END_CASE;
|
---|
1142 | } END_CASE;
|
---|
1143 |
|
---|
1144 | BEGIN_CASE("4","ãªãã·ã§ã³ãã¼ã¹ä¸ã«ä¾å¤ (activateãã)") {
|
---|
1145 | chain.renewInstance();
|
---|
1146 |
|
---|
1147 | bool result = false;
|
---|
1148 | TestComponent test;
|
---|
1149 | test.throw_parseOption = true;
|
---|
1150 | test.activation = true;
|
---|
1151 |
|
---|
1152 | Exception::setThrowControl(true);
|
---|
1153 | try { executeComponents(getOptionParameter()); }
|
---|
1154 | catch(...) { result = true; }
|
---|
1155 |
|
---|
1156 | BEGIN_CASE("1","ä¾å¤ãèµ·ãã") {
|
---|
1157 | if(!result)
|
---|
1158 | TEST_FAIL;
|
---|
1159 | } END_CASE;
|
---|
1160 |
|
---|
1161 | BEGIN_CASE("2","parseOption/onFatalExitã¯å®è¡ããããbodyã¯å®è¡ãããªã") {
|
---|
1162 | if(!test.check_parseOption || test.check_body || !test.check_onFatalExit)
|
---|
1163 | TEST_FAIL;
|
---|
1164 | } END_CASE;
|
---|
1165 | } END_CASE;
|
---|
1166 |
|
---|
1167 | BEGIN_CASE("5","bodyã§ä¾å¤") {
|
---|
1168 | chain.renewInstance();
|
---|
1169 |
|
---|
1170 | bool result = false;
|
---|
1171 | TestComponent test;
|
---|
1172 | test.throw_body = true;
|
---|
1173 | test.activation = true;
|
---|
1174 |
|
---|
1175 | Exception::setThrowControl(true);
|
---|
1176 | try { executeComponents(getOptionParameter()); }
|
---|
1177 | catch(...) { result = true; }
|
---|
1178 |
|
---|
1179 | BEGIN_CASE("1","ä¾å¤ãèµ·ãã") {
|
---|
1180 | if(!result)
|
---|
1181 | TEST_FAIL;
|
---|
1182 | } END_CASE;
|
---|
1183 |
|
---|
1184 | BEGIN_CASE("2","parseOption/body/onFatalExitã¨ãå®è¡ããã") {
|
---|
1185 | if(!test.check_parseOption || !test.check_body || !test.check_onFatalExit)
|
---|
1186 | TEST_FAIL;
|
---|
1187 | } END_CASE;
|
---|
1188 | } END_CASE;
|
---|
1189 |
|
---|
1190 |
|
---|
1191 | BEGIN_CASE("6","onFatalExitã§ä¾å¤") {
|
---|
1192 | TestSuite::clearCheckpoints();
|
---|
1193 | chain.renewInstance();
|
---|
1194 |
|
---|
1195 | bool result = false;
|
---|
1196 | TestComponent test;
|
---|
1197 | test.throw_onFatalExit = true;
|
---|
1198 | test.activation = true;
|
---|
1199 | TestComponent test2;
|
---|
1200 | test2.throw_body = true;
|
---|
1201 | test2.activation = true;
|
---|
1202 |
|
---|
1203 | Exception::setThrowControl(true);
|
---|
1204 | try { executeComponents(getOptionParameter()); }
|
---|
1205 | catch(...) { result = true; }
|
---|
1206 |
|
---|
1207 | BEGIN_CASE("1","ä¾å¤ãèµ·ãã") {
|
---|
1208 | if(!result)
|
---|
1209 | TEST_FAIL;
|
---|
1210 | if(!TestSuite::isReached("Exception_onFatalExit"))
|
---|
1211 | TEST_FAIL;
|
---|
1212 | } END_CASE;
|
---|
1213 |
|
---|
1214 | BEGIN_CASE("2","æåã®ã³ã³ãã¼ãã³ãã¯parseOption/body/onFatalExitã¨ãå®è¡ããã") {
|
---|
1215 | if(!test.check_parseOption || !test.check_body || !test.check_onFatalExit)
|
---|
1216 | TEST_FAIL;
|
---|
1217 | } END_CASE;
|
---|
1218 | BEGIN_CASE("3","次ã®ã³ã³ãã¼ãã³ããparseOption/body/onFatalExitã¨ãå®è¡ããã") {
|
---|
1219 | if(!test2.check_parseOption || !test2.check_body || !test2.check_onFatalExit)
|
---|
1220 | TEST_FAIL;
|
---|
1221 | } END_CASE;
|
---|
1222 | } END_CASE;
|
---|
1223 |
|
---|
1224 | BEGIN_CASE("7","Component::is_validãfalseã®ã¨ãã¯å®è¡ãããªã") {
|
---|
1225 | chain.renewInstance();
|
---|
1226 |
|
---|
1227 | bool result = true;
|
---|
1228 | TestComponent test;
|
---|
1229 | test.activation = true;
|
---|
1230 |
|
---|
1231 | Component::is_valid = false;
|
---|
1232 | Exception::setThrowControl(true);
|
---|
1233 | try { executeComponents(getOptionParameter()); }
|
---|
1234 | catch(...) { result = false; }
|
---|
1235 |
|
---|
1236 | BEGIN_CASE("1","ä¾å¤ã¯èµ·ãããªã") {
|
---|
1237 | if(!result)
|
---|
1238 | TEST_FAIL;
|
---|
1239 | } END_CASE;
|
---|
1240 |
|
---|
1241 | BEGIN_CASE("2","parseOption/bodyã¯å®è¡ãããªã") {
|
---|
1242 | if(test.check_parseOption || test.check_body || test.check_onFatalExit)
|
---|
1243 | TEST_FAIL;
|
---|
1244 | } END_CASE;
|
---|
1245 |
|
---|
1246 | Component::is_valid = true;
|
---|
1247 | } END_CASE;
|
---|
1248 | } END_CASE;
|
---|
1249 |
|
---|
1250 | BEGIN_CASE("_parseCommonOption","_parseCommonOption") {
|
---|
1251 |
|
---|
1252 | BEGIN_CASE("1", "-debugã§DebugMessageãæå¹ã«ãªã") {
|
---|
1253 | chain.renewInstance();
|
---|
1254 |
|
---|
1255 | char * argv[] = { "test.exe", "-debug" };
|
---|
1256 | OptionParameter & param = getOptionParameter();
|
---|
1257 |
|
---|
1258 | param.parseOption(2, argv);
|
---|
1259 | Component::_parseCommonOption(param);
|
---|
1260 |
|
---|
1261 | if(!DebugMessage::getVerbose())
|
---|
1262 | TEST_FAIL;
|
---|
1263 |
|
---|
1264 | } END_CASE;
|
---|
1265 |
|
---|
1266 | BEGIN_CASE("2", "-v ã§VerboseMessageãæå¹ã«ãªã") {
|
---|
1267 | chain.renewInstance();
|
---|
1268 |
|
---|
1269 | char * argv[] = { "test.exe", "-v" };
|
---|
1270 | OptionParameter & param = getOptionParameter();
|
---|
1271 |
|
---|
1272 | param.parseOption(2, argv);
|
---|
1273 | Component::_parseCommonOption(param);
|
---|
1274 |
|
---|
1275 | if(!VerboseMessage::getVerbose())
|
---|
1276 | TEST_FAIL;
|
---|
1277 | } END_CASE;
|
---|
1278 |
|
---|
1279 | BEGIN_CASE("3", "--verboseã§VerboseMessageãæå¹ã«ãªã") {
|
---|
1280 | chain.renewInstance();
|
---|
1281 |
|
---|
1282 | char * argv[] = { "test.exe", "--verbose" };
|
---|
1283 | OptionParameter & param = getOptionParameter();
|
---|
1284 |
|
---|
1285 | param.parseOption(2, argv);
|
---|
1286 | Component::_parseCommonOption(param);
|
---|
1287 |
|
---|
1288 | if(!VerboseMessage::getVerbose())
|
---|
1289 | TEST_FAIL;
|
---|
1290 | } END_CASE;
|
---|
1291 |
|
---|
1292 | BEGIN_CASE("4", "-lj ã§Messageãæ¥æ¬èªã«ãªã") {
|
---|
1293 | chain.renewInstance();
|
---|
1294 |
|
---|
1295 | char * argv[] = { "test.exe", "-lj" };
|
---|
1296 | OptionParameter & param = getOptionParameter();
|
---|
1297 |
|
---|
1298 | param.parseOption(2, argv);
|
---|
1299 | Component::_parseCommonOption(param);
|
---|
1300 |
|
---|
1301 | if(Message::getCurrentLanguage() != Message::JAPANESE)
|
---|
1302 | TEST_FAIL;
|
---|
1303 | } END_CASE;
|
---|
1304 |
|
---|
1305 | BEGIN_CASE("5", "--japanese ã§Messageãæ¥æ¬èªã«ãªã") {
|
---|
1306 | chain.renewInstance();
|
---|
1307 |
|
---|
1308 | char * argv[] = { "test.exe", "--japanese" };
|
---|
1309 | OptionParameter & param = getOptionParameter();
|
---|
1310 |
|
---|
1311 | param.parseOption(2, argv);
|
---|
1312 | Component::_parseCommonOption(param);
|
---|
1313 |
|
---|
1314 | if(Message::getCurrentLanguage() != Message::JAPANESE)
|
---|
1315 | TEST_FAIL;
|
---|
1316 | } END_CASE;
|
---|
1317 |
|
---|
1318 | BEGIN_CASE("6", "-le ã§Messageãè±èªã«ãªã") {
|
---|
1319 | chain.renewInstance();
|
---|
1320 |
|
---|
1321 | char * argv[] = { "test.exe", "-le" };
|
---|
1322 | OptionParameter & param = getOptionParameter();
|
---|
1323 |
|
---|
1324 | param.parseOption(2, argv);
|
---|
1325 | Component::_parseCommonOption(param);
|
---|
1326 |
|
---|
1327 | if(Message::getCurrentLanguage() != Message::ENGLISH)
|
---|
1328 | TEST_FAIL;
|
---|
1329 | } END_CASE;
|
---|
1330 |
|
---|
1331 | BEGIN_CASE("7", "--english ã§Messageãè±èªã«ãªã") {
|
---|
1332 | chain.renewInstance();
|
---|
1333 |
|
---|
1334 | char * argv[] = { "test.exe", "--english" };
|
---|
1335 | OptionParameter & param = getOptionParameter();
|
---|
1336 |
|
---|
1337 | param.parseOption(2, argv);
|
---|
1338 | Component::_parseCommonOption(param);
|
---|
1339 |
|
---|
1340 | if(Message::getCurrentLanguage() != Message::ENGLISH)
|
---|
1341 | TEST_FAIL;
|
---|
1342 | } END_CASE;
|
---|
1343 |
|
---|
1344 | BEGIN_CASE("8","ãã«ããã§ã (-h)") {
|
---|
1345 | chain.renewInstance();
|
---|
1346 |
|
---|
1347 | char * argv[] = { "test.exe", "-h" };
|
---|
1348 | OptionParameter & param = getOptionParameter();
|
---|
1349 |
|
---|
1350 | param.parseOption(2, argv);
|
---|
1351 | cout.str("");
|
---|
1352 | Component::_parseCommonOption(param);
|
---|
1353 |
|
---|
1354 | //ã¨ããããä½ãåºåããã¦ãããã¨ã ã確èªãã¦ãã
|
---|
1355 | if(cout.str().empty())
|
---|
1356 | TEST_FAIL;
|
---|
1357 | } END_CASE;
|
---|
1358 |
|
---|
1359 | BEGIN_CASE("9","ãã«ããã§ã (--help)") {
|
---|
1360 | chain.renewInstance();
|
---|
1361 |
|
---|
1362 | char * argv[] = { "test.exe", "--help" };
|
---|
1363 | OptionParameter & param = getOptionParameter();
|
---|
1364 |
|
---|
1365 | param.parseOption(2, argv);
|
---|
1366 | cout.str("");
|
---|
1367 | Component::_parseCommonOption(param);
|
---|
1368 |
|
---|
1369 | //ã¨ããããä½ãåºåããã¦ãããã¨ã ã確èªãã¦ãã
|
---|
1370 | if(cout.str().empty())
|
---|
1371 | TEST_FAIL;
|
---|
1372 | } END_CASE;
|
---|
1373 |
|
---|
1374 | } END_CASE;
|
---|
1375 |
|
---|
1376 | BEGIN_CASE("getOption","ãªãã·ã§ã³ãã©ã¡ã¼ã¿ã®åå¾") {
|
---|
1377 | chain.renewInstance();
|
---|
1378 |
|
---|
1379 | char * argv[] = { "test.exe","-test","param","-test2","param2", "--test","param3","--test2","param4" };
|
---|
1380 | getOptionParameter().parseOption(9, argv);
|
---|
1381 |
|
---|
1382 | BEGIN_CASE("1","getOption(test)ã§paramãåãã") {
|
---|
1383 | OptionParameter::OptionItem item;
|
---|
1384 |
|
---|
1385 | item = getOption("test");
|
---|
1386 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1387 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ã§ãã", item.isChecked());
|
---|
1388 | TEST_CASE("3","1ã¤ã®ãã©ã¡ã¼ã¿ããã¤", item.countParameter() == 1);
|
---|
1389 | TEST_CASE("4","ãã©ã¡ã¼ã¿ã®å
|
---|
1390 | 容ããã£ã¦ãã", item[0].compare("param") == 0);
|
---|
1391 | } END_CASE;
|
---|
1392 |
|
---|
1393 | BEGIN_CASE("2","getOption(test,test)ã§2ã¤ã®é£çµãåãã") {
|
---|
1394 | OptionParameter::OptionItem item;
|
---|
1395 |
|
---|
1396 | TEST_CASE("0","[åæ] --testã«ãã§ãã¯ã¯ã¤ãã¦ããªã", !getOptionParameter().get("-test",false).isChecked());
|
---|
1397 |
|
---|
1398 | item = getOption("test","test");
|
---|
1399 |
|
---|
1400 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1401 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ã§ãã", item.isChecked());
|
---|
1402 | TEST_CASE("3","ãã§ãã¯æ¸ã¿ã§ãã (test)", getOptionParameter().get("test",false).isChecked());
|
---|
1403 | TEST_CASE("4","ãã§ãã¯æ¸ã¿ã§ãã (-test)", getOptionParameter().get("-test",false).isChecked());
|
---|
1404 | TEST_CASE("5","2ã¤ã®ãã©ã¡ã¼ã¿ãæã¤", item.countParameter() == 2);
|
---|
1405 | TEST_CASE("6","1ã¤ãã®ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[0].compare("param") == 0);
|
---|
1406 | TEST_CASE("7","2ã¤ãã®ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[1].compare("param3") == 0);
|
---|
1407 | } END_CASE;
|
---|
1408 |
|
---|
1409 | BEGIN_CASE("3","getOption(test,unknown)ã§testã®ãã©ã¡ã¼ã¿ãåãã") {
|
---|
1410 | OptionParameter::OptionItem item;
|
---|
1411 |
|
---|
1412 | item = getOption("test","unknown");
|
---|
1413 |
|
---|
1414 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1415 | TEST_CASE("2","1ã¤ã®ãã©ã¡ã¼ã¿ãæã¤", item.countParameter() == 1);
|
---|
1416 | TEST_CASE("3","ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[0].compare("param") == 0);
|
---|
1417 | } END_CASE;
|
---|
1418 |
|
---|
1419 | BEGIN_CASE("4","getOption(unknown,test)ã§ -testã®ãã©ã¡ã¼ã¿ãåãã") {
|
---|
1420 | OptionParameter::OptionItem item;
|
---|
1421 |
|
---|
1422 | item = getOption("unknown","test");
|
---|
1423 |
|
---|
1424 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1425 | TEST_CASE("2","1ã¤ã®ãã©ã¡ã¼ã¿ãæã¤", item.countParameter() == 1);
|
---|
1426 | TEST_CASE("3","ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[0].compare("param3") == 0);
|
---|
1427 | } END_CASE;
|
---|
1428 |
|
---|
1429 | BEGIN_CASE("5","getOption(unknown,unknown)ã§ç¡å¹ãªã¢ã¤ãã ãè¿ã") {
|
---|
1430 | OptionParameter::OptionItem item;
|
---|
1431 |
|
---|
1432 | item = getOption("unknown","unknown");
|
---|
1433 |
|
---|
1434 | TEST_CASE("1","ç¡å¹ãªå¤ãè¿ã", !item.isValid());
|
---|
1435 | } END_CASE;
|
---|
1436 |
|
---|
1437 | BEGIN_CASE("6","getOption(test2,test2,false)ã§ãã§ãã¯ãã¤ããªã") {
|
---|
1438 | OptionParameter::OptionItem item;
|
---|
1439 |
|
---|
1440 | TEST_CASE("0","[åæ] -test2ã«ãã§ãã¯ã¯ã¤ãã¦ããªã", !getOptionParameter().get("test2",false).isChecked());
|
---|
1441 | TEST_CASE("0","[åæ] --test2ã«ãã§ãã¯ã¯ã¤ãã¦ããªã", !getOptionParameter().get("-test2",false).isChecked());
|
---|
1442 |
|
---|
1443 | item = getOption("test2","test2",false);
|
---|
1444 |
|
---|
1445 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1446 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ã§ãªã", !item.isChecked());
|
---|
1447 | TEST_CASE("3","ãã§ãã¯æ¸ã¿ã§ãªã (test2)", !getOptionParameter().get("test2",false).isChecked());
|
---|
1448 | TEST_CASE("4","ãã§ãã¯æ¸ã¿ã§ãªã (-test2)", !getOptionParameter().get("-test2",false).isChecked());
|
---|
1449 | TEST_CASE("5","2ã¤ã®ãã©ã¡ã¼ã¿ãæã¤", item.countParameter() == 2);
|
---|
1450 | TEST_CASE("6","1ã¤ãã®ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[0].compare("param2") == 0);
|
---|
1451 | TEST_CASE("7","2ã¤ãã®ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[1].compare("param4") == 0);
|
---|
1452 | } END_CASE;
|
---|
1453 |
|
---|
1454 | } END_CASE;
|
---|
1455 |
|
---|
1456 | BEGIN_CASE("findOption","ãªãã·ã§ã³ãã©ã¡ã¼ã¿ã®åå¾") {
|
---|
1457 | chain.renewInstance();
|
---|
1458 |
|
---|
1459 | char * argv[] = { "test.exe","-test","param","--test","param3", "-noparam"};
|
---|
1460 | getOptionParameter().parseOption(6, argv);
|
---|
1461 |
|
---|
1462 | BEGIN_CASE("1","findOption(test,test)ã§paramãåãã") {
|
---|
1463 | string result;
|
---|
1464 |
|
---|
1465 | TEST_CASE("0","[åæ] ãã§ãã¯æ¸ã¿ã§ã¯ãªã (test)", !getOptionParameter().get("test",false).isChecked());
|
---|
1466 | TEST_CASE("0","[åæ] ãã§ãã¯æ¸ã¿ã§ã¯ãªã (-test)", !getOptionParameter().get("-test",false).isChecked());
|
---|
1467 | TEST_CASE("1","颿°ã¯æåãã", findOption("test","test",&result));
|
---|
1468 | TEST_CASE("2","æååã«paramãè¿ã", result.compare("param") == 0);
|
---|
1469 | TEST_CASE("3","ãã§ãã¯æ¸ã¿ (test)", getOptionParameter().get("test",false).isChecked());
|
---|
1470 | TEST_CASE("3","ãã§ãã¯æ¸ã¿ (-test)", getOptionParameter().get("-test",false).isChecked());
|
---|
1471 | } END_CASE;
|
---|
1472 |
|
---|
1473 | BEGIN_CASE("2","findOption(test,unknown)ã§paramãåãã") {
|
---|
1474 | string result;
|
---|
1475 |
|
---|
1476 | TEST_CASE("1","颿°ã¯æåãã", findOption("test","unknown",&result));
|
---|
1477 | TEST_CASE("2","æååã«paramãè¿ã", result.compare("param") == 0);
|
---|
1478 | } END_CASE;
|
---|
1479 |
|
---|
1480 | BEGIN_CASE("3","findOption(unknown,test)ã§param3ãåãã") {
|
---|
1481 | string result;
|
---|
1482 |
|
---|
1483 | TEST_CASE("1","颿°ã¯æåãã", findOption("unknown","test",&result));
|
---|
1484 | TEST_CASE("2","æååã«paramãè¿ã", result.compare("param3") == 0);
|
---|
1485 | } END_CASE;
|
---|
1486 |
|
---|
1487 | BEGIN_CASE("4","findOption(unknown,unknown)ã§ç¡å¹ãªã¢ã¤ãã ãè¿ã") {
|
---|
1488 | string result;
|
---|
1489 |
|
---|
1490 | result.assign("dummy");
|
---|
1491 |
|
---|
1492 | TEST_CASE("1","颿°ã¯å¤±æãã", !findOption("unknown","unknown",&result));
|
---|
1493 | TEST_CASE("2","æååã¯æ¸ãæãããªã", result.compare("dummy") == 0);
|
---|
1494 | } END_CASE;
|
---|
1495 |
|
---|
1496 | BEGIN_CASE("5","findOption(noparam,NULL,&result)") {
|
---|
1497 | string result;
|
---|
1498 | result.assign("dummy");
|
---|
1499 |
|
---|
1500 | TEST_CASE("1","颿°ã¯æåãã", findOption("noparam", 0, &result));
|
---|
1501 | TEST_CASE("2","æååã¯ç½®ãæãããªã", result.compare("dummy") == 0);
|
---|
1502 | } END_CASE;
|
---|
1503 | } END_CASE;
|
---|
1504 |
|
---|
1505 | BEGIN_CASE("checkOption","ãªãã·ã§ã³ãã©ã¡ã¼ã¿ã®åå¨ç¢ºèª + ãã§ãã¯") {
|
---|
1506 | chain.renewInstance();
|
---|
1507 |
|
---|
1508 | char * argv[] = { "test.exe","-test","param","--test","param3", "-test2", "--test3"};
|
---|
1509 | getOptionParameter().parseOption(7, argv);
|
---|
1510 |
|
---|
1511 | BEGIN_CASE("1","checkOption(test,test)ã§paramãåãã") {
|
---|
1512 | string result;
|
---|
1513 |
|
---|
1514 | TEST_CASE("0","[åæ] ãã§ãã¯æ¸ã¿ã§ã¯ãªã (test)", !getOptionParameter().get("test",false).isChecked());
|
---|
1515 | TEST_CASE("0","[åæ] ãã§ãã¯æ¸ã¿ã§ã¯ãªã (-test)", !getOptionParameter().get("-test",false).isChecked());
|
---|
1516 | TEST_CASE("1","颿°ã¯æåãã", checkOption("test","test"));
|
---|
1517 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ (test)", getOptionParameter().get("test",false).isChecked());
|
---|
1518 | TEST_CASE("3","ãã§ãã¯æ¸ã¿ (-test)", getOptionParameter().get("-test",false).isChecked());
|
---|
1519 | } END_CASE;
|
---|
1520 |
|
---|
1521 | BEGIN_CASE("2","checkOption(test2,unknown)ã§paramãåãã") {
|
---|
1522 | string result;
|
---|
1523 |
|
---|
1524 | TEST_CASE("0","[åæ] ãã§ãã¯æ¸ã¿ã§ã¯ãªã (test2)", !getOptionParameter().get("test2",false).isChecked());
|
---|
1525 | TEST_CASE("1","颿°ã¯æåãã", checkOption("test2","unknown"));
|
---|
1526 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ (test2)", getOptionParameter().get("test2",false).isChecked());
|
---|
1527 | } END_CASE;
|
---|
1528 |
|
---|
1529 | BEGIN_CASE("3","checkOption(unknown,test3)ã§param3ãåãã") {
|
---|
1530 | string result;
|
---|
1531 |
|
---|
1532 | TEST_CASE("0","[åæ] ãã§ãã¯æ¸ã¿ã§ã¯ãªã (test3)", !getOptionParameter().get("-test3",false).isChecked());
|
---|
1533 | TEST_CASE("1","颿°ã¯æåãã", checkOption("unknown","test3"));
|
---|
1534 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ (test3)", getOptionParameter().get("-test3",false).isChecked());
|
---|
1535 | } END_CASE;
|
---|
1536 |
|
---|
1537 | BEGIN_CASE("4","checkOption(unknown,unknown)ã§ç¡å¹ãªã¢ã¤ãã ãè¿ã") {
|
---|
1538 | string result;
|
---|
1539 |
|
---|
1540 | result.assign("dummy");
|
---|
1541 |
|
---|
1542 | TEST_CASE("1","颿°ã¯å¤±æãã", !checkOption("unknown","unknown"));
|
---|
1543 | } END_CASE;
|
---|
1544 | } END_CASE;
|
---|
1545 |
|
---|
1546 | /* mergeOptionã®ãã§ãã¯é
|
---|
1547 | ç®ã¯ãgetOptionã¨ã»ã¼åã */
|
---|
1548 | BEGIN_CASE("mergeOption","ãªãã·ã§ã³ãã©ã¡ã¼ã¿ã®çµå") {
|
---|
1549 | chain.renewInstance();
|
---|
1550 |
|
---|
1551 | char * argv[] = { "test.exe","-test","param","-test2","param2", "--test","param3","--test2","param4" };
|
---|
1552 | getOptionParameter().parseOption(9, argv);
|
---|
1553 |
|
---|
1554 | BEGIN_CASE("1","mergeOption(test)ã§paramãåãã") {
|
---|
1555 | OptionParameter::OptionItem item;
|
---|
1556 |
|
---|
1557 | item = mergeOption("test");
|
---|
1558 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1559 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ã§ãã", item.isChecked());
|
---|
1560 | TEST_CASE("3","1ã¤ã®ãã©ã¡ã¼ã¿ããã¤", item.countParameter() == 1);
|
---|
1561 | TEST_CASE("4","ãã©ã¡ã¼ã¿ã®å
|
---|
1562 | 容ããã£ã¦ãã", item[0].compare("param") == 0);
|
---|
1563 | } END_CASE;
|
---|
1564 |
|
---|
1565 | BEGIN_CASE("2","mergeOption(test,test)ã§2ã¤ã®é£çµãåãã") {
|
---|
1566 | OptionParameter::OptionItem item;
|
---|
1567 |
|
---|
1568 | TEST_CASE("0","[åæ] --testã«ãã§ãã¯ã¯ã¤ãã¦ããªã", !getOptionParameter().get("-test",false).isChecked());
|
---|
1569 |
|
---|
1570 | item = mergeOption("test","test");
|
---|
1571 |
|
---|
1572 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1573 | TEST_CASE("2","ãã§ãã¯æ¸ã¿ã§ãã", item.isChecked());
|
---|
1574 | TEST_CASE("3","ãã§ãã¯æ¸ã¿ã§ãã (test)", getOptionParameter().get("test",false).isChecked());
|
---|
1575 | TEST_CASE("4","ãã§ãã¯æ¸ã¿ã§ãã (-test)", getOptionParameter().get("-test",false).isChecked());
|
---|
1576 | TEST_CASE("5","2ã¤ã®ãã©ã¡ã¼ã¿ãæã¤", item.countParameter() == 2);
|
---|
1577 | TEST_CASE("6","1ã¤ãã®ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[0].compare("param") == 0);
|
---|
1578 | TEST_CASE("7","2ã¤ãã®ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[1].compare("param3") == 0);
|
---|
1579 | } END_CASE;
|
---|
1580 |
|
---|
1581 | BEGIN_CASE("3","mergeOption(test,unknown)ã§testã®ãã©ã¡ã¼ã¿ãåãã") {
|
---|
1582 | OptionParameter::OptionItem item;
|
---|
1583 |
|
---|
1584 | item = mergeOption("test","unknown");
|
---|
1585 |
|
---|
1586 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1587 | TEST_CASE("2","1ã¤ã®ãã©ã¡ã¼ã¿ãæã¤", item.countParameter() == 1);
|
---|
1588 | TEST_CASE("3","ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[0].compare("param") == 0);
|
---|
1589 | } END_CASE;
|
---|
1590 |
|
---|
1591 | BEGIN_CASE("4","mergeOption(unknown,test)ã§ -testã®ãã©ã¡ã¼ã¿ãåãã") {
|
---|
1592 | OptionParameter::OptionItem item;
|
---|
1593 |
|
---|
1594 | item = mergeOption("unknown","test");
|
---|
1595 |
|
---|
1596 | TEST_CASE("1","æå¹ãªå¤ãè¿ã", item.isValid());
|
---|
1597 | TEST_CASE("2","1ã¤ã®ãã©ã¡ã¼ã¿ãæã¤", item.countParameter() == 1);
|
---|
1598 | TEST_CASE("3","ãã©ã¡ã¼ã¿ã®å¤ã¯æ£ãã", item[0].compare("param3") == 0);
|
---|
1599 | } END_CASE;
|
---|
1600 |
|
---|
1601 | BEGIN_CASE("5","mergeOption(unknown,unknown)ã§ç¡å¹ãªã¢ã¤ãã ãè¿ã") {
|
---|
1602 | OptionParameter::OptionItem item;
|
---|
1603 |
|
---|
1604 | item = mergeOption("unknown","unknown");
|
---|
1605 |
|
---|
1606 | TEST_CASE("1","ç¡å¹ãªå¤ãè¿ã", !item.isValid());
|
---|
1607 | } END_CASE;
|
---|
1608 |
|
---|
1609 | } END_CASE;
|
---|
1610 |
|
---|
1611 | chain.restoreContext();
|
---|
1612 | }
|
---|
1613 | #endif
|
---|
1614 |
|
---|
1615 |
|
---|