add_executable(gtest_lpi gtest_lpi_main.cpp gtest_lpi_plugin.cpp)

target_include_directories(gtest_lpi PRIVATE ${CMAKE_SOURCE_DIR}/deps/)
target_include_directories(gtest_lpi PRIVATE ${CMAKE_SOURCE_DIR}/decoders/lpi)

target_link_libraries(
        gtest_lpi PRIVATE stellar_lib cjson-static 
        dl "-rdynamic"
        gtest gmock
)

#target_link_libraries(gtest_lpi PRIVATE -Wl,--whole-archive lpi -Wl,--no-whole-archive)

set(TEST_NAME "LPI_TEST")
set(TEST_MAIN ${CMAKE_CURRENT_BINARY_DIR}/gtest_lpi)

add_test(NAME ${TEST_NAME}.SETUP COMMAND sh -c " 
                                            mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/conf &&
                                            mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/plugin &&
                                            mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/log &&
                                            mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/tsgconf &&
                                            cp ${CMAKE_SOURCE_DIR}/conf/stellar.toml ${CMAKE_CURRENT_BINARY_DIR}/conf/ &&
                                            cp ${CMAKE_CURRENT_SOURCE_DIR}/test_config/spec.toml ${CMAKE_CURRENT_BINARY_DIR}/plugin/ &&
                                            cp ${CMAKE_SOURCE_DIR}/conf/log.toml ${CMAKE_CURRENT_BINARY_DIR}/conf/ &&
                                            cp ${CMAKE_CURRENT_SOURCE_DIR}/test_config/tsg_l7_protocol.conf ${CMAKE_CURRENT_BINARY_DIR}/tsgconf/ &&
                                            tomlq -t -i  '.packet_io.pcap_path=\"-\"'  ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml &&
                                            tomlq -t -i  '.packet_io.mode=\"pcaplist\"' ${CMAKE_CURRENT_BINARY_DIR}/conf/stellar.toml
                                            ")
                                            

set_tests_properties(${TEST_NAME}.SETUP 
                    PROPERTIES FIXTURES_SETUP ${TEST_NAME}.SETUP)

add_test(NAME ${TEST_NAME}.APP
        COMMAND sh -c "find  ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/app_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/app_pcap.json")

add_test(NAME ${TEST_NAME}.DNS
        COMMAND sh -c "find  ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/dns_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/dns_pcap.json")

add_test(NAME ${TEST_NAME}.MIXED
        COMMAND sh -c "find  ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/mixed_pcap -type f | sort -V |${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/mixed_pcap.json")

add_test(NAME ${TEST_NAME}.OPENVPN
        COMMAND sh -c "find  ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/openvpn_pcap -type f | sort -V |${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/openvpn_pcap.json")

add_test(NAME ${TEST_NAME}.PPP
        COMMAND sh -c "find  ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/ppp_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/ppp_pcap.json")        

add_test(NAME ${TEST_NAME}.SOCKS
        COMMAND sh -c "find  ${CMAKE_CURRENT_SOURCE_DIR}/test_pcap/socks_pcap -type f | sort -V | ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_expect/socks_pcap.json")        

set_tests_properties(${TEST_NAME}.APP 
                     ${TEST_NAME}.DNS 
                     ${TEST_NAME}.MIXED 
                     ${TEST_NAME}.OPENVPN 
                     ${TEST_NAME}.PPP 
                     ${TEST_NAME}.SOCKS
                     PROPERTIES FIXTURES_REQUIRED ${TEST_NAME}.SETUP)