From 29597ff1b6fc6e213510c6c8ac14727f7a4ea82d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 21 Oct 2015 23:54:51 +0300 Subject: [PATCH] Add some GetInfo tests --- .travis.yml | 3 +- Tests/.phpunit.xml | 4 ++- Tests/Info/csgo.json | 21 ++++++++++++++ Tests/Info/csgo.raw | 1 + Tests/Info/gmod_cyrillic.json | 21 ++++++++++++++ Tests/Info/gmod_cyrillic.raw | 1 + Tests/Info/tf2.json | 23 +++++++++++++++ Tests/Info/tf2.raw | 1 + Tests/Info/theship.json | 19 ++++++++++++ Tests/Info/theship.raw | 1 + Tests/Tests.php | 54 +++++++++++++++++++++++++++++++---- composer.json | 2 +- 12 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 Tests/Info/csgo.json create mode 100644 Tests/Info/csgo.raw create mode 100644 Tests/Info/gmod_cyrillic.json create mode 100644 Tests/Info/gmod_cyrillic.raw create mode 100644 Tests/Info/tf2.json create mode 100644 Tests/Info/tf2.raw create mode 100644 Tests/Info/theship.json create mode 100644 Tests/Info/theship.raw diff --git a/.travis.yml b/.travis.yml index f53f15a..502c20c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ sudo: false language: php php: + - 5.5 - 5.6 - hhvm - nightly @@ -11,6 +12,6 @@ notifications: install: - composer install --dev --no-interaction script: - - phpunit --configuration Tests/.phpunit.xml --verbose + - phpunit --configuration Tests/.phpunit.xml after_script: - ./.codeclimate.sh diff --git a/Tests/.phpunit.xml b/Tests/.phpunit.xml index f0a722f..151adee 100644 --- a/Tests/.phpunit.xml +++ b/Tests/.phpunit.xml @@ -1,5 +1,7 @@ - + ./Tests.php diff --git a/Tests/Info/csgo.json b/Tests/Info/csgo.json new file mode 100644 index 0000000..84759e2 --- /dev/null +++ b/Tests/Info/csgo.json @@ -0,0 +1,21 @@ +{ + "Protocol": 17, + "HostName": "BombGame by xPaw & Co.", + "Map": "de_dust2", + "ModDir": "csgo", + "ModDesc": "Counter-Strike: Global Offensive", + "AppID": 730, + "Players": 0, + "MaxPlayers": 16, + "Bots": 0, + "Dedicated": "d", + "Os": "l", + "Password": false, + "Secure": true, + "Version": "1.35.0.7", + "ExtraDataFlags": 177, + "GamePort": 27036, + "SteamID": 90097713628897284, + "GameTags": "empty,*grp:1105381i,bombgame,secure", + "GameID": 730 +} diff --git a/Tests/Info/csgo.raw b/Tests/Info/csgo.raw new file mode 100644 index 0000000..7d3ae86 --- /dev/null +++ b/Tests/Info/csgo.raw @@ -0,0 +1 @@ +ffffffff4911426f6d6247616d652062792078506177202620436f2e0064655f6475737432006373676f00436f756e7465722d537472696b653a20476c6f62616c204f6666656e7369766500da02001000646c0001312e33352e302e3700b19c6904e0eca764174001656d7074792c2a6772703a31313035333831692c626f6d6267616d652c73656375726500da02000000000000 diff --git a/Tests/Info/gmod_cyrillic.json b/Tests/Info/gmod_cyrillic.json new file mode 100644 index 0000000..0eedc4b --- /dev/null +++ b/Tests/Info/gmod_cyrillic.json @@ -0,0 +1,21 @@ +{ + "Protocol": 17, + "HostName": "Город Инноваций | Русский DarkRP", + "Map": "rp_bangclaw", + "ModDir": "garrysmod", + "ModDesc": "DarkRP", + "AppID": 4000, + "Players": 33, + "MaxPlayers": 40, + "Bots": 0, + "Dedicated": "d", + "Os": "l", + "Password": false, + "Secure": true, + "Version": "15.08.10", + "ExtraDataFlags": 177, + "GamePort": 27015, + "SteamID": 90097724371517447, + "GameTags": " gm:darkrp", + "GameID": 4000 +} diff --git a/Tests/Info/gmod_cyrillic.raw b/Tests/Info/gmod_cyrillic.raw new file mode 100644 index 0000000..35a63c6 --- /dev/null +++ b/Tests/Info/gmod_cyrillic.raw @@ -0,0 +1 @@ +ffffffff4911d093d0bed180d0bed0b420d098d0bdd0bdd0bed0b2d0b0d186d0b8d0b9207c20d0a0d183d181d181d0bad0b8d0b9204461726b52500072705f62616e67636c6177006761727279736d6f64004461726b525000a00f212800646c000131352e30382e313000b1876907403c286717400120676d3a6461726b727000a00f000000000000 diff --git a/Tests/Info/tf2.json b/Tests/Info/tf2.json new file mode 100644 index 0000000..c819392 --- /dev/null +++ b/Tests/Info/tf2.json @@ -0,0 +1,23 @@ +{ + "Protocol": 17, + "HostName": " FirePowered.org | Unusual Trade | !jackpot", + "Map": "trade_unusual_center_v3", + "ModDir": "tf", + "ModDesc": "Unusual Trading", + "AppID": 440, + "Players": 32, + "MaxPlayers": 32, + "Bots": 0, + "Dedicated": "d", + "Os": "l", + "Password": false, + "Secure": true, + "Version": "3032525", + "ExtraDataFlags": 241, + "GamePort": 27045, + "SteamID": 85568392920039468, + "SpecPort": 27050, + "SpecName": "ScamCam", + "GameTags": "FirePowered,alltalk,backpack.tf,increased_maxplayers,no_ads,noads,nopinion,norespawntime,trade,trading,unusual", + "GameID": 440 +} diff --git a/Tests/Info/tf2.raw b/Tests/Info/tf2.raw new file mode 100644 index 0000000..f2b6fe8 --- /dev/null +++ b/Tests/Info/tf2.raw @@ -0,0 +1 @@ +ffffffff49112046697265506f77657265642e6f7267207c20556e757375616c205472616465207c20216a61636b706f740074726164655f756e757375616c5f63656e7465725f763300746600556e757375616c2054726164696e6700b801202000646c00013330333235323500f1a5692c00000000003001aa695363616d43616d0046697265506f77657265642c616c6c74616c6b2c6261636b7061636b2e74662c696e637265617365645f6d6178706c61796572732c6e6f5f6164732c6e6f6164732c6e6f70696e696f6e2c6e6f7265737061776e74696d652c74726164652c74726164696e672c756e757375616c00b801000000000000 diff --git a/Tests/Info/theship.json b/Tests/Info/theship.json new file mode 100644 index 0000000..16e0d44 --- /dev/null +++ b/Tests/Info/theship.json @@ -0,0 +1,19 @@ +{ + "Protocol": 7, + "HostName": "RKSzone.com | US Chicago | The Ship | Hunt", + "Map": "atalanta", + "ModDir": "ship", + "ModDesc": "The Ship", + "AppID": 2400, + "Players": 27, + "MaxPlayers": 32, + "Bots": 16, + "Dedicated": "d", + "Os": "w", + "Password": false, + "Secure": true, + "GameMode": 0, + "WitnessCount": 2, + "WitnessTime": 5, + "Version": "1.0.0.16" +} diff --git a/Tests/Info/theship.raw b/Tests/Info/theship.raw new file mode 100644 index 0000000..112ce8c --- /dev/null +++ b/Tests/Info/theship.raw @@ -0,0 +1 @@ +ffffffff4907524b537a6f6e652e636f6d207c205553204368696361676f207c205468652053686970207c2048756e74006174616c616e746100736869700054686520536869700060091b201064770001000205312e302e302e313600 diff --git a/Tests/Tests.php b/Tests/Tests.php index 2b9d5df..fb8c57b 100644 --- a/Tests/Tests.php +++ b/Tests/Tests.php @@ -1,9 +1,8 @@ NextOutput = ''; + $this->ReadInternal( $Buffer, $this->Sherlock ); + return $Buffer; } + + private function Sherlock( $Buffer, $Length ) + { + return false; + } } class SourceQueryTests extends PHPUnit_Framework_TestCase @@ -66,13 +72,51 @@ $RealOutput = $this->SourceQuery->GetInfo(); - $this->assertEquals( $ExpectedOutput, $RealOutput ); + foreach( $ExpectedOutput as $Key => $ExpectedValue ) + { + $this->assertEquals( $ExpectedValue, $RealOutput[ $Key ], $Key ); + } } public function InfoProvider() { - // read from Tests/Info/ folder + $DataProvider = []; + + $Files = glob( __DIR__ . '/Info/*.raw', GLOB_ERR ); - return [ [ '', '' ] ]; + foreach( $Files as $File ) + { + $DataProvider[] = + [ + hex2bin( trim( file_get_contents( $File ) ) ), + json_decode( file_get_contents( str_replace( '.raw', '.json', $File ) ), true ) + ]; + } + + return $DataProvider; + } + + /** + * @expectedException xPaw\SourceQuery\Exception\InvalidPacketException + * @dataProvider BadInfoProvider + */ + public function testBadGetInfo( $Data ) + { + $this->Socket->NextOutput = $Data; + + $this->SourceQuery->GetInfo(); + } + + public function BadInfoProvider( ) + { + return + [ + [ "" ], + [ "\xff\xff\xff\xff" ], // No type + [ "\xff\xff\xff\xff\x49" ], // Correct type, but no data after + [ "\xff\xff\xff\xff\x6D" ], // Old info packet, but tests are done for source + [ "\xff\xff\xff\xff\x11" ], // Wrong type + [ "\xff" ], // Should be 4 bytes, but it's 1 + ]; } } diff --git a/composer.json b/composer.json index 82c6b48..361e3d7 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ }, "require-dev": { - "phpunit/phpunit": "5.0.*", + "phpunit/phpunit": "4.8.*", "codeclimate/php-test-reporter": "dev-master" }, "autoload":