1 19 20 package org.netbeans.core.startup; 21 22 import java.io.*; 23 import java.io.File ; 24 import java.util.Collections ; 25 import java.util.Locale ; 26 import java.util.jar.*; 27 import org.netbeans.Module; 28 import org.netbeans.ModuleManager; 29 import org.netbeans.junit.*; 30 import junit.textui.TestRunner; 31 import org.openide.filesystems.Repository; 32 33 36 public class PlatformDependencySatisfiedTest extends SetupHid { 37 private File moduleJarFile; 38 39 public PlatformDependencySatisfiedTest(String name) { 40 super(name); 41 } 42 43 protected void setUp() throws Exception { 44 super.setUp(); 45 System.setProperty("org.netbeans.core.modules.NbInstaller.noAutoDeps", "true"); 46 Main.getModuleSystem (); 48 File tmp = File.createTempFile ("PlatformDependencySatisfiedModule", ".jar"); 49 moduleJarFile = tmp; 50 51 java.lang.reflect.Field f; 53 f = org.openide.util.Utilities.class.getDeclaredField("operatingSystem"); 54 f.setAccessible(true); 55 f.set(null, new Integer (-1)); 56 } 57 58 public void testWindows2000() throws Exception { 59 System.setProperty("os.name", "Windows 2000"); 60 assertTrue("We are on windows", org.openide.util.Utilities.isWindows()); 61 62 assertEnableModule("org.openide.modules.os.Windows", true); 63 assertEnableModule("org.openide.modules.os.MacOSX", false); 64 assertEnableModule("org.openide.modules.os.Unix", false); 65 assertEnableModule("org.openide.modules.os.PlainUnix", false); 66 assertEnableModule("org.openide.modules.os.Garbage", false); 67 assertEnableModule("org.openide.modules.os.OS2", false); 68 } 69 70 public void testMacOSX() throws Exception { 71 System.setProperty("os.name", "Mac OS X"); 72 assertTrue("We are on mac", (org.openide.util.Utilities.getOperatingSystem() & org.openide.util.Utilities.OS_MAC) != 0); 73 74 assertEnableModule("org.openide.modules.os.Windows", false); 75 assertEnableModule("org.openide.modules.os.MacOSX", true); 76 assertEnableModule("org.openide.modules.os.Unix", true); 77 assertEnableModule("org.openide.modules.os.PlainUnix", false); 78 assertEnableModule("org.openide.modules.os.Garbage", false); 79 assertEnableModule("org.openide.modules.os.OS2", false); 80 } 81 82 public void testDarwin() throws Exception { 83 System.setProperty("os.name", "Darwin"); 84 assertTrue("We are on mac", (org.openide.util.Utilities.getOperatingSystem() & org.openide.util.Utilities.OS_MAC) != 0); 85 86 assertEnableModule("org.openide.modules.os.Windows", false); 87 assertEnableModule("org.openide.modules.os.MacOSX", true); 88 assertEnableModule("org.openide.modules.os.Unix", true); 89 assertEnableModule("org.openide.modules.os.PlainUnix", false); 90 assertEnableModule("org.openide.modules.os.Garbage", false); 91 assertEnableModule("org.openide.modules.os.OS2", false); 92 } 93 94 public void testLinux() throws Exception { 95 System.setProperty("os.name", "Fedora Linux"); 96 assertTrue("We are on linux", (org.openide.util.Utilities.getOperatingSystem() & org.openide.util.Utilities.OS_LINUX) != 0); 97 98 assertEnableModule("org.openide.modules.os.Windows", false); 99 assertEnableModule("org.openide.modules.os.MacOSX", false); 100 assertEnableModule("org.openide.modules.os.Unix", true); 101 assertEnableModule("org.openide.modules.os.PlainUnix", true); 102 assertEnableModule("org.openide.modules.os.Garbage", false); 103 assertEnableModule("org.openide.modules.os.OS2", false); 104 } 105 106 public void testBSD() throws Exception { 107 System.setProperty("os.name", "FreeBSD X1.4"); 108 assertTrue("We are on unix", org.openide.util.Utilities.isUnix()); 109 110 assertEnableModule("org.openide.modules.os.Windows", false); 111 assertEnableModule("org.openide.modules.os.MacOSX", false); 112 assertEnableModule("org.openide.modules.os.Unix", true); 113 assertEnableModule("org.openide.modules.os.PlainUnix", true); 114 assertEnableModule("org.openide.modules.os.Garbage", false); 115 assertEnableModule("org.openide.modules.os.OS2", false); 116 } 117 118 public void testOS2() throws Exception { 119 System.setProperty("os.name", "OS/2"); 120 assertEquals ("We are on os/2", org.openide.util.Utilities.OS_OS2, org.openide.util.Utilities.getOperatingSystem()); 121 122 assertEnableModule("org.openide.modules.os.Windows", false); 123 assertEnableModule("org.openide.modules.os.MacOSX", false); 124 assertEnableModule("org.openide.modules.os.Unix", false); 125 assertEnableModule("org.openide.modules.os.PlainUnix", false); 126 assertEnableModule("org.openide.modules.os.Garbage", false); 127 assertEnableModule("org.openide.modules.os.OS2", true); 128 } 129 130 131 private void assertEnableModule(String req, boolean enable) throws Exception { 132 Manifest man = new Manifest (); 133 man.getMainAttributes ().putValue ("Manifest-Version", "1.0"); 134 man.getMainAttributes ().putValue ("OpenIDE-Module", "org.test.PlatformDependency/1"); 135 man.getMainAttributes ().putValue ("OpenIDE-Module-Public-Packages", "-"); 136 137 man.getMainAttributes ().putValue ("OpenIDE-Module-Requires", req); 138 139 JarOutputStream os = new JarOutputStream (new FileOutputStream (moduleJarFile), man); 140 os.putNextEntry (new JarEntry ("empty/test.txt")); 141 os.close (); 142 143 144 final FakeEvents ev = new FakeEvents(); 145 org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev); 146 ModuleManager mgr = new ModuleManager(installer, ev); 147 ModuleFormatSatisfiedTest.addOpenideModules(mgr); 148 installer.registerManager(mgr); 149 mgr.mutexPrivileged().enterWriteAccess(); 150 try { 151 Module m1 = mgr.create(moduleJarFile, null, false, false, false); 152 153 154 if (enable) { 155 assertEquals(Collections.EMPTY_SET, m1.getProblems()); 156 mgr.enable(m1); 157 mgr.disable(m1); 158 } else { 159 assertFalse("We should not be able to enable the module", m1.getProblems().isEmpty()); 160 } 161 mgr.delete(m1); 162 } finally { 163 mgr.mutexPrivileged().exitWriteAccess(); 164 } 165 } 166 167 } 168 | Popular Tags |