Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ServerTest.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc;
  23. import com.dmdirc.config.IdentityManager;
  24. import com.dmdirc.addons.ui_dummy.DummyController;
  25. import java.net.URI;
  26. import org.junit.BeforeClass;
  27. import org.junit.Test;
  28. import static org.junit.Assert.*;
  29. public class ServerTest {
  30. private static Server server;
  31. @BeforeClass
  32. public static void setUp() throws Exception {
  33. Main.setUI(new DummyController());
  34. IdentityManager.load();
  35. server = new Server(new URI("irc-test://255.255.255.255"),
  36. IdentityManager.getProfiles().get(0));
  37. server.connect();
  38. }
  39. @Test
  40. public void testGetNetworkFromServerName() {
  41. final String[][] tests = {
  42. {"foo.com", "foo.com"},
  43. {"bar.foo.com", "foo.com"},
  44. {"irc.us.foo.com", "foo.com"},
  45. {"irc.foo.co.uk", "foo.co.uk"},
  46. {"com", "com"},
  47. {"localhost", "localhost"},
  48. {"foo.de", "foo.de"}
  49. };
  50. for (String[] test : tests) {
  51. assertEquals(test[1], Server.getNetworkFromServerName(test[0]));
  52. }
  53. }
  54. @Test
  55. public void testDuplicateInviteRemoval() {
  56. server.disconnect();
  57. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  58. server.addInvite(new Invite(server, "#chan1", "d!e@f"));
  59. assertEquals(1, server.getInvites().size());
  60. //assertEquals("d", server.getInvites().get(0).getSource()[0]);
  61. server.removeInvites("#chan1");
  62. }
  63. @Test
  64. public void testRemoveInvites() {
  65. server.disconnect();
  66. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  67. server.addInvite(new Invite(server, "#chan2", "d!e@f"));
  68. server.removeInvites("#chan1");
  69. assertEquals(1, server.getInvites().size());
  70. server.removeInvites("#chan2");
  71. assertEquals(0, server.getInvites().size());
  72. }
  73. @Test
  74. public void testRemoveInvitesOnSocketClosed() {
  75. server.reconnect();
  76. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  77. server.onSocketClosed();
  78. assertEquals(0, server.getInvites().size());
  79. }
  80. /* @Test
  81. public void testNumericActions() throws InterruptedException {
  82. final TestActionListener tal = new TestActionListener();
  83. server.disconnect();
  84. ActionManager.init();
  85. ActionManager.addListener(tal, CoreActionType.SERVER_NUMERIC);
  86. server.reconnect();
  87. Thread.sleep(1000); // Give the parser thread time to run + inject
  88. assertEquals(1, tal.events.keySet().size());
  89. assertTrue(tal.events.containsKey(CoreActionType.SERVER_NUMERIC));
  90. final int[] counts = new int[6];
  91. for (Object[] args : tal.events.values(CoreActionType.SERVER_NUMERIC)) {
  92. counts[(Integer) args[1]]++;
  93. assertSame("Server arg for numeric " + args[1] + " should be same. "
  94. + "Actual: " + args[0].hashCode() + " Expected: " + server.hashCode(),
  95. server, args[0]);
  96. }
  97. assertEquals(1, counts[1]);
  98. assertEquals(1, counts[2]);
  99. assertEquals(1, counts[3]);
  100. assertEquals(1, counts[4]);
  101. assertEquals(2, counts[5]);
  102. server.disconnect();
  103. }*/
  104. }