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