1*890232f2SAndroid Build Coastguard Worker<?php 2*890232f2SAndroid Build Coastguard Worker 3*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__)), "php", "Constants.php")); 4*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__)), "php", "ByteBuffer.php")); 5*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__)), "php", "FlatbufferBuilder.php")); 6*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__)), "php", "Table.php")); 7*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__)), "php", "Struct.php")); 8*890232f2SAndroid Build Coastguard Worker 9*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), "php", 'Attacker.php')); 10*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), "php", 'BookReader.php')); 11*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), "php", 'Character.php')); 12*890232f2SAndroid Build Coastguard Workerrequire join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), "php", 'Movie.php')); 13*890232f2SAndroid Build Coastguard Worker 14*890232f2SAndroid Build Coastguard Workerclass Assert { 15*890232f2SAndroid Build Coastguard Worker public function ok($result, $message = "") { 16*890232f2SAndroid Build Coastguard Worker if (!$result){ 17*890232f2SAndroid Build Coastguard Worker throw new Exception(!empty($message) ? $message : "{$result} is not true."); 18*890232f2SAndroid Build Coastguard Worker } 19*890232f2SAndroid Build Coastguard Worker } 20*890232f2SAndroid Build Coastguard Worker 21*890232f2SAndroid Build Coastguard Worker public function Equal($result, $expected, $message = "") { 22*890232f2SAndroid Build Coastguard Worker if ($result != $expected) { 23*890232f2SAndroid Build Coastguard Worker throw new Exception(!empty($message) ? $message : "given the result {$result} is not equals as {$expected}"); 24*890232f2SAndroid Build Coastguard Worker } 25*890232f2SAndroid Build Coastguard Worker } 26*890232f2SAndroid Build Coastguard Worker 27*890232f2SAndroid Build Coastguard Worker 28*890232f2SAndroid Build Coastguard Worker public function strictEqual($result, $expected, $message = "") { 29*890232f2SAndroid Build Coastguard Worker if ($result !== $expected) { 30*890232f2SAndroid Build Coastguard Worker throw new Exception(!empty($message) ? $message : "given the result {$result} is not strict equals as {$expected}"); 31*890232f2SAndroid Build Coastguard Worker } 32*890232f2SAndroid Build Coastguard Worker } 33*890232f2SAndroid Build Coastguard Worker 34*890232f2SAndroid Build Coastguard Worker public function Throws($class, Callable $callback) { 35*890232f2SAndroid Build Coastguard Worker try { 36*890232f2SAndroid Build Coastguard Worker $callback(); 37*890232f2SAndroid Build Coastguard Worker 38*890232f2SAndroid Build Coastguard Worker throw new \Exception("passed statement don't throw an exception."); 39*890232f2SAndroid Build Coastguard Worker } catch (\Exception $e) { 40*890232f2SAndroid Build Coastguard Worker if (get_class($e) != get_class($class)) { 41*890232f2SAndroid Build Coastguard Worker throw new Exception("passed statement doesn't throw " . get_class($class) . ". throwws " . get_class($e)); 42*890232f2SAndroid Build Coastguard Worker } 43*890232f2SAndroid Build Coastguard Worker } 44*890232f2SAndroid Build Coastguard Worker } 45*890232f2SAndroid Build Coastguard Worker} 46*890232f2SAndroid Build Coastguard Worker 47*890232f2SAndroid Build Coastguard Workerfunction main() 48*890232f2SAndroid Build Coastguard Worker{ 49*890232f2SAndroid Build Coastguard Worker $assert = new Assert(); 50*890232f2SAndroid Build Coastguard Worker 51*890232f2SAndroid Build Coastguard Worker $fbb = new Google\FlatBuffers\FlatBufferBuilder(1); 52*890232f2SAndroid Build Coastguard Worker 53*890232f2SAndroid Build Coastguard Worker $charTypes = [ 54*890232f2SAndroid Build Coastguard Worker Character::Belle, 55*890232f2SAndroid Build Coastguard Worker Character::MuLan, 56*890232f2SAndroid Build Coastguard Worker Character::BookFan, 57*890232f2SAndroid Build Coastguard Worker ]; 58*890232f2SAndroid Build Coastguard Worker 59*890232f2SAndroid Build Coastguard Worker Attacker::startAttacker($fbb); 60*890232f2SAndroid Build Coastguard Worker Attacker::addSwordAttackDamage($fbb, 5); 61*890232f2SAndroid Build Coastguard Worker $attackerOffset = Attacker::endAttacker($fbb); 62*890232f2SAndroid Build Coastguard Worker 63*890232f2SAndroid Build Coastguard Worker $charTypesOffset = Movie::createCharactersTypeVector($fbb, $charTypes); 64*890232f2SAndroid Build Coastguard Worker $charsOffset = Movie::createCharactersVector( 65*890232f2SAndroid Build Coastguard Worker $fbb, 66*890232f2SAndroid Build Coastguard Worker [ 67*890232f2SAndroid Build Coastguard Worker BookReader::createBookReader($fbb, 7), 68*890232f2SAndroid Build Coastguard Worker $attackerOffset, 69*890232f2SAndroid Build Coastguard Worker BookReader::createBookReader($fbb, 2), 70*890232f2SAndroid Build Coastguard Worker ] 71*890232f2SAndroid Build Coastguard Worker ); 72*890232f2SAndroid Build Coastguard Worker 73*890232f2SAndroid Build Coastguard Worker Movie::startMovie($fbb); 74*890232f2SAndroid Build Coastguard Worker Movie::addCharactersType($fbb, $charTypesOffset); 75*890232f2SAndroid Build Coastguard Worker Movie::addCharacters($fbb, $charsOffset); 76*890232f2SAndroid Build Coastguard Worker Movie::finishMovieBuffer($fbb, Movie::endMovie($fbb)); 77*890232f2SAndroid Build Coastguard Worker 78*890232f2SAndroid Build Coastguard Worker $buf = Google\FlatBuffers\ByteBuffer::wrap($fbb->dataBuffer()->data()); 79*890232f2SAndroid Build Coastguard Worker 80*890232f2SAndroid Build Coastguard Worker $movie = Movie::getRootAsMovie($buf); 81*890232f2SAndroid Build Coastguard Worker 82*890232f2SAndroid Build Coastguard Worker $assert->strictEqual($movie->getCharactersTypeLength(), count($charTypes)); 83*890232f2SAndroid Build Coastguard Worker $assert->strictEqual($movie->getCharactersLength(), $movie->getCharactersTypeLength()); 84*890232f2SAndroid Build Coastguard Worker 85*890232f2SAndroid Build Coastguard Worker for ($i = 0; $i < count($charTypes); ++$i) { 86*890232f2SAndroid Build Coastguard Worker $assert->strictEqual($movie->getCharactersType($i), $charTypes[$i]); 87*890232f2SAndroid Build Coastguard Worker } 88*890232f2SAndroid Build Coastguard Worker 89*890232f2SAndroid Build Coastguard Worker $bookReader7 = $movie->getCharacters(0, new BookReader()); 90*890232f2SAndroid Build Coastguard Worker $assert->strictEqual($bookReader7->getBooksRead(), 7); 91*890232f2SAndroid Build Coastguard Worker 92*890232f2SAndroid Build Coastguard Worker $attacker = $movie->getCharacters(1, new Attacker()); 93*890232f2SAndroid Build Coastguard Worker $assert->strictEqual($attacker->getSwordAttackDamage(), 5); 94*890232f2SAndroid Build Coastguard Worker 95*890232f2SAndroid Build Coastguard Worker $bookReader2 = $movie->getCharacters(2, new BookReader()); 96*890232f2SAndroid Build Coastguard Worker $assert->strictEqual($bookReader2->getBooksRead(), 2); 97*890232f2SAndroid Build Coastguard Worker} 98*890232f2SAndroid Build Coastguard Worker 99*890232f2SAndroid Build Coastguard Workertry { 100*890232f2SAndroid Build Coastguard Worker main(); 101*890232f2SAndroid Build Coastguard Worker exit(0); 102*890232f2SAndroid Build Coastguard Worker} catch(Exception $e) { 103*890232f2SAndroid Build Coastguard Worker printf("Fatal error: Uncaught exception '%s' with message '%s. in %s:%d\n", get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()); 104*890232f2SAndroid Build Coastguard Worker printf("Stack trace:\n"); 105*890232f2SAndroid Build Coastguard Worker echo $e->getTraceAsString() . PHP_EOL; 106*890232f2SAndroid Build Coastguard Worker printf(" thrown in in %s:%d\n", $e->getFile(), $e->getLine()); 107*890232f2SAndroid Build Coastguard Worker 108*890232f2SAndroid Build Coastguard Worker die(-1); 109*890232f2SAndroid Build Coastguard Worker} 110