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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2006-2008 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 com.dmdirc.Main;
  24. import java.io.File;
  25. import java.io.IOException;
  26. import org.junit.Ignore;
  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. pi = new PluginInfo("moo", false);
  34. assertTrue(pi.checkMinimumVersion("5", 6));
  35. assertTrue(pi.checkMinimumVersion("5", 5));
  36. assertTrue(pi.checkMinimumVersion("0", 17));
  37. assertTrue(pi.checkMinimumVersion("100", 0));
  38. assertTrue(pi.checkMinimumVersion("0", 0));
  39. assertFalse(pi.checkMinimumVersion("abc", 6));
  40. assertFalse(pi.checkMinimumVersion("7", 6));
  41. }
  42. @Test
  43. public void testCheckMaximim() throws PluginException {
  44. pi = new PluginInfo("moo", false);
  45. assertTrue(pi.checkMaximumVersion("6", 6));
  46. assertTrue(pi.checkMaximumVersion("7", 6));
  47. assertTrue(pi.checkMaximumVersion("0", 6));
  48. assertTrue(pi.checkMaximumVersion("6", 0));
  49. assertTrue(pi.checkMaximumVersion("0", 0));
  50. assertTrue(pi.checkMaximumVersion("", 17));
  51. assertFalse(pi.checkMaximumVersion("abc", 6));
  52. assertFalse(pi.checkMaximumVersion("7", 10));
  53. }
  54. @Test
  55. public void testOS() throws PluginException {
  56. pi = new PluginInfo("moo", false);
  57. assertTrue(pi.checkOS("windows", "windows", "xp", "x86"));
  58. assertFalse(pi.checkOS("windows", "linux", "2.6.2.11", "x86"));
  59. assertTrue(pi.checkOS("windows:xp|98|3\\.1", "windows", "xp", "x86"));
  60. assertFalse(pi.checkOS("windows:xp|98|3\\.1", "windows", "vista", "x86"));
  61. assertFalse(pi.checkOS("windows:xp|98|3\\.1", "linux", "2.6.2.11", "x86"));
  62. assertTrue(pi.checkOS("windows:xp|98|3\\.1:.86", "windows", "xp", "x86"));
  63. assertFalse(pi.checkOS("windows:xp|98|3\\.1:.86", "windows", "xp", "mips"));
  64. assertFalse(pi.checkOS("windows:xp|98|3\\.1:.86", "windows", "vista", "x86"));
  65. assertFalse(pi.checkOS("windows:xp|98|3\\.1:.86", "linux", "2.6.2.11", "x86"));
  66. }
  67. @Test @Ignore
  68. public void testLoad() throws PluginException {
  69. Main.setConfigDir(new File(getClass().getResource("testplugin.jar").getFile()).getParent());
  70. PluginInfo pi = new PluginInfo("testplugin.jar");
  71. assertEquals("Author <em@il>", pi.getAuthor());
  72. assertEquals("Friendly", pi.getFriendlyVersion());
  73. assertEquals("Description goes here", pi.getDescription());
  74. assertEquals("randomname", pi.getName());
  75. assertEquals("Friendly name", pi.getNiceName());
  76. assertEquals(3, pi.getVersion());
  77. }
  78. @Test @Ignore
  79. public void testUpdate() throws PluginException, IOException {
  80. final File dir = new File(File.createTempFile("dmdirc-plugin-test", null).getParentFile(),
  81. "dmdirc-plugin-test-folder");
  82. final File pluginDir = new File(dir, "plugins");
  83. dir.deleteOnExit();
  84. pluginDir.mkdirs();
  85. new File(pluginDir, "test.jar").createNewFile();
  86. new File(pluginDir, "test.jar.update").createNewFile();
  87. Main.setConfigDir(dir.getAbsolutePath());
  88. System.out.println(Main.getConfigDir());
  89. System.out.println(PluginManager.getPluginManager().getDirectory());
  90. new PluginInfo("test.jar", false);
  91. assertTrue(new File(pluginDir, "test.jar").exists());
  92. assertFalse(new File(pluginDir, "test.jar.update").exists());
  93. }
  94. public static junit.framework.Test suite() {
  95. return new junit.framework.JUnit4TestAdapter(PluginInfoTest.class);
  96. }
  97. }