source: anotherchoice/tags/jsp-1.4.4-full-UTF8/cfg/base/mpstrstream.cpp@ 26

Last change on this file since 26 was 26, checked in by ykominami, 12 years ago

initial

File size: 28.5 KB
Line 
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: mpstrstream.cpp,v 1.9 2003/12/15 07:32:13 takayuki Exp $
51 */
52
53// $Header: /home/CVS/configurator/base/mpstrstream.cpp,v 1.9 2003/12/15 07:32:13 takayuki Exp $
54
55#include "base/mpstrstream.h"
56
57using namespace std;
58
59/*
60 * 複数部位からなるストリームの一部位に相当するクラス
61 */
62
63 //コンストラクタ
64MultipartStream::Part::Part(string _name) throw() : name(_name)
65{}
66
67 //コピーコンストラクタ
68MultipartStream::Part::Part(const MultipartStream::Part & src) throw() : name("")
69{
70 if(src.isValid()) {
71 name.assign(src.name);
72 setContents(src.getContents());
73 }
74}
75
76 //ストリームに書いた内
77容を受け取る
78string MultipartStream::Part::getContents(void) const throw(Exception)
79{
80 string result;
81
82 if(isValid())
83 result = stream.str();
84 else
85 ExceptionMessage("Operation was performed against an invalid stream.","無効なストリームに対して操作が行われました").throwException();
86
87 return result;
88}
89
90 //ストリームの内
91容を直接設定する
92void MultipartStream::Part::setContents(string contents) throw(Exception)
93{
94 if(isValid()) {
95 stream.clear();
96 stream << contents;
97 }
98 else
99 ExceptionMessage("Operation was performed against an invalid stream.","無効なストリームに対して操作が行われました").throwException();
100}
101
102
103
104/*
105 * 複数部位からなるストリームの一部位に相当するクラス
106 */
107
108 //コンストラクタ
109MultipartStream::MultipartStream(string _filename) throw() : filename(_filename), current(0), dirty(false), output(true)
110{
111 dirty = isValid(); //空であってもファイルを作らないといけないので...
112}
113
114MultipartStream::~MultipartStream(void) throw()
115{
116 if(isValid() && dirty) {
117 //蓋
118 try { serialize(); }
119 catch(...) {}
120 }
121}
122
123 //ファイル名の関連付け
124string MultipartStream::setFilename(string _filename) throw(Exception)
125{
126 string result;
127
128 if(this != 0) {
129 if(!_filename.empty()) {
130 result = filename;
131 filename = _filename;
132 dirty = isValid();
133 }
134 else
135 ExceptionMessage("Empty filename should not be allowed.","空のファイル名は使用できない").throwException();
136 }
137 else
138 ExceptionMessage("Invalid object can not perform the request.","無効なオブジェクトに対する要求は実行できない").throwException();
139
140 return result;
141}
142
143 //ファイル出力 (本当にファイルに出力したときだけtrue)
144bool MultipartStream::serialize(void) throw(Exception)
145{
146 bool result = false;
147
148 if(isValid() && dirty && output) {
149
150 fstream file(filename.c_str(), ios::out);
151 if(file.is_open()) {
152 list<Part>::iterator scope;
153
154 //å…
155¨ã¦ã®éƒ¨ä½ã®å†…
156容を出力
157 scope = parts.begin();
158 while(scope != parts.end()) {
159 file << scope->getContents();
160 ++ scope;
161 }
162
163 file.close();
164 dirty = false;
165 result = true;
166 }
167 else {
168 ExceptionMessage("File could not open [%]","ファイルが開けない [%]") << filename << throwException;
169 disableOutput(); //デストラクタがもう一度挑戦するので
170 }
171 }
172 else {
173 if(!isValid())
174 ExceptionMessage("Invalid object can not perform the request.","無効なオブジェクトに対する要求は実行できない").throwException();
175 }
176
177 return result;
178}
179
180 //部位の作成
181MultipartStream & MultipartStream::createPart(string name, bool precedence) throw(Exception)
182{
183 if(this != 0) {
184 list<Part>::iterator scope;
185 list<Part>::iterator newnode;
186
187 //同じ名前がないことを確認
188 scope = parts.begin();
189 while(scope != parts.end()) {
190 if(scope->getName().compare(name) == 0) {
191 ExceptionMessage("The part \"%\" is already created.","部位名[%]はすでに利用されている") << name << throwException;
192 break;
193 }
194 ++ scope;
195 }
196
197 //同じ名前がないなら要素を追加
198 if(scope == parts.end()) {
199
200 //挿å…
201¥ä½ç½®ã®æ¤œç´¢
202 if(current != 0) {
203 scope = parts.begin();
204 while(scope != parts.end() && &(*scope) != current)
205 ++ scope;
206
207 //挿å…
208¥ä½ç½®ã®èª¿ç¯€ (現在位置を後ろにずらす when precedence = false; )
209 if(scope != parts.end() && !precedence)
210 ++ scope;
211 }
212 else
213 scope = parts.end();
214
215 //要素の挿å…
216¥
217 newnode = parts.insert(scope, Part(name));
218 current = &(*newnode);
219 }
220 }else
221 ExceptionMessage("Invalid object can not perform the request.","無効なオブジェクトに対する要求は実行できない").throwException();
222
223 return *this;
224}
225
226 //部位の選択
227MultipartStream & MultipartStream::movePart(string name) throw(Exception)
228{
229 list<Part>::iterator scope;
230
231 if(this != 0 && !name.empty()) {
232
233 //名前が一致するものを探す
234 scope = parts.begin();
235 while(scope != parts.end()) {
236 if(scope->getName() == name) {
237 current = &(*scope);
238 break;
239 }
240 ++ scope;
241 }
242
243 //見つからなかった
244 if(scope == parts.end())
245 ExceptionMessage("Unknown part [%] specified.","無効な識別名 [%]") << name << throwException;
246 }
247 else{
248 if(this == 0)
249 ExceptionMessage("Invalid object can not perform the request.","無効なオブジェクトに対する要求は実行できない").throwException();
250 else //if(name.empty()) //手前のifの条件より、このifは常に真
251 ExceptionMessage("Empty identifier was passed as a name of part.","空文字が渡された").throwException();
252 }
253
254 return *this;
255}
256
257
258/********************************** テストスィート **********************************/
259
260#ifdef TESTSUITE
261
262#include "coverage_undefs.h"
263
264#include <iomanip>
265#include <cstdio>
266
267#ifdef _MSC_VER
268# pragma warning(disable:4101) //ローカル変数は一度も使われていません
269#endif
270
271TESTSUITE_(main,Part, MultipartStream)
272{
273 BEGIN_CASE("constructor/isValid","コンストラクタ / 正当性判定") {
274 BEGIN_CASE("1","名前つきで作成したら有効なパートが作れる") {
275 Part part("test");
276 if(!part.isValid())
277 TEST_FAIL;
278 } END_CASE;
279
280 BEGIN_CASE("2","名前なしで作成したら無効なパートになる") {
281 Part part("");
282 if(part.isValid())
283 TEST_FAIL;
284 } END_CASE;
285
286 BEGIN_CASE("3","NULLは無効なパート") {
287 if(((Part *)0)->isValid())
288 TEST_FAIL;
289 } END_CASE;
290
291 BEGIN_CASE("4","NULLオブジェクトでコピーコンストラクタを起動しても失敗しない") {
292 Part * part = 0;
293 Part work(*part);
294 } END_CASE;
295
296 } END_CASE;
297
298 BEGIN_CASE("operator <<","operator <<") {
299 BEGIN_CASE("1", "出力できる") {
300 Part part("test");
301
302 part << "test";
303
304 if(part.stream.str().compare("test") != 0)
305 TEST_FAIL;
306 } END_CASE;
307
308 BEGIN_CASE("2", "iomanipが使える") {
309 Part part("test");
310
311 part << setw(8) << setbase(16) << setfill('0') << 0x1234567;
312
313 if(part.stream.str().compare("01234567") != 0)
314 TEST_FAIL;
315 } END_CASE;
316
317 BEGIN_CASE("3", "無効なストリームに書いたら例外が起る") {
318 Part part("");
319 bool result = false;
320
321 if(part.isValid())
322 TEST_FAIL;
323
324 Exception::setThrowControl(true);
325 try {
326 Message::selectLanguage(Message::NEUTRAL);
327 part << setw(8) << setbase(16) << setfill('0') << 0x1234567;
328 }
329 catch(Exception & e) {
330 if(e.getDetails().compare("Operation was performed against an invalid stream.") == 0)
331 result = true;
332 }
333 if(!result)
334 TEST_FAIL;
335 } END_CASE;
336 } END_CASE;
337
338 BEGIN_CASE("getContents","getContents") {
339 BEGIN_CASE("1", "書いた内
340容が取得できる") {
341 Part part("test");
342
343 part << "test";
344
345 if(part.getContents().compare("test") != 0)
346 TEST_FAIL;
347 } END_CASE;
348
349 BEGIN_CASE("2", "書いて読んでまた書いて読める") {
350 Part part("test");
351
352 part << "abc";
353 if(part.getContents().compare("abc") != 0)
354 TEST_FAIL;
355
356 part << "def";
357 if(part.getContents().compare("abcdef") != 0)
358 TEST_FAIL;
359 } END_CASE;
360
361 BEGIN_CASE("3", "無効なストリームから読んだら例外が起る") {
362 Part part("");
363 bool result = false;
364
365 if(part.isValid())
366 TEST_FAIL;
367
368 Exception::setThrowControl(true);
369 try {
370 string work = part.getContents();
371 }
372 catch(Exception & e) {
373 if(e.getDetails().compare("Operation was performed against an invalid stream.") == 0)
374 result = true;
375 }
376 if(!result)
377 TEST_FAIL;
378 } END_CASE;
379 } END_CASE;
380
381 BEGIN_CASE("setContents","setContents") {
382 BEGIN_CASE("1", "設定した内
383容が取得できる") {
384 Part part("test");
385
386 part.setContents("test");
387
388 if(part.getContents().compare("test") != 0)
389 TEST_FAIL;
390 } END_CASE;
391
392 BEGIN_CASE("2", "setContentsで設定したあとに追記できる") {
393 Part part("test");
394
395 part.setContents("abc");
396 part << "def";
397 if(part.getContents().compare("abcdef") != 0)
398 TEST_FAIL;
399 } END_CASE;
400
401 BEGIN_CASE("3", "無効なストリームに設定したら例外が起る") {
402 Part part("");
403 bool result = false;
404
405 if(part.isValid())
406 TEST_FAIL;
407
408 Exception::setThrowControl(true);
409 try {
410 part.setContents("test");
411 }
412 catch(Exception & e) {
413 if(e.getDetails().compare("Operation was performed against an invalid stream.") == 0)
414 result = true;
415 }
416 if(!result)
417 TEST_FAIL;
418 } END_CASE;
419 } END_CASE;
420
421 BEGIN_CASE("getName","getName") {
422 BEGIN_CASE("1", "パート名が正しく取得できる") {
423 Part part("name_of_stream");
424
425 if(part.getName().compare("name_of_stream") != 0)
426 TEST_FAIL;
427 } END_CASE;
428
429 BEGIN_CASE("2", "不正なパートの名前を取ると例外が起る") {
430 Part part("");
431 bool result = false;
432
433 Exception::setThrowControl(true);
434 try { string work = part.getName(); }
435 catch(Exception & e) {
436 if(e.getDetails().compare("Operation was performed against an invalid stream.") == 0)
437 result = true;
438 }
439 if(!result)
440 TEST_FAIL;
441 } END_CASE;
442 } END_CASE;
443
444 BEGIN_CASE("CopyConstructor","コピーコンストラクタ") {
445 Part source("test");
446 source << "abcdefg";
447
448 Part dest(source);
449 BEGIN_CASE("1","ストリームの内
450容が正しくコピーできている") {
451 if(dest.getContents().compare("abcdefg") != 0)
452 TEST_FAIL;
453 } END_CASE;
454
455 BEGIN_CASE("2","部位名が正しくコピーできている") {
456 if(dest.getName() != source.getName())
457 TEST_FAIL;
458 } END_CASE;
459 } END_CASE;
460}
461
462TESTSUITE(main,MultipartStream)
463{
464 BEGIN_CASE("constructor/isValid","constructor/isValid") {
465 BEGIN_CASE("1","ファイル名を指定して生成したオブジェクトは有効") {
466 MultipartStream mps("test.dat");
467
468 if(!mps.isValid())
469 TEST_FAIL;
470 } END_CASE;
471
472 BEGIN_CASE("2","ファイル名を持たないオブジェクトは無効") {
473 MultipartStream mps;
474
475 if(mps.isValid())
476 TEST_FAIL;
477 } END_CASE;
478
479 BEGIN_CASE("3","空のファイル名を持つオブジェクトは無効") {
480 MultipartStream mps("");
481
482 if(mps.isValid())
483 TEST_FAIL;
484 } END_CASE;
485
486 BEGIN_CASE("4","NULLオブジェクトは無効") {
487 if(((MultipartStream *)0)->isValid())
488 TEST_FAIL;
489 } END_CASE;
490 } END_CASE;
491
492 BEGIN_CASE("setFilename","setFilename") {
493 BEGIN_CASE("1","ファイル名を指定せずに生成したファイルに名前をつける") {
494 MultipartStream mps;
495 if(mps.isValid())
496 TEST_FAIL;
497
498 BEGIN_CASE("1","ストリームは有効になる") {
499 mps.setFilename("test");
500 if(!mps.isValid())
501 TEST_FAIL;
502 } END_CASE;
503
504 BEGIN_CASE("2","ストリームの名前が変更されている") {
505 if(mps.filename.compare("test") != 0)
506 TEST_FAIL;
507 } END_CASE;
508 } END_CASE;
509
510 BEGIN_CASE("2","ファイル名を指定して生成したファイルに名前をつける") {
511 MultipartStream mps("initialname");
512 if(!mps.isValid())
513 TEST_FAIL;
514
515 BEGIN_CASE("1","ストリームは有効になる") {
516 mps.setFilename("test");
517 if(!mps.isValid())
518 TEST_FAIL;
519 } END_CASE;
520
521 BEGIN_CASE("2","ストリームの名前が変更されている") {
522 if(mps.filename.compare("test") != 0)
523 TEST_FAIL;
524 } END_CASE;
525 } END_CASE;
526
527 BEGIN_CASE("3","空文字を渡すと例外") {
528 MultipartStream mps;
529 bool result = false;
530
531 Exception::setThrowControl(true);
532 try { mps.setFilename(""); }
533 catch(Exception & e)
534 { result = true; }
535 if(!result)
536 TEST_FAIL;
537 } END_CASE;
538
539 BEGIN_CASE("4","NULLオブジェクトに名前をつけると例外") {
540 bool result = false;
541
542 Exception::setThrowControl(true);
543 try { ((MultipartStream *)0)->setFilename("test"); }
544 catch(Exception & e)
545 { result = true; }
546 if(!result)
547 TEST_FAIL;
548 } END_CASE;
549 } END_CASE;
550
551 BEGIN_CASE("serialize","serialize") {
552
553 BEGIN_CASE("1", "NULLオブジェクトに対するシリアライズは例外") {
554 bool result = false;
555
556 Exception::setThrowControl(true);
557 try
558 { ((MultipartStream *)0)->serialize(); }
559 catch(Exception & e)
560 { result = true; }
561
562 if(!result)
563 TEST_FAIL;
564 } END_CASE;
565
566 BEGIN_CASE("2", "無効なオブジェクトに対するシリアライズも例外") {
567 bool result = false;
568 MultipartStream mps;
569
570 Exception::setThrowControl(true);
571 try
572 { mps.serialize(); }
573 catch(Exception & e)
574 { result = true; }
575
576 if(!result)
577 TEST_FAIL;
578 } END_CASE;
579
580 BEGIN_CASE("3", "正常にシリアライズできる") {
581 MultipartStream mps("debug.out");
582 Part part("abc");
583
584 part << "abcdefg";
585 mps.parts.push_back(part);
586 mps.dirty = true;
587
588 ::remove("debug.out");
589 BEGIN_CASE("1", "シリアライズはtrueを返す") {
590 if(!mps.serialize())
591 TEST_FAIL;
592 } END_CASE;
593
594 BEGIN_CASE("2", "出力したファイルの内
595容が正しい") {
596 if(!TestSuite::compareFileContents("debug.out","abcdefg"))
597 TEST_FAIL;
598 } END_CASE;
599
600 } END_CASE;
601
602 BEGIN_CASE("4", "内
603容があってもdirty=falseなら出力されない") {
604 MultipartStream mps("debug.out");
605 Part part("abc");
606
607 part << "abcdefg";
608 mps.parts.push_back(part);
609 mps.dirty = false;
610
611 ::remove("debug.out");
612 BEGIN_CASE("1", "シリアライズはfalseを返す") {
613 if(mps.serialize())
614 TEST_FAIL;
615 } END_CASE;
616
617 BEGIN_CASE("2", "ファイルは出力されていない") {
618 fstream file("debug.out",ios::in);
619 if(file.is_open())
620 TEST_FAIL;
621 } END_CASE;
622 } END_CASE;
623
624 BEGIN_CASE("5", "内
625容があっても出力禁止なら出力されない") {
626 MultipartStream mps("debug.out");
627 Part part("abc");
628
629 part << "abcdefg";
630 mps.parts.push_back(part);
631 mps.dirty = true;
632
633 mps.disableOutput();
634
635 ::remove("debug.out");
636 BEGIN_CASE("1", "シリアライズはfalseを返す") {
637 if(mps.serialize())
638 TEST_FAIL;
639 } END_CASE;
640
641 BEGIN_CASE("2", "ファイルは出力されていない") {
642 fstream file("debug.out",ios::in);
643 if(file.is_open())
644 TEST_FAIL;
645 } END_CASE;
646 } END_CASE;
647 } END_CASE;
648
649 BEGIN_CASE("Destructor","Destructor") {
650 BEGIN_CASE("1","作って壊す") {
651 MultipartStream mps("debug.out");
652 Part part("abc");
653
654 part << "abcdefg";
655 mps.parts.push_back(part);
656 mps.dirty = true;
657
658 ::remove("debug.out");
659 } END_CASE;
660
661 BEGIN_CASE("2","内
662容がファイルに格納されている") {
663 if(!TestSuite::compareFileContents("debug.out","abcdefg"))
664 TEST_FAIL;
665 } END_CASE;
666 } END_CASE;
667
668 BEGIN_CASE("createPart","createPart") {
669 BEGIN_CASE("1","パートを登録する") {
670 MultipartStream mps("debug.out");
671 mps.disableOutput();
672
673 BEGIN_CASE("1","例外なく登録できる") {
674 Exception::setThrowControl(true);
675 mps .createPart("abc")
676 .createPart("def")
677 .createPart("ghi");
678 } END_CASE;
679
680 BEGIN_CASE("2","中身が登録順で並んでいる") {
681 list<Part>::iterator scope;
682 scope = mps.parts.begin();
683 if(scope->getName().compare("abc") != 0)
684 TEST_FAIL;
685 ++ scope;
686 if(scope->getName().compare("def") != 0)
687 TEST_FAIL;
688 ++ scope;
689 if(scope->getName().compare("ghi") != 0)
690 TEST_FAIL;
691 ++ scope;
692 if(scope != mps.parts.end())
693 TEST_FAIL;
694 } END_CASE;
695
696 } END_CASE;
697
698 BEGIN_CASE("2","パートを逆順で登録する") {
699 MultipartStream mps("debug.out");
700 mps.disableOutput();
701
702 BEGIN_CASE("1","例外なく登録できる") {
703 Exception::setThrowControl(true);
704 mps .createPart("abc",true)
705 .createPart("def",true)
706 .createPart("ghi",true);
707 } END_CASE;
708
709 BEGIN_CASE("2","中身が登録した逆順で並んでいる") {
710 list<Part>::iterator scope;
711 scope = mps.parts.begin();
712 if(scope->getName().compare("ghi") != 0)
713 TEST_FAIL;
714 ++ scope;
715 if(scope->getName().compare("def") != 0)
716 TEST_FAIL;
717 ++ scope;
718 if(scope->getName().compare("abc") != 0)
719 TEST_FAIL;
720 ++ scope;
721 if(scope != mps.parts.end())
722 TEST_FAIL;
723 } END_CASE;
724
725 } END_CASE;
726
727 BEGIN_CASE("3","NULLに対する操作で例外が発生する") {
728 bool result = false;
729 Exception::setThrowControl(true);
730 try {
731 ((MultipartStream *)0)->createPart("test");
732 }
733 catch(...)
734 { result = true; }
735 if(!result)
736 TEST_FAIL;
737 } END_CASE;
738
739 BEGIN_CASE("4","同じ名前のパートを作ると例外が起る") {
740 BEGIN_CASE("1","同じ名前のパートを作ると例外が起る") {
741 bool result = false;
742 MultipartStream mps("debug.out");
743 Exception::setThrowControl(true);
744
745 try {
746 mps .createPart("abc")
747 .createPart("def")
748 .createPart("abc");
749 }
750 catch(...)
751 { result = true; }
752
753 if(!result)
754 TEST_FAIL;
755 } END_CASE;
756
757 BEGIN_CASE("2","例外を封じても正しく動く") {
758 bool result = true;
759 MultipartStream mps("debug.out");
760 Exception::setThrowControl(false);
761
762 BEGIN_CASE("1","例外はスローされない") {
763 try {
764 mps .createPart("abc")
765 .createPart("def")
766 .createPart("abc");
767 }
768 catch(...)
769 { result = false; }
770
771 if(!result)
772 TEST_FAIL;
773 } END_CASE;
774
775 BEGIN_CASE("2","現在位置は変化しない") {
776 if(mps.current == 0 || mps.current->getName().compare("def") != 0)
777 TEST_FAIL;
778 } END_CASE;
779 } END_CASE;
780 } END_CASE;
781
782 Exception::setThrowControl(true);
783
784 BEGIN_CASE("5","登録すると現在位置が変化する") {
785 MultipartStream mps("debug.out");
786 mps.disableOutput();
787
788 BEGIN_CASE("1","登録すると位置が変化する (1)") {
789 mps.createPart("abc");
790 if(mps.current == 0 || mps.current->getName().compare("abc") != 0)
791 TEST_FAIL;
792 } END_CASE;
793
794 BEGIN_CASE("2","登録すると位置が変化する (2)") {
795 mps.createPart("def");
796 if(mps.current == 0 || mps.current->getName().compare("def") != 0)
797 TEST_FAIL;
798 } END_CASE;
799
800 BEGIN_CASE("3","登録すると位置が変化する (3)") {
801 mps.createPart("ghi");
802 if(mps.current == 0 || mps.current->getName().compare("ghi") != 0)
803 TEST_FAIL;
804 } END_CASE;
805 } END_CASE;
806 } END_CASE;
807
808 BEGIN_CASE("opeator <<","operator <<") {
809
810 BEGIN_CASE("1","operator <<が使える") {
811 MultipartStream mps("debug.out");
812
813 mps.createPart("test");
814
815 mps << "abcdefghijklmn";
816 } END_CASE;
817
818 BEGIN_CASE("2","出力された中身が正しい") {
819 if(!TestSuite::compareFileContents("debug.out","abcdefghijklmn"))
820 TEST_FAIL;
821 } END_CASE;
822
823 BEGIN_CASE("3","NULLオブジェクトに出力すると例外") {
824 bool result = false;
825 Exception::setThrowControl(true);
826 try {
827 *((MultipartStream *)0) << "test";
828 }
829 catch(...)
830 { result = true; }
831 if(!result)
832 TEST_FAIL;
833 } END_CASE;
834
835 BEGIN_CASE("4","パートをå…
836¨ãä½œã£ã¦ã„ないオブジェクトに出力すると例外") {
837 bool result = false;
838 Exception::setThrowControl(true);
839 try {
840 MultipartStream mps("debug.out");
841 mps.disableOutput();
842 *((MultipartStream *)0) << "test";
843 }
844 catch(...)
845 { result = true; }
846 if(!result)
847 TEST_FAIL;
848 } END_CASE;
849
850 } END_CASE;
851
852 BEGIN_CASE("movePart/operator []","movePart/operator []") {
853 BEGIN_CASE("1","普通に移動する") {
854 MultipartStream mps("debug.out");
855 mps.disableOutput();
856
857 mps .createPart("abc")
858 .createPart("def")
859 .createPart("ghi");
860
861 BEGIN_CASE("1","移動できる") {
862 mps.movePart("def");
863
864 if(mps.current->getName().compare("def") != 0)
865 TEST_FAIL;
866 } END_CASE;
867
868 BEGIN_CASE("2","無効な名前をå…
869¥ã‚Œã‚‹ã¨ä¾‹å¤–") {
870 bool result = false;
871 Exception::setThrowControl(true);
872
873 try {
874 mps.movePart("unknwon");
875 }
876 catch(...)
877 { result = true; }
878 if(!result)
879 TEST_FAIL;
880 } END_CASE;
881
882 BEGIN_CASE("3","空文字をå…
883¥ã‚Œã‚‹ã¨ä¾‹å¤–") {
884 bool result = false;
885 Exception::setThrowControl(true);
886
887 try {
888 mps.movePart("");
889 }
890 catch(...)
891 { result = true; }
892 if(!result)
893 TEST_FAIL;
894 } END_CASE;
895 } END_CASE;
896
897 BEGIN_CASE("2", "NULLオブジェクト相手に操作すると例外") {
898 bool result = false;
899 Exception::setThrowControl(true);
900
901 try {
902 ((MultipartStream *)0)->movePart("");
903 }
904 catch(...)
905 { result = true; }
906 if(!result)
907 TEST_FAIL;
908 } END_CASE;
909 } END_CASE;
910}
911
912
913#endif
914
915
916
917
Note: See TracBrowser for help on using the repository browser.