-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/test/scala/com/martomate/tripaint/control/action/OpenActionTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.martomate.tripaint.control.action | ||
|
||
import com.martomate.tripaint.infrastructure.FileSystem | ||
import com.martomate.tripaint.model.{Color, TriPaintModel} | ||
import com.martomate.tripaint.model.coords.{StorageCoords, TriImageCoords} | ||
import com.martomate.tripaint.model.image.RegularImage | ||
import com.martomate.tripaint.model.image.format.SimpleStorageFormat | ||
import com.martomate.tripaint.view.FileOpenSettings | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import java.io.File | ||
|
||
class OpenActionTest extends AnyFlatSpec with Matchers { | ||
"OpenAction" should "open an image" in { | ||
val file = new File("image.png") | ||
val image = RegularImage.fill(8, 8, Color.Yellow) | ||
image.setColor(5, 6, Color.Cyan) | ||
|
||
val model = TriPaintModel.createNull(new FileSystem.NullArgs(initialImages = Map(file -> image.toBufferedImage))) | ||
model.imageGrid.setImageSizeIfEmpty(8) | ||
|
||
new OpenAction( | ||
model, | ||
() => Some(file), | ||
(_, _, _) => Some(FileOpenSettings(StorageCoords(0, 0), new SimpleStorageFormat)), | ||
() => Some((3, 4)) | ||
).perform() | ||
|
||
val actualImage = model.imageGrid(TriImageCoords(3, 4)) | ||
.map(_.storage) | ||
.map(_.toRegularImage(new SimpleStorageFormat)) | ||
.orNull | ||
|
||
actualImage shouldBe image | ||
} | ||
|
||
it should "open an image at an offset" in { | ||
val file = new File("image.png") | ||
val image = RegularImage.fill(8, 8, Color.Yellow) | ||
image.setColor(5, 6, Color.Cyan) | ||
|
||
val storedImage = RegularImage.ofSize(9, 10) | ||
val offset = StorageCoords(1, 2) | ||
storedImage.pasteImage(offset, image) | ||
|
||
val model = TriPaintModel.createNull(new FileSystem.NullArgs(initialImages = Map(file -> storedImage.toBufferedImage))) | ||
model.imageGrid.setImageSizeIfEmpty(8) | ||
|
||
new OpenAction( | ||
model, | ||
() => Some(file), | ||
(_, _, _) => Some(FileOpenSettings(offset, new SimpleStorageFormat)), | ||
() => Some((3, 4)) | ||
).perform() | ||
|
||
val actualImage = model.imageGrid(TriImageCoords(3, 4)) | ||
.map(_.storage) | ||
.map(_.toRegularImage(new SimpleStorageFormat)) | ||
.orNull | ||
|
||
actualImage shouldBe image | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters