Ejemplo n.º 1
0
 public void testEventLogIteratorBackwards() {
   EventLogIterator iter =
       new EventLogIterator(null, "Application", WinNT.EVENTLOG_BACKWARDS_READ);
   try {
     int max = 100;
     int lastId = -1;
     while (iter.hasNext()) {
       EventLogRecord record = iter.next();
       /*
         System.out.println(record.getRecordNumber()
         + ": Event ID: " + record.getEventId()
         + ", Event Type: " + record.getType()
         + ", Event Source: " + record.getSource());
       */
       assertTrue(record.getRecordNumber() < lastId || lastId == -1);
       lastId = record.getRecordNumber();
       if (max-- <= 0) {
         break; // shorten test
       }
     }
   } finally {
     iter.close();
   }
 }
Ejemplo n.º 2
0
  public void testEventLogIteratorForwards() {
    EventLogIterator iter = new EventLogIterator("Application");
    try {
      int max = 100;
      int lastId = 0;
      while (iter.hasNext()) {
        EventLogRecord record = iter.next();
        assertTrue(record.getRecordNumber() > lastId);
        lastId = record.getRecordNumber();
        assertNotNull(record.getType().name());
        assertNotNull(record.getSource());
        if (record.getRecord().DataLength.intValue() > 0) {
          assertEquals(record.getData().length, record.getRecord().DataLength.intValue());
        } else {
          assertNull(record.getData());
        }
        if (record.getRecord().NumStrings.intValue() > 0) {
          assertEquals(record.getStrings().length, record.getRecord().NumStrings.intValue());
        } else {
          assertNull(record.getStrings());
        }

        if (max-- <= 0) {
          break; // shorten test
        }
        /*
          System.out.println(record.getRecordNumber()
          + ": Event ID: " + record.getEventId()
          + ", Event Type: " + record.getType()
          + ", Event Source: " + record.getSource());
        */
      }
    } finally {
      iter.close();
    }
  }