Adding tests for ranking games, fixing small issue when creating ranking games.

This commit is contained in:
lotodore
2010-11-12 22:43:17 +00:00
parent 5d22018534
commit 67b01746da
9 changed files with 139 additions and 93 deletions
+3 -2
View File
@@ -984,7 +984,7 @@ ServerGame::CheckPassword(const string &password) const
}
bool
ServerGame::CheckSettings(const GameData &data)
ServerGame::CheckSettings(const GameData &data, const string &password)
{
bool retVal = true;
if (data.gameType == GAME_TYPE_RANKING)
@@ -994,7 +994,8 @@ ServerGame::CheckSettings(const GameData &data)
|| (data.firstSmallBlind != RANKING_GAME_START_SBLIND)
|| (data.raiseIntervalMode != RAISE_ON_HANDNUMBER)
|| (data.raiseMode != DOUBLE_BLINDS)
|| (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND))
|| (data.raiseSmallBlindEveryHandsValue != RANKING_GAME_RAISE_EVERY_HAND)
|| (!password.empty()))
{
retVal = false;
}
+1 -1
View File
@@ -1349,7 +1349,7 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std::
{
SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GUEST_FORBIDDEN);
}
else if (!ServerGame::CheckSettings(tmpData))
else if (!ServerGame::CheckSettings(tmpData, password))
{
SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_INVALID_SETTINGS);
}
+1 -1
View File
@@ -69,7 +69,7 @@ public:
bool IsPasswordProtected() const;
bool CheckPassword(const std::string &password) const;
static bool CheckSettings(const GameData &data);
static bool CheckSettings(const GameData &data, const std::string &password);
const GameData &GetGameData() const;
boost::shared_ptr<PlayerData> GetPlayerDataByUniqueId(unsigned playerId) const;
@@ -40,6 +40,11 @@ import org.bn.types.*;
private ChatRequestTypeGame chatRequestTypeGame = null;
@ASN1Element ( name = "chatRequestTypePrivate", isOptional = false , hasTag = true, tag = 2 , hasDefaultValue = false )
private ChatRequestTypePrivate chatRequestTypePrivate = null;
public ChatRequestTypeLobby getChatRequestTypeLobby () {
return this.chatRequestTypeLobby;
@@ -58,6 +63,8 @@ import org.bn.types.*;
this.chatRequestTypeLobby = value;
setChatRequestTypeGame(null);
setChatRequestTypePrivate(null);
}
@@ -81,6 +88,33 @@ import org.bn.types.*;
this.chatRequestTypeGame = value;
setChatRequestTypeLobby(null);
setChatRequestTypePrivate(null);
}
public ChatRequestTypePrivate getChatRequestTypePrivate () {
return this.chatRequestTypePrivate;
}
public boolean isChatRequestTypePrivateSelected () {
return this.chatRequestTypePrivate != null;
}
private void setChatRequestTypePrivate (ChatRequestTypePrivate value) {
this.chatRequestTypePrivate = value;
}
public void selectChatRequestTypePrivate (ChatRequestTypePrivate value) {
this.chatRequestTypePrivate = value;
setChatRequestTypeLobby(null);
setChatRequestTypeGame(null);
}
+8 -7
View File
@@ -322,16 +322,17 @@ import org.bn.types.*;
private Integer startMoney = null;
@ASN1Integer( name = "" )
@ASN1ValueRangeConstraint (
min = 1L,
max = 1000000L
)
@ASN1SequenceOf( name = "manualBlinds", isSetOf = false )
@ASN1ValueRangeConstraint (
min = 0L,
max = 30L
)
@ASN1Element ( name = "manualBlinds", isOptional = false , hasTag = false , hasDefaultValue = false )
private java.util.Collection<Integer> manualBlinds = null;
+2 -1
View File
@@ -26,7 +26,8 @@ import org.junit.runners.Suite;
@Suite.SuiteClasses( {
GuestLoginTest.class,
AuthLoginTest.class,
CreateGameTest.class
CreateGameTest.class,
CreateRankingGameTest.class
})
public class AllTests {
public static void main(String[] args)
+1 -77
View File
@@ -30,82 +30,6 @@ public class AuthLoginTest extends TestBase {
@Test
public void testAuthLogin() throws Exception {
PokerTHMessage msg = receiveMessage();
AnnounceMessage announce = msg.getAnnounceMessage();
assertTrue(announce.getValue().getServerType().getValue() == ServerTypeEnumType.EnumType.serverTypeInternetAuth);
ScramSha1 scramAuth = new ScramSha1();
// Send challenge.
Version requestedVersion = new Version();
requestedVersion.setMajor(PROTOCOL_VERSION_MAJOR);
requestedVersion.setMinor(PROTOCOL_VERSION_MINOR);
AuthenticatedLogin authLogin = new AuthenticatedLogin();
authLogin.setClientUserData(scramAuth.executeStep1(AuthUser).getBytes());
LoginChoiceType loginType = new LoginChoiceType();
loginType.selectAuthenticatedLogin(authLogin);
InitMessageSequenceType msgType = new InitMessageSequenceType();
msgType.setBuildId(0L);
msgType.setLogin(loginType);
msgType.setRequestedVersion(requestedVersion);
InitMessage init = new InitMessage();
init.setValue(msgType);
msg = new PokerTHMessage();
msg.selectInitMessage(init);
sendMessage(msg);
msg = receiveMessage();
if (msg.isAuthMessageSelected() && msg.getAuthMessage().getValue().isAuthServerChallengeSelected())
{
String serverFirstMessage = new String(msg.getAuthMessage().getValue().getAuthServerChallenge().getServerChallenge());
AuthClientResponse authClient = new AuthClientResponse();
authClient.setClientResponse(scramAuth.executeStep2(AuthPassword, serverFirstMessage).getBytes());
AuthMessageChoiceType authChoice = new AuthMessageChoiceType();
authChoice.selectAuthClientResponse(authClient);
AuthMessage authResponse = new AuthMessage();
authResponse.setValue(authChoice);
msg = new PokerTHMessage();
msg.selectAuthMessage(authResponse);
sendMessage(msg);
}
else if (msg.isErrorMessageSelected())
{
ErrorMessage error = msg.getErrorMessage();
fail("Received error: " + error.getValue().getErrorReason().getValue().toString());
}
else
{
fail("Invalid auth message.");
}
msg = receiveMessage();
if (msg.isErrorMessageSelected())
{
ErrorMessage error = msg.getErrorMessage();
fail("Received error: " + error.getValue().getErrorReason().getValue().toString());
}
else if (!msg.isAuthMessageSelected() || !msg.getAuthMessage().getValue().isAuthServerVerificationSelected())
{
fail("Invalid auth message.");
}
msg = receiveMessage();
if (msg.isInitAckMessageSelected())
{
InitAckMessage initAck = msg.getInitAckMessage();
assertTrue(initAck.getValue().getYourPlayerId().getValue() != 0L);
assertTrue(!initAck.getValue().isYourAvatarPresent());
}
else if (msg.isErrorMessageSelected())
{
ErrorMessage error = msg.getErrorMessage();
fail("Received error: " + error.getValue().getErrorReason().getValue().toString());
}
else
{
fail("Invalid response message.");
}
userInit();
}
}
@@ -25,11 +25,8 @@ import java.util.Collection;
import org.junit.Test;
import pokerth_protocol.*;
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;
public class CreateGameTest extends TestBase {
+89 -1
View File
@@ -26,6 +26,7 @@ import org.junit.Test;
import pokerth_protocol.*;
import pokerth_protocol.AnnounceMessage.AnnounceMessageSequenceType.ServerTypeEnumType;
import pokerth_protocol.AuthMessage.AuthMessageChoiceType;
import pokerth_protocol.InitMessage.InitMessageSequenceType;
import pokerth_protocol.InitMessage.InitMessageSequenceType.LoginChoiceType;
import pokerth_protocol.JoinGameRequestMessage.JoinGameRequestMessageSequenceType;
@@ -125,6 +126,90 @@ public abstract class TestBase {
}
}
public void userInit() throws Exception {
userInit(sock);
}
public void userInit(Socket s) throws Exception {
PokerTHMessage msg = receiveMessage(s);
AnnounceMessage announce = msg.getAnnounceMessage();
assertTrue(announce.getValue().getServerType().getValue() == ServerTypeEnumType.EnumType.serverTypeInternetAuth);
ScramSha1 scramAuth = new ScramSha1();
// Send challenge.
Version requestedVersion = new Version();
requestedVersion.setMajor(PROTOCOL_VERSION_MAJOR);
requestedVersion.setMinor(PROTOCOL_VERSION_MINOR);
AuthenticatedLogin authLogin = new AuthenticatedLogin();
authLogin.setClientUserData(scramAuth.executeStep1(AuthUser).getBytes());
LoginChoiceType loginType = new LoginChoiceType();
loginType.selectAuthenticatedLogin(authLogin);
InitMessageSequenceType msgType = new InitMessageSequenceType();
msgType.setBuildId(0L);
msgType.setLogin(loginType);
msgType.setRequestedVersion(requestedVersion);
InitMessage init = new InitMessage();
init.setValue(msgType);
msg = new PokerTHMessage();
msg.selectInitMessage(init);
sendMessage(msg, s);
msg = receiveMessage(s);
if (msg.isAuthMessageSelected() && msg.getAuthMessage().getValue().isAuthServerChallengeSelected())
{
String serverFirstMessage = new String(msg.getAuthMessage().getValue().getAuthServerChallenge().getServerChallenge());
AuthClientResponse authClient = new AuthClientResponse();
authClient.setClientResponse(scramAuth.executeStep2(AuthPassword, serverFirstMessage).getBytes());
AuthMessageChoiceType authChoice = new AuthMessageChoiceType();
authChoice.selectAuthClientResponse(authClient);
AuthMessage authResponse = new AuthMessage();
authResponse.setValue(authChoice);
msg = new PokerTHMessage();
msg.selectAuthMessage(authResponse);
sendMessage(msg, s);
}
else if (msg.isErrorMessageSelected())
{
ErrorMessage error = msg.getErrorMessage();
fail("Received error: " + error.getValue().getErrorReason().getValue().toString());
}
else
{
fail("Invalid auth message.");
}
msg = receiveMessage(s);
if (msg.isErrorMessageSelected())
{
ErrorMessage error = msg.getErrorMessage();
fail("Received error: " + error.getValue().getErrorReason().getValue().toString());
}
else if (!msg.isAuthMessageSelected() || !msg.getAuthMessage().getValue().isAuthServerVerificationSelected())
{
fail("Invalid auth message.");
}
msg = receiveMessage(s);
if (msg.isInitAckMessageSelected())
{
InitAckMessage initAck = msg.getInitAckMessage();
assertTrue(initAck.getValue().getYourPlayerId().getValue() != 0L);
assertTrue(!initAck.getValue().isYourAvatarPresent());
}
else if (msg.isErrorMessageSelected())
{
ErrorMessage error = msg.getErrorMessage();
fail("Received error: " + error.getValue().getErrorReason().getValue().toString());
}
else
{
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);
@@ -137,7 +222,9 @@ public abstract class TestBase {
joinAction.selectJoinNewGame(joinNew);
JoinGameRequestMessageSequenceType joinType = new JoinGameRequestMessageSequenceType();
joinType.setJoinGameAction(joinAction);
joinType.setPassword(password);
if (!password.isEmpty()) {
joinType.setPassword(password);
}
JoinGameRequestMessage joinRequest = new JoinGameRequestMessage();
joinRequest.setValue(joinType);
@@ -167,6 +254,7 @@ public abstract class TestBase {
}
gameInfo.setRaiseIntervalMode(raiseInterval);
gameInfo.setStartMoney(startMoney);
return gameInfo;
}
}