You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServerTest.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2006-2009 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.harness.parser.TestParserFactory;
  25. import com.dmdirc.addons.ui_dummy.DummyController;
  26. import java.util.ArrayList;
  27. import org.junit.BeforeClass;
  28. import org.junit.Test;
  29. import static org.junit.Assert.*;
  30. public class ServerTest {
  31. private static Server server;
  32. @BeforeClass
  33. public static void setUp() throws Exception {
  34. Main.setUI(new DummyController());
  35. IdentityManager.load();
  36. server = new Server("255.255.255.255", 6667, "", false,
  37. IdentityManager.getProfiles().get(0), new ArrayList<String>(),
  38. new TestParserFactory());
  39. }
  40. @Test
  41. public void testGetNetworkFromServerName() {
  42. final String[][] tests = {
  43. {"foo.com", "foo.com"},
  44. {"bar.foo.com", "foo.com"},
  45. {"irc.us.foo.com", "foo.com"},
  46. {"irc.foo.co.uk", "foo.co.uk"},
  47. {"com", "com"},
  48. {"localhost", "localhost"},
  49. {"foo.de", "foo.de"}
  50. };
  51. for (String[] test : tests) {
  52. assertEquals(test[1], Server.getNetworkFromServerName(test[0]));
  53. }
  54. }
  55. @Test
  56. public void testDuplicateInviteRemoval() {
  57. server.disconnect();
  58. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  59. server.addInvite(new Invite(server, "#chan1", "d!e@f"));
  60. assertEquals(1, server.getInvites().size());
  61. assertEquals("d", server.getInvites().get(0).getSource()[0]);
  62. server.removeInvites("#chan1");
  63. }
  64. @Test
  65. public void testRemoveInvites() {
  66. server.disconnect();
  67. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  68. server.addInvite(new Invite(server, "#chan2", "d!e@f"));
  69. server.removeInvites("#chan1");
  70. assertEquals(1, server.getInvites().size());
  71. server.removeInvites("#chan2");
  72. assertEquals(0, server.getInvites().size());
  73. }
  74. @Test
  75. public void testRemoveInvitesOnSocketClosed() {
  76. server.reconnect();
  77. server.addInvite(new Invite(server, "#chan1", "a!b@c"));
  78. server.onSocketClosed();
  79. assertEquals(0, server.getInvites().size());
  80. }
  81. /* @Test
  82. public void testNumericActions() throws InterruptedException {
  83. final TestActionListener tal = new TestActionListener();
  84. server.disconnect();
  85. ActionManager.init();
  86. ActionManager.addListener(tal, CoreActionType.SERVER_NUMERIC);
  87. server.reconnect();
  88. Thread.sleep(1000); // Give the parser thread time to run + inject
  89. assertEquals(1, tal.events.keySet().size());
  90. assertTrue(tal.events.containsKey(CoreActionType.SERVER_NUMERIC));
  91. final int[] counts = new int[6];
  92. for (Object[] args : tal.events.values(CoreActionType.SERVER_NUMERIC)) {
  93. counts[(Integer) args[1]]++;
  94. assertSame("Server arg for numeric " + args[1] + " should be same. "
  95. + "Actual: " + args[0].hashCode() + " Expected: " + server.hashCode(),
  96. server, args[0]);
  97. }
  98. assertEquals(1, counts[1]);
  99. assertEquals(1, counts[2]);
  100. assertEquals(1, counts[3]);
  101. assertEquals(1, counts[4]);
  102. assertEquals(2, counts[5]);
  103. server.disconnect();
  104. }*/
  105. }