VirtualBox

Changeset 29231 in vbox for trunk/src/libs/xpcom18a4/java


Ignore:
Timestamp:
May 7, 2010 7:42:03 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
61312
Message:

bridge: tests reworked

Location:
trunk/src/libs/xpcom18a4/java
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/java/Makefile.kmk

    r29216 r29231  
    256256        $(VBOX_JXPCOM_JSRC)/internal/XPCOMJavaProxyBase.java \
    257257        $(VBOX_JXPCOM_JSRC)/internal/XPCOMJavaProxy.java
    258 VBOX_JXPCOM_MGR = $(VBOX_JXPCOM_SRC)/src/org/virtualbox/VirtualBoxManager.java
     258VBOX_JXPCOM_MGR = \
     259     $(VBOX_JXPCOM_SRC)/src/org/virtualbox/VirtualBoxManager.java \
     260     $(VBOX_JXPCOM_SRC)/src/org/virtualbox/VBoxObjectBase.java
    259261
    260262$$(VBOX_JXPCOM_JAR): $(VBOX_JXPCOM_JAR_SRC) $(VBOX_JXPCOM_GEN)/jxpcomgen.list $(VBOX_JXPCOM_NSERROR) $(VBOX_JXPCOM_MGR) | $$(dir $$@)
  • trunk/src/libs/xpcom18a4/java/tests/TestVBox.java

    r29212 r29231  
    1515import org.virtualbox.*;
    1616
     17class VBoxCallbacks extends VBoxObjectBase implements IVirtualBoxCallback
     18{
     19    public void onGuestPropertyChange(String machineId, String name, String value, String flags)
     20    {
     21        System.out.println("onGuestPropertyChange -- VM: " + machineId + ", " + name + "->" + value);
     22    }
     23    public void onSnapshotChange(String machineId, String snapshotId)
     24    {
     25    }
     26    public void onSnapshotDeleted(String machineId, String snapshotId)
     27    {
     28    }
     29    public void onSnapshotTaken(String machineId, String snapshotId) {}
     30    public void onSessionStateChange(String machineId, long state)
     31    {
     32        System.out.println("onSessionStateChange -- VM: " + machineId + ", state: " + state);
     33    }
     34    public void onMachineRegistered(String machineId, boolean registered) {}
     35    public void onMediumRegistered(String mediumId, long mediumType, boolean registered) {}
     36    public void onExtraDataChange(String machineId, String key, String value)
     37    {
     38        System.out.println("onExtraDataChange -- VM: " + machineId + ": " + key+"->"+value);
     39    }
     40    public boolean onExtraDataCanChange(String machineId, String key, String value, String[] error) { return true; }
     41    public void onMachineDataChange(String machineId)
     42    {}
     43    public void onMachineStateChange(String machineId, long state)
     44    {
     45        System.out.println("onMachineStateChange -- VM: " + machineId + ", state: " + state);
     46    }
     47}
     48
    1749public class TestVBox
    1850{
     51    static void testCallbacks(VirtualBoxManager mgr, IVirtualBox vbox)
     52    {
     53        IVirtualBoxCallback cbs = new VBoxCallbacks();
     54        vbox.registerCallback(cbs);
     55        for (int i=0; i<100; i++)
     56        {
     57            mgr.waitForEvents(500);
     58        }
     59        vbox.unregisterCallback(cbs);
     60    }
    1961
    20     public static class VBoxCallbacks implements IVirtualBoxCallback
     62    static void testEnumeration(VirtualBoxManager mgr, IVirtualBox vbox)
    2163    {
    22         public void onGuestPropertyChange(String machineId, String name, String value, String flags) {}
    23         public void onSnapshotChange(String machineId, String snapshotId) {}
    24         public void onSnapshotDeleted(String machineId, String snapshotId) {}
    25         public void onSnapshotTaken(String machineId, String snapshotId) {}
    26         /** @todo is there a type SessionState instead of long? */
    27         public void onSessionStateChange(String machineId, long state) {}
    28         public void onMachineRegistered(String machineId, boolean registered) {}
    29         /** @todo long -> MediumType */
    30         public void onMediumRegistered(String mediumId, long mediumType, boolean registered) {}
    31         public void onExtraDataChange(String machineId, String key, String value) {}
    32         public boolean onExtraDataCanChange(String machineId, String key, String value, String[] error) { return true; }
    33         public void onMachineDataChange(String machineId) {}
    34         /** @todo long -> MachineState */
    35         public void onMachineStateChange(String machineId, long state) { System.out.println("onMachineStateChange -- VM: " + machineId + ", state: " + state); };
     64        IMachine[] machs = vbox.getMachines(null);
     65        for (IMachine m : machs)
     66        {
     67            System.out.println("VM name: " + m.getName() + ", RAM size: " + m.getMemorySize() + "MB");
     68            System.out.println(" HWVirt: " + m.getHWVirtExProperty(HWVirtExPropertyType.Enabled)
     69                               + ", Nested Paging: " + m.getHWVirtExProperty(HWVirtExPropertyType.NestedPaging)
     70                               + ", PAE: " + m.getCPUProperty(CPUPropertyType.PAE) );
     71        }
     72    }
    3673
    37         /** @todo ugly reimplementation of queryInterface, should have base class to derive from */
    38         public nsISupports queryInterface(String iid) { return org.mozilla.xpcom.Mozilla.queryInterface(this, iid); }
    39     };
    40 
     74    static void testStart(VirtualBoxManager mgr, IVirtualBox vbox)
     75    {
     76        String m =  vbox.getMachines(null)[0].getName();
     77        System.out.println("\nAttempting to start VM '" + m + "'");
     78        mgr.startVm(m, null, 7000);
     79    }
    4180
    4281    public static void main(String[] args)
     
    5089            IVirtualBox vbox = mgr.getVBox();
    5190            System.out.println("VirtualBox version: " + vbox.getVersion() + "\n");
     91            testEnumeration(mgr, vbox);
     92            testCallbacks(mgr, vbox);
    5293
    53             /* list all VMs and print some info for each */
    54             IMachine[] machs = vbox.getMachines(null);
    55             for (IMachine m : machs)
    56             {
    57                 try
    58                 {
    59                     System.out.println("VM name: " + m.getName() + ", RAM size: " + m.getMemorySize() + "MB");
    60                     System.out.println(" HWVirt: " + m.getHWVirtExProperty(HWVirtExPropertyType.Enabled)
    61                                        + ", Nested Paging: " + m.getHWVirtExProperty(HWVirtExPropertyType.NestedPaging)
    62                                        + ", PAE: " + m.getCPUProperty(CPUPropertyType.PAE) );
    63                 }
    64                 catch (Throwable e)
    65                 {
    66                     e.printStackTrace();
    67                 }
    68             }
    69 
    70             boolean withCallbacks = false;
    71             VBoxCallbacks vboxCallbacks = null;
    72 
    73             if (withCallbacks)
    74             {
    75                 vboxCallbacks = new VBoxCallbacks();
    76                 vbox.registerCallback(mgr.makeVirtualBoxCallback(vboxCallbacks));
    77             }
    78 
    79             /* do something silly, start the first VM in the list */
    80             String m = machs[0].getName();
    81             System.out.println("\nAttempting to start VM '" + m + "'");
    82             if (false || mgr.startVm(m, 7000))
    83             {
    84                 if (!withCallbacks)
    85                 {
    86                     System.out.println("started, presss any key...");
    87                     int ch = System.in.read();
    88                 } else {
    89                     while (true)
    90                     {
    91                         mgr.waitForEvents(500);
    92                     }
    93                 }
    94             }
    95             else
    96             {
    97                 System.out.println("cannot start machine "+m);
    98             }
    99 
    100             if (withCallbacks)
    101                 vbox.unregisterCallback(vboxCallbacks);
     94            System.out.println("done, press Enter...");
     95            int ch = System.in.read();
    10296        }
    10397        catch (Throwable e)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette