More work on tests.
This commit is contained in:
+3
-3
@@ -59,9 +59,9 @@ enum PlayerInfoRights {
|
||||
}
|
||||
|
||||
enum NetAvatarType {
|
||||
avatarImagePng = 0;
|
||||
avatarImageJpg = 1;
|
||||
avatarImageGif = 2;
|
||||
avatarImagePng = 1;
|
||||
avatarImageJpg = 2;
|
||||
avatarImageGif = 3;
|
||||
}
|
||||
|
||||
// Message part containing game information.
|
||||
|
||||
+7
-7
@@ -2598,8 +2598,8 @@ void protobuf_AddDesc_pokerth_2eproto() {
|
||||
"*X\n\020PlayerInfoRights\022\025\n\021playerRightsGues"
|
||||
"t\020\001\022\026\n\022playerRightsNormal\020\002\022\025\n\021playerRig"
|
||||
"htsAdmin\020\003*K\n\rNetAvatarType\022\022\n\016avatarIma"
|
||||
"gePng\020\000\022\022\n\016avatarImageJpg\020\001\022\022\n\016avatarIma"
|
||||
"geGif\020\002", 17727);
|
||||
"gePng\020\001\022\022\n\016avatarImageJpg\020\002\022\022\n\016avatarIma"
|
||||
"geGif\020\003B\037\n\023de.pokerth.protocolB\010ProtoBuf", 17760);
|
||||
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
|
||||
"pokerth.proto", &protobuf_RegisterTypes);
|
||||
NetGameInfo::default_instance_ = new NetGameInfo();
|
||||
@@ -2866,9 +2866,9 @@ const ::google::protobuf::EnumDescriptor* NetAvatarType_descriptor() {
|
||||
}
|
||||
bool NetAvatarType_IsValid(int value) {
|
||||
switch(value) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -6727,7 +6727,7 @@ AvatarHeaderMessage::AvatarHeaderMessage(const AvatarHeaderMessage& from)
|
||||
void AvatarHeaderMessage::SharedCtor() {
|
||||
_cached_size_ = 0;
|
||||
requestid_ = 0u;
|
||||
avatartype_ = 0;
|
||||
avatartype_ = 1;
|
||||
avatarsize_ = 0u;
|
||||
::memset(_has_bits_, 0, sizeof(_has_bits_));
|
||||
}
|
||||
@@ -6764,7 +6764,7 @@ AvatarHeaderMessage* AvatarHeaderMessage::New() const {
|
||||
void AvatarHeaderMessage::Clear() {
|
||||
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
|
||||
requestid_ = 0u;
|
||||
avatartype_ = 0;
|
||||
avatartype_ = 1;
|
||||
avatarsize_ = 0u;
|
||||
}
|
||||
::memset(_has_bits_, 0, sizeof(_has_bits_));
|
||||
@@ -9616,7 +9616,7 @@ PlayerInfoReplyMessage_PlayerInfoData_AvatarData::PlayerInfoReplyMessage_PlayerI
|
||||
|
||||
void PlayerInfoReplyMessage_PlayerInfoData_AvatarData::SharedCtor() {
|
||||
_cached_size_ = 0;
|
||||
avatartype_ = 0;
|
||||
avatartype_ = 1;
|
||||
avatarhash_ = const_cast< ::std::string*>(&::google::protobuf::internal::kEmptyString);
|
||||
::memset(_has_bits_, 0, sizeof(_has_bits_));
|
||||
}
|
||||
@@ -9655,7 +9655,7 @@ PlayerInfoReplyMessage_PlayerInfoData_AvatarData* PlayerInfoReplyMessage_PlayerI
|
||||
|
||||
void PlayerInfoReplyMessage_PlayerInfoData_AvatarData::Clear() {
|
||||
if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) {
|
||||
avatartype_ = 0;
|
||||
avatartype_ = 1;
|
||||
if (has_avatarhash()) {
|
||||
if (avatarhash_ != &::google::protobuf::internal::kEmptyString) {
|
||||
avatarhash_->clear();
|
||||
|
||||
+5
-5
@@ -774,9 +774,9 @@ inline bool PlayerInfoRights_Parse(
|
||||
PlayerInfoRights_descriptor(), name, value);
|
||||
}
|
||||
enum NetAvatarType {
|
||||
avatarImagePng = 0,
|
||||
avatarImageJpg = 1,
|
||||
avatarImageGif = 2
|
||||
avatarImagePng = 1,
|
||||
avatarImageJpg = 2,
|
||||
avatarImageGif = 3
|
||||
};
|
||||
bool NetAvatarType_IsValid(int value);
|
||||
const NetAvatarType NetAvatarType_MIN = avatarImagePng;
|
||||
@@ -12232,7 +12232,7 @@ inline void AvatarHeaderMessage::clear_has_avatartype() {
|
||||
_has_bits_[0] &= ~0x00000002u;
|
||||
}
|
||||
inline void AvatarHeaderMessage::clear_avatartype() {
|
||||
avatartype_ = 0;
|
||||
avatartype_ = 1;
|
||||
clear_has_avatartype();
|
||||
}
|
||||
inline NetAvatarType AvatarHeaderMessage::avatartype() const {
|
||||
@@ -12832,7 +12832,7 @@ inline void PlayerInfoReplyMessage_PlayerInfoData_AvatarData::clear_has_avatarty
|
||||
_has_bits_[0] &= ~0x00000001u;
|
||||
}
|
||||
inline void PlayerInfoReplyMessage_PlayerInfoData_AvatarData::clear_avatartype() {
|
||||
avatartype_ = 0;
|
||||
avatartype_ = 1;
|
||||
clear_has_avatartype();
|
||||
}
|
||||
inline NetAvatarType PlayerInfoReplyMessage_PlayerInfoData_AvatarData::avatartype() const {
|
||||
|
||||
@@ -391,23 +391,23 @@ public final class ProtoBuf {
|
||||
|
||||
public enum NetAvatarType
|
||||
implements com.google.protobuf.ProtocolMessageEnum {
|
||||
avatarImagePng(0, 0),
|
||||
avatarImageJpg(1, 1),
|
||||
avatarImageGif(2, 2),
|
||||
avatarImagePng(0, 1),
|
||||
avatarImageJpg(1, 2),
|
||||
avatarImageGif(2, 3),
|
||||
;
|
||||
|
||||
public static final int avatarImagePng_VALUE = 0;
|
||||
public static final int avatarImageJpg_VALUE = 1;
|
||||
public static final int avatarImageGif_VALUE = 2;
|
||||
public static final int avatarImagePng_VALUE = 1;
|
||||
public static final int avatarImageJpg_VALUE = 2;
|
||||
public static final int avatarImageGif_VALUE = 3;
|
||||
|
||||
|
||||
public final int getNumber() { return value; }
|
||||
|
||||
public static NetAvatarType valueOf(int value) {
|
||||
switch (value) {
|
||||
case 0: return avatarImagePng;
|
||||
case 1: return avatarImageJpg;
|
||||
case 2: return avatarImageGif;
|
||||
case 1: return avatarImagePng;
|
||||
case 2: return avatarImageJpg;
|
||||
case 3: return avatarImageGif;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
@@ -55550,8 +55550,8 @@ public final class ProtoBuf {
|
||||
"*X\n\020PlayerInfoRights\022\025\n\021playerRightsGues",
|
||||
"t\020\001\022\026\n\022playerRightsNormal\020\002\022\025\n\021playerRig" +
|
||||
"htsAdmin\020\003*K\n\rNetAvatarType\022\022\n\016avatarIma" +
|
||||
"gePng\020\000\022\022\n\016avatarImageJpg\020\001\022\022\n\016avatarIma" +
|
||||
"geGif\020\002B\037\n\023de.pokerth.protocolB\010ProtoBuf"
|
||||
"gePng\020\001\022\022\n\016avatarImageJpg\020\002\022\022\n\016avatarIma" +
|
||||
"geGif\020\003B\037\n\023de.pokerth.protocolB\010ProtoBuf"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
|
||||
@@ -26,6 +26,14 @@ import java.util.Collection;
|
||||
|
||||
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.PokerTHMessage.PokerTHMessageType;
|
||||
import de.pokerth.protocol.ProtoBuf.MyActionRequestMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.NetPlayerAction;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
|
||||
|
||||
|
||||
public class LoadTest extends TestBase {
|
||||
|
||||
@@ -39,8 +47,8 @@ public class LoadTest extends TestBase {
|
||||
|
||||
// We need a lot of sockets and player ids.
|
||||
Socket s[] = new Socket[NumGames * 10];
|
||||
long playerId[] = new long[NumGames * 10];
|
||||
long gameId[] = new long[NumGames];
|
||||
int playerId[] = new int[NumGames * 10];
|
||||
int gameId[] = new int[NumGames];
|
||||
|
||||
PokerTHMessage msg;
|
||||
// First players are game admins.
|
||||
@@ -53,20 +61,17 @@ public class LoadTest extends TestBase {
|
||||
|
||||
do {
|
||||
msg = receiveMessage(s[i * 10]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
|
||||
if (!msg.hasPlayerListMessage()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
Collection<Integer> l = new ArrayList<Integer>();
|
||||
String gameName = AuthUser + " load game " + i;
|
||||
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 200, gameName, l, 10, 0, 1, 10000);
|
||||
NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 5, 7, 5, EndRaiseMode.doubleBlinds, 0, 200, gameName, l, 10, 0, 1, 10000);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
NetGameTypeEnumType.EnumType.normalGame,
|
||||
5,
|
||||
7,
|
||||
"",
|
||||
false),
|
||||
s[i * 10]);
|
||||
@@ -75,19 +80,14 @@ public class LoadTest extends TestBase {
|
||||
do {
|
||||
msg = receiveMessage(s[i * 10]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (msg.isGameListMessageSelected() || msg.isPlayerListMessageSelected());
|
||||
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasPlayerListMessage());
|
||||
|
||||
// Join game ack.
|
||||
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!");
|
||||
}
|
||||
gameId[i] = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
gameId[i] = msg.getJoinGameAckMessage().getGameId();
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ public class LoadTest extends TestBase {
|
||||
// Waiting for player list update.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
} while (msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage());
|
||||
if (!msg.hasPlayerListMessage()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
@@ -112,40 +112,39 @@ public class LoadTest extends TestBase {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("User " + username + " could not join ranking game.");
|
||||
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
|
||||
if (!msg.hasJoinGameAckMessage()) {
|
||||
fail("User " + username + " could not join normal game.");
|
||||
}
|
||||
}
|
||||
|
||||
boolean abort = false;
|
||||
long handNum = 0;
|
||||
int handNum[] = new int[NumGames];
|
||||
do {
|
||||
for (int i = 0; i < NumGames * 10; i++) {
|
||||
while (s[i].getInputStream().available() > 0) {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
if (msg.isHandStartMessageSelected()) {
|
||||
handNum++;
|
||||
if (msg.hasHandStartMessage()) {
|
||||
handNum[i / 10]++;
|
||||
}
|
||||
else if (msg.isPlayersTurnMessageSelected()) {
|
||||
if (msg.getPlayersTurnMessage().getValue().getPlayerId().getValue() == playerId[i / 10]) {
|
||||
NetPlayerAction action = new NetPlayerAction();
|
||||
action.setValue(NetPlayerAction.EnumType.actionAllIn);
|
||||
MyActionRequestMessageSequenceType myRequest = new MyActionRequestMessageSequenceType();
|
||||
myRequest.setGameId(new NonZeroId(gameId[i / 10]));
|
||||
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() == playerId[i / 10]) {
|
||||
MyActionRequestMessage myRequest = MyActionRequestMessage.newBuilder()
|
||||
.setGameId(gameId[i / 10])
|
||||
.setGameState(msg.getPlayersTurnMessage().getGameState())
|
||||
.setHandNum(handNum[i / 10])
|
||||
.setMyAction(NetPlayerAction.actionAllIn)
|
||||
.setMyRelativeBet(0)
|
||||
.build();
|
||||
PokerTHMessage outMsg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_MyActionRequestMessage)
|
||||
.setMyActionRequestMessage(myRequest)
|
||||
.build();
|
||||
sendMessage(outMsg, s[i]);
|
||||
}
|
||||
}
|
||||
else if (msg.isEndOfGameMessageSelected()) {
|
||||
else if (msg.hasEndOfGameMessage()) {
|
||||
abort = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,14 @@ import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
|
||||
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.SubscriptionRequestMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
|
||||
import de.pokerth.protocol.ProtoBuf.SubscriptionRequestMessage.SubscriptionAction;
|
||||
|
||||
|
||||
public class LobbySubscriptionTest extends TestBase {
|
||||
|
||||
@@ -35,38 +43,33 @@ public class LobbySubscriptionTest extends TestBase {
|
||||
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
if (!msg.hasPlayerListMessage()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
SubscriptionRequestMessageSequenceType subscriptionType = new SubscriptionRequestMessageSequenceType();
|
||||
SubscriptionActionEnumType action = new SubscriptionActionEnumType();
|
||||
action.setValue(SubscriptionActionEnumType.EnumType.unsubscribeGameList);
|
||||
subscriptionType.setSubscriptionAction(action);
|
||||
SubscriptionRequestMessage subscriptionRequest = new SubscriptionRequestMessage();
|
||||
subscriptionRequest.setValue(subscriptionType);
|
||||
msg = new PokerTHMessage();
|
||||
msg.selectSubscriptionRequestMessage(subscriptionRequest);
|
||||
SubscriptionRequestMessage subscriptionRequest = SubscriptionRequestMessage.newBuilder()
|
||||
.setSubscriptionAction(SubscriptionAction.unsubscribeGameList)
|
||||
.build();
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_SubscriptionRequestMessage)
|
||||
.setSubscriptionRequestMessage(subscriptionRequest)
|
||||
.build();
|
||||
sendMessage(msg);
|
||||
|
||||
// Create a new game.
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 100, GuestUser + " game list 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 + " game list normal game", l, 10, 0, 2, 2000);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
NetGameTypeEnumType.EnumType.normalGame,
|
||||
10,
|
||||
5,
|
||||
"",
|
||||
false));
|
||||
|
||||
// No game list message should be sent by the server.
|
||||
// Next message is join game ack.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isJoinGameReplyMessageSelected());
|
||||
assertTrue(msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected());
|
||||
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue().longValue();
|
||||
assertTrue(msg.hasJoinGameAckMessage());
|
||||
int gameId = msg.getJoinGameAckMessage().getGameId();
|
||||
|
||||
Socket s[] = new Socket[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
@@ -80,30 +83,29 @@ public class LobbySubscriptionTest extends TestBase {
|
||||
// No game list message should be received.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
if (msg.isGameListMessageSelected() || msg.isPlayerListMessageSelected()) {
|
||||
if (msg.hasGameListNewMessage() || msg.hasPlayerListMessage()) {
|
||||
fail("Game/player list messages are switched off!");
|
||||
}
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
} while (!msg.hasStartEventMessage());
|
||||
|
||||
// Resubscribe game list
|
||||
subscriptionType = new SubscriptionRequestMessageSequenceType();
|
||||
action = new SubscriptionActionEnumType();
|
||||
action.setValue(SubscriptionActionEnumType.EnumType.resubscribeGameList);
|
||||
subscriptionType.setSubscriptionAction(action);
|
||||
subscriptionRequest = new SubscriptionRequestMessage();
|
||||
subscriptionRequest.setValue(subscriptionType);
|
||||
msg = new PokerTHMessage();
|
||||
msg.selectSubscriptionRequestMessage(subscriptionRequest);
|
||||
subscriptionRequest = SubscriptionRequestMessage.newBuilder()
|
||||
.setSubscriptionAction(SubscriptionAction.resubscribeGameList)
|
||||
.build();
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_SubscriptionRequestMessage)
|
||||
.setSubscriptionRequestMessage(subscriptionRequest)
|
||||
.build();
|
||||
sendMessage(msg);
|
||||
|
||||
// Next messages should player list messages for all 10 players.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.hasPlayerListMessage());
|
||||
}
|
||||
// Now there should be one game list message.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isGameListMessageSelected());
|
||||
assertTrue(msg.hasGameListNewMessage());
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
|
||||
@@ -25,22 +25,31 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.pokerth.protocol.ProtoBuf.NetAvatarType;
|
||||
import de.pokerth.protocol.ProtoBuf.PlayerInfoReplyMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.PlayerInfoReplyMessage.PlayerInfoData;
|
||||
import de.pokerth.protocol.ProtoBuf.PlayerInfoRequestMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.PlayerInfoRights;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
|
||||
|
||||
public class PlayerInfoTest extends TestBase {
|
||||
|
||||
protected void sendPlayerInfoRequest(Socket s, long playerId) throws Exception {
|
||||
PlayerInfoRequestMessageSequenceType type = new PlayerInfoRequestMessageSequenceType();
|
||||
type.setPlayerId(new NonZeroId(playerId));
|
||||
PlayerInfoRequestMessage request = new PlayerInfoRequestMessage();
|
||||
request.setValue(type);
|
||||
PokerTHMessage msg = new PokerTHMessage();
|
||||
msg.selectPlayerInfoRequestMessage(request);
|
||||
protected void sendPlayerInfoRequest(Socket s, int playerId) throws Exception {
|
||||
PlayerInfoRequestMessage request = PlayerInfoRequestMessage.newBuilder()
|
||||
.setPlayerId(playerId)
|
||||
.build();
|
||||
PokerTHMessage msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_PlayerInfoRequestMessage)
|
||||
.setPlayerInfoRequestMessage(request)
|
||||
.build();
|
||||
sendMessage(msg, s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerInfoRequest() throws Exception {
|
||||
|
||||
long firstPlayerId = guestInit();
|
||||
int firstPlayerId = guestInit();
|
||||
byte[] avatarHash =
|
||||
{
|
||||
// one of the builtin avatars.
|
||||
@@ -52,8 +61,8 @@ public class PlayerInfoTest extends TestBase {
|
||||
|
||||
// Let 9 additional clients join.
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
long maxPlayerId = 0;
|
||||
int playerId[] = new int[9];
|
||||
int maxPlayerId = 0;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
@@ -75,48 +84,49 @@ public class PlayerInfoTest extends TestBase {
|
||||
sendPlayerInfoRequest(s[i], firstPlayerId);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.isPlayerInfoReplyMessageSelected());
|
||||
} while (msg.hasPlayerListMessage());
|
||||
assertTrue(msg.hasPlayerInfoReplyMessage() && msg.getMessageType() == PokerTHMessageType.Type_PlayerInfoReplyMessage);
|
||||
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage();
|
||||
assertTrue(reply.getValue().getPlayerId().getValue() == firstPlayerId);
|
||||
assertTrue(reply.getValue().getPlayerInfoResult().isPlayerInfoDataSelected());
|
||||
PlayerInfoData info = reply.getValue().getPlayerInfoResult().getPlayerInfoData();
|
||||
assertTrue(reply.getPlayerId() == firstPlayerId);
|
||||
assertTrue(reply.hasPlayerInfoData());
|
||||
PlayerInfoData info = reply.getPlayerInfoData();
|
||||
assertEquals(GuestUser, info.getPlayerName());
|
||||
assertEquals(null, info.getCountryCode());
|
||||
assertFalse(info.hasCountryCode());
|
||||
assertTrue(info.getIsHuman());
|
||||
assertEquals(PlayerInfoRights.EnumType.playerRightsGuest, info.getPlayerRights().getValue());
|
||||
assertEquals(null, info.getAvatarData());
|
||||
assertEquals(PlayerInfoRights.playerRightsGuest, info.getPlayerRights());
|
||||
assertFalse(info.hasAvatarData());
|
||||
}
|
||||
// Request other players' info.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendPlayerInfoRequest(sock, playerId[i]);
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
} while (msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.isPlayerInfoReplyMessageSelected());
|
||||
} while (msg.hasPlayerListMessage());
|
||||
assertTrue(msg.hasPlayerInfoReplyMessage() && msg.getMessageType() == PokerTHMessageType.Type_PlayerInfoReplyMessage);
|
||||
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage();
|
||||
assertTrue(reply.getValue().getPlayerId().getValue() == playerId[i]);
|
||||
assertTrue(reply.getValue().getPlayerInfoResult().isPlayerInfoDataSelected());
|
||||
PlayerInfoData info = reply.getValue().getPlayerInfoResult().getPlayerInfoData();
|
||||
assertTrue(reply.getPlayerId() == playerId[i]);
|
||||
assertTrue(reply.hasPlayerInfoData());
|
||||
PlayerInfoData info = reply.getPlayerInfoData();
|
||||
assertEquals("test" + (i+1), info.getPlayerName());
|
||||
assertEquals(null, info.getCountryCode());
|
||||
assertFalse(info.hasCountryCode());
|
||||
assertTrue(info.getIsHuman());
|
||||
assertEquals(PlayerInfoRights.EnumType.playerRightsNormal, info.getPlayerRights().getValue());
|
||||
assertEquals(PlayerInfoRights.playerRightsNormal, info.getPlayerRights());
|
||||
// Every second player has an avatar, see above.
|
||||
if (i % 2 == 0) {
|
||||
assertEquals(null, info.getAvatarData());
|
||||
assertFalse(info.hasAvatarData());
|
||||
} else {
|
||||
assertTrue(Arrays.equals(info.getAvatarData().getAvatar().getValue(), avatarHash));
|
||||
assertEquals(NetAvatarType.EnumType.avatarImagePng, info.getAvatarData().getAvatarType().getValue());
|
||||
assertTrue(info.hasAvatarData());
|
||||
assertTrue(Arrays.equals(info.getAvatarData().getAvatarHash().toByteArray(), avatarHash));
|
||||
assertEquals(NetAvatarType.avatarImagePng, info.getAvatarData().getAvatarType());
|
||||
}
|
||||
}
|
||||
// Request invalid player info.
|
||||
sendPlayerInfoRequest(sock, maxPlayerId + 1);
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerInfoReplyMessageSelected());
|
||||
assertTrue(msg.hasPlayerInfoReplyMessage() && msg.getMessageType() == PokerTHMessageType.Type_PlayerInfoReplyMessage);
|
||||
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage();
|
||||
assertTrue(reply.getValue().getPlayerId().getValue() == maxPlayerId + 1);
|
||||
assertTrue(reply.getValue().getPlayerInfoResult().isUnknownPlayerInfoSelected());
|
||||
assertTrue(reply.getPlayerId() == maxPlayerId + 1);
|
||||
assertFalse(reply.hasPlayerInfoData());
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
|
||||
@@ -24,23 +24,27 @@ import java.net.Socket;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.pokerth.protocol.ProtoBuf.PlayerListMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.PlayerListMessage.PlayerListNotification;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
|
||||
|
||||
|
||||
public class PlayerListTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testPlayerList() throws Exception {
|
||||
|
||||
long myId = guestInit();
|
||||
int myId = guestInit();
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.hasPlayerListMessage());
|
||||
|
||||
// This should be a "player list new" notification with correct player id.
|
||||
PlayerListMessage listMsg = msg.getPlayerListMessage();
|
||||
assertEquals(myId, listMsg.getValue().getPlayerId().getValue().longValue());
|
||||
assertEquals(PlayerListNotificationEnumType.EnumType.playerListNew, listMsg.getValue().getPlayerListNotification().getValue());
|
||||
assertEquals(myId, listMsg.getPlayerId());
|
||||
assertEquals(PlayerListNotification.playerListNew, listMsg.getPlayerListNotification());
|
||||
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
@@ -51,22 +55,22 @@ public class PlayerListTest extends TestBase {
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.hasPlayerListMessage());
|
||||
listMsg = msg.getPlayerListMessage();
|
||||
// Id should be different from first id.
|
||||
assertTrue(myId != playerId[i]);
|
||||
// This should be a "player list new" notification with correct player id.
|
||||
assertEquals(playerId[i], listMsg.getValue().getPlayerId().getValue().longValue());
|
||||
assertEquals(PlayerListNotificationEnumType.EnumType.playerListNew, listMsg.getValue().getPlayerListNotification().getValue());
|
||||
assertEquals(playerId[i], listMsg.getPlayerId());
|
||||
assertEquals(PlayerListNotification.playerListNew, listMsg.getPlayerListNotification());
|
||||
|
||||
s[i].close();
|
||||
|
||||
// After the connection is closed, a "player list left" notification should be received.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.hasPlayerListMessage());
|
||||
listMsg = msg.getPlayerListMessage();
|
||||
assertEquals(playerId[i], listMsg.getValue().getPlayerId().getValue().longValue());
|
||||
assertEquals(PlayerListNotificationEnumType.EnumType.playerListLeft, listMsg.getValue().getPlayerListNotification().getValue());
|
||||
assertEquals(playerId[i], listMsg.getPlayerId());
|
||||
assertEquals(PlayerListNotification.playerListLeft, listMsg.getPlayerListNotification());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user