Annotation of embedaddon/php/ext/spl/tests/heap_corruption.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: SPL: SplHeap - heap corruption via compare exception (with top element deletion)
! 3: --CREDITS--
! 4: Mike Sullivan <mikesul@php.net>
! 5: #TestFest 2009 (London)
! 6: --FILE--
! 7: <?php
! 8:
! 9: class myHeap extends SplHeap
! 10: {
! 11: public $allow_compare = true;
! 12:
! 13: public function compare($v1, $v2)
! 14: {
! 15: if ($this->allow_compare == true)
! 16: {
! 17: if ($v1 > $v2)
! 18: {
! 19: return 1;
! 20: }
! 21: else if ($v1 < $v2)
! 22: {
! 23: return -1;
! 24: }
! 25: else
! 26: {
! 27: return 0;
! 28: }
! 29: }
! 30: else
! 31: {
! 32: throw new Exception('Compare exception');
! 33: }
! 34: }
! 35: }
! 36:
! 37: $heap = new myHeap();
! 38: $heap->insert(1);
! 39: $heap->insert(2);
! 40: $heap->insert(3);
! 41: $heap->insert(4);
! 42:
! 43: $heap->allow_compare = false;
! 44:
! 45: try {
! 46: $heap->extract();
! 47: }
! 48: catch (Exception $e) {
! 49: echo "Compare Exception: " . $e->getMessage() . PHP_EOL;
! 50: }
! 51:
! 52: try {
! 53: $heap->top();
! 54: }
! 55: catch (Exception $e) {
! 56: echo "Corruption Exception: " . $e->getMessage() . PHP_EOL;
! 57: }
! 58:
! 59: ?>
! 60: --EXPECT--
! 61: Compare Exception: Compare exception
! 62: Corruption Exception: Heap is corrupted, heap properties are no longer ensured.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>