package net.hyperic.sigar.test;

import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.ProcState;

public class TestProcState extends SigarTestCase {

    public TestProcState(String name) {
        super(name);
    }

    private void traceState(Sigar sigar, long pid) {
        try {
            ProcState procState =
                sigar.getProcState(pid);
            char state = procState.getState();
            traceln("[" + procState.getName() + "] " +
                    "pid=" + pid +
                    ",state=" + state +
                    ",threads=" + procState.getThreads() +
                    ",processor=" + procState.getProcessor() +
                    ",priority=" + procState.getPriority());
        } catch (SigarException e) {
            traceln("pid " + pid + ": " + e.getMessage());
        }
    }

    public void testCreate() throws Exception {
        Sigar sigar = getSigar();

        try {
            sigar.getProcState(getInvalidPid());
        } catch (SigarException e) {
        }

        ProcState procState = sigar.getProcState(sigar.getPid());
        traceState(sigar, sigar.getPid());

        char state = procState.getState();
        assertTrue((state == 'R') || (state == 'S'));
        assertTrue(procState.getName().indexOf("java") != -1);

        long[] pids = sigar.getProcList();
        for (int i=0; i<pids.length; i++) {
            traceState(sigar, pids[i]);
        }
    }
}

@@ -414,353 +414,48 @@
     
-char state = procState.getState();%0A            traceln(%22%5B%22 + procState.getName() + %22%5D %22 +%0A                    %22pid=%22 + pid +%0A                    %22,state=%22 + state +%0A                    %22,threads=%22 + procState.getThreads() +%0A                    %22,processor=%22 + procState.getProcessor() +%0A                    %22,priority=%22 + procState.getPriority()
+traceln(%22%5Bpid=%22 + pid + %22%5D %22 + procState
 );%0A 

use ProcState.toString