27.01.2014, 22:13
(
Last edited by Misiur; 31/01/2014 at 08:29 PM.
)
ut_mock_players
Player mocking system for unit tests
y_testing is really powerful library, but most of you people won't use it ever - therefore ut_mock_players isn't for you. For the rest of you folks, sometimes you might need to simulate a lot of users on your server at once. Some people will use NPC's to do that, other will hire cheap Mexican labour. However, I'm not clever enough to do that, so I've started to overwrite functions from a_players. There is a metric alot of them, and I've done only few so far - this gives you idea how to do more of them, and even with this limited toolset, it's pretty helpful.
Dependencies
Of course y_testing, and y_utils. Later on there will be y_iterate as well, so you can test with less than MAX_PLAYERS at once.
How to use that thing
pawn Code:
#define RUN_TESTS
#include <ut_mock_players>
main() {
new
tests,
fails,
func[33];
Testing_Run(tests, fails, func);
}
public OnPlayerConnect(playerid)
{
printf("Player %d connected!", playerid);
SetPlayerScore(playerid, GetPlayerScore(playerid) + 25);
return 1;
}
Test:Connection()
{
//Randomly selected number
new
playerid = 256, score = GetPlayerScore(playerid);
ASSERT(score == 0);
printf("Player score before: %d", score);
OnPlayerConnect(playerid);
score = GetPlayerScore(playerid);
ASSERT(score == 25);
printf("Player score after: %d", score);
}
#include <ut_mock_players>
Very important note! It is essential to compile with suppresed warnings 203-206. "Why?" you might ask. Normally when you grab, for example, user position using GetPlayerPos, like:
pawn Code:
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
pawn Code:
new Float:X, Float:Y, Float:Z;
(X = MockPlayer[playerid][mu_pos][0], Y = MockPlayer[playerid][mu_pos][1], Z = MockPlayer[playerid][mu_pos][2]);
pawn Code:
if(1) { /*(...)*/ }
Example compiler call (used by me):
Quote:
pawncc "$file" -;+ -v2 -w203 -w204 -w205 -w206 -d3 |
Download
Gist link
Pastebin mirror
Save as ut_mock_players.inc in your pawno/includes folder. Compiled with Zeex patches, but it should compile nicely with normal pawncc.
Changelog
Initial commit
- Few functions
- Most of user structure initialised
Update 2014-01-28
- Added information about compiler flags
- Added roadmap
Issues
Working with static data, instead with live players has its toll. Creating for example GetPlayerTargetPlayer requires some additional computation, and will be really off in many cases. You have to do anything by hand - setting the player camera, position, using callbacks (well, unit tests should be consistent across runs, so that's a good thing though once you get that done).
Roadmap
- Creating separate logs for client messages sent to specific players
- Override of all player functions, with simulated actions like vehicle entering
- Changing IsPlayerConnected behaviour
More
If you have any questions, this thread is yours. I'll add functions on the fly as needed for me. Feel free to fork the gist, I'd really appreciate help with it.