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.

ProcessModeTest.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (c) 2006-2015 DMDirc Developers
  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.parser.irc.processors;
  23. import com.dmdirc.harness.parser.TestParser;
  24. import com.dmdirc.parser.common.CallbackNotFoundException;
  25. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  26. import org.junit.Ignore;
  27. import org.junit.Test;
  28. import static org.junit.Assert.assertEquals;
  29. import static org.junit.Assert.assertNotNull;
  30. import static org.junit.Assert.assertTrue;
  31. @Ignore
  32. public class ProcessModeTest {
  33. @Test
  34. public void testBasicUmodes() throws CallbackNotFoundException {
  35. final TestParser parser = new TestParser();
  36. parser.injectConnectionStrings();
  37. parser.injectLine(":server 221 nick iw");
  38. assertTrue(parser.getLocalClient().getModes().indexOf('i') > -1);
  39. assertTrue(parser.getLocalClient().getModes().indexOf('w') > -1);
  40. }
  41. @Test
  42. public void testAlteringUmodes() throws CallbackNotFoundException {
  43. final TestParser parser = new TestParser();
  44. parser.injectConnectionStrings();
  45. parser.injectLine(":server 221 nick iw");
  46. parser.injectLine(":server MODE nick :-iw+ox");
  47. assertTrue(parser.getLocalClient().getModes().indexOf('o') > -1);
  48. assertTrue(parser.getLocalClient().getModes().indexOf('x') > -1);
  49. assertEquals(-1, parser.getLocalClient().getModes().indexOf('i'));
  50. assertEquals(-1, parser.getLocalClient().getModes().indexOf('w'));
  51. }
  52. @Test
  53. public void testChannelUmodes() {
  54. final TestParser parser = new TestParser();
  55. parser.injectConnectionStrings();
  56. parser.injectLine(":nick JOIN #DMDirc_testing");
  57. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
  58. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
  59. final ChannelClientInfo cci = parser.getClient("luser").getChannelClients().get(0);
  60. parser.injectLine(":server MODE #DMDirc_testing +v luser");
  61. assertEquals("v", cci.getAllModes());
  62. assertEquals("+", cci.getAllModesPrefix());
  63. parser.injectLine(":server MODE #DMDirc_testing +o luser");
  64. assertEquals("ov", cci.getAllModes());
  65. assertEquals("@+", cci.getAllModesPrefix());
  66. parser.injectLine(":server MODE #DMDirc_testing +bov moo luser luser");
  67. assertEquals("ov", cci.getAllModes());
  68. parser.injectLine(":server MODE #DMDirc_testing -bov moo luser luser");
  69. assertEquals("", cci.getAllModes());
  70. assertEquals("", cci.getAllModesPrefix());
  71. }
  72. @Test
  73. public void testUnknownUser1() {
  74. final TestParser parser = new TestParser();
  75. parser.injectConnectionStrings();
  76. parser.injectLine(":nick JOIN #DMDirc_testing");
  77. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
  78. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
  79. parser.injectLine(":luser!me@my MODE #DMDirc_testing +v :moo");
  80. assertNotNull(parser.getClient("moo"));
  81. assertEquals(0, parser.getClient("moo").getChannelCount());
  82. assertEquals("Parser should update ident when it sees a MODE line",
  83. "me", parser.getClient("luser").getUsername());
  84. assertEquals("Parser should update host when it sees a MODE line",
  85. "my", parser.getClient("luser").getHostname());
  86. }
  87. @Test
  88. public void testChannelModes() {
  89. final TestParser parser = new TestParser();
  90. parser.injectConnectionStrings();
  91. parser.injectLine(":nick JOIN #DMDirc_testing");
  92. parser.injectLine(":server 353 nick = #DMDirc_testing :@nick +luser");
  93. parser.injectLine(":server 366 nick #DMDirc_testing :End of /NAMES list");
  94. parser.injectLine(":server 324 nick #DMDirc_testing +Zstnl 1234");
  95. assertEquals("1234", parser.getChannel("#DMDirc_testing").getMode('l'));
  96. String modes = parser.getChannel("#DMDirc_testing").getModes().split(" ")[0];
  97. assertEquals(6, modes.length());
  98. assertEquals('+', modes.charAt(0));
  99. assertTrue(modes.indexOf('Z') > -1);
  100. assertTrue(modes.indexOf('s') > -1);
  101. assertTrue(modes.indexOf('t') > -1);
  102. assertTrue(modes.indexOf('n') > -1);
  103. assertTrue(modes.indexOf('l') > -1);
  104. parser.injectLine(":server MODE #DMDirc_testing :-Z");
  105. modes = parser.getChannel("#DMDirc_testing").getModes().split(" ")[0];
  106. assertEquals(5, modes.length());
  107. assertEquals('+', modes.charAt(0));
  108. assertTrue(modes.indexOf('s') > -1);
  109. assertTrue(modes.indexOf('t') > -1);
  110. assertTrue(modes.indexOf('n') > -1);
  111. assertTrue(modes.indexOf('l') > -1);
  112. }
  113. }