test validate method

This commit is contained in:
Doug MacEachern 2007-03-06 00:05:25 +00:00
parent 34899987c0
commit ebf212248e
1 changed files with 30 additions and 4 deletions

View File

@ -61,9 +61,6 @@ public class TestPdh extends SigarTestCase {
traceln(path + " validate: " + Pdh.validate(path)); traceln(path + " validate: " + Pdh.validate(path));
getValue(path); getValue(path);
} }
String bogusKey = "\\Does Not\\Exist";
assertTrue(Pdh.validate(bogusKey) != 0);
} }
public void testCounterMap() throws Exception { public void testCounterMap() throws Exception {
@ -88,7 +85,8 @@ public class TestPdh extends SigarTestCase {
int last = -1; int last = -1;
for (int i=0; i<keys.length; i++) { for (int i=0; i<keys.length; i++) {
String name = keys[i]; String name = keys[i];
int[] ix = (int[])counters.get(name); int[] ix =
(int[])counters.get(name.toLowerCase());
assertFalse(ix[0] == last); assertFalse(ix[0] == last);
traceln(name + "=" + ix[0]); traceln(name + "=" + ix[0]);
last = ix[0]; last = ix[0];
@ -98,6 +96,34 @@ public class TestPdh extends SigarTestCase {
} }
} }
public void testValidate() {
Object[][] tests = {
{ "\\Does Not\\Exist", new Integer(Pdh.NO_OBJECT) },
{ "Does Not Exist", new Integer(Pdh.BAD_COUNTERNAME) },
{ "\\System\\DoesNotExist", new Integer(Pdh.NO_COUNTER) },
{ "\\Processor(666)\\% User Time", new Integer(Pdh.NO_INSTANCE) },
{ "\\System\\Threads", new Integer(Pdh.VALID_DATA) },
//slow
//{ "\\\\-\\System\\Threads", new Integer(Pdh.NO_MACHINE) },
};
for (int i=0; i<tests.length; i++) {
String path = (String)tests[i][0];
int expect = ((Integer)tests[i][1]).intValue();
int status = Pdh.validate(path);
boolean expectedResult = (status == expect);
if (!expectedResult) {
traceln("[validate] " + path + "-->" +
Integer.toHexString(status).toUpperCase() +
" != " +
Integer.toHexString(expect).toUpperCase());
}
assertTrue(expectedResult);
}
}
public void testPdh() throws Exception { public void testPdh() throws Exception {
String[] iface = Pdh.getKeys("Thread"); String[] iface = Pdh.getKeys("Thread");