beef up tests
This commit is contained in:
parent
9b749dff51
commit
f6a9d2ff3e
@ -1,22 +1,19 @@
|
|||||||
package net.hyperic.sigar.win32.test;
|
package net.hyperic.sigar.win32.test;
|
||||||
|
|
||||||
|
import net.hyperic.sigar.test.SigarTestCase;
|
||||||
import net.hyperic.sigar.win32.EventLog;
|
import net.hyperic.sigar.win32.EventLog;
|
||||||
import net.hyperic.sigar.win32.EventLogNotification;
|
import net.hyperic.sigar.win32.EventLogNotification;
|
||||||
import net.hyperic.sigar.win32.EventLogRecord;
|
import net.hyperic.sigar.win32.EventLogRecord;
|
||||||
import net.hyperic.sigar.win32.EventLogThread;
|
import net.hyperic.sigar.win32.EventLogThread;
|
||||||
import net.hyperic.sigar.win32.Win32Exception;
|
import net.hyperic.sigar.win32.Win32Exception;
|
||||||
|
|
||||||
|
public class TestEventLog extends SigarTestCase {
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class TestEventLog extends TestCase {
|
|
||||||
|
|
||||||
public TestEventLog(String name) {
|
public TestEventLog(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOpenClose() throws Exception {
|
public void testOpenClose() throws Exception {
|
||||||
|
|
||||||
EventLog log = new EventLog();
|
EventLog log = new EventLog();
|
||||||
|
|
||||||
// Try to close an event log that isn't open
|
// Try to close an event log that isn't open
|
||||||
@ -77,20 +74,44 @@ public class TestEventLog extends TestCase {
|
|||||||
log.close();
|
log.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test reading all records
|
private boolean readAll(String logname) throws Exception {
|
||||||
public void testRead() throws Exception {
|
int fail = 0, success = 0;
|
||||||
EventLogRecord record;
|
EventLogRecord record;
|
||||||
EventLog log = new EventLog();
|
EventLog log = new EventLog();
|
||||||
|
|
||||||
log.open(EventLog.APPLICATION);
|
log.open(logname);
|
||||||
int oldestRecord = log.getOldestRecord();
|
int oldestRecord = log.getOldestRecord();
|
||||||
int numRecords = log.getNumberOfRecords();
|
int numRecords = log.getNumberOfRecords();
|
||||||
|
|
||||||
for (int i = oldestRecord; i < oldestRecord + numRecords; i++) {
|
for (int i = oldestRecord; i < oldestRecord + numRecords; i++) {
|
||||||
record = log.read(i);
|
try {
|
||||||
|
record = log.read(i);
|
||||||
|
success++;
|
||||||
|
} catch (Win32Exception e) {
|
||||||
|
fail++;
|
||||||
|
traceln("Error reading record " + i + ": " +
|
||||||
|
e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.close();
|
log.close();
|
||||||
|
|
||||||
|
return success > fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test reading all records
|
||||||
|
public void testRead() throws Exception {
|
||||||
|
String[] logs = {
|
||||||
|
EventLog.SYSTEM,
|
||||||
|
EventLog.APPLICATION
|
||||||
|
};
|
||||||
|
for (int i=0; i<logs.length; i++) {
|
||||||
|
String msg = "readAll(" + logs[i] + ")";
|
||||||
|
traceln(msg);
|
||||||
|
if (!readAll(logs[i])) {
|
||||||
|
fail(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SSHEventLogNotification
|
private class SSHEventLogNotification
|
||||||
@ -107,7 +128,6 @@ public class TestEventLog extends TestCase {
|
|||||||
|
|
||||||
// Test event log thread
|
// Test event log thread
|
||||||
public void testEventLogThread() throws Exception {
|
public void testEventLogThread() throws Exception {
|
||||||
|
|
||||||
EventLogThread thread =
|
EventLogThread thread =
|
||||||
EventLogThread.getInstance(EventLog.APPLICATION);
|
EventLogThread.getInstance(EventLog.APPLICATION);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user