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.

PluginInfoTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.plugins;
  23. import java.io.File;
  24. import java.io.IOException;
  25. import java.net.URL;
  26. import java.net.MalformedURLException;
  27. import org.junit.Test;
  28. import static org.junit.Assert.*;
  29. public class PluginInfoTest {
  30. private PluginInfo pi;
  31. @Test
  32. public void testCheckMinimum() throws PluginException {
  33. try {
  34. pi = new PluginInfo(new URL("file:///dev/null"), false);
  35. assertTrue(pi.checkMinimumVersion("5", 6));
  36. assertTrue(pi.checkMinimumVersion("5", 5));
  37. assertTrue(pi.checkMinimumVersion("0", 17));
  38. assertTrue(pi.checkMinimumVersion("100", 0));
  39. assertTrue(pi.checkMinimumVersion("0", 0));
  40. assertFalse(pi.checkMinimumVersion("abc", 6));
  41. assertFalse(pi.checkMinimumVersion("7", 6));
  42. } catch (MalformedURLException mue) { }
  43. }
  44. @Test
  45. public void testCheckMaximim() throws PluginException {
  46. try {
  47. pi = new PluginInfo(new URL("file:///dev/null"), false);
  48. assertTrue(pi.checkMaximumVersion("6", 6));
  49. assertTrue(pi.checkMaximumVersion("7", 6));
  50. assertTrue(pi.checkMaximumVersion("0", 6));
  51. assertTrue(pi.checkMaximumVersion("6", 0));
  52. assertTrue(pi.checkMaximumVersion("0", 0));
  53. assertTrue(pi.checkMaximumVersion("", 17));
  54. assertFalse(pi.checkMaximumVersion("abc", 6));
  55. assertFalse(pi.checkMaximumVersion("7", 10));
  56. } catch (MalformedURLException mue) { }
  57. }
  58. @Test
  59. public void testOS() throws PluginException {
  60. try {
  61. pi = new PluginInfo(new URL("file:///dev/null"), false);
  62. assertTrue(pi.checkOS("windows", "windows", "xp", "x86"));
  63. assertFalse(pi.checkOS("windows", "linux", "2.6.2.11", "x86"));
  64. assertTrue(pi.checkOS("windows:xp|98|3\\.1", "windows", "xp", "x86"));
  65. assertFalse(pi.checkOS("windows:xp|98|3\\.1", "windows", "vista", "x86"));
  66. assertFalse(pi.checkOS("windows:xp|98|3\\.1", "linux", "2.6.2.11", "x86"));
  67. assertTrue(pi.checkOS("windows:xp|98|3\\.1:.86", "windows", "xp", "x86"));
  68. assertFalse(pi.checkOS("windows:xp|98|3\\.1:.86", "windows", "xp", "mips"));
  69. assertFalse(pi.checkOS("windows:xp|98|3\\.1:.86", "windows", "vista", "x86"));
  70. assertFalse(pi.checkOS("windows:xp|98|3\\.1:.86", "linux", "2.6.2.11", "x86"));
  71. } catch (MalformedURLException mue) { }
  72. }
  73. @Test
  74. public void testLoad() throws PluginException {
  75. PluginInfo pi = new PluginInfo(getClass().getResource("testplugin.jar"));
  76. assertEquals("Author <em@il>", pi.getAuthor());
  77. assertEquals("Friendly", pi.getFriendlyVersion());
  78. assertEquals("Description goes here", pi.getDescription());
  79. assertEquals("randomname", pi.getName());
  80. assertEquals("Friendly name", pi.getNiceName());
  81. assertEquals(3, pi.getVersion());
  82. }
  83. @Test
  84. public void testUpdate() throws PluginException, IOException {
  85. final File dir = new File(File.createTempFile("dmdirc-plugin-test", null).getParentFile(),
  86. "dmdirc-plugin-test-folder");
  87. final File pluginDir = new File(dir, "plugins");
  88. dir.deleteOnExit();
  89. pluginDir.mkdirs();
  90. final File target = new File(pluginDir, "test.jar");
  91. target.createNewFile();
  92. new File(pluginDir, "test.jar.update").createNewFile();
  93. new PluginInfo(target.toURI().toURL(), false);
  94. assertTrue(new File(pluginDir, "test.jar").exists());
  95. assertFalse(new File(pluginDir, "test.jar.update").exists());
  96. }
  97. }