|
| 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