コード例 #1
0
        public void TestSerializePositionInfo()
        {
            GameManager.Instance.CreateGame(new Player(), "test game");
            BaseUnit unit = new BaseUnit();

            unit.UnitClass = new UnitClass("Ship", GameConstants.UnitType.SurfaceShip);
            unit.UnitClass.TurnRangeDegrSec      = 10;
            unit.UnitClass.MaxAccelerationKphSec = 10;
            unit.UnitClass.MaxSpeedKph           = 40;
            unit.Position = new Position(60.0, 1.0, 0, 2);
            unit.Name     = "USS Neverdock";
            Position dest = new Position(61.0, 2.0);

            unit.MovementOrder.AddWaypoint(new Waypoint(dest));
            CommsMarshaller marshaller = new CommsMarshaller();
            PositionInfo    pos        = unit.GetPositionInfo();

            byte[] bytes1 = marshaller.SerializeObjectForSending(pos);
            marshaller.AddToReceiveBufferEnd(bytes1, bytes1.Length);
            IMarshallable obj1 = marshaller.DeSerializeNextObjectInReceiveBuffer();

            Assert.IsNotNull(obj1, "Should be 1 object in buffer.");
            PositionInfo posinfo = (PositionInfo)obj1;

            Assert.AreEqual(unit.Id, posinfo.UnitId, "Id should be the same");
            GameManager.Instance.TerminateGame();
        }
コード例 #2
0
        public void TestSerializingDeserializing()
        {
            CommsMarshaller marshaller = new CommsMarshaller();
            MessageString   str        = new MessageString();

            str.Message = "Hello!";
            byte[] bytes = marshaller.SerializeObjectForSending(str);
            marshaller.AddToReceiveBufferEnd(bytes, bytes.Length);
            IMarshallable obj = marshaller.DeSerializeNextObjectInReceiveBuffer();

            Assert.IsNotNull(obj, "Object from send buffer should not be null.");
        }