aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/scala
diff options
context:
space:
mode:
authorJakob Odersky <jakob@odersky.com>2017-01-08 21:16:25 +0100
committerJakob Odersky <jakob@odersky.com>2017-01-21 17:22:10 -0800
commit23959966760174477a6b0fcbf9dd1e8ef37c643b (patch)
tree9a0ee44eb43a8c13af57b0d06313f3aabf9e4555 /core/src/test/scala
parent6c371ba6d69c891c1f0d6df00bb643e1d543cc9d (diff)
downloadakka-serial-23959966760174477a6b0fcbf9dd1e8ef37c643b.tar.gz
akka-serial-23959966760174477a6b0fcbf9dd1e8ef37c643b.tar.bz2
akka-serial-23959966760174477a6b0fcbf9dd1e8ef37c643b.zip
Rename project to akka-serial
Diffstat (limited to 'core/src/test/scala')
-rw-r--r--core/src/test/scala/akka/serial/SerialManagerSpec.scala40
-rw-r--r--core/src/test/scala/akka/serial/SerialOperatorSpec.scala50
2 files changed, 90 insertions, 0 deletions
diff --git a/core/src/test/scala/akka/serial/SerialManagerSpec.scala b/core/src/test/scala/akka/serial/SerialManagerSpec.scala
new file mode 100644
index 0000000..eab5013
--- /dev/null
+++ b/core/src/test/scala/akka/serial/SerialManagerSpec.scala
@@ -0,0 +1,40 @@
+package akka.serial
+
+import akka.actor.ActorSystem
+import akka.io.IO
+import akka.testkit.{ImplicitSender, TestKit}
+import org.scalatest._
+
+class SerialManagerSpec
+ extends TestKit(ActorSystem("serial-manager"))
+ with ImplicitSender
+ with WordSpecLike
+ with Matchers
+ with BeforeAndAfterAll
+ with PseudoTerminal {
+
+ override def afterAll {
+ TestKit.shutdownActorSystem(system)
+ }
+
+ "Serial manager" should {
+ val manager = IO(Serial)
+
+ "open an existing port" in {
+ withEcho{ case (port, settings) =>
+ manager ! Serial.Open(port, settings)
+ expectMsgType[Serial.Opened]
+ }
+ }
+
+ "fail opening a non-existing port" in {
+ val cmd = Serial.Open("nonexistent", SerialSettings(115200))
+ manager ! cmd
+
+ //manager.context.set
+ assert(expectMsgType[Serial.CommandFailed].command == cmd)
+ }
+
+ }
+
+}
diff --git a/core/src/test/scala/akka/serial/SerialOperatorSpec.scala b/core/src/test/scala/akka/serial/SerialOperatorSpec.scala
new file mode 100644
index 0000000..6907494
--- /dev/null
+++ b/core/src/test/scala/akka/serial/SerialOperatorSpec.scala
@@ -0,0 +1,50 @@
+package akka.serial
+
+import scala.concurrent.duration._
+
+import akka.actor.{ActorRef, ActorSystem}
+import akka.testkit.{ImplicitSender, TestKit}
+import akka.util.ByteString
+import org.scalatest._
+import sync._
+
+case class Ack(n: Int) extends Serial.Event
+
+class SerialOperatorSpec
+ extends TestKit(ActorSystem("serial-operator"))
+ with ImplicitSender
+ with WordSpecLike
+ with Matchers
+ with BeforeAndAfterAll
+ with SequentialNestedSuiteExecution
+ with PseudoTerminal {
+
+ override def afterAll {
+ TestKit.shutdownActorSystem(system)
+ }
+
+ def withEchoOp[A](action: ActorRef => A): A = {
+ withEcho { case (port, settings) =>
+ val connection = SerialConnection.open(port, settings)
+ val operator = system.actorOf(SerialOperator.apply(connection, 1024, testActor))
+ action(operator)
+ }
+ }
+
+ "Serial operator" should {
+
+ "follow the correct protocol" in withEchoOp { op =>
+ expectMsgType[Serial.Opened]
+
+ val data = ByteString("hello world".getBytes("utf-8"))
+ op ! Serial.Write(data)
+ expectMsg(Serial.Received(data))
+
+ op ! Serial.Close
+ expectMsg(Serial.Closed)
+
+ }
+
+ }
+
+}