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.3KB

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