チェンジセット 513

差分発生行の前後
無視リスト:
コミット日時:
2008/05/26 22:57:08 (6 ヶ月前)
コミッタ:
yossy
ログメッセージ:

Thread(soumen): テスト更新

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/Thread/branches/soumen/tests/org/libspark/thread/AuxiliaryTest.as

    r509 r513  
    44        import org.libspark.as3unit.assert.*; 
    55        import org.libspark.as3unit.before; 
     6        import org.libspark.as3unit.after; 
    67        import org.libspark.as3unit.test; 
    78         
    89        use namespace before; 
     10        use namespace after; 
    911        use namespace test; 
    1012         
     
    2123                 
    2224                /** 
     25                 * 念のため、終了処理もしておく 
     26                 */ 
     27                after function finalize():void 
     28                { 
     29                        Thread.initialize(null); 
     30                } 
     31                 
     32                /** 
    2333                 * join によってスレッドの終了を待機できているかどうか。 
    2434                 * join の呼び出しによってスレッドが待機状態に入る場合は true それ以外(つまりスレッドがすでに終了している場合)は false が返る。 
     
    2636                test function join():void 
    2737                { 
     38                        Static.log = ''; 
     39                         
    2840                        var j:JoinTestThread = new JoinTestThread(); 
    2941                        var t:TesterThread = new TesterThread(j); 
     
    4456                test function timedJoin():void 
    4557                { 
     58                        Static.log = ''; 
     59                         
    4660                        var t:TesterThread = new TesterThread(new TimedJoinTestThread()); 
    4761                         
     
    7589                 
    7690                _thread = new JoinChildThread(); 
     91                _thread.start(); 
    7792                 
    7893                join1 = _thread.join(); 
     
    109124                Static.log += 'run '; 
    110125                var t:Thread = new Thread(); 
     126                t.start(); 
    111127                t.join(20); 
    112128                next(joined1); 
  • as3/Thread/branches/soumen/tests/org/libspark/thread/MonitorTest.as

    r509 r513  
    44        import org.libspark.as3unit.assert.*; 
    55        import org.libspark.as3unit.before; 
     6        import org.libspark.as3unit.after; 
    67        import org.libspark.as3unit.test; 
    78        import org.libspark.as3unit.ignore; 
    89         
    910        use namespace before; 
     11        use namespace after; 
    1012        use namespace test; 
    1113        use namespace ignore; 
     
    2325                 
    2426                /** 
     27                 * 念のため、終了処理もしておく 
     28                 */ 
     29                after function finalize():void 
     30                { 
     31                        Thread.initialize(null); 
     32                } 
     33                 
     34                /** 
    2535                 * wait を呼び出して待機しているスレッドが notify の呼び出しで起きるかどうか。 
    2636                 * 待機しているスレッドのうち、ひとつだけが起きる。 
     
    8292                test function timeout():void 
    8393                { 
     94                        Static.log = ''; 
     95                         
    8496                        var t:TesterThread = new TesterThread(new TimeoutTestThread()); 
    8597                         
     
    109121                        t.start(); 
    110122                } 
    111         } 
    112 
    113  
     123                 
     124                /** 
     125                 * 終了フェーズに入る直前で wait した場合きちんと動作するかどうか。 
     126                 */ 
     127                test function waitFinalize():void 
     128                { 
     129                        Static.log = ''; 
     130                         
     131                        var t:TesterThread = new TesterThread(new WaitFinalizeTestThread()); 
     132                         
     133                        t.addEventListener(Event.COMPLETE, async(function(e:Event):void 
     134                        { 
     135                                assertEquals('wait notifyAll finalize ', Static.log); 
     136                        }, 1000)); 
     137                         
     138                        t.start(); 
     139                } 
     140                 
     141                /** 
     142                 * 終了フェーズに入る直前で wait がタイムアウトした場合きちんと動作するかどうか。 
     143                 */ 
     144                test function timeoutFinalize():void 
     145                { 
     146                        Static.log = ''; 
     147                         
     148                        var t:TesterThread = new TesterThread(new TimeoutFinaizeTestThread()); 
     149                         
     150                        t.addEventListener(Event.COMPLETE, async(function(e:Event):void 
     151                        { 
     152                                assertEquals('wait finalize ', Static.log); 
     153                        }, 1000)); 
     154                         
     155                        t.start(); 
     156                } 
     157                 
     158                /** 
     159                 * 終了直前で wait した場合きちんと動作するかどうか。 
     160                 */ 
     161                test function finalizeWait():void 
     162                { 
     163                        Static.log = ''; 
     164                         
     165                        var t:TesterThread = new TesterThread(new FinalizeWaitTestThread()); 
     166                         
     167                        t.addEventListener(Event.COMPLETE, async(function(e:Event):void 
     168                        { 
     169                                assertEquals('finalize notifyAll ', Static.log); 
     170                        }, 1000)); 
     171                         
     172                        t.start(); 
     173                } 
     174                 
     175                /** 
     176                 * 終了直前で wait がタイムアウトした場合きちんと動作するかどうか。 
     177                 */ 
     178                test function finalizeTimeout():void 
     179                { 
     180                        Static.log = ''; 
     181                         
     182                        var t:TesterThread = new TesterThread(new FinalizeTimeoutTestThread()); 
     183                         
     184                        t.addEventListener(Event.COMPLETE, async(function(e:Event):void 
     185                        { 
     186                                assertEquals('finalize ', Static.log); 
     187                        }, 1000)); 
     188                         
     189                        t.start(); 
     190                } 
     191                 
     192                /** 
     193                 * 終了直前で wait がタイムアウトした場合タイムアウトハンドラを実行して終了できるかどうか。 
     194                 */ 
     195                test function finalizeTimeoutHandler():void 
     196                { 
     197                        Static.log = ''; 
     198                         
     199                        var t:TesterThread = new TesterThread(new FinalizeTimeoutHandlerTestThread()); 
     200                         
     201                        t.addEventListener(Event.COMPLETE, async(function(e:Event):void 
     202                        { 
     203                                assertEquals('finalize wakeup ', Static.log); 
     204                        }, 1000)); 
     205                         
     206                        t.start(); 
     207                } 
     208        } 
     209
     210 
     211import flash.events.Event; 
    114212import org.libspark.thread.Thread; 
    115213import org.libspark.thread.ThreadState; 
     
    117215import org.libspark.thread.Monitor; 
    118216 
     217import flash.utils.setTimeout; 
     218 
    119219class Static 
    120220{ 
     
    264364        { 
    265365                Static.log += 'wakeup '; 
     366                next(run2); 
     367        } 
     368         
     369        private function run2():void 
     370        { 
     371                 
    266372        } 
    267373} 
     
    302408        private function run4():void 
    303409        { 
    304                 Static.log = 'notify '; 
     410                Static.log += 'notify '; 
    305411                _monitor.notifyAll(); 
    306412                next(run5); 
     
    371477        { 
    372478                Static.log += 'wait '; 
    373                 _monitor.wait(20); 
     479                _monitor.wait(500); 
    374480                next(wakeup); 
    375481                timeout(wakeup2); 
     
    380486                wu = true; 
    381487                Static.log += 'wakeup '; 
     488                next(run2); 
    382489        } 
    383490         
     
    386493                wu = true; 
    387494                Static.log += 'wakeup2 '; 
    388         } 
    389 
     495                next(run2); 
     496        } 
     497         
     498        private function run2():void 
     499        { 
     500                next(run3); 
     501        } 
     502         
     503        private function run3():void 
     504        { 
     505                 
     506        } 
     507
     508 
     509class WaitFinalizeTestThread extends Thread 
     510
     511        private var _monitor:IMonitor = new Monitor(); 
     512         
     513        override protected function run():void 
     514        { 
     515                Static.log += 'wait '; 
     516                 
     517                _monitor.wait(); 
     518                 
     519                setTimeout(timeoutHandler, 100); 
     520        } 
     521         
     522        private function timeoutHandler():void 
     523        { 
     524                Static.log += 'notifyAll '; 
     525                 
     526                _monitor.notifyAll(); 
     527        } 
     528         
     529        override protected function finalize():void 
     530        { 
     531                Static.log += 'finalize '; 
     532        } 
     533
     534 
     535class TimeoutFinaizeTestThread extends Thread 
     536
     537        override protected function run():void 
     538        { 
     539                Static.log += 'wait '; 
     540                 
     541                new Monitor().wait(100); 
     542        } 
     543         
     544        override protected function finalize():void 
     545        { 
     546                Static.log += 'finalize '; 
     547        } 
     548
     549 
     550class FinalizeWaitTestThread extends Thread 
     551
     552        private var _monitor:IMonitor = new Monitor(); 
     553         
     554        override protected function finalize():void 
     555        { 
     556                Static.log += 'finalize '; 
     557                 
     558                _monitor.wait(); 
     559                 
     560                setTimeout(timeoutHandler, 500); 
     561        } 
     562         
     563        private function timeoutHandler():void 
     564        { 
     565                Static.log += 'notifyAll '; 
     566                 
     567                _monitor.notifyAll(); 
     568        } 
     569
     570 
     571class FinalizeTimeoutTestThread extends Thread 
     572
     573        override protected function finalize():void 
     574        { 
     575                Static.log += 'finalize '; 
     576                 
     577                new Monitor().wait(100); 
     578        } 
     579
     580 
     581class FinalizeTimeoutHandlerTestThread extends Thread 
     582
     583        override protected function finalize():void 
     584        { 
     585                Static.log += 'finalize '; 
     586                 
     587                new Monitor().wait(100); 
     588                 
     589                timeout(wakeup); 
     590        } 
     591         
     592        private function wakeup():void 
     593        { 
     594                Static.log += 'wakeup '; 
     595        } 
     596
  • as3/Thread/branches/soumen/tests/org/libspark/thread/TesterThread.as

    r507 r513  
    55        import flash.events.Event; 
    66        import flash.events.EventDispatcher; 
     7        import flash.utils.setTimeout; 
    78         
    89        public class TesterThread extends Thread 
     
    3233                protected override function finalize():void  
    3334                { 
     35                        setTimeout(dispatchHandler, 1); 
     36                } 
     37                 
     38                private function dispatchHandler():void 
     39                { 
    3440                        _e.dispatchEvent(new Event(Event.COMPLETE)); 
    3541                } 
  • as3/Thread/branches/soumen/tests/org/libspark/thread/TesterThreadTest.as

    r507 r513  
    44        import org.libspark.as3unit.assert.*; 
    55        import org.libspark.as3unit.before; 
     6        import org.libspark.as3unit.after; 
    67        import org.libspark.as3unit.test; 
    78         
    89        use namespace before; 
     10        use namespace after; 
    911        use namespace test; 
    1012         
    1113        public class TesterThreadTest 
    1214        { 
     15                /** 
     16                 * テストに相互作用が出ないようにテスト毎にスレッドライブラリを初期化。 
     17                 * 通常であれば、initializeの呼び出しは一度きり。 
     18                 */ 
    1319                before function initialize():void 
    1420                { 
     
    1622                } 
    1723                 
     24                /** 
     25                 * 念のため、終了処理もしておく 
     26                 */ 
     27                after function finalize():void 
     28                { 
     29                        Thread.initialize(null); 
     30                } 
     31                 
     32                /** 
     33                 * TesterThread が終了した際に Event.COMPLETE が配信されるかどうか。 
     34                 */ 
    1835                test function tester():void 
    1936                { 
  • as3/Thread/branches/soumen/tests/org/libspark/thread/ThreadExecutionTest.as

    r507 r513  
    44        import org.libspark.as3unit.assert.*; 
    55        import org.libspark.as3unit.before; 
     6        import org.libspark.as3unit.after; 
    67        import org.libspark.as3unit.test; 
     8        import org.libspark.as3unit.test_expected; 
     9        import org.libspark.thread.errors.IllegalThreadStateError; 
    710         
    811        use namespace before; 
     12        use namespace after; 
    913        use namespace test; 
     14        use namespace test_expected; 
    1015         
    1116        public class ThreadExecutionTest 
     
    2126                 
    2227                /** 
     28                 * 念のため、終了処理もしておく 
     29                 */ 
     30                after function finalize():void 
     31                { 
     32                        Thread.initialize(null); 
     33                } 
     34                 
     35                /** 
    2336                 * start したら run が実行されるか 
    2437                 */ 
     
    3649                        }, 1000)); 
    3750                         
     51                        t.start(); 
     52                } 
     53                 
     54                /** 
     55                 * 既に実行しているスレッドを start したら IllegalThreadStateError がスローされるか。 
     56                 */ 
     57                test_expected static const startError:Class = IllegalThreadStateError; 
     58                test function startError():void 
     59                { 
     60                        var t:Thread = new Thread(); 
     61                        t.start(); 
    3862                        t.start(); 
    3963                } 
     
    5175                        { 
    5276                                assertSame(c, c.current); 
    53                                 assertNull(Thread.currentThread); 
    5477                        }, 1000)); 
    5578                         
     
    279302        override protected function finalize():void 
    280303        { 
    281                 Static.log += _name + '.finalzie '; 
     304                Static.log += _name + '.finalize '; 
    282305        } 
    283306} 
     
    332355        { 
    333356                Static.log += 'c.run2 '; 
    334                 next(run2); 
    335357        } 
    336358