| 1 |
package org.libspark.gunyarapaint.framework |
|---|
| 2 |
{ |
|---|
| 3 |
import flash.utils.ByteArray; |
|---|
| 4 |
|
|---|
| 5 |
import org.flexunit.Assert; |
|---|
| 6 |
import org.libspark.gunyarapaint.framework.commands.ICommand; |
|---|
| 7 |
import org.libspark.gunyarapaint.framework.events.CommandEvent; |
|---|
| 8 |
import org.libspark.gunyarapaint.framework.events.UndoEvent; |
|---|
| 9 |
|
|---|
| 10 |
public class RecorderTest |
|---|
| 11 |
{ |
|---|
| 12 |
|
|---|
| 13 |
[Test] |
|---|
| 14 |
public function prepare():void |
|---|
| 15 |
{ |
|---|
| 16 |
var recorder:Recorder = Recorder.create(123, 321, 16); |
|---|
| 17 |
Assert.assertStrictlyEquals(123, recorder.width); |
|---|
| 18 |
Assert.assertStrictlyEquals(321, recorder.height); |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
[Test(async)] |
|---|
| 22 |
public function commitCommand():void |
|---|
| 23 |
{ |
|---|
| 24 |
var commands:CommandCollection = new CommandCollection(); |
|---|
| 25 |
var bytes:ByteArray = new ByteArray(); |
|---|
| 26 |
var recorder:Recorder = new Recorder(1, 1, bytes, commands); |
|---|
| 27 |
var command:ICommand = new FakeCommand(); |
|---|
| 28 |
commands.registerCommand(command); |
|---|
| 29 |
recorder.addEventListener(CommandEvent.COMMITTED, onCommitCommand); |
|---|
| 30 |
recorder.commitCommand(FakeCommand.ID, command); |
|---|
| 31 |
Assert.assertTrue(FakeCommand.didExecute); |
|---|
| 32 |
Assert.assertTrue(FakeCommand.didWrite); |
|---|
| 33 |
Assert.assertEquals(command, FakeCommand.writeArgument); |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
[Test(async)] |
|---|
| 37 |
public function undo():void |
|---|
| 38 |
{ |
|---|
| 39 |
var recorder:Recorder = Recorder.create(1, 1, 16); |
|---|
| 40 |
recorder.addEventListener(UndoEvent.UNDO, onUndo); |
|---|
| 41 |
recorder.addEventListener(UndoEvent.REDO, onRedo); |
|---|
| 42 |
recorder.addEventListener(UndoEvent.PUSH, onPushUndo); |
|---|
| 43 |
recorder.pushUndo(); |
|---|
| 44 |
recorder.undo(); |
|---|
| 45 |
recorder.redo(); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
private function onCommitCommand(event:CommandEvent):void |
|---|
| 49 |
{ |
|---|
| 50 |
Assert.assertEquals(FakeCommand.ID, event.command.commandID); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
private function onUndo(event:UndoEvent):void |
|---|
| 54 |
{ |
|---|
| 55 |
Assert.assertStrictlyEquals(UndoEvent.UNDO, event.type); |
|---|
| 56 |
Assert.assertStrictlyEquals(0, event.undoCount); |
|---|
| 57 |
Assert.assertStrictlyEquals(1, event.redoCount); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
private function onRedo(event:UndoEvent):void |
|---|
| 61 |
{ |
|---|
| 62 |
Assert.assertStrictlyEquals(UndoEvent.REDO, event.type); |
|---|
| 63 |
Assert.assertStrictlyEquals(1, event.undoCount); |
|---|
| 64 |
Assert.assertStrictlyEquals(0, event.redoCount); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
private function onPushUndo(event:UndoEvent):void |
|---|
| 68 |
{ |
|---|
| 69 |
Assert.assertStrictlyEquals(UndoEvent.PUSH, event.type); |
|---|
| 70 |
Assert.assertStrictlyEquals(1, event.undoCount); |
|---|
| 71 |
Assert.assertStrictlyEquals(0, event.redoCount); |
|---|
| 72 |
} |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|