In the process of fixing the Java test cases for google protocol buffers.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,53 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import org.junit.internal.TextListener;
|
||||
import org.junit.runner.JUnitCore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses( {
|
||||
AnnounceTest.class,
|
||||
GuestLoginTest.class,
|
||||
AuthLoginTest.class,
|
||||
PlayerListTest.class,
|
||||
GameListTest.class,
|
||||
PlayerInfoTest.class,
|
||||
LobbySubscriptionTest.class,
|
||||
ChatTest.class,
|
||||
CreateGameTest.class,
|
||||
CreateRankingGameTest.class,
|
||||
StartNormalGameTest.class,
|
||||
RunNormalGameTest.class,
|
||||
BlockedPlayerTest.class,
|
||||
RunRankingGameTest.class,
|
||||
RejoinGameTest.class,
|
||||
RejoinMultiGameTest.class,
|
||||
SeatStateTest.class
|
||||
})
|
||||
public class AllTests {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
JUnitCore junit = new JUnitCore();
|
||||
junit.addListener(new TextListener(System.out));
|
||||
if (!junit.run(AllTests.class).wasSuccessful())
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.pokerth.protocol.ProtoBuf.AnnounceMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.AnnounceMessage.ServerType;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
|
||||
|
||||
|
||||
public class AnnounceTest extends TestBase {
|
||||
|
||||
protected void TestAnnounceMsg(AnnounceMessage announce, int numPlayersOnServer) {
|
||||
assertEquals(PROTOCOL_VERSION_MAJOR, announce.getProtocolVersion().getMajor());
|
||||
assertEquals(PROTOCOL_VERSION_MINOR, announce.getProtocolVersion().getMinor());
|
||||
assertEquals(ServerType.serverTypeInternetAuth, announce.getServerType());
|
||||
assertEquals(numPlayersOnServer, announce.getNumPlayersOnServer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnounce() throws Exception {
|
||||
|
||||
PokerTHMessage msg = receiveMessage();
|
||||
assertTrue(msg.hasAnnounceMessage() && msg.getMessageType() == PokerTHMessageType.Type_AnnounceMessage);
|
||||
TestAnnounceMsg(msg.getAnnounceMessage(), 0);
|
||||
|
||||
// numPlayersOnServer should only be incremented after login.
|
||||
Socket s[] = new Socket[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
msg = receiveMessage(s[i]);
|
||||
assertTrue(msg.hasAnnounceMessage() && msg.getMessageType() == PokerTHMessageType.Type_AnnounceMessage);
|
||||
// Without login: Counter stays at 0.
|
||||
TestAnnounceMsg(msg.getAnnounceMessage(), 0);
|
||||
}
|
||||
|
||||
Socket t[] = new Socket[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
t[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
userInit(t[i], username, password);
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.hasAnnounceMessage() && msg.getMessageType() == PokerTHMessageType.Type_AnnounceMessage);
|
||||
// After login: Counter is incremented.
|
||||
TestAnnounceMsg(msg.getAnnounceMessage(), i + 1);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
|
||||
// Closing non-established sessions: counter stays the same.
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.hasAnnounceMessage() && msg.getMessageType() == PokerTHMessageType.Type_AnnounceMessage);
|
||||
// After login: Counter is incremented.
|
||||
TestAnnounceMsg(msg.getAnnounceMessage(), 9);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
t[i].close();
|
||||
Thread.sleep(1000);
|
||||
|
||||
// Closing established sessions: counter is decremented.
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.hasAnnounceMessage() && msg.getMessageType() == PokerTHMessageType.Type_AnnounceMessage);
|
||||
// After login: Counter is incremented.
|
||||
TestAnnounceMsg(msg.getAnnounceMessage(), 8 - i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AuthLoginTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testAuthLogin() throws Exception {
|
||||
userInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
|
||||
//Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
|
||||
//www.source-code.biz, www.inventec.ch/chdh
|
||||
//
|
||||
//This module is multi-licensed and may be used under the terms
|
||||
//of any of the following licenses:
|
||||
//
|
||||
//EPL, Eclipse Public License, V1.0 or later, http://www.eclipse.org/legal
|
||||
//LGPL, GNU Lesser General Public License, V2.1 or later, http://www.gnu.org/licenses/lgpl.html
|
||||
//GPL, GNU General Public License, V2 or later, http://www.gnu.org/licenses/gpl.html
|
||||
//AL, Apache License, V2.0 or later, http://www.apache.org/licenses
|
||||
//BSD, BSD License, http://www.opensource.org/licenses/bsd-license.php
|
||||
//
|
||||
//Please contact the author if you need another license.
|
||||
//This module is provided "as is", without warranties of any kind.
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
/**
|
||||
* A Base64 encoder/decoder.
|
||||
*
|
||||
* <p>
|
||||
* This class is used to encode and decode data in Base64 format as described in RFC 1521.
|
||||
*
|
||||
* <p>
|
||||
* Project home page: <a href="http://www.source-code.biz/base64coder/java/">www.source-code.biz/base64coder/java</a><br>
|
||||
* Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland<br>
|
||||
* Multi-licensed: EPL / LGPL / GPL / AL / BSD.
|
||||
*/
|
||||
public class Base64Coder {
|
||||
|
||||
//The line separator string of the operating system.
|
||||
private static final String systemLineSeparator = System.getProperty("line.separator");
|
||||
|
||||
//Mapping table from 6-bit nibbles to Base64 characters.
|
||||
private static char[] map1 = new char[64];
|
||||
static {
|
||||
int i=0;
|
||||
for (char c='A'; c<='Z'; c++) map1[i++] = c;
|
||||
for (char c='a'; c<='z'; c++) map1[i++] = c;
|
||||
for (char c='0'; c<='9'; c++) map1[i++] = c;
|
||||
map1[i++] = '+'; map1[i++] = '/'; }
|
||||
|
||||
//Mapping table from Base64 characters to 6-bit nibbles.
|
||||
private static byte[] map2 = new byte[128];
|
||||
static {
|
||||
for (int i=0; i<map2.length; i++) map2[i] = -1;
|
||||
for (int i=0; i<64; i++) map2[map1[i]] = (byte)i; }
|
||||
|
||||
/**
|
||||
* Encodes a string into Base64 format.
|
||||
* No blanks or line breaks are inserted.
|
||||
* @param s A String to be encoded.
|
||||
* @return A String containing the Base64 encoded data.
|
||||
*/
|
||||
public static String encodeString (String s) {
|
||||
return new String(encode(s.getBytes())); }
|
||||
|
||||
/**
|
||||
* Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters.
|
||||
* This method is compatible with <code>sun.misc.BASE64Encoder.encodeBuffer(byte[])</code>.
|
||||
* @param in An array containing the data bytes to be encoded.
|
||||
* @return A String containing the Base64 encoded data, broken into lines.
|
||||
*/
|
||||
public static String encodeLines (byte[] in) {
|
||||
return encodeLines(in, 0, in.length, 76, systemLineSeparator); }
|
||||
|
||||
/**
|
||||
* Encodes a byte array into Base 64 format and breaks the output into lines.
|
||||
* @param in An array containing the data bytes to be encoded.
|
||||
* @param iOff Offset of the first byte in <code>in</code> to be processed.
|
||||
* @param iLen Number of bytes to be processed in <code>in</code>, starting at <code>iOff</code>.
|
||||
* @param lineLen Line length for the output data. Should be a multiple of 4.
|
||||
* @param lineSeparator The line separator to be used to separate the output lines.
|
||||
* @return A String containing the Base64 encoded data, broken into lines.
|
||||
*/
|
||||
public static String encodeLines (byte[] in, int iOff, int iLen, int lineLen, String lineSeparator) {
|
||||
int blockLen = (lineLen*3) / 4;
|
||||
if (blockLen <= 0) throw new IllegalArgumentException();
|
||||
int lines = (iLen+blockLen-1) / blockLen;
|
||||
int bufLen = ((iLen+2)/3)*4 + lines*lineSeparator.length();
|
||||
StringBuilder buf = new StringBuilder(bufLen);
|
||||
int ip = 0;
|
||||
while (ip < iLen) {
|
||||
int l = Math.min(iLen-ip, blockLen);
|
||||
buf.append (encode(in, iOff+ip, l));
|
||||
buf.append (lineSeparator);
|
||||
ip += l; }
|
||||
return buf.toString(); }
|
||||
|
||||
/**
|
||||
* Encodes a byte array into Base64 format.
|
||||
* No blanks or line breaks are inserted in the output.
|
||||
* @param in An array containing the data bytes to be encoded.
|
||||
* @return A character array containing the Base64 encoded data.
|
||||
*/
|
||||
public static char[] encode (byte[] in) {
|
||||
return encode(in, 0, in.length); }
|
||||
|
||||
/**
|
||||
* Encodes a byte array into Base64 format.
|
||||
* No blanks or line breaks are inserted in the output.
|
||||
* @param in An array containing the data bytes to be encoded.
|
||||
* @param iLen Number of bytes to process in <code>in</code>.
|
||||
* @return A character array containing the Base64 encoded data.
|
||||
*/
|
||||
public static char[] encode (byte[] in, int iLen) {
|
||||
return encode(in, 0, iLen); }
|
||||
|
||||
/**
|
||||
* Encodes a byte array into Base64 format.
|
||||
* No blanks or line breaks are inserted in the output.
|
||||
* @param in An array containing the data bytes to be encoded.
|
||||
* @param iOff Offset of the first byte in <code>in</code> to be processed.
|
||||
* @param iLen Number of bytes to process in <code>in</code>, starting at <code>iOff</code>.
|
||||
* @return A character array containing the Base64 encoded data.
|
||||
*/
|
||||
public static char[] encode (byte[] in, int iOff, int iLen) {
|
||||
int oDataLen = (iLen*4+2)/3; // output length without padding
|
||||
int oLen = ((iLen+2)/3)*4; // output length including padding
|
||||
char[] out = new char[oLen];
|
||||
int ip = iOff;
|
||||
int iEnd = iOff + iLen;
|
||||
int op = 0;
|
||||
while (ip < iEnd) {
|
||||
int i0 = in[ip++] & 0xff;
|
||||
int i1 = ip < iEnd ? in[ip++] & 0xff : 0;
|
||||
int i2 = ip < iEnd ? in[ip++] & 0xff : 0;
|
||||
int o0 = i0 >>> 2;
|
||||
int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
|
||||
int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
|
||||
int o3 = i2 & 0x3F;
|
||||
out[op++] = map1[o0];
|
||||
out[op++] = map1[o1];
|
||||
out[op] = op < oDataLen ? map1[o2] : '='; op++;
|
||||
out[op] = op < oDataLen ? map1[o3] : '='; op++; }
|
||||
return out; }
|
||||
|
||||
/**
|
||||
* Decodes a string from Base64 format.
|
||||
* No blanks or line breaks are allowed within the Base64 encoded input data.
|
||||
* @param s A Base64 String to be decoded.
|
||||
* @return A String containing the decoded data.
|
||||
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
|
||||
*/
|
||||
public static String decodeString (String s) {
|
||||
return new String(decode(s)); }
|
||||
|
||||
/**
|
||||
* Decodes a byte array from Base64 format and ignores line separators, tabs and blanks.
|
||||
* CR, LF, Tab and Space characters are ignored in the input data.
|
||||
* This method is compatible with <code>sun.misc.BASE64Decoder.decodeBuffer(String)</code>.
|
||||
* @param s A Base64 String to be decoded.
|
||||
* @return An array containing the decoded data bytes.
|
||||
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
|
||||
*/
|
||||
public static byte[] decodeLines (String s) {
|
||||
char[] buf = new char[s.length()];
|
||||
int p = 0;
|
||||
for (int ip = 0; ip < s.length(); ip++) {
|
||||
char c = s.charAt(ip);
|
||||
if (c != ' ' && c != '\r' && c != '\n' && c != '\t')
|
||||
buf[p++] = c; }
|
||||
return decode(buf, 0, p); }
|
||||
|
||||
/**
|
||||
* Decodes a byte array from Base64 format.
|
||||
* No blanks or line breaks are allowed within the Base64 encoded input data.
|
||||
* @param s A Base64 String to be decoded.
|
||||
* @return An array containing the decoded data bytes.
|
||||
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
|
||||
*/
|
||||
public static byte[] decode (String s) {
|
||||
return decode(s.toCharArray()); }
|
||||
|
||||
/**
|
||||
* Decodes a byte array from Base64 format.
|
||||
* No blanks or line breaks are allowed within the Base64 encoded input data.
|
||||
* @param in A character array containing the Base64 encoded data.
|
||||
* @return An array containing the decoded data bytes.
|
||||
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
|
||||
*/
|
||||
public static byte[] decode (char[] in) {
|
||||
return decode(in, 0, in.length); }
|
||||
|
||||
/**
|
||||
* Decodes a byte array from Base64 format.
|
||||
* No blanks or line breaks are allowed within the Base64 encoded input data.
|
||||
* @param in A character array containing the Base64 encoded data.
|
||||
* @param iOff Offset of the first character in <code>in</code> to be processed.
|
||||
* @param iLen Number of characters to process in <code>in</code>, starting at <code>iOff</code>.
|
||||
* @return An array containing the decoded data bytes.
|
||||
* @throws IllegalArgumentException If the input is not valid Base64 encoded data.
|
||||
*/
|
||||
public static byte[] decode (char[] in, int iOff, int iLen) {
|
||||
if (iLen%4 != 0) throw new IllegalArgumentException ("Length of Base64 encoded input string is not a multiple of 4.");
|
||||
while (iLen > 0 && in[iOff+iLen-1] == '=') iLen--;
|
||||
int oLen = (iLen*3) / 4;
|
||||
byte[] out = new byte[oLen];
|
||||
int ip = iOff;
|
||||
int iEnd = iOff + iLen;
|
||||
int op = 0;
|
||||
while (ip < iEnd) {
|
||||
int i0 = in[ip++];
|
||||
int i1 = in[ip++];
|
||||
int i2 = ip < iEnd ? in[ip++] : 'A';
|
||||
int i3 = ip < iEnd ? in[ip++] : 'A';
|
||||
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
|
||||
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
|
||||
int b0 = map2[i0];
|
||||
int b1 = map2[i1];
|
||||
int b2 = map2[i2];
|
||||
int b3 = map2[i3];
|
||||
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
|
||||
throw new IllegalArgumentException ("Illegal character in Base64 encoded data.");
|
||||
int o0 = ( b0 <<2) | (b1>>>4);
|
||||
int o1 = ((b1 & 0xf)<<4) | (b2>>>2);
|
||||
int o2 = ((b2 & 3)<<6) | b3;
|
||||
out[op++] = (byte)o0;
|
||||
if (op<oLen) out[op++] = (byte)o1;
|
||||
if (op<oLen) out[op++] = (byte)o2; }
|
||||
return out; }
|
||||
|
||||
//Dummy constructor.
|
||||
private Base64Coder() {}
|
||||
|
||||
} // end class Base64Coder
|
||||
@@ -0,0 +1,118 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import de.pokerth.protocol.ProtoBuf.AnnounceMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.ErrorMessage.ErrorReason;
|
||||
import de.pokerth.protocol.ProtoBuf.InitMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.AnnounceMessage.ServerType;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
|
||||
|
||||
|
||||
public class BlockedPlayerTest extends TestBase {
|
||||
|
||||
void verifyLoginBlocked() throws Exception {
|
||||
PokerTHMessage msg = receiveMessage(sock);
|
||||
AnnounceMessage announce = msg.getAnnounceMessage();
|
||||
assertTrue(announce.getServerType() == ServerType.serverTypeInternetAuth);
|
||||
|
||||
ScramSha1 scramAuth = new ScramSha1();
|
||||
|
||||
// Send challenge.
|
||||
AnnounceMessage.Version requestedVersion = AnnounceMessage.Version.newBuilder()
|
||||
.setMajor(PROTOCOL_VERSION_MAJOR)
|
||||
.setMinor(PROTOCOL_VERSION_MINOR)
|
||||
.build();
|
||||
InitMessage init = InitMessage.newBuilder()
|
||||
.setBuildId(0)
|
||||
.setLogin(InitMessage.LoginType.authenticatedLogin)
|
||||
.setRequestedVersion(requestedVersion)
|
||||
.setClientUserData(ByteString.copyFromUtf8(scramAuth.executeStep1("test1")))
|
||||
.build();
|
||||
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_InitMessage)
|
||||
.setInitMessage(init)
|
||||
.build();
|
||||
sendMessage(msg, sock);
|
||||
|
||||
msg = receiveMessage(sock);
|
||||
assertTrue(msg.hasErrorMessage() && msg.getMessageType() == PokerTHMessageType.Type_ErrorMessage);
|
||||
assertEquals(ErrorReason.blockedByServer, msg.getErrorMessage().getErrorReason());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRunRankingGame() throws Exception {
|
||||
|
||||
Statement dbStatement = dbConn.createStatement();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 0 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 2 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 4 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET valid = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 0 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 2 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 4 WHERE username = 'test1'");
|
||||
verifyLoginBlocked();
|
||||
dbStatement.executeUpdate("UPDATE player_login SET aktivator = 1 WHERE username = 'test1'");
|
||||
|
||||
sock.close();
|
||||
sock = new Socket("localhost", 7234);
|
||||
|
||||
userInit(sock, "test1", "test1");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.pokerth.protocol.ProtoBuf.ChatMessage.ChatType;
|
||||
import de.pokerth.protocol.ProtoBuf.ChatRequestMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.NetGameInfo;
|
||||
import de.pokerth.protocol.ProtoBuf.StartEventAckMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
|
||||
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
|
||||
import de.pokerth.protocol.ProtoBuf.StartEventMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.StartEventMessage.StartEventType;
|
||||
|
||||
|
||||
public class ChatTest extends TestBase {
|
||||
|
||||
final String ChatText = "Hello World ÖÄÜöäüẞ€";
|
||||
|
||||
PokerTHMessage createLobbyChatMsg(String chatText) {
|
||||
ChatRequestMessage chatLobby = ChatRequestMessage.newBuilder()
|
||||
.setChatText(chatText)
|
||||
.build();
|
||||
PokerTHMessage msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_ChatRequestMessage)
|
||||
.setChatRequestMessage(chatLobby)
|
||||
.build();
|
||||
return msg;
|
||||
}
|
||||
|
||||
PokerTHMessage createGameChatMsg(String chatText, int gameId) {
|
||||
ChatRequestMessage chatGame = ChatRequestMessage.newBuilder()
|
||||
.setChatText(chatText)
|
||||
.setTargetGameId(gameId)
|
||||
.build();
|
||||
PokerTHMessage msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_ChatRequestMessage)
|
||||
.setChatRequestMessage(chatGame)
|
||||
.build();
|
||||
return msg;
|
||||
}
|
||||
|
||||
PokerTHMessage createPrivateChatMsg(String chatText, int playerId) {
|
||||
ChatRequestMessage chatPrivate = ChatRequestMessage.newBuilder()
|
||||
.setChatText(chatText)
|
||||
.setTargetPlayerId(playerId)
|
||||
.build();
|
||||
PokerTHMessage msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_ChatRequestMessage)
|
||||
.setChatRequestMessage(chatPrivate)
|
||||
.build();
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChat() throws Exception {
|
||||
guestInit();
|
||||
|
||||
Socket s[] = new Socket[8];
|
||||
int playerId[] = new int[8];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
}
|
||||
|
||||
PokerTHMessage msg = createLobbyChatMsg(ChatText + 1);
|
||||
// Message as guest user should be rejected.
|
||||
sendMessage(msg);
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
} while (msg.hasPlayerListMessage());
|
||||
assertTrue(msg.hasChatRejectMessage());
|
||||
assertEquals(ChatText + 1, msg.getChatRejectMessage().getChatText());
|
||||
|
||||
// Message as registered user should be sent to other users and guests.
|
||||
msg = createLobbyChatMsg(ChatText + 2);
|
||||
sendMessage(msg, s[0]);
|
||||
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.hasChatMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
|
||||
assertEquals(ChatText + 2, msg.getChatMessage().getChatText());
|
||||
assertEquals(ChatType.chatTypeLobby, msg.getChatMessage().getChatType());
|
||||
assertEquals(playerId[0], msg.getChatMessage().getPlayerId());
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.hasPlayerListMessage());
|
||||
assertTrue(msg.hasChatMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
|
||||
assertEquals(ChatText + 2, msg.getChatMessage().getChatText());
|
||||
assertEquals(ChatType.chatTypeLobby, msg.getChatMessage().getChatType());
|
||||
assertEquals(playerId[0], msg.getChatMessage().getPlayerId());
|
||||
}
|
||||
|
||||
// A game chat message, if not within a game, should be rejected.
|
||||
msg = createGameChatMsg(ChatText + 3, 1);
|
||||
sendMessage(msg);
|
||||
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.hasChatRejectMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
|
||||
assertEquals(ChatText + 3, msg.getChatRejectMessage().getChatText());
|
||||
|
||||
msg = createGameChatMsg(ChatText + 4, 1);
|
||||
sendMessage(msg, s[0]);
|
||||
|
||||
msg = receiveMessage(s[0]);
|
||||
assertTrue(msg.hasChatRejectMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
|
||||
assertEquals(ChatText + 4, msg.getChatRejectMessage().getChatText());
|
||||
|
||||
// Guests are not allowed to send private messages in the lobby.
|
||||
msg = createPrivateChatMsg(ChatText + 5, playerId[1]);
|
||||
sendMessage(msg);
|
||||
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.hasChatRejectMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
|
||||
assertEquals(ChatText + 5, msg.getChatRejectMessage().getChatText());
|
||||
|
||||
// Registered users are allowed to send private messages in the lobby.
|
||||
msg = createPrivateChatMsg(ChatText + 6, playerId[1]);
|
||||
sendMessage(msg, s[0]);
|
||||
|
||||
msg = receiveMessage(s[1]);
|
||||
assertTrue(msg.hasChatMessage() && msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
|
||||
assertEquals(ChatText + 6, msg.getChatMessage().getChatText());
|
||||
assertEquals(ChatType.chatTypePrivate, msg.getChatMessage().getChatType());
|
||||
assertEquals(playerId[0], msg.getChatMessage().getPlayerId());
|
||||
|
||||
// Game messages can be sent by registered users within a game.
|
||||
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,
|
||||
"",
|
||||
false));
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
|
||||
assertTrue(msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage);
|
||||
int gameId = msg.getJoinGameAckMessage().getGameId();
|
||||
|
||||
// Let 8 players join the game, and test game chat.
|
||||
for (int i = 0; i < 8; i++) {
|
||||
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage());
|
||||
assertTrue(msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage);
|
||||
}
|
||||
|
||||
StartEventMessage startEvent = StartEventMessage.newBuilder()
|
||||
.setGameId(gameId)
|
||||
.setFillWithComputerPlayers(false)
|
||||
.setStartEventType(StartEventType.startEvent)
|
||||
.build();
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_StartEventMessage)
|
||||
.setStartEventMessage(startEvent)
|
||||
.build();
|
||||
sendMessage(msg);
|
||||
|
||||
// Server should confirm start event.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.hasStartEventMessage());
|
||||
|
||||
// Acknowledge start event.
|
||||
StartEventAckMessage startAck = StartEventAckMessage.newBuilder()
|
||||
.setGameId(gameId)
|
||||
.build();
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_StartEventAckMessage)
|
||||
.setStartEventAckMessage(startAck)
|
||||
.build();
|
||||
sendMessage(msg);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
sendMessage(msg, s[i]);
|
||||
}
|
||||
|
||||
// Server should game start.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.hasGameStartInitialMessage());
|
||||
|
||||
|
||||
// Guest user: not allowed.
|
||||
msg = createGameChatMsg(ChatText + 7, gameId);
|
||||
sendMessage(msg);
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
assertFalse(msg.hasChatMessage());
|
||||
} while (!msg.hasChatRejectMessage());
|
||||
assertEquals(ChatText + 7, msg.getChatRejectMessage().getChatText());
|
||||
|
||||
// Other users: allowed.
|
||||
for (int c = 0; c < 8; c++) {
|
||||
msg = createGameChatMsg(ChatText + "c" + c, gameId);
|
||||
sendMessage(msg, s[c]);
|
||||
do {
|
||||
msg = receiveMessage(s[c]);
|
||||
failOnErrorMessage(msg);
|
||||
assertFalse(msg.hasChatRejectMessage() || msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
|
||||
} while (!msg.hasChatMessage());
|
||||
|
||||
assertEquals(ChatText + "c" + c, msg.getChatMessage().getChatText());
|
||||
assertEquals(ChatType.chatTypeGame, msg.getChatMessage().getChatType());
|
||||
assertEquals(playerId[c], msg.getChatMessage().getPlayerId());
|
||||
assertEquals(gameId, msg.getChatMessage().getGameId());
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (i != c) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
assertFalse(msg.hasChatRejectMessage() || msg.getMessageType() == PokerTHMessageType.Type_ChatRejectMessage);
|
||||
} while (!msg.hasChatMessage());
|
||||
assertEquals(ChatText + "c" + c, msg.getChatMessage().getChatText());
|
||||
assertEquals(ChatType.chatTypeGame, msg.getChatMessage().getChatType());
|
||||
assertEquals(playerId[c], msg.getChatMessage().getPlayerId());
|
||||
assertEquals(gameId, msg.getChatMessage().getGameId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Private chat message should now be rejected.
|
||||
msg = createPrivateChatMsg(ChatText + 8, playerId[1]);
|
||||
sendMessage(msg, s[0]);
|
||||
do {
|
||||
msg = receiveMessage(s[0]);
|
||||
failOnErrorMessage(msg);
|
||||
assertFalse(msg.hasChatMessage() || msg.getMessageType() == PokerTHMessageType.Type_ChatMessage);
|
||||
} while (!msg.hasChatRejectMessage());
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
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.PokerTHMessage.PokerTHMessageType;
|
||||
|
||||
public class CreateGameTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testJoinGameRequestMessage() throws Exception {
|
||||
guestInit();
|
||||
|
||||
Collection<Integer> l = new ArrayList<Integer>();
|
||||
l.add(250);
|
||||
l.add(600);
|
||||
l.add(1000);
|
||||
NetGameInfo gameInfo = createGameInfo(NetGameInfo.NetGameType.normalGame, 20, 7, 8, EndRaiseMode.raiseByEndValue, 1000, 100, GuestUser + " create test game", l, 10, 0, 7, 2000);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
GamePassword,
|
||||
false));
|
||||
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.hasPlayerListMessage() || msg.getMessageType() != PokerTHMessageType.Type_PlayerListMessage) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (!msg.hasGameListNewMessage() || msg.getMessageType() != PokerTHMessageType.Type_GameListNewMessage) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage)
|
||||
{
|
||||
assertTrue(msg.getJoinGameAckMessage().getGameId() != 0);
|
||||
NetGameInfo receivedGameInfo = msg.getJoinGameAckMessage().getGameInfo();
|
||||
assertEquals(receivedGameInfo.getDelayBetweenHands(), gameInfo.getDelayBetweenHands());
|
||||
assertEquals(receivedGameInfo.getEndRaiseMode(), gameInfo.getEndRaiseMode());
|
||||
assertEquals(receivedGameInfo.getEndRaiseSmallBlindValue(), gameInfo.getEndRaiseSmallBlindValue());
|
||||
assertEquals(receivedGameInfo.getFirstSmallBlind(), gameInfo.getFirstSmallBlind());
|
||||
assertEquals(receivedGameInfo.getGameName(), gameInfo.getGameName());
|
||||
assertEquals(receivedGameInfo.getManualBlindsCount(), gameInfo.getManualBlindsCount());
|
||||
for (Iterator<Integer> rec_it = receivedGameInfo.getManualBlindsList().iterator(),
|
||||
game_it = gameInfo.getManualBlindsList().iterator();
|
||||
rec_it.hasNext() && game_it.hasNext();)
|
||||
{
|
||||
assertEquals(rec_it.next(), game_it.next());
|
||||
}
|
||||
assertEquals(receivedGameInfo.getMaxNumPlayers(), gameInfo.getMaxNumPlayers());
|
||||
assertEquals(receivedGameInfo.getNetGameType(), gameInfo.getNetGameType());
|
||||
assertEquals(receivedGameInfo.getPlayerActionTimeout(), gameInfo.getPlayerActionTimeout());
|
||||
assertEquals(receivedGameInfo.getProposedGuiSpeed(), gameInfo.getProposedGuiSpeed());
|
||||
assertEquals(receivedGameInfo.getRaiseIntervalMode(), gameInfo.getRaiseIntervalMode());
|
||||
assertEquals(receivedGameInfo.getRaiseEveryHands(), gameInfo.getRaiseEveryHands());
|
||||
assertEquals(receivedGameInfo.getRaiseEveryMinutes(), gameInfo.getRaiseEveryMinutes());
|
||||
assertEquals(receivedGameInfo.getStartMoney(), gameInfo.getStartMoney());
|
||||
}
|
||||
else {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
|
||||
|
||||
public class CreateRankingGameTest extends TestBase {
|
||||
|
||||
static private int counter = 0;
|
||||
|
||||
private void createRankingGame(String password) throws Exception {
|
||||
counter++;
|
||||
Collection<Integer> l = new ArrayList<Integer>();
|
||||
NetGameInfo gameInfo = createGameInfo(NetGameType.rankingGame, 20, 7, 8, EndRaiseMode.doubleBlinds, 0, 50, GuestUser + " create ranking game " + counter, l, 10, 0, 11, 10000);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
password,
|
||||
false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRankingGameAsGuest() throws Exception {
|
||||
guestInit();
|
||||
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.hasPlayerListMessage()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
createRankingGame("");
|
||||
msg = receiveMessage();
|
||||
|
||||
if (!msg.hasJoinGameFailedMessage())
|
||||
{
|
||||
failOnErrorMessage(msg);
|
||||
fail("Guest user could create ranking game!");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRankingGameNoPasswordAsUser() throws Exception {
|
||||
userInit();
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.hasPlayerListMessage()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
createRankingGame("");
|
||||
msg = receiveMessage();
|
||||
|
||||
if (msg.hasGameListNewMessage())
|
||||
{
|
||||
msg = receiveMessage();
|
||||
if (msg.hasJoinGameFailedMessage())
|
||||
{
|
||||
fail("Registered user could not join ranking game!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Registered user could not create ranking game!");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRankingGameWithPasswordAsUser() throws Exception {
|
||||
userInit();
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.hasPlayerListMessage()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
createRankingGame(GamePassword);
|
||||
msg = receiveMessage();
|
||||
|
||||
if (!msg.hasJoinGameFailedMessage())
|
||||
{
|
||||
failOnErrorMessage(msg);
|
||||
fail("Registered user should not be allowed to create ranking game with password!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class GameListTest extends TestBase {
|
||||
|
||||
protected void checkGameListNewMsg(long myId, GameListNew gameListNew, NetGameMode.EnumType mode, NetGameInfo gameInfo) {
|
||||
assertEquals(NetGameMode.EnumType.gameCreated, gameListNew.getGameMode().getValue());
|
||||
assertTrue(!gameListNew.getIsPrivate());
|
||||
assertEquals(myId, gameListNew.getAdminPlayerId().getValue().longValue());
|
||||
NetGameInfo receivedGameInfo = gameListNew.getGameInfo();
|
||||
assertEquals(gameInfo.getDelayBetweenHands(), receivedGameInfo.getDelayBetweenHands());
|
||||
assertEquals(gameInfo.getEndRaiseMode().getValue(), receivedGameInfo.getEndRaiseMode().getValue());
|
||||
assertEquals(gameInfo.getEndRaiseSmallBlindValue().getValue(), receivedGameInfo.getEndRaiseSmallBlindValue().getValue());
|
||||
assertEquals(gameInfo.getFirstSmallBlind(), receivedGameInfo.getFirstSmallBlind());
|
||||
assertEquals(gameInfo.getGameName(), receivedGameInfo.getGameName());
|
||||
assertTrue(receivedGameInfo.getManualBlinds().isEmpty());
|
||||
assertEquals(gameInfo.getMaxNumPlayers(), receivedGameInfo.getMaxNumPlayers());
|
||||
assertEquals(gameInfo.getNetGameType().getValue(), receivedGameInfo.getNetGameType().getValue());
|
||||
assertEquals(gameInfo.getPlayerActionTimeout(), receivedGameInfo.getPlayerActionTimeout());
|
||||
assertEquals(gameInfo.getProposedGuiSpeed(), receivedGameInfo.getProposedGuiSpeed());
|
||||
assertTrue(gameInfo.getRaiseIntervalMode().isRaiseEveryHandsSelected());
|
||||
assertEquals(gameInfo.getStartMoney().getValue(), receivedGameInfo.getStartMoney().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGameList() throws Exception {
|
||||
|
||||
long myId = guestInit();
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
|
||||
// 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);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
NetGameTypeEnumType.EnumType.normalGame,
|
||||
10,
|
||||
5,
|
||||
"",
|
||||
false));
|
||||
|
||||
// Game list message is sent before join game ack.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isGameListMessageSelected());
|
||||
GameListMessage gameListMsg = msg.getGameListMessage();
|
||||
long gameId = gameListMsg.getValue().getGameId().getValue();
|
||||
assertTrue(0 != gameListMsg.getValue().getGameId().getValue());
|
||||
assertTrue(gameListMsg.getValue().getGameListNotification().isGameListNewSelected());
|
||||
checkGameListNewMsg(
|
||||
myId,
|
||||
gameListMsg.getValue().getGameListNotification().getGameListNew(),
|
||||
NetGameMode.EnumType.gameCreated,
|
||||
gameInfo);
|
||||
assertTrue(gameListMsg.getValue().getGameListNotification().getGameListNew().getPlayerIds().isEmpty());
|
||||
|
||||
// Next message is join game ack.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isJoinGameReplyMessageSelected());
|
||||
assertTrue(msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected());
|
||||
// Make sure game list id equals join game ack id.
|
||||
assertEquals(gameId, msg.getJoinGameReplyMessage().getValue().getGameId().getValue().longValue());
|
||||
|
||||
// Next message is game list player joined.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isGameListMessageSelected());
|
||||
gameListMsg = msg.getGameListMessage();
|
||||
assertTrue(gameListMsg.getValue().getGameListNotification().isGameListPlayerJoinedSelected());
|
||||
|
||||
// Check game list for newly connected players.
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.isGameListMessageSelected());
|
||||
gameListMsg = msg.getGameListMessage();
|
||||
assertEquals(gameId, gameListMsg.getValue().getGameId().getValue().longValue());
|
||||
assertTrue(0 != gameListMsg.getValue().getGameId().getValue());
|
||||
assertTrue(gameListMsg.getValue().getGameListNotification().isGameListNewSelected());
|
||||
checkGameListNewMsg(
|
||||
myId,
|
||||
gameListMsg.getValue().getGameListNotification().getGameListNew(),
|
||||
NetGameMode.EnumType.gameCreated,
|
||||
gameInfo);
|
||||
assertEquals(1, gameListMsg.getValue().getGameListNotification().getGameListNew().getPlayerIds().size());
|
||||
assertEquals(myId, gameListMsg.getValue().getGameListNotification().getGameListNew().getPlayerIds().iterator().next().getValue().longValue());
|
||||
}
|
||||
|
||||
// Let 9 players join the game.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isPlayerListMessageSelected());
|
||||
for (int j = 0; j < i; j++) {
|
||||
assertTrue(msg.isGameListMessageSelected());
|
||||
gameListMsg = msg.getGameListMessage();
|
||||
assertTrue(gameListMsg.getValue().getGameListNotification().isGameListPlayerJoinedSelected());
|
||||
assertEquals(playerId[j], gameListMsg.getValue().getGameListNotification().getGameListPlayerJoined().getPlayerId().getValue().longValue());
|
||||
msg = receiveMessage(s[i]);
|
||||
}
|
||||
failOnErrorMessage(msg);
|
||||
// Next message is join game ack.
|
||||
assertTrue(msg.isJoinGameReplyMessageSelected());
|
||||
assertTrue(msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected());
|
||||
// Make sure game list id equals join game ack id.
|
||||
assertEquals(gameId, msg.getJoinGameReplyMessage().getValue().getGameId().getValue().longValue());
|
||||
|
||||
// Next message is game list player joined.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isGamePlayerMessageSelected());
|
||||
assertTrue(msg.isGameListMessageSelected());
|
||||
gameListMsg = msg.getGameListMessage();
|
||||
assertTrue(gameListMsg.getValue().getGameListNotification().isGameListPlayerJoinedSelected());
|
||||
assertEquals(playerId[i], gameListMsg.getValue().getGameListNotification().getGameListPlayerJoined().getPlayerId().getValue().longValue());
|
||||
}
|
||||
|
||||
// Wait for game list update which marks start of game.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!(msg.isGameListMessageSelected() && msg.getGameListMessage().getValue().getGameListNotification().isGameListUpdateSelected()));
|
||||
|
||||
assertEquals(NetGameMode.EnumType.gameStarted, msg.getGameListMessage().getValue().getGameListNotification().getGameListUpdate().getGameMode().getValue());
|
||||
|
||||
// Wait for player left messages.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isGameListMessageSelected());
|
||||
gameListMsg = msg.getGameListMessage();
|
||||
assertTrue(gameListMsg.getValue().getGameListNotification().isGameListPlayerLeftSelected());
|
||||
assertEquals(playerId[i], gameListMsg.getValue().getGameListNotification().getGameListPlayerLeft().getPlayerId().getValue().longValue());
|
||||
}
|
||||
|
||||
// Wait for game list update which marks close of game.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!(msg.isGameListMessageSelected() && msg.getGameListMessage().getValue().getGameListNotification().isGameListUpdateSelected()));
|
||||
|
||||
assertEquals(NetGameMode.EnumType.gameClosed, msg.getGameListMessage().getValue().getGameListNotification().getGameListUpdate().getGameMode().getValue());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GuestLoginTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testInitMessage() throws Exception {
|
||||
guestInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class LoadTest extends TestBase {
|
||||
|
||||
static final int NumGames = 4; // Number of games which are run, 10 players each.
|
||||
|
||||
@Test
|
||||
public void testRunMultipleGames() throws Exception {
|
||||
|
||||
// We don't need the default socket.
|
||||
sock.close();
|
||||
|
||||
// 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];
|
||||
|
||||
PokerTHMessage msg;
|
||||
// First players are game admins.
|
||||
// Create several games.
|
||||
for (int i = 0; i < NumGames; i++) {
|
||||
s[i * 10] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i*10+1);
|
||||
String password = username;
|
||||
playerId[i * 10] = userInit(s[i * 10], username, password);
|
||||
|
||||
do {
|
||||
msg = receiveMessage(s[i * 10]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
String gameName = AuthUser + " load game " + i;
|
||||
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 200, gameName, l, 10, 0, 1, 10000);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
NetGameTypeEnumType.EnumType.normalGame,
|
||||
5,
|
||||
7,
|
||||
"",
|
||||
false),
|
||||
s[i * 10]);
|
||||
|
||||
// Game list update (new game)
|
||||
do {
|
||||
msg = receiveMessage(s[i * 10]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (msg.isGameListMessageSelected() || msg.isPlayerListMessageSelected());
|
||||
|
||||
// Join game ack.
|
||||
if (msg.isJoinGameReplyMessageSelected()) {
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("Could not create game!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
gameId[i] = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
}
|
||||
|
||||
|
||||
// Let additional clients join.
|
||||
for (int i = 0; i < NumGames * 10; i++) {
|
||||
if (i % 10 == 0) {
|
||||
continue;
|
||||
}
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
// Waiting for player list update.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
sendMessage(joinGameRequestMsg(gameId[i/10], "", false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("User " + username + " could not join ranking game.");
|
||||
}
|
||||
}
|
||||
|
||||
boolean abort = false;
|
||||
long handNum = 0;
|
||||
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++;
|
||||
}
|
||||
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);
|
||||
sendMessage(outMsg, s[i]);
|
||||
}
|
||||
}
|
||||
else if (msg.isEndOfGameMessageSelected()) {
|
||||
abort = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (!abort);
|
||||
|
||||
for (int i = 0; i < NumGames; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class LobbySubscriptionTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testLobbySubscription() throws Exception {
|
||||
guestInit();
|
||||
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
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);
|
||||
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);
|
||||
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();
|
||||
|
||||
Socket s[] = new Socket[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
userInit(s[i], username, password);
|
||||
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
|
||||
}
|
||||
|
||||
// No game list message should be received.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
if (msg.isGameListMessageSelected() || msg.isPlayerListMessageSelected()) {
|
||||
fail("Game/player list messages are switched off!");
|
||||
}
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
|
||||
// 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);
|
||||
sendMessage(msg);
|
||||
|
||||
// Next messages should player list messages for all 10 players.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
}
|
||||
// Now there should be one game list message.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isGameListMessageSelected());
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
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);
|
||||
sendMessage(msg, s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlayerInfoRequest() throws Exception {
|
||||
|
||||
long firstPlayerId = guestInit();
|
||||
byte[] avatarHash =
|
||||
{
|
||||
// one of the builtin avatars.
|
||||
(byte)0x00, (byte)0xa0, (byte)0xb3, (byte)0xd2,
|
||||
(byte)0x6a, (byte)0x67, (byte)0x84, (byte)0x12,
|
||||
(byte)0x39, (byte)0xb8, (byte)0x88, (byte)0x31,
|
||||
(byte)0x83, (byte)0xb7, (byte)0xa8, (byte)0xf0
|
||||
};
|
||||
|
||||
// Let 9 additional clients join.
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
long maxPlayerId = 0;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
// Every second player has an avatar.
|
||||
if (i % 2 == 0) {
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
} else {
|
||||
playerId[i] = userInit(s[i], username, password, avatarHash, null);
|
||||
}
|
||||
if (playerId[i] > maxPlayerId) {
|
||||
maxPlayerId = playerId[i];
|
||||
}
|
||||
}
|
||||
PokerTHMessage msg;
|
||||
|
||||
// Request player info, for guest first.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendPlayerInfoRequest(s[i], firstPlayerId);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.isPlayerInfoReplyMessageSelected());
|
||||
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage();
|
||||
assertTrue(reply.getValue().getPlayerId().getValue() == firstPlayerId);
|
||||
assertTrue(reply.getValue().getPlayerInfoResult().isPlayerInfoDataSelected());
|
||||
PlayerInfoData info = reply.getValue().getPlayerInfoResult().getPlayerInfoData();
|
||||
assertEquals(GuestUser, info.getPlayerName());
|
||||
assertEquals(null, info.getCountryCode());
|
||||
assertTrue(info.getIsHuman());
|
||||
assertEquals(PlayerInfoRights.EnumType.playerRightsGuest, info.getPlayerRights().getValue());
|
||||
assertEquals(null, info.getAvatarData());
|
||||
}
|
||||
// Request other players' info.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendPlayerInfoRequest(sock, playerId[i]);
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
} while (msg.isPlayerListMessageSelected());
|
||||
assertTrue(msg.isPlayerInfoReplyMessageSelected());
|
||||
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage();
|
||||
assertTrue(reply.getValue().getPlayerId().getValue() == playerId[i]);
|
||||
assertTrue(reply.getValue().getPlayerInfoResult().isPlayerInfoDataSelected());
|
||||
PlayerInfoData info = reply.getValue().getPlayerInfoResult().getPlayerInfoData();
|
||||
assertEquals("test" + (i+1), info.getPlayerName());
|
||||
assertEquals(null, info.getCountryCode());
|
||||
assertTrue(info.getIsHuman());
|
||||
assertEquals(PlayerInfoRights.EnumType.playerRightsNormal, info.getPlayerRights().getValue());
|
||||
// Every second player has an avatar, see above.
|
||||
if (i % 2 == 0) {
|
||||
assertEquals(null, info.getAvatarData());
|
||||
} else {
|
||||
assertTrue(Arrays.equals(info.getAvatarData().getAvatar().getValue(), avatarHash));
|
||||
assertEquals(NetAvatarType.EnumType.avatarImagePng, info.getAvatarData().getAvatarType().getValue());
|
||||
}
|
||||
}
|
||||
// Request invalid player info.
|
||||
sendPlayerInfoRequest(sock, maxPlayerId + 1);
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerInfoReplyMessageSelected());
|
||||
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage();
|
||||
assertTrue(reply.getValue().getPlayerId().getValue() == maxPlayerId + 1);
|
||||
assertTrue(reply.getValue().getPlayerInfoResult().isUnknownPlayerInfoSelected());
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class PlayerListTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testPlayerList() throws Exception {
|
||||
|
||||
long myId = guestInit();
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
|
||||
// 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());
|
||||
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
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());
|
||||
|
||||
s[i].close();
|
||||
|
||||
// After the connection is closed, a "player list left" notification should be received.
|
||||
msg = receiveMessage();
|
||||
assertTrue(msg.isPlayerListMessageSelected());
|
||||
listMsg = msg.getPlayerListMessage();
|
||||
assertEquals(playerId[i], listMsg.getValue().getPlayerId().getValue().longValue());
|
||||
assertEquals(PlayerListNotificationEnumType.EnumType.playerListLeft, listMsg.getValue().getPlayerListNotification().getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2011 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class RejoinGameTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testRejoinGame() throws Exception {
|
||||
|
||||
Guid firstPlayerSession = new Guid();
|
||||
long firstPlayerId = userInit(sock, AuthUser, AuthPassword, null, firstPlayerSession);
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
String gameName = AuthUser + " rejoin game";
|
||||
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.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()) {
|
||||
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 {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
|
||||
// Game list update (player joined).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
// Let 9 additional clients join.
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
// Waiting for player list update.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("User " + username + " could not join ranking game.");
|
||||
}
|
||||
|
||||
// The player should have joined the game.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGamePlayerMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
}
|
||||
|
||||
// Server should automatically send start event.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isStartEventMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
}
|
||||
// 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);
|
||||
sendMessage(msg);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendMessage(msg, s[i]);
|
||||
}
|
||||
|
||||
// Game list update (game now running).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameStartMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
// Wait for start of hand.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
while (s[i].getInputStream().available() > 0) {
|
||||
PokerTHMessage inMsg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(inMsg);
|
||||
}
|
||||
}
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
|
||||
// Leave the game by closing the socket.
|
||||
sock.close();
|
||||
// No rejoin game id set yet.
|
||||
assertEquals(0, lastRejoinGameId);
|
||||
|
||||
// All other players should have received "player left".
|
||||
for (int i = 0; i < 9; i++) {
|
||||
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());
|
||||
}
|
||||
|
||||
sock = new Socket("localhost", 7234);
|
||||
// Reconnect to the server.
|
||||
long 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()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
// Rejoin the game.
|
||||
sendMessage(rejoinGameRequestMsg(gameId, false));
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("User " + AuthUser + " could not rejoin ranking game.");
|
||||
}
|
||||
|
||||
// All other players should have received "player joined".
|
||||
for (int i = 0; i < 9; i++) {
|
||||
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());
|
||||
}
|
||||
|
||||
// Wait for start event.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
|
||||
assertEquals(gameId, msg.getStartEventMessage().getValue().getGameId().getValue().longValue());
|
||||
assertTrue(msg.getStartEventMessage().getValue().getStartEventType().isRejoinEventSelected());
|
||||
|
||||
// Acknowledge start event.
|
||||
startType = new StartEventAckMessageSequenceType();
|
||||
startType.setGameId(new NonZeroId(gameId));
|
||||
startAck = new StartEventAckMessage();
|
||||
startAck.setValue(startType);
|
||||
msg = new PokerTHMessage();
|
||||
msg.selectStartEventAckMessage(startAck);
|
||||
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());
|
||||
|
||||
// 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();
|
||||
// We left at the first hand.
|
||||
assertEquals(1, rejoinData.getHandNum().getValue().longValue());
|
||||
// 10 Players should now be active again.
|
||||
assertEquals(10, rejoinData.getRejoinPlayerData().size());
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
// Everyone should receive a "hand start message" now.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
for (int i = 0; i < 9; i++) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2011 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import java.net.Socket;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class RejoinMultiGameTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testRejoinMultiGame() throws Exception {
|
||||
|
||||
Statement dbStatement = dbConn.createStatement();
|
||||
ResultSet countBeforeResult = dbStatement.executeQuery("SELECT COUNT(idgame) FROM game");
|
||||
countBeforeResult.first();
|
||||
long countBefore = countBeforeResult.getLong(1);
|
||||
|
||||
userInit();
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
String gameName = AuthUser + " rejoin game";
|
||||
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.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()) {
|
||||
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 {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
|
||||
// Game list update (player joined).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
// Let 9 additional clients join.
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
Guid playerSession[] = new Guid[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
playerSession[i] = new Guid();
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password, null, playerSession[i]);
|
||||
// Waiting for player list update.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("User " + username + " could not join ranking game.");
|
||||
}
|
||||
|
||||
// The player should have joined the game.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGamePlayerMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
}
|
||||
|
||||
// Server should automatically send start event.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isStartEventMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
}
|
||||
// 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);
|
||||
sendMessage(msg);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendMessage(msg, s[i]);
|
||||
}
|
||||
|
||||
// Game list update (game now running).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameStartMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
// Wait for start of hand.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
while (s[i].getInputStream().available() > 0) {
|
||||
PokerTHMessage inMsg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(inMsg);
|
||||
}
|
||||
}
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
|
||||
// 9 players leave the game by closing the socket.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
Thread.sleep(500);
|
||||
}
|
||||
// No rejoin game id set yet.
|
||||
assertEquals(0, lastRejoinGameId);
|
||||
|
||||
// The remaining player should have received "player left" 9 times.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
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());
|
||||
}
|
||||
|
||||
// Let all players reconnect.
|
||||
long playerIdAfterRejoin[] = new long[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerIdAfterRejoin[i] = userInit(s[i], username, password, null, playerSession[i]);
|
||||
assertEquals(gameId, lastRejoinGameId);
|
||||
// Waiting for player list update.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
sendMessage(rejoinGameRequestMsg(gameId, false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("User " + username + " could not rejoin ranking game.");
|
||||
}
|
||||
}
|
||||
// The remaining player should have received "player joined" 9 times.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
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());
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
// Wait for start event.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
|
||||
assertEquals(gameId, msg.getStartEventMessage().getValue().getGameId().getValue().longValue());
|
||||
assertTrue(msg.getStartEventMessage().getValue().getStartEventType().isRejoinEventSelected());
|
||||
|
||||
// Acknowledge start event.
|
||||
startType = new StartEventAckMessageSequenceType();
|
||||
startType.setGameId(new NonZeroId(gameId));
|
||||
startAck = new StartEventAckMessage();
|
||||
startAck.setValue(startType);
|
||||
msg = new PokerTHMessage();
|
||||
msg.selectStartEventAckMessage(startAck);
|
||||
sendMessage(msg, s[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
// Wait for game start. This may take a while, because rejoin is performed at the beginning of the next hand.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isGameStartMessageSelected());
|
||||
|
||||
// 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();
|
||||
// We left at the first hand.
|
||||
assertTrue(rejoinData.getHandNum().getValue().longValue() >= 1);
|
||||
// 10 Players should now be active again.
|
||||
assertEquals(10, rejoinData.getRejoinPlayerData().size());
|
||||
}
|
||||
|
||||
// The remaining player should have received 9 "player id changed".
|
||||
for (int i = 0; i < 9; i++) {
|
||||
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());
|
||||
}
|
||||
|
||||
// Everyone should receive a "hand start message" now.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
for (int i = 0; i < 9; i++) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
}
|
||||
|
||||
// The game should continue to the end.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isEndOfGameMessageSelected());
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
|
||||
// Check database entry for the game.
|
||||
ResultSet countAfterResult = dbStatement.executeQuery("SELECT COUNT(idgame) FROM game");
|
||||
countAfterResult.first();
|
||||
long countAfter = countAfterResult.getLong(1);
|
||||
assertEquals(countBefore + 1, countAfter);
|
||||
|
||||
// Select the latest game.
|
||||
ResultSet gameResult = dbStatement.executeQuery("SELECT idgame, name, start_time, end_time FROM game WHERE start_time = (SELECT MAX(start_time) from game)");
|
||||
gameResult.first();
|
||||
long idgame = gameResult.getLong(1);
|
||||
|
||||
// Check database entries for the players in the game.
|
||||
// There should be exactly 10 entries, just as usual.
|
||||
ResultSet gamePlayerResult = dbStatement.executeQuery("SELECT COUNT(*) FROM game_has_player WHERE game_idgame = " + idgame);
|
||||
gamePlayerResult.first();
|
||||
assertEquals(10, gamePlayerResult.getLong(1));
|
||||
// Each player should have a place in the range 1..10
|
||||
ResultSet winnerResult = dbStatement.executeQuery(
|
||||
"SELECT place FROM game_has_player LEFT JOIN player_login on (game_has_player.player_idplayer = player_login.id) WHERE game_idgame = " + idgame);
|
||||
winnerResult.first();
|
||||
for (int i = 0; i < 9; i++) {
|
||||
assertTrue(winnerResult.getLong(1) >= 1);
|
||||
assertTrue(winnerResult.getLong(1) <= 10);
|
||||
winnerResult.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class RunNormalGameTest extends TestBase {
|
||||
|
||||
@Test
|
||||
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);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
NetGameTypeEnumType.EnumType.normalGame,
|
||||
10,
|
||||
5,
|
||||
"",
|
||||
false));
|
||||
|
||||
PokerTHMessage msg;
|
||||
|
||||
// Waiting for player list update.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
// Game list update (new game)
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
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 {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
|
||||
// Game list update (player joined).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
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);
|
||||
sendMessage(msg);
|
||||
|
||||
// Now the computer players should join.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGamePlayerMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
}
|
||||
|
||||
// Server should confirm start event.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isStartEventMessageSelected()) {
|
||||
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);
|
||||
sendMessage(msg);
|
||||
|
||||
// Game list update (game now running).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameStartMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
lastPlayerMoney = maxPlayerMoney;
|
||||
}
|
||||
}
|
||||
} while (
|
||||
msg.isHandStartMessageSelected()
|
||||
|| msg.isDealFlopCardsMessageSelected()
|
||||
|| msg.isDealRiverCardMessageSelected()
|
||||
|| msg.isDealTurnCardMessageSelected()
|
||||
|| msg.isPlayersTurnMessageSelected()
|
||||
|| msg.isPlayersActionDoneMessageSelected()
|
||||
|| msg.isEndOfHandMessageSelected()
|
||||
|| msg.isAllInShowCardsMessageSelected()
|
||||
|| msg.isTimeoutWarningMessageSelected()
|
||||
);
|
||||
if (!msg.isEndOfGameMessageSelected()) {
|
||||
fail("No end of game received.");
|
||||
}
|
||||
// Last player money should be sum of all money.
|
||||
assertEquals(2000 * 10, lastPlayerMoney);
|
||||
|
||||
// Now the computer players should leave.
|
||||
for (int i = 0; i < 9; i++) {
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGamePlayerMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class RunRankingGameTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testRunRankingGame() throws Exception {
|
||||
|
||||
Statement dbStatement = dbConn.createStatement();
|
||||
ResultSet countBeforeResult = dbStatement.executeQuery("SELECT COUNT(idgame) FROM game");
|
||||
countBeforeResult.first();
|
||||
long countBefore = countBeforeResult.getLong(1);
|
||||
|
||||
long firstPlayerId = userInit();
|
||||
|
||||
// Waiting for player list update.
|
||||
PokerTHMessage msg;
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
String gameName = AuthUser + " run ranking game";
|
||||
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.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()) {
|
||||
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 {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
|
||||
// Game list update (player joined).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
// Let 9 additional clients join.
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
// Waiting for player list update.
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
} while (msg.isGameListMessageSelected() || msg.isGamePlayerMessageSelected());
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("User " + username + " could not join ranking game.");
|
||||
}
|
||||
|
||||
// The player should have joined the game.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGamePlayerMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
}
|
||||
|
||||
// Server should automatically send start event.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isStartEventMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
}
|
||||
// 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);
|
||||
sendMessage(msg);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendMessage(msg, s[i]);
|
||||
}
|
||||
|
||||
// Game list update (game now running).
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameStartMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
long handNum = 0;
|
||||
long lastPlayerMoney = 0;
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
if (msg.isHandStartMessageSelected()) {
|
||||
handNum++;
|
||||
// Cards should be encrypted for registered users.
|
||||
assertTrue(msg.getHandStartMessage().getValue().getYourCards().isEncryptedCardsSelected());
|
||||
byte[] encData = msg.getHandStartMessage().getValue().getYourCards().getEncryptedCards().getCardData();
|
||||
byte[] cardData = decryptCards(AuthPassword, encData);
|
||||
int size = cardData.length;
|
||||
while (size > 0 && cardData[size-1] == 0) {
|
||||
size--;
|
||||
}
|
||||
String cardStr = new String(cardData, 0, size);
|
||||
String[] cardTok = cardStr.split("\\s");
|
||||
// First token is player id.
|
||||
assertEquals(String.valueOf(firstPlayerId), cardTok[0]);
|
||||
// Second token is game id.
|
||||
assertEquals(String.valueOf(gameId), cardTok[1]);
|
||||
// Third token is hand num.
|
||||
assertEquals(String.valueOf(handNum), cardTok[2]);
|
||||
// Fourth and fifth tokens are cards.
|
||||
int card1 = Integer.valueOf(cardTok[3]);
|
||||
int card2 = Integer.valueOf(cardTok[4]);
|
||||
assertTrue(card1 < 52);
|
||||
assertTrue(card1 >= 0);
|
||||
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);
|
||||
sendMessage(outMsg);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < 9; i++) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
lastPlayerMoney = maxPlayerMoney;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (!msg.isEndOfGameMessageSelected());
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
Thread.sleep(2000);
|
||||
|
||||
// Last player money should be sum of all money.
|
||||
assertEquals(10000 * 10, lastPlayerMoney);
|
||||
|
||||
// Check database entry for the game.
|
||||
ResultSet countAfterResult = dbStatement.executeQuery("SELECT COUNT(idgame) FROM game");
|
||||
countAfterResult.first();
|
||||
long countAfter = countAfterResult.getLong(1);
|
||||
assertEquals(countBefore + 1, countAfter);
|
||||
|
||||
// Select the latest game.
|
||||
ResultSet gameResult = dbStatement.executeQuery("SELECT idgame, name, start_time, end_time FROM game WHERE start_time = (SELECT MAX(start_time) from game)");
|
||||
gameResult.first();
|
||||
long idgame = gameResult.getLong(1);
|
||||
String dbGameName = gameResult.getString(2);
|
||||
assertEquals(dbGameName, gameName);
|
||||
java.sql.Timestamp gameStart = gameResult.getTimestamp(3);
|
||||
java.sql.Timestamp gameEnd = gameResult.getTimestamp(4);
|
||||
assertTrue(gameEnd.after(gameStart));
|
||||
// Do not consider daylight saving time, just calculate the raw difference.
|
||||
long gameDurationMsec = gameEnd.getTime() - gameStart.getTime();
|
||||
assertTrue(gameDurationMsec > 10 * 1000); // game duration should be larger than 10 seconds.
|
||||
assertTrue(gameDurationMsec < 60 * 60 * 1000); // game duration should be smaller than 1 hour.
|
||||
|
||||
// Check database entries for the players in the game.
|
||||
ResultSet gamePlayerResult = dbStatement.executeQuery("SELECT COUNT(*) FROM game_has_player WHERE game_idgame = " + idgame);
|
||||
gamePlayerResult.first();
|
||||
assertEquals(10, gamePlayerResult.getLong(1));
|
||||
// The one who always went all in should have won!
|
||||
ResultSet winnerResult = dbStatement.executeQuery(
|
||||
"SELECT place FROM game_has_player LEFT JOIN player_login on (game_has_player.player_idplayer = player_login.id) WHERE game_idgame = " + idgame + " AND username = '" + AuthUser + "'");
|
||||
winnerResult.first();
|
||||
assertEquals(1, winnerResult.getLong(1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import de.rtner.security.auth.spi.MacBasedPRF;
|
||||
import de.rtner.security.auth.spi.PBKDF2Engine;
|
||||
import de.rtner.security.auth.spi.PBKDF2Parameters;
|
||||
|
||||
public class ScramSha1 {
|
||||
|
||||
String clientFirstMessageBare;
|
||||
SecureRandom random = new SecureRandom();
|
||||
|
||||
public String executeStep1(String username)
|
||||
{
|
||||
byte bytes[] = new byte[8];
|
||||
random.nextBytes(bytes);
|
||||
|
||||
String clientR = Base64Coder.encodeLines(bytes).trim();
|
||||
clientFirstMessageBare = "n=" + username + ",r=" + clientR + "\n";
|
||||
return "n,," + clientFirstMessageBare;
|
||||
}
|
||||
|
||||
public String executeStep2(String password, String serverFirstMessage) throws NoSuchAlgorithmException
|
||||
{
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
||||
MacBasedPRF hmac = new MacBasedPRF("HMacSha1");
|
||||
|
||||
StringTokenizer st = new StringTokenizer(serverFirstMessage, "=", true);
|
||||
st.nextToken("=");
|
||||
st.nextToken();
|
||||
String serverR = st.nextToken(",");
|
||||
st.nextToken();
|
||||
st.nextToken("=");
|
||||
st.nextToken();
|
||||
byte[] serverSalt = Base64Coder.decodeLines(st.nextToken(","));
|
||||
st.nextToken();
|
||||
st.nextToken("=");
|
||||
st.nextToken();
|
||||
String iterationCount = st.nextToken(",");
|
||||
|
||||
// SaltedPassword := Hi(Normalize(password), salt, i)
|
||||
PBKDF2Engine engine = new PBKDF2Engine(new PBKDF2Parameters("HMacSHA1", null, serverSalt, Integer.parseInt(iterationCount)));
|
||||
byte[] saltedPassword = engine.deriveKey(password, 20);
|
||||
|
||||
// ClientKey := HMAC(SaltedPassword, "Client Key")
|
||||
hmac.init(saltedPassword);
|
||||
byte[] clientKey = hmac.doFinal("Client Key".getBytes());
|
||||
|
||||
// StoredKey := H(ClientKey)
|
||||
byte[] storedKey = md.digest(clientKey);
|
||||
|
||||
// AuthMessage := client-first-message-bare + "," +
|
||||
// server-first-message + "," +
|
||||
// client-final-message-without-proof
|
||||
String clientFinalMessage = "c=biws,r=" + serverR;
|
||||
String strAuthMessage = clientFirstMessageBare + "," + serverFirstMessage + "," + clientFinalMessage;
|
||||
|
||||
// ClientSignature := HMAC(StoredKey, AuthMessage)
|
||||
hmac = new MacBasedPRF("HMacSha1");
|
||||
hmac.init(storedKey);
|
||||
byte[] clientSignature = hmac.doFinal(strAuthMessage.getBytes());
|
||||
|
||||
// ClientProof := ClientKey XOR ClientSignature
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
clientKey[i] ^= clientSignature[i];
|
||||
}
|
||||
|
||||
String clientProof = Base64Coder.encodeLines(clientKey).trim();
|
||||
clientFinalMessage += ",p=" + clientProof;
|
||||
return clientFinalMessage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class SeatStateTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testSeatState() throws Exception {
|
||||
long firstPlayerId = userInit();
|
||||
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
String gameName = AuthUser + " run normal game for seatState";
|
||||
NetGameInfo gameInfo = createGameInfo(5, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 200, gameName, l, 10, 0, 2, 10000);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
NetGameTypeEnumType.EnumType.normalGame,
|
||||
5,
|
||||
7,
|
||||
"",
|
||||
false));
|
||||
|
||||
// Wait for join game ack.
|
||||
PokerTHMessage msg;
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("Could not create game!");
|
||||
}
|
||||
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
|
||||
// Let 9 additional clients join.
|
||||
Socket s[] = new Socket[9];
|
||||
long playerId[] = new long[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i] = new Socket("localhost", 7234);
|
||||
String username = "test" + (i+1);
|
||||
String password = username;
|
||||
playerId[i] = userInit(s[i], username, password);
|
||||
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isJoinGameReplyMessageSelected());
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("Could not join game!");
|
||||
}
|
||||
}
|
||||
|
||||
// Server should automatically send start event.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
for (int i = 0; i < 9; i++) {
|
||||
do {
|
||||
msg = receiveMessage(s[i]);
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isStartEventMessageSelected());
|
||||
}
|
||||
// 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);
|
||||
sendMessage(msg);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
sendMessage(msg, s[i]);
|
||||
}
|
||||
|
||||
// Wait for game start message.
|
||||
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();
|
||||
assertEquals(10, seats.size());
|
||||
int firstPlayerPos = 0;
|
||||
for (Iterator<NonZeroId> it = seats.iterator(); it.hasNext(); ) {
|
||||
NonZeroId seat = it.next();
|
||||
if (seat.getValue().longValue() == firstPlayerId)
|
||||
break;
|
||||
firstPlayerPos++;
|
||||
}
|
||||
|
||||
// Wait for first seat state list.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
Collection<NetPlayerState> seatStates = msg.getHandStartMessage().getValue().getSeatStates();
|
||||
|
||||
// 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());
|
||||
}
|
||||
// All other players leave (and are in autofold state then).
|
||||
for (int i = 0; i < 9; i++) {
|
||||
s[i].close();
|
||||
}
|
||||
// Wait for next seat state list.
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
failOnErrorMessage(msg);
|
||||
assertTrue(!msg.isEndOfGameMessageSelected());
|
||||
} while (!msg.isHandStartMessageSelected());
|
||||
seatStates = msg.getHandStartMessage().getValue().getSeatStates();
|
||||
|
||||
// Check whether the correct seat states are sent.
|
||||
assertEquals(10, seatStates.size());
|
||||
int stateNormalCounter = 0;
|
||||
int stateInactiveCounter = 0;
|
||||
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()) {
|
||||
assertEquals(firstPlayerPos, seatPos);
|
||||
stateNormalCounter++;
|
||||
}
|
||||
if (NetPlayerState.EnumType.playerStateSessionInactive == state.getValue()) {
|
||||
stateInactiveCounter++;
|
||||
}
|
||||
seatPos++;
|
||||
}
|
||||
assertEquals(1, stateNormalCounter);
|
||||
assertEquals(9, stateInactiveCounter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class StartNormalGameTest extends TestBase {
|
||||
|
||||
@Test
|
||||
public void testGameStartMessage() throws Exception {
|
||||
guestInit();
|
||||
|
||||
Collection<InitialNonZeroAmountOfMoney> l = new ArrayList<InitialNonZeroAmountOfMoney>();
|
||||
NetGameInfo gameInfo = createGameInfo(10, EndRaiseModeEnumType.EnumType.doubleBlinds, 0, 100, GuestUser + " start normal game", l, 10, 0, 11, 20000);
|
||||
sendMessage(createGameRequestMsg(
|
||||
gameInfo,
|
||||
NetGameTypeEnumType.EnumType.normalGame,
|
||||
10,
|
||||
7,
|
||||
"",
|
||||
false));
|
||||
|
||||
PokerTHMessage msg;
|
||||
// Waiting for player list update.
|
||||
msg = receiveMessage();
|
||||
if (!msg.isPlayerListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (!msg.isGameListMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
|
||||
msg = receiveMessage();
|
||||
if (msg.isJoinGameReplyMessageSelected()) {
|
||||
if (!msg.getJoinGameReplyMessage().getValue().getJoinGameResult().isJoinGameAckSelected()) {
|
||||
fail("Could not create game!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
long gameId = msg.getJoinGameReplyMessage().getValue().getGameId().getValue();
|
||||
|
||||
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);
|
||||
sendMessage(msg);
|
||||
|
||||
do {
|
||||
msg = receiveMessage();
|
||||
} while (msg.isGameListMessageSelected());
|
||||
|
||||
if (msg.isGameStartMessageSelected()) {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
/* PokerTH automated tests.
|
||||
Copyright (C) 2010 Lothar May
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.pokerth.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import de.pokerth.protocol.ProtoBuf.AnnounceMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.AnnounceMessage.ServerType;
|
||||
import de.pokerth.protocol.ProtoBuf.AuthClientResponseMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.ErrorMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.InitAckMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.InitMessage;
|
||||
import de.pokerth.protocol.ProtoBuf.JoinExistingGameMessage;
|
||||
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;
|
||||
|
||||
public abstract class TestBase {
|
||||
|
||||
public final int PROTOCOL_VERSION_MAJOR = 5;
|
||||
public final int PROTOCOL_VERSION_MINOR = 1;
|
||||
public final String AuthUser = "user";
|
||||
public final String AuthPassword = "pencil";
|
||||
public final String GuestUser = "Guest112233";
|
||||
public final String GamePassword = "äöü?ßÄÖÜ";
|
||||
|
||||
protected Socket sock;
|
||||
protected Connection dbConn;
|
||||
protected int lastRejoinGameId = 0;
|
||||
|
||||
@Before
|
||||
public void dbInit() throws Exception {
|
||||
String configFileName = System.getProperty("user.home");
|
||||
if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) {
|
||||
configFileName += "/.pokerth/config.xml";
|
||||
} else {
|
||||
configFileName += "/AppData/Roaming/pokerth/config.xml";
|
||||
}
|
||||
File file = new File(configFileName);
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
Document doc = db.parse(file);
|
||||
doc.getDocumentElement().normalize();
|
||||
Element configNode = (Element)doc.getElementsByTagName("Configuration").item(0);
|
||||
|
||||
Element dbAddressNode = (Element)configNode.getElementsByTagName("DBServerAddress").item(0);
|
||||
String dbAddress = dbAddressNode.getAttribute("value");
|
||||
|
||||
Element dbUserNode = (Element)configNode.getElementsByTagName("DBServerUser").item(0);
|
||||
String dbUser = dbUserNode.getAttribute("value");
|
||||
|
||||
Element dbPasswordNode = (Element)configNode.getElementsByTagName("DBServerPassword").item(0);
|
||||
String dbPassword = dbPasswordNode.getAttribute("value");
|
||||
|
||||
Element dbNameNode = (Element)configNode.getElementsByTagName("DBServerDatabaseName").item(0);
|
||||
String dbName = dbNameNode.getAttribute("value");
|
||||
|
||||
final String dbUrl = "jdbc:mysql://" + dbAddress + ":3306/" + dbName;
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance ();
|
||||
dbConn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
|
||||
}
|
||||
|
||||
@After
|
||||
public void dbClose() throws Exception {
|
||||
dbConn.close();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Thread.sleep(2000);
|
||||
sock = new Socket("localhost", 7234);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException {
|
||||
sock.close();
|
||||
}
|
||||
|
||||
public void sendMessage(PokerTHMessage msg) throws Exception {
|
||||
sendMessage(msg, sock);
|
||||
}
|
||||
|
||||
public void sendMessage(PokerTHMessage msg, Socket s) throws Exception {
|
||||
int size = msg.getSerializedSize();
|
||||
byte[] header = new byte[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
header[i] = (new Integer(size >>> 24)).byteValue();
|
||||
size <<= 8;
|
||||
}
|
||||
s.getOutputStream().write(header);
|
||||
s.getOutputStream().write(msg.toByteArray());
|
||||
}
|
||||
|
||||
public PokerTHMessage receiveMessage() throws Exception {
|
||||
return receiveMessage(sock);
|
||||
}
|
||||
|
||||
public PokerTHMessage receiveMessage(Socket s) throws Exception {
|
||||
byte[] header = new byte[4];
|
||||
s.getInputStream().read(header);
|
||||
int size = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
size <<= 8;
|
||||
size |= (int)header[i];
|
||||
}
|
||||
byte[] data = new byte[size];
|
||||
s.getInputStream().read(data);
|
||||
return PokerTHMessage.parseFrom(data);
|
||||
}
|
||||
|
||||
public int guestInit() throws Exception {
|
||||
return guestInit(sock);
|
||||
}
|
||||
|
||||
public int guestInit(Socket s) throws Exception {
|
||||
int playerId = 0;
|
||||
PokerTHMessage msg = receiveMessage(s);
|
||||
assertTrue(msg.hasAnnounceMessage());
|
||||
|
||||
AnnounceMessage.Version requestedVersion = AnnounceMessage.Version.newBuilder()
|
||||
.setMajor(PROTOCOL_VERSION_MAJOR)
|
||||
.setMinor(PROTOCOL_VERSION_MINOR)
|
||||
.build();
|
||||
InitMessage init = InitMessage.newBuilder()
|
||||
.setBuildId(0)
|
||||
.setLogin(InitMessage.LoginType.guestLogin)
|
||||
.setRequestedVersion(requestedVersion)
|
||||
.setNickName(GuestUser)
|
||||
.build();
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_InitMessage)
|
||||
.setInitMessage(init)
|
||||
.build();
|
||||
sendMessage(msg, s);
|
||||
|
||||
msg = receiveMessage(s);
|
||||
if (msg.hasInitAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_InitAckMessage) {
|
||||
InitAckMessage initAck = msg.getInitAckMessage();
|
||||
assertTrue(initAck.getYourPlayerId() != 0L);
|
||||
assertTrue(!initAck.hasYourAvatarHash());
|
||||
playerId = initAck.getYourPlayerId();
|
||||
}
|
||||
else {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public int userInit() throws Exception {
|
||||
return userInit(sock, AuthUser, AuthPassword);
|
||||
}
|
||||
|
||||
public int userInit(Socket s, String user, String password) throws Exception {
|
||||
return userInit(s, user, password, null, null);
|
||||
}
|
||||
|
||||
public int userInit(Socket s, String user, String password, byte[] avatarData, byte[] lastSessionId) throws Exception {
|
||||
int playerId = 0;
|
||||
PokerTHMessage msg = receiveMessage(s);
|
||||
AnnounceMessage announce = msg.getAnnounceMessage();
|
||||
assertTrue(announce.getServerType() == ServerType.serverTypeInternetAuth);
|
||||
|
||||
ScramSha1 scramAuth = new ScramSha1();
|
||||
|
||||
// Send challenge.
|
||||
AnnounceMessage.Version requestedVersion = AnnounceMessage.Version.newBuilder()
|
||||
.setMajor(PROTOCOL_VERSION_MAJOR)
|
||||
.setMinor(PROTOCOL_VERSION_MINOR)
|
||||
.build();
|
||||
InitMessage.Builder initBuilder = InitMessage.newBuilder();
|
||||
initBuilder
|
||||
.setBuildId(0)
|
||||
.setLogin(InitMessage.LoginType.authenticatedLogin)
|
||||
.setRequestedVersion(requestedVersion)
|
||||
.setClientUserData(ByteString.copyFromUtf8(scramAuth.executeStep1(user)));
|
||||
if (avatarData != null) {
|
||||
initBuilder.setAvatarHash(ByteString.copyFrom(avatarData));
|
||||
}
|
||||
if (lastSessionId != null) {
|
||||
initBuilder.setMyLastSessionId(ByteString.copyFrom(lastSessionId));
|
||||
}
|
||||
InitMessage init = initBuilder.build();
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_InitMessage)
|
||||
.setInitMessage(init)
|
||||
.build();
|
||||
sendMessage(msg, s);
|
||||
|
||||
msg = receiveMessage(s);
|
||||
|
||||
if (msg.hasAuthServerChallengeMessage() && msg.getMessageType() == PokerTHMessageType.Type_AuthServerChallengeMessage)
|
||||
{
|
||||
String serverFirstMessage = new String(msg.getAuthServerChallengeMessage().getServerChallenge().toStringUtf8());
|
||||
AuthClientResponseMessage authClient = AuthClientResponseMessage.newBuilder()
|
||||
.setClientResponse(ByteString.copyFromUtf8(scramAuth.executeStep2(password, serverFirstMessage)))
|
||||
.build();
|
||||
|
||||
msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_AuthClientResponseMessage)
|
||||
.setAuthClientResponseMessage(authClient)
|
||||
.build();
|
||||
sendMessage(msg, s);
|
||||
}
|
||||
failOnErrorMessage(msg);
|
||||
|
||||
msg = receiveMessage(s);
|
||||
failOnErrorMessage(msg);
|
||||
|
||||
msg = receiveMessage(s);
|
||||
if (msg.hasInitAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_InitAckMessage) {
|
||||
InitAckMessage initAck = msg.getInitAckMessage();
|
||||
assertTrue(initAck.getYourPlayerId() != 0L);
|
||||
assertTrue(!initAck.hasYourAvatarHash());
|
||||
playerId = initAck.getYourPlayerId();
|
||||
if (lastSessionId != null) {
|
||||
lastSessionId = initAck.getYourSessionId().toByteArray();
|
||||
}
|
||||
if (initAck.hasRejoinGameId()) {
|
||||
lastRejoinGameId = initAck.getRejoinGameId();
|
||||
}
|
||||
else {
|
||||
lastRejoinGameId = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
failOnErrorMessage(msg);
|
||||
fail("Invalid message.");
|
||||
}
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public PokerTHMessage createGameRequestMsg(NetGameInfo gameInfo, String password, boolean autoLeave) {
|
||||
JoinNewGameMessage.Builder joinBuilder = JoinNewGameMessage.newBuilder();
|
||||
joinBuilder.setGameInfo(gameInfo);
|
||||
joinBuilder.setAutoLeave(autoLeave);
|
||||
if (!password.isEmpty()) {
|
||||
joinBuilder.setPassword(password);
|
||||
}
|
||||
JoinNewGameMessage joinNew = joinBuilder.build();
|
||||
|
||||
PokerTHMessage msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_JoinNewGameMessage)
|
||||
.setJoinNewGameMessage(joinNew)
|
||||
.build();
|
||||
return msg;
|
||||
}
|
||||
|
||||
public PokerTHMessage joinGameRequestMsg(int gameId, String password, boolean autoLeave) {
|
||||
JoinExistingGameMessage.Builder joinBuilder = JoinExistingGameMessage.newBuilder();
|
||||
joinBuilder.setGameId(gameId);
|
||||
joinBuilder.setAutoLeave(autoLeave);
|
||||
if (!password.isEmpty()) {
|
||||
joinBuilder.setPassword(password);
|
||||
}
|
||||
JoinExistingGameMessage joinExisting = joinBuilder.build();
|
||||
|
||||
PokerTHMessage msg = PokerTHMessage.newBuilder()
|
||||
.setMessageType(PokerTHMessageType.Type_JoinExistingGameMessage)
|
||||
.setJoinExistingGameMessage(joinExisting)
|
||||
.build();
|
||||
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);
|
||||
|
||||
JoinGameRequestMessage joinRequest = new JoinGameRequestMessage();
|
||||
joinRequest.setValue(joinType);
|
||||
|
||||
PokerTHMessage msg = new PokerTHMessage();
|
||||
msg.selectJoinGameRequestMessage(joinRequest);
|
||||
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) {
|
||||
|
||||
NetGameInfo.RaiseIntervalMode raiseInterval;
|
||||
if (raiseEveryMinutes > 0) {
|
||||
raiseInterval = NetGameInfo.RaiseIntervalMode.raiseOnMinutes;
|
||||
}
|
||||
else {
|
||||
raiseInterval = NetGameInfo.RaiseIntervalMode.raiseOnHandNum;
|
||||
}
|
||||
|
||||
NetGameInfo gameInfo = NetGameInfo.newBuilder()
|
||||
.setNetGameType(gameType)
|
||||
.setPlayerActionTimeout(playerActionTimeout)
|
||||
.setProposedGuiSpeed(proposedGuiSpeed)
|
||||
.setDelayBetweenHands(delayBetweenHands)
|
||||
.setEndRaiseMode(endMode)
|
||||
.setEndRaiseSmallBlindValue(endRaiseValue)
|
||||
.setFirstSmallBlind(sb)
|
||||
.setGameName(gameName)
|
||||
.setMaxNumPlayers(maxNumPlayers)
|
||||
.addAllManualBlinds(manualBlinds)
|
||||
.setRaiseIntervalMode(raiseInterval)
|
||||
.setRaiseEveryMinutes(raiseEveryMinutes)
|
||||
.setRaiseEveryHands(raiseEveryHands)
|
||||
.setStartMoney(startMoney)
|
||||
.build();
|
||||
|
||||
return gameInfo;
|
||||
}
|
||||
|
||||
void failOnErrorMessage(PokerTHMessage msg) {
|
||||
if (msg.hasErrorMessage())
|
||||
{
|
||||
ErrorMessage error = msg.getErrorMessage();
|
||||
fail("Received error: " + error.getErrorReason().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] decryptCards(final String password, final byte[] ciphertext) throws Exception
|
||||
{
|
||||
final MessageDigest shaDigest = MessageDigest.getInstance("SHA-1");
|
||||
byte[] pw1 = password.getBytes("UTF-8");
|
||||
|
||||
byte[] keyHash1 = shaDigest.digest(pw1);
|
||||
keyHash1 = shaDigest.digest(keyHash1);
|
||||
byte[] pw2 = new byte[keyHash1.length + pw1.length];
|
||||
System.arraycopy(keyHash1, 0, pw2, 0, keyHash1.length);
|
||||
System.arraycopy(pw1, 0, pw2, keyHash1.length, pw1.length);
|
||||
byte[] keyHash2 = shaDigest.digest(pw2);
|
||||
keyHash2 = shaDigest.digest(keyHash2);
|
||||
|
||||
byte[] key = new byte[16];
|
||||
System.arraycopy(keyHash1, 0, key, 0, key.length);
|
||||
byte[] iv = new byte[16];
|
||||
System.arraycopy(keyHash1, 16, iv, 0, 4);
|
||||
System.arraycopy(keyHash2, 0, iv, 4, 12);
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
|
||||
|
||||
cipher.init(
|
||||
Cipher.DECRYPT_MODE,
|
||||
new SecretKeySpec(key, "AES"),
|
||||
new IvParameterSpec(iv));
|
||||
|
||||
return cipher.doFinal(ciphertext);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user