Adding tests for ranking games, fixing small issue when creating ranking games.
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user