mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-02-22 16:13:35 +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
|
|
@ -149,7 +149,8 @@ class ConverterTest extends Specification {
|
|||
val tool = Tool(tdef)
|
||||
tool.GUID = PlanetSideGUID(92)
|
||||
tool.AmmoSlot.Box.GUID = PlanetSideGUID(90)
|
||||
val obj = Player(PlanetSideGUID(93), "Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
val obj = Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.GUID = PlanetSideGUID(93)
|
||||
obj.Slot(2).Equipment = tool
|
||||
obj.Slot(5).Equipment.get.GUID = PlanetSideGUID(94)
|
||||
obj.Inventory += 8 -> AmmoBox(GlobalDefinitions.bullet_9mm)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,21 @@ import net.psforever.objects.GlobalDefinitions._
|
|||
import org.specs2.mutable._
|
||||
|
||||
class EquipmentTest extends Specification {
|
||||
"EquipmentSize" should {
|
||||
"equal" in {
|
||||
//basic equality
|
||||
EquipmentSize.isEqual(EquipmentSize.Pistol, EquipmentSize.Pistol) mustEqual true
|
||||
EquipmentSize.isEqual(EquipmentSize.Pistol, EquipmentSize.Rifle) mustEqual false
|
||||
//Inventory is always allowed
|
||||
EquipmentSize.isEqual(EquipmentSize.Inventory, EquipmentSize.Rifle) mustEqual true
|
||||
EquipmentSize.isEqual(EquipmentSize.Pistol, EquipmentSize.Inventory) mustEqual true
|
||||
//Blocked is never allowed
|
||||
EquipmentSize.isEqual(EquipmentSize.Blocked, EquipmentSize.Rifle) mustEqual false
|
||||
EquipmentSize.isEqual(EquipmentSize.Pistol, EquipmentSize.Blocked) mustEqual false
|
||||
EquipmentSize.isEqual(EquipmentSize.Blocked, EquipmentSize.Inventory) mustEqual false
|
||||
}
|
||||
}
|
||||
|
||||
"AmmoBox" should {
|
||||
"define" in {
|
||||
val obj = AmmoBoxDefinition(86)
|
||||
|
|
@ -59,13 +74,13 @@ class EquipmentTest extends Specification {
|
|||
obj.Size = EquipmentSize.Rifle
|
||||
obj.AmmoTypes += GlobalDefinitions.shotgun_shell
|
||||
obj.AmmoTypes += GlobalDefinitions.shotgun_shell_AP
|
||||
obj.FireModes += new FireModeDefinition
|
||||
obj.FireModes += FireModeDefinition()
|
||||
obj.FireModes.head.AmmoTypeIndices += 0
|
||||
obj.FireModes.head.AmmoTypeIndices += 1
|
||||
obj.FireModes.head.AmmoSlotIndex = 0
|
||||
obj.FireModes.head.Magazine = 18
|
||||
obj.FireModes.head.ResetAmmoIndexOnSwap = true
|
||||
obj.FireModes += new FireModeDefinition
|
||||
obj.FireModes += FireModeDefinition()
|
||||
obj.FireModes(1).AmmoTypeIndices += 0
|
||||
obj.FireModes(1).AmmoTypeIndices += 1
|
||||
obj.FireModes(1).AmmoSlotIndex = 1
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package objects
|
||||
|
||||
import net.psforever.objects.{Player, SimpleItem}
|
||||
import net.psforever.objects._
|
||||
import net.psforever.objects.definition.{ImplantDefinition, SimpleItemDefinition}
|
||||
import net.psforever.objects.equipment.EquipmentSize
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import net.psforever.types.{CharacterGender, ExoSuitType, ImplantType, PlanetSideEmpire}
|
||||
import org.specs2.mutable._
|
||||
|
||||
|
|
@ -13,17 +14,55 @@ class PlayerTest extends Specification {
|
|||
obj.isAlive mustEqual false
|
||||
}
|
||||
|
||||
"different players" in {
|
||||
(Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5) ==
|
||||
Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)) mustEqual true
|
||||
(Player("Chord1", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5) ==
|
||||
Player("Chord2", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)) mustEqual false
|
||||
(Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5) ==
|
||||
Player("Chord", PlanetSideEmpire.NC, CharacterGender.Male, 0, 5)) mustEqual false
|
||||
(Player("Chord1", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5) ==
|
||||
Player("Chord2", PlanetSideEmpire.TR, CharacterGender.Female, 0, 5)) mustEqual false
|
||||
(Player("Chord1", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5) ==
|
||||
Player("Chord2", PlanetSideEmpire.TR, CharacterGender.Male, 1, 5)) mustEqual false
|
||||
(Player("Chord1", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5) ==
|
||||
Player("Chord2", PlanetSideEmpire.TR, CharacterGender.Male, 0, 6)) mustEqual false
|
||||
}
|
||||
|
||||
"become a backpack" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.isAlive mustEqual false
|
||||
obj.isBackpack mustEqual false
|
||||
obj.Release
|
||||
obj.isAlive mustEqual false
|
||||
obj.isBackpack mustEqual true
|
||||
}
|
||||
|
||||
"(re)spawn" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.isAlive mustEqual false
|
||||
obj.Health mustEqual 0
|
||||
obj.Stamina mustEqual 0
|
||||
obj.Armor mustEqual 0
|
||||
obj.MaxHealth mustEqual 100
|
||||
obj.MaxStamina mustEqual 100
|
||||
obj.MaxArmor mustEqual 50
|
||||
obj.Spawn
|
||||
obj.isAlive mustEqual true
|
||||
obj.Health mustEqual obj.MaxHealth
|
||||
obj.Stamina mustEqual obj.MaxStamina
|
||||
obj.Armor mustEqual obj.MaxArmor
|
||||
obj.Health mustEqual 100
|
||||
obj.Stamina mustEqual 100
|
||||
obj.Armor mustEqual 50
|
||||
}
|
||||
|
||||
"set new maximum values (health, stamina)" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.MaxHealth mustEqual 100
|
||||
obj.MaxStamina mustEqual 100
|
||||
obj.MaxHealth = 123
|
||||
obj.MaxStamina = 456
|
||||
obj.Spawn
|
||||
obj.Health mustEqual 123
|
||||
obj.Stamina mustEqual 456
|
||||
}
|
||||
|
||||
"init (Standard Exo-Suit)" in {
|
||||
|
|
@ -106,6 +145,40 @@ class PlayerTest extends Specification {
|
|||
obj.LastDrawnSlot mustEqual 1
|
||||
}
|
||||
|
||||
"hold something in their free hand" in {
|
||||
val wep = SimpleItem(SimpleItemDefinition(149))
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.Slot(Player.FreeHandSlot).Equipment = wep
|
||||
|
||||
obj.Slot(Player.FreeHandSlot).Equipment.get.Definition.ObjectId mustEqual 149
|
||||
}
|
||||
|
||||
"provide an invalid hand that can not hold anything" in {
|
||||
val wep = SimpleItem(SimpleItemDefinition(149))
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.Slot(-1).Equipment = wep
|
||||
|
||||
obj.Slot(-1).Equipment mustEqual None
|
||||
}
|
||||
|
||||
"search for the smallest available slot in which to satore equipment" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.Inventory.Resize(3,3)
|
||||
|
||||
obj.Fit(Tool(GlobalDefinitions.beamer)) mustEqual Some(0)
|
||||
|
||||
obj.Fit(Tool(GlobalDefinitions.suppressor)) mustEqual Some(2)
|
||||
|
||||
val ammo = AmmoBox(GlobalDefinitions.bullet_9mm)
|
||||
val ammo2 = AmmoBox(GlobalDefinitions.bullet_9mm)
|
||||
val ammo3 = AmmoBox(GlobalDefinitions.bullet_9mm)
|
||||
obj.Fit(ammo) mustEqual Some(6)
|
||||
obj.Slot(6).Equipment = ammo
|
||||
obj.Fit(ammo2) mustEqual Some(Player.FreeHandSlot)
|
||||
obj.Slot(Player.FreeHandSlot).Equipment = ammo2
|
||||
obj.Fit(ammo2) mustEqual None
|
||||
}
|
||||
|
||||
"install an implant" in {
|
||||
val testplant : ImplantDefinition = ImplantDefinition(1)
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
|
|
@ -141,6 +214,31 @@ class PlayerTest extends Specification {
|
|||
obj.Implants(0).Installed mustEqual None
|
||||
}
|
||||
|
||||
"seat in a vehicle" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.VehicleSeated mustEqual None
|
||||
obj.VehicleSeated = PlanetSideGUID(65)
|
||||
obj.VehicleSeated mustEqual Some(PlanetSideGUID(65))
|
||||
obj.VehicleSeated = None
|
||||
obj.VehicleSeated mustEqual None
|
||||
}
|
||||
|
||||
"own in a vehicle" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.VehicleOwned mustEqual None
|
||||
obj.VehicleOwned = PlanetSideGUID(65)
|
||||
obj.VehicleOwned mustEqual Some(PlanetSideGUID(65))
|
||||
obj.VehicleOwned = None
|
||||
obj.VehicleOwned mustEqual None
|
||||
}
|
||||
|
||||
"remember what zone he is in" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.Continent mustEqual "home2"
|
||||
obj.Continent = "ugd01"
|
||||
obj.Continent mustEqual "ugd01"
|
||||
}
|
||||
|
||||
"administrate" in {
|
||||
val obj = new Player("Chord", PlanetSideEmpire.TR, CharacterGender.Male, 0, 5)
|
||||
obj.Admin mustEqual false
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class VehicleSpawnControl2Test extends ActorTest() {
|
|||
assert(reply2.asInstanceOf[VehicleSpawnPad.LoadVehicle].vehicle == vehicle)
|
||||
assert(reply2.asInstanceOf[VehicleSpawnPad.LoadVehicle].pad == obj)
|
||||
|
||||
player.VehicleOwned = vehicle
|
||||
player.VehicleOwned = Some(vehicle.GUID)
|
||||
val reply3 = receiveOne(Duration.create(10000, "ms"))
|
||||
assert(reply3.isInstanceOf[VehicleSpawnPad.PlayerSeatedInVehicle])
|
||||
assert(reply3.asInstanceOf[VehicleSpawnPad.PlayerSeatedInVehicle].vehicle == vehicle)
|
||||
|
|
|
|||
|
|
@ -281,5 +281,43 @@ class NumberPoolHubTest extends Specification {
|
|||
val hub = new NumberPoolHub(src)
|
||||
hub.unregister(4).isFailure mustEqual true
|
||||
}
|
||||
|
||||
"identity an object that is registered to it" in {
|
||||
val hub1 = new NumberPoolHub(new LimitedNumberSource(10))
|
||||
val hub2 = new NumberPoolHub(new LimitedNumberSource(10))
|
||||
val obj1 = new EntityTestClass()
|
||||
val obj2 = new EntityTestClass()
|
||||
hub1.register(obj1)
|
||||
hub2.register(obj2)
|
||||
|
||||
hub1.isRegistered(obj1) mustEqual true
|
||||
hub2.isRegistered(obj2) mustEqual true
|
||||
hub1.isRegistered(obj2) mustEqual false
|
||||
hub2.isRegistered(obj1) mustEqual false
|
||||
}
|
||||
|
||||
"identity a number that is registered to it" in {
|
||||
val src1 = new LimitedNumberSource(5)
|
||||
val hub1 = new NumberPoolHub(src1)
|
||||
val src2 = new LimitedNumberSource(10)
|
||||
src2.Restrict(0)
|
||||
src2.Restrict(1)
|
||||
src2.Restrict(2)
|
||||
src2.Restrict(3)
|
||||
src2.Restrict(4)
|
||||
src2.Restrict(5)
|
||||
val hub2 = new NumberPoolHub(src2)
|
||||
val obj1 = new EntityTestClass()
|
||||
val obj2 = new EntityTestClass()
|
||||
hub1.register(obj1)
|
||||
hub2.register(obj2)
|
||||
val num1 = obj1.GUID.guid
|
||||
val num2 = obj2.GUID.guid
|
||||
|
||||
hub1.isRegistered(num1) mustEqual true
|
||||
hub2.isRegistered(num2) mustEqual true
|
||||
hub1.isRegistered(num2) mustEqual false
|
||||
hub2.isRegistered(num1) mustEqual false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,14 @@ class NumberPoolTest extends Specification {
|
|||
ok
|
||||
}
|
||||
|
||||
"fail to construct 1 (number less than zero)" in {
|
||||
new SimplePool(-1 :: Nil) must throwA[IllegalArgumentException]
|
||||
}
|
||||
|
||||
"fail to construct 2 (duplicate numbers)" in {
|
||||
new SimplePool(1 :: 1 :: Nil) must throwA[IllegalArgumentException]
|
||||
}
|
||||
|
||||
"get a number" in {
|
||||
val obj = new SimplePool((0 to 10).toList)
|
||||
obj.Get() match {
|
||||
|
|
@ -26,6 +34,13 @@ class NumberPoolTest extends Specification {
|
|||
}
|
||||
}
|
||||
|
||||
"used number count is always zero" in {
|
||||
val obj = new SimplePool((0 to 10).toList)
|
||||
obj.Count mustEqual 0
|
||||
obj.Get()
|
||||
obj.Count mustEqual 0
|
||||
}
|
||||
|
||||
"return a number" in {
|
||||
//returning a number for a SimplePool is actually just a way of checking that the number is in the "pool" at all
|
||||
val obj = new SimplePool((0 to 10).toList)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package objects.number
|
|||
|
||||
import net.psforever.objects.guid.AvailabilityPolicy
|
||||
import net.psforever.objects.guid.key.{LoanedKey, SecureKey}
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
class NumberSourceTest extends Specification {
|
||||
|
|
@ -102,6 +103,17 @@ class NumberSourceTest extends Specification {
|
|||
result2.get.Object mustEqual Some(test)
|
||||
}
|
||||
|
||||
"return a secure key" in {
|
||||
val obj = LimitedNumberSource(25)
|
||||
val test = new TestClass()
|
||||
val result1 : Option[LoanedKey] = obj.Available(5)
|
||||
result1.get.Object = test
|
||||
test.GUID = PlanetSideGUID(5)
|
||||
val result2 : Option[SecureKey] = obj.Get(5)
|
||||
|
||||
obj.Return(result2.get) mustEqual Some(test)
|
||||
}
|
||||
|
||||
"restrict a previously-assigned number" in {
|
||||
val obj = LimitedNumberSource(25)
|
||||
val test = new TestClass()
|
||||
|
|
|
|||
60
common/src/test/scala/objects/number/RegisterTest.scala
Normal file
60
common/src/test/scala/objects/number/RegisterTest.scala
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package objects.number
|
||||
|
||||
import akka.actor.Actor
|
||||
import net.psforever.objects.guid.actor.Register
|
||||
import org.specs2.mutable.Specification
|
||||
|
||||
class RegisterTest extends Specification {
|
||||
val obj = new net.psforever.objects.entity.IdentifiableEntity() {}
|
||||
|
||||
"Register" should {
|
||||
"construct (object)" in {
|
||||
val reg = Register(obj)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual None
|
||||
}
|
||||
|
||||
"construct (object, callback)" in {
|
||||
val reg = Register(obj, Actor.noSender)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual Some(Actor.noSender)
|
||||
}
|
||||
|
||||
"construct (object, suggested number)" in {
|
||||
val reg = Register(obj, 5)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual Some(5)
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual None
|
||||
}
|
||||
|
||||
"construct (object, suggested number, callback)" in {
|
||||
val reg = Register(obj, 5, Actor.noSender)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual Some(5)
|
||||
reg.name mustEqual None
|
||||
reg.callback mustEqual Some(Actor.noSender)
|
||||
}
|
||||
|
||||
"construct (object, pool name)" in {
|
||||
val reg = Register(obj, "pool")
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual Some("pool")
|
||||
reg.callback mustEqual None
|
||||
}
|
||||
|
||||
"construct (object, pool name, callback)" in {
|
||||
val reg = Register(obj, "pool", Actor.noSender)
|
||||
reg.obj mustEqual obj
|
||||
reg.number mustEqual None
|
||||
reg.name mustEqual Some("pool")
|
||||
reg.callback mustEqual Some(Actor.noSender)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ import objects.ActorTest
|
|||
|
||||
import scala.concurrent.duration.Duration
|
||||
|
||||
class TerminalControlTest extends ActorTest() {
|
||||
class TerminalControl1Test extends ActorTest() {
|
||||
"TerminalControl" should {
|
||||
"construct (cert terminal)" in {
|
||||
val terminal = Terminal(GlobalDefinitions.cert_terminal)
|
||||
|
|
@ -19,6 +19,17 @@ class TerminalControlTest extends ActorTest() {
|
|||
}
|
||||
}
|
||||
|
||||
class TerminalControl2Test extends ActorTest() {
|
||||
"TerminalControl can not process wrong messages" in {
|
||||
val terminal = Terminal(GlobalDefinitions.cert_terminal)
|
||||
terminal.Actor = system.actorOf(Props(classOf[TerminalControl], terminal), "test-cert-term")
|
||||
|
||||
terminal.Actor !"hello"
|
||||
val reply = receiveOne(Duration.create(500, "ms"))
|
||||
assert(reply.isInstanceOf[Terminal.NoDeal])
|
||||
}
|
||||
}
|
||||
|
||||
//terminal control is mostly a pass-through actor for Terminal.Exchange messages, wrapped in Terminal.TerminalMessage protocol
|
||||
//test for Cert_Terminal messages (see CertTerminalTest)
|
||||
class CertTerminalControl1Test extends ActorTest() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue