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

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