mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 05:15:13 +00:00
these tests are now done by pocketmine/bedrock-protocol
This commit is contained in:
parent
a2e2196a90
commit
53d7ed2b5c
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* ____ _ _ __ __ _ __ __ ____
|
|
||||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
||||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
||||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
||||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* @author PocketMine Team
|
|
||||||
* @link http://www.pocketmine.net/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace pocketmine\network\mcpe\protocol;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
|
|
||||||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
|
|
||||||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext;
|
|
||||||
|
|
||||||
class DataPacketTest extends TestCase{
|
|
||||||
|
|
||||||
public function testHeaderFidelity() : void{
|
|
||||||
$pk = new TestPacket();
|
|
||||||
$pk->senderSubId = 3;
|
|
||||||
$pk->recipientSubId = 2;
|
|
||||||
|
|
||||||
$context = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
|
|
||||||
$serializer = PacketSerializer::encoder($context);
|
|
||||||
$pk->encode($serializer);
|
|
||||||
|
|
||||||
$pk2 = new TestPacket();
|
|
||||||
$pk2->decode(PacketSerializer::decoder($serializer->getBuffer(), 0, $context));
|
|
||||||
self::assertSame($pk2->senderSubId, 3);
|
|
||||||
self::assertSame($pk2->recipientSubId, 2);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* ____ _ _ __ __ _ __ __ ____
|
|
||||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
||||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
||||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
||||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* @author PocketMine Team
|
|
||||||
* @link http://www.pocketmine.net/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace pocketmine\network\mcpe\protocol;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
|
|
||||||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
|
|
||||||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext;
|
|
||||||
use function strlen;
|
|
||||||
|
|
||||||
class LoginPacketTest extends TestCase{
|
|
||||||
|
|
||||||
public function testInvalidChainDataJsonHandling() : void{
|
|
||||||
$context = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
|
|
||||||
$stream = PacketSerializer::encoder($context);
|
|
||||||
$stream->putUnsignedVarInt(ProtocolInfo::LOGIN_PACKET);
|
|
||||||
$payload = '{"chain":[]'; //intentionally malformed
|
|
||||||
$stream->putInt(ProtocolInfo::CURRENT_PROTOCOL);
|
|
||||||
|
|
||||||
$stream2 = PacketSerializer::encoder($context);
|
|
||||||
$stream2->putLInt(strlen($payload));
|
|
||||||
$stream2->put($payload);
|
|
||||||
$stream->putString($stream2->getBuffer());
|
|
||||||
|
|
||||||
$pk = PacketPool::getInstance()->getPacket($stream->getBuffer());
|
|
||||||
|
|
||||||
$this->expectException(PacketDecodeException::class);
|
|
||||||
$pk->decode(PacketSerializer::decoder($stream->getBuffer(), 0, $context)); //bang
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* ____ _ _ __ __ _ __ __ ____
|
|
||||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
||||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
||||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
||||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* @author PocketMine Team
|
|
||||||
* @link http://www.pocketmine.net/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace pocketmine\network\mcpe\protocol;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
final class ProtocolInfoTest extends TestCase{
|
|
||||||
|
|
||||||
public function testMinecraftVersionNetwork() : void{
|
|
||||||
self::assertMatchesRegularExpression(
|
|
||||||
'/^(?:\d+\.)?(?:\d+\.)?(?:\d+\.)?\d+$/',
|
|
||||||
ProtocolInfo::MINECRAFT_VERSION_NETWORK,
|
|
||||||
"Network version should only contain 0-9 and \".\", and no more than 4 groups of digits"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* ____ _ _ __ __ _ __ __ ____
|
|
||||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
||||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
||||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
||||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* @author PocketMine Team
|
|
||||||
* @link http://www.pocketmine.net/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace pocketmine\network\mcpe\protocol;
|
|
||||||
|
|
||||||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
|
|
||||||
|
|
||||||
class TestPacket extends DataPacket{
|
|
||||||
public const NETWORK_ID = 1023;
|
|
||||||
|
|
||||||
protected function decodePayload(PacketSerializer $in) : void{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function encodePayload(PacketSerializer $out) : void{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function handle(PacketHandlerInterface $handler) : bool{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* ____ _ _ __ __ _ __ __ ____
|
|
||||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
||||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
||||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
||||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* @author PocketMine Team
|
|
||||||
* @link http://www.pocketmine.net/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace pocketmine\mcpe\protocol\serializer;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use pocketmine\network\mcpe\convert\GlobalItemTypeDictionary;
|
|
||||||
use pocketmine\network\mcpe\protocol\PacketDecodeException;
|
|
||||||
use pocketmine\network\mcpe\protocol\PacketPool;
|
|
||||||
use pocketmine\network\mcpe\protocol\serializer\PacketBatch;
|
|
||||||
use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext;
|
|
||||||
use pocketmine\network\mcpe\protocol\TestPacket;
|
|
||||||
use function array_fill;
|
|
||||||
|
|
||||||
class PacketBatchTest extends TestCase{
|
|
||||||
|
|
||||||
public function testDecodeTooBig() : void{
|
|
||||||
$limit = 10;
|
|
||||||
$decoderContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
|
|
||||||
$write = PacketBatch::fromPackets($decoderContext, ...array_fill(0, $limit + 1, new TestPacket()));
|
|
||||||
$read = new PacketBatch($write->getBuffer());
|
|
||||||
$this->expectException(PacketDecodeException::class);
|
|
||||||
$readCount = 0;
|
|
||||||
foreach($read->getPackets(PacketPool::getInstance(), $decoderContext, $limit) as $packet){
|
|
||||||
$readCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDecodeAtLimit() : void{
|
|
||||||
$limit = 10;
|
|
||||||
$decoderContext = new PacketSerializerContext(GlobalItemTypeDictionary::getInstance()->getDictionary());
|
|
||||||
$write = PacketBatch::fromPackets($decoderContext, ...array_fill(0, $limit, new TestPacket()));
|
|
||||||
$read = new PacketBatch($write->getBuffer());
|
|
||||||
$readCount = 0;
|
|
||||||
foreach($read->getPackets(PacketPool::getInstance(), $decoderContext, $limit) as $packet){
|
|
||||||
$readCount++;
|
|
||||||
}
|
|
||||||
self::assertSame($limit, $readCount);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user