Fixing remaining test cases for google protocol buffers.

This commit is contained in:
lotodore
2012-09-22 12:39:34 +02:00
parent 09545d86a7
commit 5ef456e15b
6 changed files with 334 additions and 329 deletions
+69 -68
View File
@@ -26,6 +26,15 @@ import java.util.Collection;
import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.PlayerListMessage.PlayerListNotification;
import de.pokerth.protocol.ProtoBuf.StartEventAckMessage;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
import de.pokerth.protocol.ProtoBuf.StartEventMessage.StartEventType;
public class RejoinGameTest extends TestBase {
@@ -33,57 +42,49 @@ public class RejoinGameTest extends TestBase {
public void testRejoinGame() throws Exception {
Guid firstPlayerSession = new Guid();
long firstPlayerId = userInit(sock, AuthUser, AuthPassword, null, firstPlayerSession);
int firstPlayerId = userInit(sock, AuthUser, AuthPassword, null, firstPlayerSession);
// Waiting for player list update.
PokerTHMessage msg;
msg = receiveMessage();
if (!msg.isPlayerListMessageSelected()) {
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
Collection<Integer> l = new ArrayList<Integer>();
String gameName = AuthUser + " rejoin game";
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 5, 7, 5, EndRaiseMode.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
sendMessage(createGameRequestMsg(
gameInfo,
NetGameTypeEnumType.EnumType.normalGame,
5,
7,
"",
false));
// Game list update (new game)
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListNewMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Join game ack.
msg = receiveMessage();
if (msg.isJoinGameReplyMessageSelected()) {
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
fail("Could not create game!");
}
}
else {
if (!msg.hasJoinGameAckMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
fail("Could not create game!");
}
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
int gameId = msg.getJoinGameAckMessage().getGameId();
// Game list update (player joined).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Let 9 additional clients join.
Socket s[] = new Socket[9];
long playerId[] = new long[9];
int playerId[] = new int[9];
for (int i = 0; i < 9; i++) {
s[i] = new Socket("localhost", 7234);
String username = "test" + (i+1);
@@ -92,8 +93,8 @@ public class RejoinGameTest extends TestBase {
// Waiting for player list update.
do {
msg = receiveMessage(s[i]);
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
if (!msg.isPlayerListMessageSelected()) {
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -101,24 +102,24 @@ public class RejoinGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isJoinGameReplyMessageSelected());
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
if (!msg.hasJoinGameAckMessage()) {
fail("User " + username + " could not join ranking game.");
}
// The player should have joined the game.
msg = receiveMessage();
if (!msg.isPlayerListMessageSelected()) {
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGamePlayerMessageSelected()) {
if (!msg.hasGamePlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -126,7 +127,7 @@ public class RejoinGameTest extends TestBase {
// Server should automatically send start event.
msg = receiveMessage();
if (!msg.isStartEventMessageSelected()) {
if (!msg.hasStartEventMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -134,15 +135,16 @@ public class RejoinGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
} while (!msg.hasStartEventMessage());
}
// Acknowledge start event.
StartEventAckMessageSequenceType startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
StartEventAckMessage startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
.setGameId(gameId)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
.setStartEventAckMessage(startAck)
.build();
sendMessage(msg);
for (int i = 0; i < 9; i++) {
sendMessage(msg, s[i]);
@@ -150,13 +152,13 @@ public class RejoinGameTest extends TestBase {
// Game list update (game now running).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListUpdateMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameStartMessageSelected()) {
if (!msg.hasGameStartInitialMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -171,7 +173,7 @@ public class RejoinGameTest extends TestBase {
failOnErrorMessage(inMsg);
}
}
} while (!msg.isHandStartMessageSelected());
} while (!msg.hasHandStartMessage());
// Leave the game by closing the socket.
sock.close();
@@ -183,20 +185,20 @@ public class RejoinGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isPlayerListMessageSelected());
assertEquals(firstPlayerId, msg.getPlayerListMessage().getValue().getPlayerId().getValue().longValue());
assertEquals(PlayerListNotificationEnumType.EnumType.playerListLeft, msg.getPlayerListMessage().getValue().getPlayerListNotification().getValue());
} while (!msg.hasPlayerListMessage());
assertEquals(firstPlayerId, msg.getPlayerListMessage().getPlayerId());
assertEquals(PlayerListNotification.playerListLeft, msg.getPlayerListMessage().getPlayerListNotification());
}
sock = new Socket("localhost", 7234);
// Reconnect to the server.
long firstPlayerIdAfterRejoin = userInit(sock, AuthUser, AuthPassword, null, firstPlayerSession);
int firstPlayerIdAfterRejoin = userInit(sock, AuthUser, AuthPassword, null, firstPlayerSession);
assertEquals(gameId, lastRejoinGameId);
// Waiting for player list update.
do {
msg = receiveMessage();
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
if (!msg.isPlayerListMessageSelected()) {
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -205,9 +207,9 @@ public class RejoinGameTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isJoinGameReplyMessageSelected());
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
fail("User " + AuthUser + " could not rejoin ranking game.");
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
if (!msg.hasJoinGameAckMessage()) {
fail("User " + AuthUser + " could not rejoin normal game.");
}
// All other players should have received "player joined".
@@ -215,64 +217,63 @@ public class RejoinGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isPlayerListMessageSelected());
assertEquals(firstPlayerIdAfterRejoin, msg.getPlayerListMessage().getValue().getPlayerId().getValue().longValue());
assertEquals(PlayerListNotificationEnumType.EnumType.playerListNew, msg.getPlayerListMessage().getValue().getPlayerListNotification().getValue());
} while (!msg.hasPlayerListMessage());
assertEquals(firstPlayerIdAfterRejoin, msg.getPlayerListMessage().getPlayerId());
assertEquals(PlayerListNotification.playerListNew, msg.getPlayerListMessage().getPlayerListNotification());
}
// Wait for start event.
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
} while (!msg.hasStartEventMessage());
assertEquals(gameId, msg.getStartEventMessage().getValue().getGameId().getValue().longValue());
assertTrue(msg.getStartEventMessage().getValue().getStartEventType().isRejoinEventSelected());
assertEquals(gameId, msg.getStartEventMessage().getGameId());
assertEquals(StartEventType.rejoinEvent, msg.getStartEventMessage().getStartEventType());
// Acknowledge start event.
startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
startAck = StartEventAckMessage.newBuilder()
.setGameId(gameId)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
.setStartEventAckMessage(startAck)
.build();
sendMessage(msg);
// Wait for game start. This may take a while, because rejoin is performed at the beginning of the next hand.
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isGameStartMessageSelected());
} while (!msg.hasGameStartRejoinMessage());
// Check whether we got all necessary data to rejoin.
assertEquals(gameId, msg.getGameStartMessage().getValue().getGameId().getValue().longValue());
assertTrue(msg.getGameStartMessage().getValue().getGameStartMode().isGameStartModeRejoinSelected());
GameStartModeRejoin rejoinData = msg.getGameStartMessage().getValue().getGameStartMode().getGameStartModeRejoin();
assertEquals(gameId, msg.getGameStartRejoinMessage().getGameId());
// We left at the first hand.
assertEquals(1, rejoinData.getHandNum().getValue().longValue());
assertEquals(1, msg.getGameStartRejoinMessage().getHandNum());
// 10 Players should now be active again.
assertEquals(10, rejoinData.getRejoinPlayerData().size());
assertEquals(10, msg.getGameStartRejoinMessage().getRejoinPlayerDataCount());
// All other players should have received "player id changed".
for (int i = 0; i < 9; i++) {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isPlayerIdChangedMessageSelected());
assertEquals(firstPlayerId, msg.getPlayerIdChangedMessage().getValue().getOldPlayerId().getValue().longValue());
assertEquals(firstPlayerIdAfterRejoin, msg.getPlayerIdChangedMessage().getValue().getNewPlayerId().getValue().longValue());
} while (!msg.hasPlayerIdChangedMessage());
assertEquals(firstPlayerId, msg.getPlayerIdChangedMessage().getOldPlayerId());
assertEquals(firstPlayerIdAfterRejoin, msg.getPlayerIdChangedMessage().getNewPlayerId());
}
// Everyone should receive a "hand start message" now.
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isHandStartMessageSelected());
} while (!msg.hasHandStartMessage());
for (int i = 0; i < 9; i++) {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isHandStartMessageSelected());
} while (!msg.hasHandStartMessage());
}
for (int i = 0; i < 9; i++) {
@@ -28,6 +28,15 @@ import java.util.Collection;
import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.StartEventAckMessage;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
import de.pokerth.protocol.ProtoBuf.PlayerListMessage.PlayerListNotification;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
import de.pokerth.protocol.ProtoBuf.StartEventMessage.StartEventType;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
public class RejoinMultiGameTest extends TestBase {
@@ -44,52 +53,44 @@ public class RejoinMultiGameTest extends TestBase {
// Waiting for player list update.
PokerTHMessage msg;
msg = receiveMessage();
if (!msg.isPlayerListMessageSelected()) {
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
Collection<Integer> l = new ArrayList<Integer>();
String gameName = AuthUser + " rejoin game";
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
NetGameInfo gameInfo = createGameInfo(NetGameType.rankingGame, 5, 7, 5, EndRaiseMode.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
sendMessage(createGameRequestMsg(
gameInfo,
NetGameTypeEnumType.EnumType.rankingGame,
5,
7,
"",
false));
// Game list update (new game)
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListNewMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Join game ack.
msg = receiveMessage();
if (msg.isJoinGameReplyMessageSelected()) {
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
fail("Could not create game!");
}
}
else {
if (!msg.hasJoinGameAckMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
fail("Could not create game!");
}
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
int gameId = msg.getJoinGameAckMessage().getGameId();
// Game list update (player joined).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Let 9 additional clients join.
Socket s[] = new Socket[9];
long playerId[] = new long[9];
int playerId[] = new int[9];
Guid playerSession[] = new Guid[9];
for (int i = 0; i < 9; i++) {
s[i] = new Socket("localhost", 7234);
@@ -100,8 +101,8 @@ public class RejoinMultiGameTest extends TestBase {
// Waiting for player list update.
do {
msg = receiveMessage(s[i]);
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
if (!msg.isPlayerListMessageSelected()) {
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -109,24 +110,24 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isJoinGameReplyMessageSelected());
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
if (!msg.hasJoinGameAckMessage()) {
fail("User " + username + " could not join ranking game.");
}
// The player should have joined the game.
msg = receiveMessage();
if (!msg.isPlayerListMessageSelected()) {
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGamePlayerMessageSelected()) {
if (!msg.hasGamePlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -134,7 +135,7 @@ public class RejoinMultiGameTest extends TestBase {
// Server should automatically send start event.
msg = receiveMessage();
if (!msg.isStartEventMessageSelected()) {
if (!msg.hasStartEventMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -142,15 +143,16 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
} while (!msg.hasStartEventMessage());
}
// Acknowledge start event.
StartEventAckMessageSequenceType startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
StartEventAckMessage startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
.setGameId(gameId)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
.setStartEventAckMessage(startAck)
.build();
sendMessage(msg);
for (int i = 0; i < 9; i++) {
sendMessage(msg, s[i]);
@@ -158,13 +160,13 @@ public class RejoinMultiGameTest extends TestBase {
// Game list update (game now running).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListUpdateMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameStartMessageSelected()) {
if (!msg.hasGameStartInitialMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -179,7 +181,7 @@ public class RejoinMultiGameTest extends TestBase {
failOnErrorMessage(inMsg);
}
}
} while (!msg.isHandStartMessageSelected());
} while (!msg.hasHandStartMessage());
// 9 players leave the game by closing the socket.
for (int i = 0; i < 9; i++) {
@@ -194,9 +196,9 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isPlayerListMessageSelected());
assertEquals(playerId[i], msg.getPlayerListMessage().getValue().getPlayerId().getValue().longValue());
assertEquals(PlayerListNotificationEnumType.EnumType.playerListLeft, msg.getPlayerListMessage().getValue().getPlayerListNotification().getValue());
} while (!msg.hasPlayerListMessage());
assertEquals(playerId[i], msg.getPlayerListMessage().getPlayerId());
assertEquals(PlayerListNotification.playerListLeft, msg.getPlayerListMessage().getPlayerListNotification());
}
// Let all players reconnect.
@@ -210,8 +212,8 @@ public class RejoinMultiGameTest extends TestBase {
// Waiting for player list update.
do {
msg = receiveMessage(s[i]);
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
if (!msg.isPlayerListMessageSelected()) {
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -219,8 +221,8 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isJoinGameReplyMessageSelected());
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
if (!msg.hasJoinGameAckMessage()) {
fail("User " + username + " could not rejoin ranking game.");
}
}
@@ -229,9 +231,9 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isPlayerListMessageSelected());
assertEquals(playerIdAfterRejoin[i], msg.getPlayerListMessage().getValue().getPlayerId().getValue().longValue());
assertEquals(PlayerListNotificationEnumType.EnumType.playerListNew, msg.getPlayerListMessage().getValue().getPlayerListNotification().getValue());
} while (!msg.hasPlayerListMessage());
assertEquals(playerIdAfterRejoin[i], msg.getPlayerListMessage().getPlayerId());
assertEquals(PlayerListNotification.playerListNew, msg.getPlayerListMessage().getPlayerListNotification());
}
for (int i = 0; i < 9; i++) {
@@ -239,18 +241,19 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
} while (!msg.hasStartEventMessage());
assertEquals(gameId, msg.getStartEventMessage().getValue().getGameId().getValue().longValue());
assertTrue(msg.getStartEventMessage().getValue().getStartEventType().isRejoinEventSelected());
assertEquals(gameId, msg.getStartEventMessage().getGameId());
assertEquals(StartEventType.rejoinEvent, msg.getStartEventMessage().getStartEventType());
// Acknowledge start event.
startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
startAck = StartEventAckMessage.newBuilder()
.setGameId(gameId)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
.setStartEventAckMessage(startAck)
.build();
sendMessage(msg, s[i]);
}
@@ -259,16 +262,14 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isGameStartMessageSelected());
} while (!msg.hasGameStartRejoinMessage());
// Check whether we got all necessary data to rejoin.
assertEquals(gameId, msg.getGameStartMessage().getValue().getGameId().getValue().longValue());
assertTrue(msg.getGameStartMessage().getValue().getGameStartMode().isGameStartModeRejoinSelected());
GameStartModeRejoin rejoinData = msg.getGameStartMessage().getValue().getGameStartMode().getGameStartModeRejoin();
assertEquals(gameId, msg.getGameStartRejoinMessage().getGameId());
// We left at the first hand.
assertTrue(rejoinData.getHandNum().getValue().longValue() >= 1);
assertTrue(msg.getGameStartRejoinMessage().getHandNum() >= 1);
// 10 Players should now be active again.
assertEquals(10, rejoinData.getRejoinPlayerData().size());
assertEquals(10, msg.getGameStartRejoinMessage().getRejoinPlayerDataCount());
}
// The remaining player should have received 9 "player id changed".
@@ -276,28 +277,28 @@ public class RejoinMultiGameTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isPlayerIdChangedMessageSelected());
assertEquals(playerId[i], msg.getPlayerIdChangedMessage().getValue().getOldPlayerId().getValue().longValue());
assertEquals(playerIdAfterRejoin[i], msg.getPlayerIdChangedMessage().getValue().getNewPlayerId().getValue().longValue());
} while (!msg.hasPlayerIdChangedMessage());
assertEquals(playerId[i], msg.getPlayerIdChangedMessage().getOldPlayerId());
assertEquals(playerIdAfterRejoin[i], msg.getPlayerIdChangedMessage().getNewPlayerId());
}
// Everyone should receive a "hand start message" now.
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isHandStartMessageSelected());
} while (!msg.hasHandStartMessage());
for (int i = 0; i < 9; i++) {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isHandStartMessageSelected());
} while (!msg.hasHandStartMessage());
}
// The game should continue to the end.
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isEndOfGameMessageSelected());
} while (!msg.hasEndOfGameMessage());
for (int i = 0; i < 9; i++) {
s[i].close();
@@ -27,6 +27,16 @@ import java.util.Iterator;
import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.PlayerResult;
import de.pokerth.protocol.ProtoBuf.StartEventAckMessage;
import de.pokerth.protocol.ProtoBuf.StartEventMessage;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
import de.pokerth.protocol.ProtoBuf.StartEventMessage.StartEventType;
public class RunNormalGameTest extends TestBase {
@@ -34,13 +44,10 @@ public class RunNormalGameTest extends TestBase {
public void testRunNormalGameAsGuest() throws Exception {
guestInit();
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 100, GuestUser + " run normal game", l, 10, 0, 2, 2000);
Collection<Integer> l = new ArrayList<Integer>();
NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 10, 5, 5, EndRaiseMode.doubleBlinds, 0, 100, GuestUser + " run normal game", l, 10, 0, 2, 2000);
sendMessage(createGameRequestMsg(
gameInfo,
NetGameTypeEnumType.EnumType.normalGame,
10,
5,
"",
false));
@@ -48,60 +55,53 @@ public class RunNormalGameTest extends TestBase {
// Waiting for player list update.
msg = receiveMessage();
if (!msg.isPlayerListMessageSelected()) {
if (!msg.hasPlayerListMessage() || msg.getMessageType() != PokerTHMessageType.Type_PlayerListMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Game list update (new game)
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListNewMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListNewMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Join game ack.
msg = receiveMessage();
if (msg.isJoinGameReplyMessageSelected()) {
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
fail("Could not create game!");
}
}
else {
if (!msg.hasJoinGameAckMessage() || msg.getMessageType() != PokerTHMessageType.Type_JoinGameAckMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
fail("Could not create game!");
}
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
int gameId = msg.getJoinGameAckMessage().getGameId();
// Game list update (player joined).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListPlayerJoinedMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
StartEvent startEvent = new StartEvent();
startEvent.setFillWithComputerPlayers(true);
StartEventTypeChoiceType eventType = new StartEventTypeChoiceType();
eventType.selectStartEvent(startEvent);
StartEventMessageSequenceType gameStartType = new StartEventMessageSequenceType();
gameStartType.setGameId(new NonZeroId(gameId));
gameStartType.setStartEventType(eventType);
StartEventMessage startMsg = new StartEventMessage();
startMsg.setValue(gameStartType);
msg = new PokerTHMessage();
msg.selectStartEventMessage(startMsg);
StartEventMessage startMsg = StartEventMessage.newBuilder()
.setGameId(gameId)
.setFillWithComputerPlayers(true)
.setStartEventType(StartEventType.startEvent)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventMessage)
.setStartEventMessage(startMsg)
.build();
sendMessage(msg);
// Now the computer players should join.
for (int i = 0; i < 9; i++) {
msg = receiveMessage();
if (!msg.isGamePlayerMessageSelected()) {
if (!msg.hasGamePlayerJoinedMessage() || msg.getMessageType() != PokerTHMessageType.Type_GamePlayerJoinedMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListPlayerJoinedMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -109,28 +109,29 @@ public class RunNormalGameTest extends TestBase {
// Server should confirm start event.
msg = receiveMessage();
if (!msg.isStartEventMessageSelected()) {
if (!msg.hasStartEventMessage() || msg.getMessageType() != PokerTHMessageType.Type_StartEventMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Acknowledge start event.
StartEventAckMessageSequenceType startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
StartEventAckMessage startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
.setGameId(gameId)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
.setStartEventAckMessage(startAck)
.build();
sendMessage(msg);
// Game list update (game now running).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListUpdateMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListUpdateMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameStartMessageSelected()) {
if (!msg.hasGameStartInitialMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameStartInitialMessage) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -138,35 +139,34 @@ public class RunNormalGameTest extends TestBase {
long lastPlayerMoney = 0;
do {
msg = receiveMessage();
if (msg.isEndOfHandMessageSelected()) {
if (msg.getEndOfHandMessage().getValue().getEndOfHandType().isEndOfHandHideCardsSelected()) {
lastPlayerMoney = msg.getEndOfHandMessage().getValue().getEndOfHandType().getEndOfHandHideCards().getPlayerMoney().getValue();
} else if (msg.getEndOfHandMessage().getValue().getEndOfHandType().isEndOfHandShowCardsSelected()) {
Collection<PlayerResult> result = msg.getEndOfHandMessage().getValue().getEndOfHandType().getEndOfHandShowCards().getPlayerResults();
assertFalse(result.isEmpty());
long maxPlayerMoney = 0;
for (Iterator<PlayerResult> it = result.iterator(); it.hasNext(); ) {
PlayerResult r = it.next();
long curMoney = r.getPlayerMoney().getValue();
if (curMoney > maxPlayerMoney) {
maxPlayerMoney = curMoney;
}
if (msg.hasEndOfHandHideCardsMessage()) {
lastPlayerMoney = msg.getEndOfHandHideCardsMessage().getPlayerMoney();
} else if (msg.hasEndOfHandShowCardsMessage()) {
Collection<PlayerResult> result = msg.getEndOfHandShowCardsMessage().getPlayerResultsList();
assertFalse(result.isEmpty());
long maxPlayerMoney = 0;
for (Iterator<PlayerResult> it = result.iterator(); it.hasNext(); ) {
PlayerResult r = it.next();
int curMoney = r.getPlayerMoney();
if (curMoney > maxPlayerMoney) {
maxPlayerMoney = curMoney;
}
lastPlayerMoney = maxPlayerMoney;
}
lastPlayerMoney = maxPlayerMoney;
}
} while (
msg.isHandStartMessageSelected()
|| msg.isDealFlopCardsMessageSelected()
|| msg.isDealRiverCardMessageSelected()
|| msg.isDealTurnCardMessageSelected()
|| msg.isPlayersTurnMessageSelected()
|| msg.isPlayersActionDoneMessageSelected()
|| msg.isEndOfHandMessageSelected()
|| msg.isAllInShowCardsMessageSelected()
|| msg.isTimeoutWarningMessageSelected()
msg.hasHandStartMessage()
|| msg.hasDealFlopCardsMessage()
|| msg.hasDealRiverCardMessage()
|| msg.hasDealTurnCardMessage()
|| msg.hasPlayersTurnMessage()
|| msg.hasPlayersActionDoneMessage()
|| msg.hasEndOfHandHideCardsMessage()
|| msg.hasEndOfHandShowCardsMessage()
|| msg.hasAllInShowCardsMessage()
|| msg.hasTimeoutWarningMessage()
);
if (!msg.isEndOfGameMessageSelected()) {
if (!msg.hasEndOfGameMessage() || msg.getMessageType() != PokerTHMessageType.Type_EndOfGameMessage) {
fail("No end of game received.");
}
// Last player money should be sum of all money.
@@ -175,12 +175,12 @@ public class RunNormalGameTest extends TestBase {
// Now the computer players should leave.
for (int i = 0; i < 9; i++) {
msg = receiveMessage();
if (!msg.isGamePlayerMessageSelected()) {
if (!msg.hasGamePlayerLeftMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerLeftMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -29,6 +29,16 @@ import java.util.Iterator;
import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.MyActionRequestMessage;
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.NetPlayerAction;
import de.pokerth.protocol.ProtoBuf.PlayerResult;
import de.pokerth.protocol.ProtoBuf.StartEventAckMessage;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
public class RunRankingGameTest extends TestBase {
@@ -40,50 +50,41 @@ public class RunRankingGameTest extends TestBase {
countBeforeResult.first();
long countBefore = countBeforeResult.getLong(1);
long firstPlayerId = userInit();
int firstPlayerId = userInit();
// Waiting for player list update.
PokerTHMessage msg;
msg = receiveMessage();
if (!msg.isPlayerListMessageSelected()) {
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
Collection<Integer> l = new ArrayList<Integer>();
String gameName = AuthUser + " run ranking game";
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
NetGameInfo gameInfo = createGameInfo(NetGameType.rankingGame, 5, 7, 5, EndRaiseMode.doubleBlinds, 0, 50, gameName, l, 10, 0, 11, 10000);
sendMessage(createGameRequestMsg(
gameInfo,
NetGameTypeEnumType.EnumType.rankingGame,
5,
7,
"",
false));
// Game list update (new game)
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListNewMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
// Join game ack.
msg = receiveMessage();
if (msg.isJoinGameReplyMessageSelected()) {
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
fail("Could not create game!");
}
if (!msg.hasJoinGameAckMessage()) {
fail("Could not create game!");
}
else {
failOnErrorMessage(msg);
fail("Invalid message.");
}
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
int gameId = msg.getJoinGameAckMessage().getGameId();
// Game list update (player joined).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -99,8 +100,8 @@ public class RunRankingGameTest extends TestBase {
// Waiting for player list update.
do {
msg = receiveMessage(s[i]);
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
if (!msg.isPlayerListMessageSelected()) {
} while (msg.hasGameListNewMessage() || msg.hasGamePlayerJoinedMessage());
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -108,24 +109,24 @@ public class RunRankingGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isJoinGameReplyMessageSelected());
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
if (!msg.hasJoinGameAckMessage()) {
fail("User " + username + " could not join ranking game.");
}
// The player should have joined the game.
msg = receiveMessage();
if (!msg.isPlayerListMessageSelected()) {
if (!msg.hasPlayerListMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGamePlayerMessageSelected()) {
if (!msg.hasGamePlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListPlayerJoinedMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -133,7 +134,7 @@ public class RunRankingGameTest extends TestBase {
// Server should automatically send start event.
msg = receiveMessage();
if (!msg.isStartEventMessageSelected()) {
if (!msg.hasStartEventMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
@@ -141,15 +142,16 @@ public class RunRankingGameTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
} while (!msg.hasStartEventMessage());
}
// Acknowledge start event.
StartEventAckMessageSequenceType startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
StartEventAckMessage startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
.setGameId(gameId)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
.setStartEventAckMessage(startAck)
.build();
sendMessage(msg);
for (int i = 0; i < 9; i++) {
sendMessage(msg, s[i]);
@@ -157,27 +159,27 @@ public class RunRankingGameTest extends TestBase {
// Game list update (game now running).
msg = receiveMessage();
if (!msg.isGameListMessageSelected()) {
if (!msg.hasGameListUpdateMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
msg = receiveMessage();
if (!msg.isGameStartMessageSelected()) {
if (!msg.hasGameStartInitialMessage()) {
failOnErrorMessage(msg);
fail("Invalid message.");
}
long handNum = 0;
long lastPlayerMoney = 0;
int handNum = 0;
int lastPlayerMoney = 0;
do {
msg = receiveMessage();
failOnErrorMessage(msg);
if (msg.isHandStartMessageSelected()) {
if (msg.hasHandStartMessage()) {
handNum++;
// Cards should be encrypted for registered users.
assertTrue(msg.getHandStartMessage().getValue().getYourCards().isEncryptedCardsSelected());
byte[] encData = msg.getHandStartMessage().getValue().getYourCards().getEncryptedCards().getCardData();
assertTrue(msg.getHandStartMessage().hasEncryptedCards());
byte[] encData = msg.getHandStartMessage().getEncryptedCards().toByteArray();
byte[] cardData = decryptCards(AuthPassword, encData);
int size = cardData.length;
while (size > 0 && cardData[size-1] == 0) {
@@ -199,20 +201,19 @@ public class RunRankingGameTest extends TestBase {
assertTrue(card2 < 52);
assertTrue(card2 >= 0);
}
else if (msg.isPlayersTurnMessageSelected()) {
if (msg.getPlayersTurnMessage().getValue().getPlayerId().getValue() == firstPlayerId) {
NetPlayerAction action = new NetPlayerAction();
action.setValue(NetPlayerAction.EnumType.actionAllIn);
MyActionRequestMessageSequenceType myRequest = new MyActionRequestMessageSequenceType();
myRequest.setGameId(new NonZeroId(gameId));
myRequest.setGameState(msg.getPlayersTurnMessage().getValue().getGameState());
myRequest.setHandNum(new NonZeroId(handNum));
myRequest.setMyAction(action);
myRequest.setMyRelativeBet(new AmountOfMoney(0));
MyActionRequestMessage myAction = new MyActionRequestMessage();
myAction.setValue(myRequest);
PokerTHMessage outMsg = new PokerTHMessage();
outMsg.selectMyActionRequestMessage(myAction);
else if (msg.hasPlayersTurnMessage()) {
if (msg.getPlayersTurnMessage().getPlayerId() == firstPlayerId) {
MyActionRequestMessage myRequest = MyActionRequestMessage.newBuilder()
.setGameId(gameId)
.setGameState(msg.getPlayersTurnMessage().getGameState())
.setHandNum(handNum)
.setMyAction(NetPlayerAction.actionAllIn)
.setMyRelativeBet(0)
.build();
PokerTHMessage outMsg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_MyActionRequestMessage)
.setMyActionRequestMessage(myRequest)
.build();
sendMessage(outMsg);
}
}
@@ -220,43 +221,41 @@ public class RunRankingGameTest extends TestBase {
while (s[i].getInputStream().available() > 0) {
PokerTHMessage inMsg = receiveMessage(s[i]);
failOnErrorMessage(inMsg);
if (inMsg.isPlayersTurnMessageSelected()) {
if (inMsg.getPlayersTurnMessage().getValue().getPlayerId().getValue() == playerId[i]) {
NetPlayerAction action = new NetPlayerAction();
action.setValue(NetPlayerAction.EnumType.actionFold);
MyActionRequestMessageSequenceType myRequest = new MyActionRequestMessageSequenceType();
myRequest.setGameId(new NonZeroId(gameId));
myRequest.setGameState(inMsg.getPlayersTurnMessage().getValue().getGameState());
myRequest.setHandNum(new NonZeroId(handNum));
myRequest.setMyAction(action);
myRequest.setMyRelativeBet(new AmountOfMoney(0));
MyActionRequestMessage myAction = new MyActionRequestMessage();
myAction.setValue(myRequest);
PokerTHMessage outMsg = new PokerTHMessage();
outMsg.selectMyActionRequestMessage(myAction);
if (inMsg.hasPlayersTurnMessage()) {
if (inMsg.getPlayersTurnMessage().getPlayerId() == playerId[i]) {
MyActionRequestMessage myRequest = MyActionRequestMessage.newBuilder()
.setGameId(gameId)
.setGameState(inMsg.getPlayersTurnMessage().getGameState())
.setHandNum(handNum)
.setMyAction(NetPlayerAction.actionFold)
.setMyRelativeBet(0)
.build();
PokerTHMessage outMsg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_MyActionRequestMessage)
.setMyActionRequestMessage(myRequest)
.build();
sendMessage(outMsg, s[i]);
}
}
else if (inMsg.isEndOfHandMessageSelected()) {
if (inMsg.getEndOfHandMessage().getValue().getEndOfHandType().isEndOfHandHideCardsSelected()) {
lastPlayerMoney = inMsg.getEndOfHandMessage().getValue().getEndOfHandType().getEndOfHandHideCards().getPlayerMoney().getValue();
} else if (inMsg.getEndOfHandMessage().getValue().getEndOfHandType().isEndOfHandShowCardsSelected()) {
Collection<PlayerResult> result = inMsg.getEndOfHandMessage().getValue().getEndOfHandType().getEndOfHandShowCards().getPlayerResults();
assertFalse(result.isEmpty());
long maxPlayerMoney = 0;
for (Iterator<PlayerResult> it = result.iterator(); it.hasNext(); ) {
PlayerResult r = it.next();
long curMoney = r.getPlayerMoney().getValue();
if (curMoney > maxPlayerMoney) {
maxPlayerMoney = curMoney;
}
else if (inMsg.hasEndOfHandHideCardsMessage()) {
lastPlayerMoney = inMsg.getEndOfHandHideCardsMessage().getPlayerMoney();
} else if (inMsg.hasEndOfHandShowCardsMessage()) {
Collection<PlayerResult> result = inMsg.getEndOfHandShowCardsMessage().getPlayerResultsList();
assertFalse(result.isEmpty());
int maxPlayerMoney = 0;
for (Iterator<PlayerResult> it = result.iterator(); it.hasNext(); ) {
PlayerResult r = it.next();
int curMoney = r.getPlayerMoney();
if (curMoney > maxPlayerMoney) {
maxPlayerMoney = curMoney;
}
lastPlayerMoney = maxPlayerMoney;
}
lastPlayerMoney = maxPlayerMoney;
}
}
}
} while (!msg.isEndOfGameMessageSelected());
} while (!msg.hasEndOfGameMessage());
for (int i = 0; i < 9; i++) {
s[i].close();
+33 -30
View File
@@ -31,7 +31,10 @@ import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
import de.pokerth.protocol.ProtoBuf.NetPlayerState;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
import de.pokerth.protocol.ProtoBuf.StartEventAckMessage;
public class SeatStateTest extends TestBase {
@@ -53,15 +56,15 @@ public class SeatStateTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isJoinGameReplyMessageSelected());
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
if (!msg.hasJoinGameAckMessage()) {
fail("Could not create game!");
}
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
int gameId = msg.getJoinGameAckMessage().getGameId();
// Let 9 additional clients join.
Socket s[] = new Socket[9];
long playerId[] = new long[9];
int playerId[] = new int[9];
for (int i = 0; i < 9; i++) {
s[i] = new Socket("localhost", 7234);
String username = "test" + (i+1);
@@ -71,8 +74,8 @@ public class SeatStateTest extends TestBase {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isJoinGameReplyMessageSelected());
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
if (!msg.hasJoinGameAckMessage()) {
fail("Could not join game!");
}
}
@@ -81,20 +84,21 @@ public class SeatStateTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
} while (!msg.hasStartEventMessage());
for (int i = 0; i < 9; i++) {
do {
msg = receiveMessage(s[i]);
failOnErrorMessage(msg);
} while (!msg.isStartEventMessageSelected());
} while (!msg.hasStartEventMessage());
}
// Acknowledge start event.
StartEventAckMessageSequenceType startType = new StartEventAckMessageSequenceType();
startType.setGameId(new NonZeroId(gameId));
StartEventAckMessage startAck = new StartEventAckMessage();
startAck.setValue(startType);
msg = new PokerTHMessage();
msg.selectStartEventAckMessage(startAck);
StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
.setGameId(gameId)
.build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
.setStartEventAckMessage(startAck)
.build();
sendMessage(msg);
for (int i = 0; i < 9; i++) {
sendMessage(msg, s[i]);
@@ -104,15 +108,14 @@ public class SeatStateTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isGameStartMessageSelected());
assertEquals(gameId, msg.getGameStartMessage().getValue().getGameId().getValue().longValue());
assertTrue(msg.getGameStartMessage().getValue().getGameStartMode().isGameStartModeInitialSelected());
Collection<NonZeroId> seats = msg.getGameStartMessage().getValue().getGameStartMode().getGameStartModeInitial().getPlayerSeats();
} while (!msg.hasGameStartInitialMessage());
assertEquals(gameId, msg.getGameStartInitialMessage().getGameId());
Collection<Integer> seats = msg.getGameStartInitialMessage().getPlayerSeatsList();
assertEquals(10, seats.size());
int firstPlayerPos = 0;
for (Iterator<NonZeroId> it = seats.iterator(); it.hasNext(); ) {
NonZeroId seat = it.next();
if (seat.getValue().longValue() == firstPlayerId)
for (Iterator<Integer> it = seats.iterator(); it.hasNext(); ) {
int seat = it.next();
if (seat == firstPlayerId)
break;
firstPlayerPos++;
}
@@ -121,14 +124,14 @@ public class SeatStateTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
} while (!msg.isHandStartMessageSelected());
Collection<NetPlayerState> seatStates = msg.getHandStartMessage().getValue().getSeatStates();
} while (!msg.hasHandStartMessage());
Collection<NetPlayerState> seatStates = msg.getHandStartMessage().getSeatStatesList();
// Check whether the correct default seat states are sent.
assertEquals(10, seatStates.size());
for (Iterator<NetPlayerState> it = seatStates.iterator(); it.hasNext(); ) {
NetPlayerState state = it.next();
assertEquals(NetPlayerState.EnumType.playerStateNormal, state.getValue());
assertEquals(NetPlayerState.playerStateNormal, state);
}
// All other players leave (and are in autofold state then).
for (int i = 0; i < 9; i++) {
@@ -138,9 +141,9 @@ public class SeatStateTest extends TestBase {
do {
msg = receiveMessage();
failOnErrorMessage(msg);
assertTrue(!msg.isEndOfGameMessageSelected());
} while (!msg.isHandStartMessageSelected());
seatStates = msg.getHandStartMessage().getValue().getSeatStates();
assertTrue(!msg.hasEndOfGameMessage());
} while (!msg.hasHandStartMessage());
seatStates = msg.getHandStartMessage().getSeatStatesList();
// Check whether the correct seat states are sent.
assertEquals(10, seatStates.size());
@@ -149,12 +152,12 @@ public class SeatStateTest extends TestBase {
int seatPos = 0;
for (Iterator<NetPlayerState> it = seatStates.iterator(); it.hasNext(); ) {
NetPlayerState state = it.next();
assertTrue(NetPlayerState.EnumType.playerStateNoMoney != state.getValue());
if (NetPlayerState.EnumType.playerStateNormal == state.getValue()) {
assertTrue(NetPlayerState.playerStateNoMoney != state);
if (NetPlayerState.playerStateNormal == state) {
assertEquals(firstPlayerPos, seatPos);
stateNormalCounter++;
}
if (NetPlayerState.EnumType.playerStateSessionInactive == state.getValue()) {
if (NetPlayerState.playerStateSessionInactive == state) {
stateInactiveCounter++;
}
seatPos++;
+19 -18
View File
@@ -50,6 +50,7 @@ import de.pokerth.protocol.ProtoBuf.JoinNewGameMessage;
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
import de.pokerth.protocol.ProtoBuf.RejoinExistingGameMessage;
public abstract class TestBase {
@@ -192,7 +193,11 @@ public abstract class TestBase {
return userInit(s, user, password, null, null);
}
public int userInit(Socket s, String user, String password, byte[] avatarData, byte[] lastSessionId) throws Exception {
public class Guid {
public byte[] value;
}
public int userInit(Socket s, String user, String password, byte[] avatarData, Guid lastSessionId) throws Exception {
int playerId = 0;
PokerTHMessage msg = receiveMessage(s);
AnnounceMessage announce = msg.getAnnounceMessage();
@@ -214,8 +219,8 @@ public abstract class TestBase {
if (avatarData != null) {
initBuilder.setAvatarHash(ByteString.copyFrom(avatarData));
}
if (lastSessionId != null) {
initBuilder.setMyLastSessionId(ByteString.copyFrom(lastSessionId));
if (lastSessionId != null && lastSessionId.value != null) {
initBuilder.setMyLastSessionId(ByteString.copyFrom(lastSessionId.value));
}
InitMessage init = initBuilder.build();
msg = PokerTHMessage.newBuilder()
@@ -251,7 +256,7 @@ public abstract class TestBase {
assertTrue(!initAck.hasYourAvatarHash());
playerId = initAck.getYourPlayerId();
if (lastSessionId != null) {
lastSessionId = initAck.getYourSessionId().toByteArray();
lastSessionId.value = initAck.getYourSessionId().toByteArray();
}
if (initAck.hasRejoinGameId()) {
lastRejoinGameId = initAck.getRejoinGameId();
@@ -299,22 +304,18 @@ public abstract class TestBase {
return msg;
}
/* public PokerTHMessage rejoinGameRequestMsg(long gameId, boolean autoLeave) {
RejoinExistingGame rejoinExisting = new RejoinExistingGame();
rejoinExisting.setGameId(new NonZeroId(gameId));
JoinGameActionChoiceType joinAction = new JoinGameActionChoiceType();
joinAction.selectRejoinExistingGame(rejoinExisting);
JoinGameRequestMessageSequenceType joinType = new JoinGameRequestMessageSequenceType();
joinType.setJoinGameAction(joinAction);
joinType.setAutoLeave(autoLeave);
public PokerTHMessage rejoinGameRequestMsg(int gameId, boolean autoLeave) {
RejoinExistingGameMessage rejoinRequest = RejoinExistingGameMessage.newBuilder()
.setGameId(gameId)
.setAutoLeave(autoLeave)
.build();
JoinGameRequestMessage joinRequest = new JoinGameRequestMessage();
joinRequest.setValue(joinType);
PokerTHMessage msg = new PokerTHMessage();
msg.selectJoinGameRequestMessage(joinRequest);
PokerTHMessage msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_RejoinExistingGameMessage)
.setRejoinExistingGameMessage(rejoinRequest)
.build();
return msg;
}*/
}
public NetGameInfo createGameInfo(NetGameInfo.NetGameType gameType, int playerActionTimeout, int proposedGuiSpeed, int delayBetweenHands, NetGameInfo.EndRaiseMode endMode, int endRaiseValue, int sb,
String gameName, Collection<Integer> manualBlinds, int maxNumPlayers, int raiseEveryMinutes, int raiseEveryHands, int startMoney) {