Skip to content

Commit

Permalink
Add some GetInfo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Oct 21, 2015
1 parent af50a4a commit 29597ff
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sudo: false
language: php
php:
- 5.5
- 5.6
- hhvm
- nightly
Expand All @@ -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
4 changes: 3 additions & 1 deletion Tests/.phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<phpunit colors="true"
bootstrap="../SourceQuery/bootstrap.php"
verbose="true">
<testsuites>
<testsuite name="Tests">
<file>./Tests.php</file>
Expand Down
21 changes: 21 additions & 0 deletions Tests/Info/csgo.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions Tests/Info/csgo.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffffffff4911426f6d6247616d652062792078506177202620436f2e0064655f6475737432006373676f00436f756e7465722d537472696b653a20476c6f62616c204f6666656e7369766500da02001000646c0001312e33352e302e3700b19c6904e0eca764174001656d7074792c2a6772703a31313035333831692c626f6d6267616d652c73656375726500da02000000000000
21 changes: 21 additions & 0 deletions Tests/Info/gmod_cyrillic.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions Tests/Info/gmod_cyrillic.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffffffff4911d093d0bed180d0bed0b420d098d0bdd0bdd0bed0b2d0b0d186d0b8d0b9207c20d0a0d183d181d181d0bad0b8d0b9204461726b52500072705f62616e67636c6177006761727279736d6f64004461726b525000a00f212800646c000131352e30382e313000b1876907403c286717400120676d3a6461726b727000a00f000000000000
23 changes: 23 additions & 0 deletions Tests/Info/tf2.json
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions Tests/Info/tf2.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffffffff49112046697265506f77657265642e6f7267207c20556e757375616c205472616465207c20216a61636b706f740074726164655f756e757375616c5f63656e7465725f763300746600556e757375616c2054726164696e6700b801202000646c00013330333235323500f1a5692c00000000003001aa695363616d43616d0046697265506f77657265642c616c6c74616c6b2c6261636b7061636b2e74662c696e637265617365645f6d6178706c61796572732c6e6f5f6164732c6e6f6164732c6e6f70696e696f6e2c6e6f7265737061776e74696d652c74726164652c74726164696e672c756e757375616c00b801000000000000
19 changes: 19 additions & 0 deletions Tests/Info/theship.json
Original file line number Diff line number Diff line change
@@ -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"
}
1 change: 1 addition & 0 deletions Tests/Info/theship.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffffffff4907524b537a6f6e652e636f6d207c205553204368696361676f207c205468652053686970207c2048756e74006174616c616e746100736869700054686520536869700060091b201064770001000205312e302e302e313600
54 changes: 49 additions & 5 deletions Tests/Tests.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
require __DIR__ . '/../SourceQuery/bootstrap.php';

use xPaw\SourceQuery\BaseSocket;
use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\SourceQuery;
use xPaw\SourceQuery\Buffer;

class TestableSocket extends BaseSocket
{
Expand Down Expand Up @@ -36,8 +35,15 @@ public function Read( $Length = 1400 )

$this->NextOutput = '';

$this->ReadInternal( $Buffer, $this->Sherlock );

return $Buffer;
}

private function Sherlock( $Buffer, $Length )
{
return false;
}
}

class SourceQueryTests extends PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -66,13 +72,51 @@ public function testGetInfo( $RawInput, $ExpectedOutput )

$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
];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"require-dev":
{
"phpunit/phpunit": "5.0.*",
"phpunit/phpunit": "4.8.*",
"codeclimate/php-test-reporter": "dev-master"
},
"autoload":
Expand Down

0 comments on commit 29597ff

Please sign in to comment.