Skip to content

Commit 8e83c8d

Browse files
committed
Forgot to stage tests for a26bed6
1 parent 7740238 commit 8e83c8d

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Test that working with palettes as strings works as expected
3+
--FILE--
4+
<?php
5+
6+
use pocketmine\world\format\PalettedBlockArray;
7+
8+
$array = new PalettedBlockArray(0);
9+
for($x = 0; $x < 16; $x++){
10+
for($y = 0; $y < 16; $y++){
11+
for($z = 0; $z < 16; $z++){
12+
$array->set($x, $y, $z, ($x << 8) | ($y << 4) | $z);
13+
}
14+
}
15+
}
16+
$expected = "";
17+
for($i = 0; $i < 4096; $i++){
18+
$expected .= pack("V", $i);
19+
}
20+
var_dump($expected === $array->getPaletteBytes());
21+
?>
22+
--EXPECT--
23+
bool(true)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
Test that PalettedBlockArray::fromData() works as expected with bytes
3+
--FILE--
4+
<?php
5+
6+
use pocketmine\world\format\PalettedBlockArray;
7+
use pocketmine\world\format\PalettedBlockArrayLoadException;
8+
9+
$array = new PalettedBlockArray(0);
10+
for($x = 0; $x < 16; $x++){
11+
for($y = 0; $y < 16; $y++){
12+
for($z = 0; $z < 16; $z++){
13+
$array->set($x, $y, $z, ($x << 8) | ($y << 4) | $z);
14+
}
15+
}
16+
}
17+
18+
$array2 = PalettedBlockArray::fromData($array->getBitsPerBlock(), $array->getWordArray(), $array->getPaletteBytes());
19+
$matched = 0;
20+
for($x = 0; $x < 16; $x++){
21+
for($y = 0; $y < 16; $y++){
22+
for($z = 0; $z < 16; $z++){
23+
$expect = ($x << 8) | ($y << 4) | $z;
24+
if($array2->get($x, $y, $z) === $expect){
25+
$matched++;
26+
}else{
27+
echo "Mismatch at $x, $y, $z: actual " . $array->get($x, $y, $z) . ", expected " . $expect . "\n";
28+
}
29+
}
30+
}
31+
}
32+
var_dump($matched);
33+
34+
try{
35+
PalettedBlockArray::fromData($array->getBitsPerBlock(), $array->getWordArray(), $array->getPaletteBytes() . "\n");
36+
echo "This is not supposed to work\n";
37+
}catch(PalettedBlockArrayLoadException $e){
38+
echo $e->getMessage() . "\n";
39+
}
40+
try{
41+
PalettedBlockArray::fromData($array->getBitsPerBlock(), $array->getWordArray(), substr($array->getPaletteBytes(), 0, -1));
42+
echo "This is not supposed to work\n";
43+
}catch(PalettedBlockArrayLoadException $e){
44+
echo $e->getMessage() . "\n";
45+
}
46+
try{
47+
PalettedBlockArray::fromData($array->getBitsPerBlock(), $array->getWordArray(), "");
48+
echo "This is not supposed to work\n";
49+
}catch(PalettedBlockArrayLoadException $e){
50+
//TODO: this exception type is confusing, but it comes from a different place than the bytes-handling, so it's currently expected
51+
echo $e->getMessage() . "\n";
52+
}
53+
?>
54+
--EXPECT--
55+
int(4096)
56+
palette length in bytes must be a multiple of 4, but have 16385 bytes
57+
palette length in bytes must be a multiple of 4, but have 16383 bytes
58+
palette cannot have a zero size

0 commit comments

Comments
 (0)