blob: 863efa891031701192d5caa75188bd9e03179fb1 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2007, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.tests.bundles;
import java.io.*;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
public class NativeCodeBundleTests extends AbstractBundleTests {
public static Test suite() {
return new TestSuite(NativeCodeBundleTests.class);
}
public void testNativeCode01() throws Exception {
Bundle nativetestA1 = installer.installBundle("nativetest.a1");
nativetestA1.start();
nativetestA1.stop();
Object[] a1Results = simpleResults.getResults(1);
installer.updateBundle("nativetest.a1", "nativetest.a2");
nativetestA1.start();
nativetestA1.stop();
Object[] a2Results = simpleResults.getResults(1);
assertTrue("1.0", a1Results.length == 1);
assertTrue("1.1", a2Results.length == 1);
assertNotNull("1.2", a1Results[0]);
assertNotNull("1.3", a2Results[0]);
assertFalse("1.4", a1Results[0].equals(a2Results[0]));
}
public void testNativeCode02() throws Exception {
Bundle nativetestB1 = installer.installBundle("nativetest.b1");
nativetestB1.start();
nativetestB1.stop();
Object[] b1Results = simpleResults.getResults(1);
installer.updateBundle("nativetest.b1", "nativetest.b2");
nativetestB1.start();
nativetestB1.stop();
Object[] b2Results = simpleResults.getResults(1);
assertTrue("1.0", b1Results.length == 1);
assertTrue("1.1", b2Results.length == 1);
assertNotNull("1.2", b1Results[0]);
assertNotNull("1.3", b2Results[0]);
assertFalse("1.4", b1Results[0].equals(b2Results[0]));
}
public void testNativeCode03() throws Exception {
System.setProperty("nativecodetest", "1");
setPlatformProperties();
Bundle nativetestC = installer.installBundle("nativetest.c");
nativetestC.start();
nativetestC.stop();
Object[] results = simpleResults.getResults(1);
assertTrue("1.0", results.length == 1);
assertEquals("1.1", "libs.test1", getContent((String) results[0]));
}
public void testNativeCode04() throws Exception {
System.setProperty("nativecodetest", "unresolved");
setPlatformProperties();
Bundle nativetestC = installer.installBundle("nativetest.c");
installer.resolveBundles(new Bundle[] {nativetestC});
assertTrue("1.0", nativetestC.getState() == Bundle.INSTALLED);
}
public void testNativeCode05() throws Exception {
System.setProperty("nativecodetest", "2");
setPlatformProperties();
Bundle nativetestC = installer.installBundle("nativetest.c");
nativetestC.start();
nativetestC.stop();
Object[] results = simpleResults.getResults(1);
assertTrue("1.0", results.length == 1);
assertEquals("1.1", "libs.test3", getContent((String) results[0]));
}
public void testNativeCode06() throws Exception {
System.setProperty("nativecodetest", "3");
setPlatformProperties();
Bundle nativetestC = installer.installBundle("nativetest.c");
nativetestC.start();
nativetestC.stop();
Object[] results = simpleResults.getResults(1);
assertTrue("1.0", results.length == 1);
assertEquals("1.1", "libs.test2", getContent((String) results[0]));
}
public void testNativeCode07() throws Exception {
Bundle nativetestC = installer.installBundle("nativetest.d");
nativetestC.start();
nativetestC.stop();
Object[] results = simpleResults.getResults(1);
assertTrue("1.0", results.length == 1);
assertNull("1.1", results[0]);
}
public void testNativeCode08() throws Exception {
System.setProperty("nativecodetest", "4");
setPlatformProperties();
Bundle nativetestC = installer.installBundle("nativetest.c");
try {
nativetestC.start();
fail("Should not be able to start bundle with missing native code path");
} catch (BundleException e) {
// expected
assertEquals("Wrong exception type", BundleException.NATIVECODE_ERROR, e.getType());
}
}
private String getContent(String file) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
try {
return br.readLine();
} finally {
br.close();
}
}
}