Пример #1
0
  /** Test filter compile no pcap and accessors. */
  public void testFilterCompileNoPcapAndAccessors() {
    PcapBpfProgram bpf = new PcapBpfProgram();

    String str = "host 192.168.1.1";

    int r = Pcap.compileNoPcap(1024, 1, bpf, str, 0, 0);
    assertEquals(OK, r);

    assertEquals(26, bpf.getInstructionCount());
    assertEquals(120259084320L, bpf.getInstruction(10));

    // Boundary checks
    try {
      bpf.getInstruction(-10);
      fail("Failed to generate exception on low index boundary");
    } catch (IndexOutOfBoundsException e) {
      // OK
    }

    // Boundary checks
    try {
      bpf.getInstruction(26);
      fail("Failed to generate exception on upper index boundary");
    } catch (IndexOutOfBoundsException e) {
      // OK
    }

    Pcap.freecode(bpf);
  }
Пример #2
0
 /** Test compile no pcap null ptr handling. */
 public void testCompileNoPcapNullPtrHandling() {
   try {
     Pcap.compileNoPcap(1, 1, null, null, 1, 1);
     fail("Expected a NULL pointer exception.");
   } catch (NullPointerException e) {
     // OK
   }
 }