More network tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@604 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
ce6cc738ad
commit
f1ecdcbe59
8 changed files with 110 additions and 28 deletions
|
@ -75,6 +75,8 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
public boolean nextPlayer;
|
public boolean nextPlayer;
|
||||||
/** */
|
/** */
|
||||||
public boolean startRoundCalled;
|
public boolean startRoundCalled;
|
||||||
|
/** */
|
||||||
|
public boolean redealCalled;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNickname() {
|
public String getNickname() {
|
||||||
|
@ -269,7 +271,6 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void redeal() {
|
public void redeal() {
|
||||||
// TODO Auto-generated method stub
|
redealCalled = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,12 @@ import jrummikub.util.MockEvent;
|
||||||
public class MockConnectPanel implements IConnectPanel {
|
public class MockConnectPanel implements IConnectPanel {
|
||||||
/** */
|
/** */
|
||||||
public MockEvent cancelEvent = new MockEvent();
|
public MockEvent cancelEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
|
public LoginError errorMode;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMode(LoginError error) {
|
public void setMode(LoginError error) {
|
||||||
// TODO Auto-generated method stub
|
errorMode = error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class GameControl {
|
||||||
protected GameState gameState;
|
protected GameState gameState;
|
||||||
protected List<Connection> connections = new ArrayList<Connection>();
|
protected List<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
private Event endOfGameEvent = new Event();
|
protected Event endOfGameEvent = new Event();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
|
|
@ -362,14 +362,6 @@ public class NetworkControl {
|
||||||
private void createGameControl(GameSettings settings, boolean host) {
|
private void createGameControl(GameSettings settings, boolean host) {
|
||||||
gameControl = new NetworkGameControl(settings, saveControl, view,
|
gameControl = new NetworkGameControl(settings, saveControl, view,
|
||||||
connectionControl, host);
|
connectionControl, host);
|
||||||
gameControl.getBackEvent().add(new IListener() {
|
|
||||||
@Override
|
|
||||||
public void handle() {
|
|
||||||
view.setBottomPanel(BottomPanelType.START_GAME_PANEL);
|
|
||||||
abortControls();
|
|
||||||
view.showGameListPanel(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
gameControl.getEndOfGameEvent().add(new IListener() {
|
gameControl.getEndOfGameEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
|
|
|
@ -7,8 +7,6 @@ import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.IRoundState;
|
import jrummikub.model.IRoundState;
|
||||||
import jrummikub.model.PlayerSettings;
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.model.PlayerSettings.Type;
|
import jrummikub.model.PlayerSettings.Type;
|
||||||
import jrummikub.util.Event;
|
|
||||||
import jrummikub.util.IEvent;
|
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.util.IListener1;
|
import jrummikub.util.IListener1;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
@ -20,7 +18,6 @@ import jrummikub.view.IView.BottomPanelType;
|
||||||
public class NetworkGameControl extends GameControl {
|
public class NetworkGameControl extends GameControl {
|
||||||
private IConnectionControl connectionControl;
|
private IConnectionControl connectionControl;
|
||||||
private boolean host;
|
private boolean host;
|
||||||
private Event backEvent = new Event();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new network game control
|
* Creates new network game control
|
||||||
|
@ -62,16 +59,6 @@ public class NetworkGameControl extends GameControl {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The back event is emitted when the network game has ended and the player
|
|
||||||
* wants to return to the game list
|
|
||||||
*
|
|
||||||
* @return the event
|
|
||||||
*/
|
|
||||||
public IEvent getBackEvent() {
|
|
||||||
return backEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startRound() {
|
protected void startRound() {
|
||||||
connections.add(connectionControl.getRoundStartEvent().add(new IListener() {
|
connections.add(connectionControl.getRoundStartEvent().add(new IListener() {
|
||||||
|
@ -109,7 +96,7 @@ public class NetworkGameControl extends GameControl {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
abortGame();
|
abortGame();
|
||||||
backEvent.emit();
|
endOfGameEvent.emit();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
connections.add(view.getEndProgramEvent().add(new IListener() {
|
connections.add(view.getEndProgramEvent().add(new IListener() {
|
||||||
|
|
|
@ -10,8 +10,11 @@ import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.PlayerSettings;
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.model.PlayerSettings.Type;
|
import jrummikub.model.PlayerSettings.Type;
|
||||||
import jrummikub.util.GameData;
|
import jrummikub.util.GameData;
|
||||||
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.util.LoginData;
|
import jrummikub.util.LoginData;
|
||||||
import jrummikub.view.ISettingsPanel.SettingsMode;
|
import jrummikub.view.ISettingsPanel.SettingsMode;
|
||||||
|
import jrummikub.view.IView.BottomPanelType;
|
||||||
|
import jrummikub.view.LoginError;
|
||||||
import jrummikub.view.MockView;
|
import jrummikub.view.MockView;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -28,6 +31,7 @@ public class NetworkControlTest {
|
||||||
UUID id1 = UUID.randomUUID();
|
UUID id1 = UUID.randomUUID();
|
||||||
UUID id2 = UUID.randomUUID();
|
UUID id2 = UUID.randomUUID();
|
||||||
UUID id3 = UUID.randomUUID();
|
UUID id3 = UUID.randomUUID();
|
||||||
|
boolean backToLoginFired;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Before
|
@Before
|
||||||
|
@ -38,6 +42,7 @@ public class NetworkControlTest {
|
||||||
loginData = new LoginData("Karl", "server", "password", "channel");
|
loginData = new LoginData("Karl", "server", "password", "channel");
|
||||||
networkControl = new NetworkControl(loginData, mockConnection, new SaveControl(view), view);
|
networkControl = new NetworkControl(loginData, mockConnection, new SaveControl(view), view);
|
||||||
networkControl.startNetwork();
|
networkControl.startNetwork();
|
||||||
|
backToLoginFired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
|
@ -92,6 +97,18 @@ public class NetworkControlTest {
|
||||||
assertTrue(view.isSettingsPanelVisible);
|
assertTrue(view.isSettingsPanelVisible);
|
||||||
assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode);
|
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
|
@Test
|
||||||
|
@ -182,5 +199,58 @@ public class NetworkControlTest {
|
||||||
view.settingsPanel.startGameEvent.emit();
|
view.settingsPanel.startGameEvent.emit();
|
||||||
|
|
||||||
assertTrue(mockConnection.startRoundCalled);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class NetworkGameControlTest {
|
||||||
assertEquals(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL,
|
assertEquals(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL,
|
||||||
view.bottomPanelType);
|
view.bottomPanelType);
|
||||||
|
|
||||||
hostControl.getBackEvent().add(new IListener() {
|
hostControl.getEndOfGameEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
fired = true;
|
fired = true;
|
||||||
|
|
|
@ -221,4 +221,35 @@ public class NetworkRoundControlTest {
|
||||||
connectionControl.turnStartEvent.emit();
|
connectionControl.turnStartEvent.emit();
|
||||||
assertFalse(connectionControl.turnEnded);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue