Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/bedrock-1.21.50'
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Dec 3, 2024
2 parents cdf2c05 + 001b83e commit 714f947
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/serializer/BitSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function write(PacketSerializer $out, int $length = null) : void{
$nextShift = $currentShift + self::SHIFT;
if($nextShift >= self::INT_BITS){
$nextShift -= self::INT_BITS;
$bits |= ($parts[++$currentIndex] ?? 0) << (self::SHIFT - $nextShift);
$bits |= $parts[++$currentIndex] << (self::SHIFT - $nextShift);
}
$currentShift = $nextShift;

Expand Down
9 changes: 0 additions & 9 deletions tests/phpstan/configs/phpstan-bugs.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,3 @@ parameters:
message: "#^Parameter \\#3 \\$packets of static method pocketmine\\\\network\\\\mcpe\\\\protocol\\\\serializer\\\\PacketBatch\\:\\:encodePackets\\(\\) expects array\\<int, pocketmine\\\\network\\\\mcpe\\\\protocol\\\\Packet\\>, array\\<int\\|string, pocketmine\\\\network\\\\mcpe\\\\protocol\\\\Packet\\> given\\.$#"
count: 1
path: ../../../src/serializer/PacketBatch.php
-
message: "#^Parameter \\#2 \\$parts of class pocketmine\\\\network\\\\mcpe\\\\protocol\\\\serializer\\\\BitSet constructor expects array\\<int\\>, array\\<int, float\\> given\\.$#"
count: 1
path: tests/phpunit/BitSetTest.php

-
message: "#^Parameter \\#2 \\$parts of class pocketmine\\\\network\\\\mcpe\\\\protocol\\\\serializer\\\\BitSet constructor expects array\\<int\\>, array\\<int, float\\|int\\> given\\.$#"
count: 1
path: tests/phpunit/BitSetTest.php
27 changes: 9 additions & 18 deletions tests/phpunit/BitSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use PHPUnit\Framework\TestCase;
use pocketmine\network\mcpe\protocol\serializer\BitSet;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use function PHPUnit\Framework\assertTrue;
use function var_dump;

class BitSetTest extends TestCase{

Expand All @@ -34,12 +32,12 @@ public function testBitSet() : void{
$packetSerializer = PacketSerializer::decoder(ProtocolInfo::CURRENT_PROTOCOL, $packetSerializer->getBuffer(), 0);
$readTest = BitSet::read($packetSerializer, 65);

assertTrue($this->setsEqual($writeTest, $readTest));
self::assertEqualBitSets($writeTest, $readTest);
}

public function testBitSetConstructor() : void{
$test = new BitSet(65, [-9223372036854775808, 1]);
$test2 = new BitSet(65, [-9223372036854775808]);
$test = new BitSet(65, [-9223372036854775807 - 1, 1]);
$test2 = new BitSet(65, [-9223372036854775807 - 1]);

$test2->set(64, true);

Expand All @@ -62,7 +60,7 @@ public function testBitSetParts() : void{
$packetSerializer = PacketSerializer::decoder(ProtocolInfo::CURRENT_PROTOCOL, $packetSerializer->getBuffer(), 0);
$readTest = BitSet::read($packetSerializer, 128);

assertTrue($this->setsEqual($writeTest, $readTest));
self::assertEqualBitSets($writeTest, $readTest);
}

public function testVarUnsignedLongCompatibility() : void{
Expand All @@ -75,23 +73,16 @@ public function testVarUnsignedLongCompatibility() : void{
$expectedResult = new BitSet(64);
$expectedResult->set(63, true);

assertTrue($this->setsEqual($expectedResult, $readTest));
self::assertEqualBitSets($expectedResult, $readTest);
}

private function setsEqual(BitSet $a, BitSet $b) : bool{
$length = $a->getLength();
if($length !== $b->getLength()){
var_dump($length, $b->getLength());
return false;
}
private static function assertEqualBitSets(BitSet $a, BitSet $b) : void{
self::assertEquals($length = $a->getLength(), $b->getLength(), "BitSet lengths are not equal");

for($i = 0; $i < $length; ++$i){
if($a->get($i) !== $b->get($i)){
var_dump($i, $a->get($i), $b->get($i));
return false;
}
self::assertEquals($a->get($i), $b->get($i), "BitSet values at index $i are not equal");
}

return $a->getPartsCount() === $b->getPartsCount();
self::assertEquals($a->getPartsCount(), $b->getPartsCount(), "BitSet parts count is not equal");
}
}

0 comments on commit 714f947

Please sign in to comment.