Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Public Attributes
TestProps Class Reference

Simple testcase that uses the nsIProperties interface to test the JavaXPCOM code. More...

List of all members.

Static Public Member Functions

static void main (String[] args) throws Exception

Static Public Attributes

static final String NS_PROPERTIES_CONTRACTID = ";1"

Detailed Description

Simple testcase that uses the nsIProperties interface to test the JavaXPCOM code.

In particular, it tests for 'out' and 'array' params (see method call to getKeys).

Definition at line 49 of file

Member Function Documentation

static void TestProps.main ( String[]  args) throws Exception [inline, static]

Definition at line 52 of file


    String mozillaPath = System.getProperty("MOZILLA_FIVE_HOME");
    if (mozillaPath == null) {
      throw new RuntimeException("MOZILLA_FIVE_HOME system property not set.");

    File localFile = new File(mozillaPath);
    XPCOM.initXPCOM(localFile, null);
    // XPCOM.initXPCOM() only initializes XPCOM.  If you want to initialize
    // Gecko, you would do the following instead:
    //    GeckoEmbed.initEmbedding(localFile, null);

    nsIComponentManager componentManager = XPCOM.getComponentManager();
    nsIProperties props = (nsIProperties)
      componentManager.createInstanceByContractID(NS_PROPERTIES_CONTRACTID, null,
    if (props == null) {
      throw new RuntimeException("Failed to create nsIProperties.");

    // create the nsISupports objects we will use
    nsILocalFile localFile1 = XPCOM.newLocalFile("/user/local/share", false);
    nsILocalFile localFile2 = XPCOM.newLocalFile("/home/foo", false);
    nsILocalFile localFile3 = XPCOM.newLocalFile("/home/foo/bar", false);

    // set the properties and associate with the created objects
    props.set("File One", localFile1);
    props.set("File Two", localFile2);
    props.set("File One Repeated", localFile1);
    props.set("File Three", localFile3);

    // test the "has" method
    boolean hasProp = props.has("File One");
    if (hasProp == false)
      throw new NoSuchElementException("Could not find property 'File One'.");
    hasProp = props.has("File One Repeated");
    if (hasProp == false)
      throw new NoSuchElementException("Could not find property 'File One Repeated'.");
    hasProp = props.has("Nonexistant Property");
    if (hasProp == true)
      throw new Exception("Found property that doesn't exist.");

    // test the "get" method
    nsILocalFile tempLocalFile = (nsILocalFile) props.get("File One Repeated",
    if (tempLocalFile == null)
      throw new NoSuchElementException("Property 'File One Repeated' not found.");
    if (tempLocalFile != localFile1)
      throw new Exception("Object returned by 'get' not the same as object passed to 'set'.");

    // test the "undefine" method
    hasProp = props.has("File Two");
    if (hasProp == false)
      throw new NoSuchElementException();
    props.undefine("File Two");
    hasProp = props.has("File Two");
    if (hasProp == true)
      throw new NoSuchElementException();

    // test the "getKeys" method
    long[] count = new long[1];
    String[] keys = props.getKeys(count);
    if (keys == null || keys.length != 3) {
      System.out.println("getKeys returned incorrect array.");
    for (int i = 0; i < keys.length; i++) {
      System.out.println("key " + i + ": " + keys[i]);

    //    GeckoEmbed.termEmbedding();

    System.out.println("Test Passed.");

Here is the call graph for this function:

Member Data Documentation

final String TestProps.NS_PROPERTIES_CONTRACTID = ";1" [static]

Definition at line 50 of file

The documentation for this class was generated from the following file: