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

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