OSDN Git Service

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