// Path: src/main/java/com/github/ffalcinelli/jdivert/exceptions/WinDivertException.java
// public class WinDivertException extends Exception {
//     protected int code;
//     protected String message;
//     protected LastErrorException lee;
// 
//     public WinDivertException(int code) {
//         this(code, Kernel32Util.formatMessage(code));
//     }
// 
//     public WinDivertException(int code, String message) {
//         this(code, message, null);
//     }
// 
//     public WinDivertException(int code, String message, Throwable cause) {
//         super(message, cause);
//         this.code = code;
//     }
// 
//     /**
//      * Throw a WinDivertException whenever GetLastError returned a code different from
//      * <ul>
//      * <li>0 (Success)</li>
//      * <li>997 (Overlapped I/O is in progress)</li>
//      *</ul>
//      * @return The GetLastError code.
//      * @throws WinDivertException When {@code GetLastError} returns a code different from 0 or 997, {@link WinDivertException} is thrown.
//      */
//     public static int throwExceptionOnGetLastError() throws WinDivertException {
//         int lastError = Native.getLastError();
//         if (lastError != 0 && lastError != 997) {
//             throw new WinDivertException(lastError);
//         }
//         return lastError;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     @Override
//     public String toString() {
//         return "WinDivertException{" +
//                 "code=" + code +
//                 ", message='" + message + '\'' +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/Enums.java
// public enum Flag {
//     DEFAULT(0),
//     /**
//      * This flag opens the WinDivert handle in packet sniffing mode. In packet sniffing mode the original packet is not dropped-and-diverted (the default) but copied-and-diverted. This mode is useful for implementing packet sniffing tools similar to those applications that currently use Winpcap.
//      */
//     SNIFF(1),
//     /**
//      * This flag indicates that the user application does not intend to read matching packets with WinDivertRecv(), instead the packets should be silently dropped. This is useful for implementing simple packet filters using the <a href="https://www.reqrypt.org/windivert-doc.html#filter_language">WinDivert filter language</a>.
//      */
//     DROP(2),
//     /**
//      * By default WinDivert ensures that each diverted packet has a valid checksum. If the checksum is missing (e.g. with Tcp checksum offloading), WinDivert will calculate it before passing the packet to the user application. This flag disables this behavior.
//      */
//     NO_CHECKSUM(1024);
//     private int value;
// 
//     Flag(int value) {
//         this.value = value;
//     }
// 
//     public int getValue() {
//         return value;
//     }
// }


import com.github.ffalcinelli.jdivert.exceptions.WinDivertException;
import org.junit.After;
import org.junit.Test;
import java.util.Random;
import static com.github.ffalcinelli.jdivert.Enums.Flag.*;
import static com.github.ffalcinelli.jdivert.Enums.Layer.NETWORK;
import static org.junit.Assert.*;
/*
 * Copyright (c) Fabio Falcinelli 2016.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.github.ffalcinelli.jdivert;




/**
 * Created by fabio on 26/10/2016.
 */
public class WinDivertTestCase {

    //this can be safely static
    static Random rnd = new Random();
    protected WinDivert w;

    public static int randInt(int min, int max) {
        return rnd.nextInt(max - min + 1) + min;
    }

    @After
    public void tearDown() {
        if (w != null)
            w.close();
    }

    @Test(expected = IllegalArgumentException.class)
    public void wrongFlags() {
        w = new WinDivert("true", NETWORK, 0, SNIFF, DROP);
    }

    @Test
// Path: src/main/java/com/github/ffalcinelli/jdivert/exceptions/WinDivertException.java
// public class WinDivertException extends Exception {
//     protected int code;
//     protected String message;
//     protected LastErrorException lee;
// 
//     public WinDivertException(int code) {
//         this(code, Kernel32Util.formatMessage(code));
//     }
// 
//     public WinDivertException(int code, String message) {
//         this(code, message, null);
//     }
// 
//     public WinDivertException(int code, String message, Throwable cause) {
//         super(message, cause);
//         this.code = code;
//     }
// 
//     /**
//      * Throw a WinDivertException whenever GetLastError returned a code different from
//      * <ul>
//      * <li>0 (Success)</li>
//      * <li>997 (Overlapped I/O is in progress)</li>
//      *</ul>
//      * @return The GetLastError code.
//      * @throws WinDivertException When {@code GetLastError} returns a code different from 0 or 997, {@link WinDivertException} is thrown.
//      */
//     public static int throwExceptionOnGetLastError() throws WinDivertException {
//         int lastError = Native.getLastError();
//         if (lastError != 0 && lastError != 997) {
//             throw new WinDivertException(lastError);
//         }
//         return lastError;
//     }
// 
//     public int getCode() {
//         return code;
//     }
// 
//     @Override
//     public String toString() {
//         return "WinDivertException{" +
//                 "code=" + code +
//                 ", message='" + message + '\'' +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/github/ffalcinelli/jdivert/Enums.java
// public enum Flag {
//     DEFAULT(0),
//     /**
//      * This flag opens the WinDivert handle in packet sniffing mode. In packet sniffing mode the original packet is not dropped-and-diverted (the default) but copied-and-diverted. This mode is useful for implementing packet sniffing tools similar to those applications that currently use Winpcap.
//      */
//     SNIFF(1),
//     /**
//      * This flag indicates that the user application does not intend to read matching packets with WinDivertRecv(), instead the packets should be silently dropped. This is useful for implementing simple packet filters using the <a href="https://www.reqrypt.org/windivert-doc.html#filter_language">WinDivert filter language</a>.
//      */
//     DROP(2),
//     /**
//      * By default WinDivert ensures that each diverted packet has a valid checksum. If the checksum is missing (e.g. with Tcp checksum offloading), WinDivert will calculate it before passing the packet to the user application. This flag disables this behavior.
//      */
//     NO_CHECKSUM(1024);
//     private int value;
// 
//     Flag(int value) {
//         this.value = value;
//     }
// 
//     public int getValue() {
//         return value;
//     }
// }


// Path: src/test/java/com/github/ffalcinelli/jdivert/WinDivertTestCase.java
import com.github.ffalcinelli.jdivert.exceptions.WinDivertException;
import org.junit.After;
import org.junit.Test;
import java.util.Random;
import static com.github.ffalcinelli.jdivert.Enums.Flag.*;
import static com.github.ffalcinelli.jdivert.Enums.Layer.NETWORK;
import static org.junit.Assert.*;

/*
 * Copyright (c) Fabio Falcinelli 2016.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.github.ffalcinelli.jdivert;




/**
 * Created by fabio on 26/10/2016.
 */
public class WinDivertTestCase {

    //this can be safely static
    static Random rnd = new Random();
    protected WinDivert w;

    public static int randInt(int min, int max) {
        return rnd.nextInt(max - min + 1) + min;
    }

    @After
    public void tearDown() {
        if (w != null)
            w.close();
    }

    @Test(expected = IllegalArgumentException.class)
    public void wrongFlags() {
        w = new WinDivert("true", NETWORK, 0, SNIFF, DROP);
    }

    @Test
    public void open() throws WinDivertException {