mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-17 21:53:38 +00:00
added and expanded tests in hopes of increasing code coverage score
added tests for AvatarService and PacketCodingActor; especially PCA tests
This commit is contained in:
parent
0e5afe6cfd
commit
3aee0ab4e8
69 changed files with 4534 additions and 3037 deletions
|
|
@ -120,10 +120,6 @@ class PacketCodingActor extends Actor with MDCContextAware {
|
|||
// failWithError(s"Invalid message '$default' received in state Established")
|
||||
}
|
||||
|
||||
def resetState() : Unit = {
|
||||
context.become(receive)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current subslot number.
|
||||
* Increment the `subslot` for the next time it is needed.
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ class WorldSessionActor extends Actor with MDCContextAware {
|
|||
sendResponse(PacketCoding.CreateGamePacket(0, ObjectHeldMessage(guid, slot, true)))
|
||||
}
|
||||
|
||||
case AvatarResponse.PlanetSideAttribute(attribute_type, attribute_value) =>
|
||||
case AvatarResponse.PlanetsideAttribute(attribute_type, attribute_value) =>
|
||||
if(player.GUID != guid) {
|
||||
sendResponse(PacketCoding.CreateGamePacket(0, PlanetsideAttributeMessage(guid, attribute_type, attribute_value)))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ object AvatarResponse {
|
|||
// final case class LoadMap() extends Response
|
||||
final case class ObjectDelete(item_guid : PlanetSideGUID, unk : Int) extends Response
|
||||
final case class ObjectHeld(slot : Int) extends Response
|
||||
final case class PlanetSideAttribute(attribute_type : Int, attribute_value : Long) extends Response
|
||||
final case class PlanetsideAttribute(attribute_type : Int, attribute_value : Long) extends Response
|
||||
final case class PlayerState(msg : PlayerStateMessageUpstream, spectator : Boolean, weaponInHand : Boolean) extends Response
|
||||
final case class Reload(mag : Int) extends Response
|
||||
// final case class PlayerStateShift(itemID : PlanetSideGUID) extends Response
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class AvatarService extends Actor {
|
|||
)
|
||||
case AvatarAction.PlanetsideAttribute(guid, attribute_type, attribute_value) =>
|
||||
AvatarEvents.publish(
|
||||
AvatarServiceResponse(s"/$forChannel/Avatar", guid, AvatarResponse.PlanetSideAttribute(attribute_type, attribute_value))
|
||||
AvatarServiceResponse(s"/$forChannel/Avatar", guid, AvatarResponse.PlanetsideAttribute(attribute_type, attribute_value))
|
||||
)
|
||||
case AvatarAction.PlayerState(guid, msg, spectator, weapon) =>
|
||||
AvatarEvents.publish(
|
||||
|
|
|
|||
57
pslogin/src/main/test/scala/ActorTest.scala
Normal file
57
pslogin/src/main/test/scala/ActorTest.scala
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem, MDCContextAware}
|
||||
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
|
||||
import net.psforever.packet.{ControlPacket, GamePacket}
|
||||
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
|
||||
import org.specs2.specification.Scope
|
||||
|
||||
abstract class ActorTest(sys : ActorSystem = ActorSystem("system")) extends TestKit(sys) with Scope with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll {
|
||||
override def afterAll {
|
||||
TestKit.shutdownActorSystem(system)
|
||||
}
|
||||
}
|
||||
|
||||
object ActorTest {
|
||||
final case class MDCGamePacket(packet : GamePacket)
|
||||
|
||||
final case class MDCControlPacket(packet : ControlPacket)
|
||||
|
||||
class MDCTestProbe(probe : TestProbe) extends MDCContextAware {
|
||||
/*
|
||||
The way this test mediator works needs to be explained.
|
||||
|
||||
MDCContextAware objects initialize themselves in a chain of ActorRefs defined in the HelloFriend message.
|
||||
As the iterator is consumed, it produces a right-neighbor (r-neighbor) that is much further along the chain.
|
||||
The HelloFriend is passed to that r-neighbor and that is how subsequent neighbors are initialized and chained.
|
||||
|
||||
MDCContextAware objects consume and produce internal messages called MdcMsg that wrap around the payload.
|
||||
Normally inaccessible from the outside, the payload is unwrapped within the standard receive PartialFunction.
|
||||
By interacting with a TestProbe constructor param, information that would be concealed by MdcMsg can be polled.
|
||||
|
||||
The l-neighbor of the MDCContextAware is the system of the ActorTest TestKit.
|
||||
The r-neighbor of the MDCContextAware is this MDCTestProbe and, indirectly, the TestProbe that was interjected.
|
||||
Pass l-input into the MDCContextAware itself.
|
||||
The r-output is a normal message that can be polled on that TestProbe.
|
||||
Pass r-input into this MDCTestProbe directly.
|
||||
The l-output is an MdcMsg that can be treated just as r-output, sending it to this Actor and polling the TestProbe.
|
||||
*/
|
||||
private var left : ActorRef = ActorRef.noSender
|
||||
|
||||
def receive : Receive = {
|
||||
case msg @ HelloFriend(_, _) =>
|
||||
left = sender()
|
||||
probe.ref ! msg
|
||||
|
||||
case MDCGamePacket(msg) =>
|
||||
left ! msg
|
||||
|
||||
case MDCControlPacket(msg) =>
|
||||
left ! msg
|
||||
|
||||
case msg =>
|
||||
left ! msg
|
||||
probe.ref ! msg
|
||||
}
|
||||
}
|
||||
}
|
||||
187
pslogin/src/main/test/scala/AvatarServiceTest.scala
Normal file
187
pslogin/src/main/test/scala/AvatarServiceTest.scala
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
import akka.actor.Props
|
||||
import net.psforever.objects._
|
||||
import net.psforever.packet.game.{PlanetSideGUID, PlayerStateMessageUpstream}
|
||||
import net.psforever.types.{CharacterGender, ExoSuitType, PlanetSideEmpire, Vector3}
|
||||
import services.Service
|
||||
import services.avatar._
|
||||
|
||||
class AvatarService0Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"construct" in {
|
||||
system.actorOf(Props[AvatarService], "service")
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService1ATest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"subscribe" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService1BTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"subscribe" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! Service.Leave()
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService1CTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"subscribe" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! Service.LeaveAll()
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService2Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass an unhandled message" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! "hello"
|
||||
expectNoMsg()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService3Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ArmorChanged" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ArmorChanged(PlanetSideGUID(10), ExoSuitType.Reinforced, 0))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ArmorChanged(ExoSuitType.Reinforced, 0)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService4Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ConcealPlayer" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ConcealPlayer(PlanetSideGUID(10)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ConcealPlayer()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService5Test extends ActorTest {
|
||||
val tool = Tool(GlobalDefinitions.beamer)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass EquipmentInHand" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.EquipmentInHand(PlanetSideGUID(10), 2, tool))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.EquipmentInHand(2, tool)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService6Test extends ActorTest {
|
||||
val tool = Tool(GlobalDefinitions.beamer)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass EquipmentOnGround" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.EquipmentOnGround(PlanetSideGUID(10), Vector3(300f, 200f, 100f), Vector3(450f, 300f, 150f), tool))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.EquipmentOnGround(Vector3(300f, 200f, 100f), Vector3(450f, 300f, 150f), tool)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService7Test extends ActorTest {
|
||||
val obj = Player("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, 1)
|
||||
obj.GUID = PlanetSideGUID(10)
|
||||
obj.Slot(5).Equipment.get.GUID = PlanetSideGUID(11)
|
||||
val pdata = obj.Definition.Packet.DetailedConstructorData(obj).get
|
||||
|
||||
"AvatarService" should {
|
||||
"pass LoadPlayer" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.LoadPlayer(PlanetSideGUID(10), pdata))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.LoadPlayer(pdata)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService8Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ObjectDelete" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ObjectDelete(PlanetSideGUID(10), PlanetSideGUID(11)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ObjectDelete(PlanetSideGUID(11), 0)))
|
||||
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ObjectDelete(PlanetSideGUID(10), PlanetSideGUID(11), 55))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ObjectDelete(PlanetSideGUID(11), 55)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService9Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ObjectHeld" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ObjectHeld(PlanetSideGUID(10), 1))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ObjectHeld(1)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarServiceATest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass PlanetsideAttribute" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.PlanetsideAttribute(PlanetSideGUID(10), 5, 1200L))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.PlanetsideAttribute(5, 1200L)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarServiceBTest extends ActorTest {
|
||||
val msg = PlayerStateMessageUpstream(PlanetSideGUID(75), Vector3(3694.1094f, 2735.4531f, 90.84375f), Some(Vector3(4.375f, 2.59375f, 0.0f)), 61.875f, 351.5625f, 0.0f, 136, 0, false, false, false, false, 112, 0)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass PlayerState" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.PlayerState(PlanetSideGUID(10), msg, false, false))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.PlayerState(msg, false, false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarServiceCTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass Reload" in {
|
||||
val service = system.actorOf(Props[AvatarService], "service")
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.Reload(PlanetSideGUID(10), 35))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.Reload(35)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object AvatarServiceTest {
|
||||
//decoy
|
||||
}
|
||||
369
pslogin/src/main/test/scala/PacketCodingActorTest.scala
Normal file
369
pslogin/src/main/test/scala/PacketCodingActorTest.scala
Normal file
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue