Generic test code for creating games.

This commit is contained in:
lotodore
2010-11-12 19:50:11 +00:00
parent 85d26e79a4
commit 5d22018534
2 changed files with 61 additions and 38 deletions
+8 -31
View File
@@ -37,42 +37,19 @@ public class CreateGameTest extends TestBase {
public void testJoinGameRequestMessage() throws Exception {
guestInit();
EndRaiseModeEnumType endRaise = new EndRaiseModeEnumType();
endRaise.setValue(EndRaiseModeEnumType.EnumType.keepLastBlind);
NetGameInfo gameInfo = new NetGameInfo();
gameInfo.setDelayBetweenHands(6);
gameInfo.setEndRaiseMode(endRaise);
gameInfo.setEndRaiseSmallBlindValue(1000);
gameInfo.setFirstSmallBlind(100);
gameInfo.setGameName(GuestUser + " game test");
Collection<Integer> l = new ArrayList<Integer>();
l.add(250);
l.add(600);
l.add(1000);
gameInfo.setManualBlinds(l);
gameInfo.setMaxNumPlayers(10);
NetGameTypeEnumType gameType = new NetGameTypeEnumType();
gameType.setValue(NetGameTypeEnumType.EnumType.normalGame);
gameInfo.setNetGameType(gameType);
gameInfo.setPlayerActionTimeout(20);
gameInfo.setProposedGuiSpeed(8);
RaiseIntervalModeChoiceType raiseInterval = new RaiseIntervalModeChoiceType();
raiseInterval.selectRaiseEveryHands(7);
gameInfo.setRaiseIntervalMode(raiseInterval);
gameInfo.setStartMoney(2000);
JoinNewGame joinNew = new JoinNewGame();
joinNew.setGameInfo(gameInfo);
JoinGameActionChoiceType joinAction = new JoinGameActionChoiceType();
joinAction.selectJoinNewGame(joinNew);
JoinGameRequestMessageSequenceType joinType = new JoinGameRequestMessageSequenceType();
joinType.setJoinGameAction(joinAction);
joinType.setPassword(GamePassword);
JoinGameRequestMessage joinRequest = new JoinGameRequestMessage();
joinRequest.setValue(joinType);
PokerTHMessage msg = new PokerTHMessage();
msg.selectJoinGameRequestMessage(joinRequest);
sendMessage(msg);
NetGameInfo gameInfo = createGameInfo(8, EndRaiseModeEnumType.EnumType.raiseByEndValue, 1000, 100, GuestUser + " create test game", l, 10, 0, 7, 2000);
sendMessage(createJoinGameRequestMsg(
gameInfo,
NetGameTypeEnumType.EnumType.normalGame,
20,
7,
GamePassword));
PokerTHMessage msg;
do {
msg = receiveMessage();
} while (msg.isPlayerListMessageSelected() || msg.isGameListMessageSelected());
+53 -7
View File
@@ -24,19 +24,20 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import pokerth_protocol.AnnounceMessage;
import pokerth_protocol.ErrorMessage;
import pokerth_protocol.GuestLogin;
import pokerth_protocol.InitAckMessage;
import pokerth_protocol.InitMessage;
import pokerth_protocol.PokerTHMessage;
import pokerth_protocol.Version;
import pokerth_protocol.*;
import pokerth_protocol.AnnounceMessage.AnnounceMessageSequenceType.ServerTypeEnumType;
import pokerth_protocol.InitMessage.InitMessageSequenceType;
import pokerth_protocol.InitMessage.InitMessageSequenceType.LoginChoiceType;
import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType;
import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType.JoinGameActionChoiceType;
import pokerth_protocol.NetGameInfo.EndRaiseModeEnumType;
import pokerth_protocol.NetGameInfo.NetGameTypeEnumType;
import pokerth_protocol.NetGameInfo.RaiseIntervalModeChoiceType;
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.Collection;
public abstract class TestBase {
@@ -123,4 +124,49 @@ public abstract class TestBase {
fail("Invalid response message.");
}
}
public PokerTHMessage createJoinGameRequestMsg(NetGameInfo gameInfo, NetGameTypeEnumType.EnumType type, int playerActionTimeout, int guiSpeed, String password) {
NetGameTypeEnumType gameType = new NetGameTypeEnumType();
gameType.setValue(type);
gameInfo.setNetGameType(gameType);
gameInfo.setPlayerActionTimeout(playerActionTimeout);
gameInfo.setProposedGuiSpeed(guiSpeed);
JoinNewGame joinNew = new JoinNewGame();
joinNew.setGameInfo(gameInfo);
JoinGameActionChoiceType joinAction = new JoinGameActionChoiceType();
joinAction.selectJoinNewGame(joinNew);
JoinGameRequestMessageSequenceType joinType = new JoinGameRequestMessageSequenceType();
joinType.setJoinGameAction(joinAction);
joinType.setPassword(password);
JoinGameRequestMessage joinRequest = new JoinGameRequestMessage();
joinRequest.setValue(joinType);
PokerTHMessage msg = new PokerTHMessage();
msg.selectJoinGameRequestMessage(joinRequest);
return msg;
}
public NetGameInfo createGameInfo(int delayBetweenHands, EndRaiseModeEnumType.EnumType endMode, int endRaiseValue, int sb, String gameName,
Collection<Integer> manualBlinds, int maxNumPlayers, int raiseEveryMinutes, int raiseEveryHands, int startMoney) {
NetGameInfo gameInfo = new NetGameInfo();
EndRaiseModeEnumType endRaise = new EndRaiseModeEnumType();
endRaise.setValue(endMode);
gameInfo.setDelayBetweenHands(delayBetweenHands);
gameInfo.setEndRaiseMode(endRaise);
gameInfo.setEndRaiseSmallBlindValue(endRaiseValue);
gameInfo.setFirstSmallBlind(sb);
gameInfo.setGameName(gameName);
gameInfo.setManualBlinds(manualBlinds);
gameInfo.setMaxNumPlayers(maxNumPlayers);
RaiseIntervalModeChoiceType raiseInterval = new RaiseIntervalModeChoiceType();
if (raiseEveryMinutes > 0) {
raiseInterval.selectRaiseEveryMinutes(raiseEveryMinutes);
}
else {
raiseInterval.selectRaiseEveryHands(raiseEveryHands);
}
gameInfo.setRaiseIntervalMode(raiseInterval);
gameInfo.setStartMoney(startMoney);
return gameInfo;
}
}