summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/control
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-07-04 22:26:29 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-07-04 22:26:29 +0200
commitf1ecdcbe59cfaaad647cb5a6c50ceb39c9496c8d (patch)
tree8ed56faebc6194bb92c620916bed8c19dc15a521 /test/jrummikub/control
parentce6cc738adb3c923b3e993adf5c338327df6ecf2 (diff)
downloadJRummikub-f1ecdcbe59cfaaad647cb5a6c50ceb39c9496c8d.tar
JRummikub-f1ecdcbe59cfaaad647cb5a6c50ceb39c9496c8d.zip
More network tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@604 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test/jrummikub/control')
-rw-r--r--test/jrummikub/control/network/NetworkControlTest.java70
-rw-r--r--test/jrummikub/control/network/NetworkGameControlTest.java2
-rw-r--r--test/jrummikub/control/network/NetworkRoundControlTest.java31
3 files changed, 102 insertions, 1 deletions
diff --git a/test/jrummikub/control/network/NetworkControlTest.java b/test/jrummikub/control/network/NetworkControlTest.java
index 6d772ff..f22fd74 100644
--- a/test/jrummikub/control/network/NetworkControlTest.java
+++ b/test/jrummikub/control/network/NetworkControlTest.java
@@ -10,8 +10,11 @@ import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.GameData;
+import jrummikub.util.IListener;
import jrummikub.util.LoginData;
import jrummikub.view.ISettingsPanel.SettingsMode;
+import jrummikub.view.IView.BottomPanelType;
+import jrummikub.view.LoginError;
import jrummikub.view.MockView;
import org.junit.Before;
@@ -28,6 +31,7 @@ public class NetworkControlTest {
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
+ boolean backToLoginFired;
/** */
@Before
@@ -38,6 +42,7 @@ public class NetworkControlTest {
loginData = new LoginData("Karl", "server", "password", "channel");
networkControl = new NetworkControl(loginData, mockConnection, new SaveControl(view), view);
networkControl.startNetwork();
+ backToLoginFired = false;
}
/** */
@@ -92,6 +97,18 @@ public class NetworkControlTest {
assertTrue(view.isSettingsPanelVisible);
assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode);
}
+
+ /** */
+ @Test
+ public void joinGameNackTest() {
+ mockConnection.connectedEvent.emit();
+ GameData data = offerTestGame(id1, "Berta");
+ view.gameListPanel.joinEvent.emit(data);
+ assertSame(data, mockConnection.joinedGame);
+ mockConnection.gameJoinAckEvent.emit(false);
+ assertFalse(view.isSettingsPanelVisible);
+ assertTrue(view.isGameListPanelVisible);
+ }
/** */
@Test
@@ -182,5 +199,58 @@ public class NetworkControlTest {
view.settingsPanel.startGameEvent.emit();
assertTrue(mockConnection.startRoundCalled);
+ assertTrue(networkControl.isGameRunning());
+ }
+
+ /** */
+ @Test
+ public void connectionLostTest() {
+ mockConnection.connectedEvent.emit();
+ GameData data = offerTestGame(id1, "Berta");
+ view.gameListPanel.joinEvent.emit(data);
+ assertSame(data, mockConnection.joinedGame);
+ mockConnection.gameJoinAckEvent.emit(true);
+
+ mockConnection.connectionLostEvent.emit();
+ assertSame(BottomPanelType.NETWORK_SERVER_CONNECTION_LOST_PANEL, view.bottomPanelType);
+ }
+
+ /** */
+ @Test
+ public void connectionFailedTest() {
+ mockConnection.connectionFailedEvent.emit(LoginError.UNKNOWN_ERROR);
+ assertTrue(view.isConnectPanelVisible);
+ assertSame(LoginError.UNKNOWN_ERROR, view.connectPanel.errorMode);
}
+
+ /** */
+ @Test
+ public void connectionCancelTest() {
+ networkControl.getBackToLoginEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ backToLoginFired = true;
+ }
+ });
+
+ view.connectPanel.cancelEvent.emit();
+ assertTrue(backToLoginFired);
+ }
+
+ /** */
+ @Test
+ public void backToGameListTest() {
+ mockConnection.connectedEvent.emit();
+ GameData data = offerTestGame(id1, "Berta");
+ view.gameListPanel.joinEvent.emit(data);
+ assertSame(data, mockConnection.joinedGame);
+ mockConnection.gameJoinAckEvent.emit(true);
+ assertTrue(view.isSettingsPanelVisible);
+ assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode);
+ mockConnection.gameStartEvent.emit();
+
+ view.newGameEvent.emit();
+ assertTrue(view.isGameListPanelVisible);
+ }
+
}
diff --git a/test/jrummikub/control/network/NetworkGameControlTest.java b/test/jrummikub/control/network/NetworkGameControlTest.java
index ea0dabe..c4db9af 100644
--- a/test/jrummikub/control/network/NetworkGameControlTest.java
+++ b/test/jrummikub/control/network/NetworkGameControlTest.java
@@ -63,7 +63,7 @@ public class NetworkGameControlTest {
assertEquals(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL,
view.bottomPanelType);
- hostControl.getBackEvent().add(new IListener() {
+ hostControl.getEndOfGameEvent().add(new IListener() {
@Override
public void handle() {
fired = true;
diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java
index be5952e..56647ac 100644
--- a/test/jrummikub/control/network/NetworkRoundControlTest.java
+++ b/test/jrummikub/control/network/NetworkRoundControlTest.java
@@ -221,4 +221,35 @@ public class NetworkRoundControlTest {
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);
}
+
+ @Test
+ public void testRedeal() {
+ gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
+ gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
+ gameSettings.getPlayerList().get(3).setType(Type.COMPUTER);
+
+ testRoundState = new RoundState(gameSettings, new GameState());
+ for (int i = 0; i < 4; ++i) {
+ IPlayer player = testRoundState.getNthPlayer(i);
+
+ for (int j = 0; j < 6; j++) {
+ player.getHand().drop(new Stone(1, StoneColor.RED), new Position(0, 0));
+ }
+ }
+ testRound = new NetworkRoundControl(null, view, connectionControl, true);
+
+ connectionControl.turnStarted = false;
+ connectionControl.turnEnded = false;
+
+ testRound.startRound();
+
+ connectionControl.roundStateUpdateEvent.emit(testRoundState);
+
+
+ connectionControl.turnStartEvent.emit();
+
+ view.playerPanel.redealEvent.emit();
+
+ assertTrue(connectionControl.redealCalled);
+ }
}