#
#  Copyright (c) 2020, The OpenThread Authors.
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions are met:
#  1. Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#  3. Neither the name of the copyright holder nor the
#     names of its contributors may be used to endorse or promote products
#     derived from this software without specific prior written permission.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#  POSSIBILITY OF SUCH DAMAGE.
#

set(COMMON_INCLUDES
    ${PROJECT_SOURCE_DIR}/include
    ${PROJECT_SOURCE_DIR}/src
    ${PROJECT_SOURCE_DIR}/src/core
    ${PROJECT_SOURCE_DIR}/examples/platforms/simulation
)

set(COMMON_COMPILE_OPTIONS
    -DOPENTHREAD_FTD=1
    -DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1
)

add_library(test-platform
    test_platform.cpp
    test_util.cpp
)

target_include_directories(test-platform
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-platform
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-platform
    PRIVATE
        ot-config
        ${OT_MBEDTLS}
)

set(COMMON_LIBS
    test-platform
    openthread-ftd
    test-platform
    ${OT_MBEDTLS}
    ot-config
)

add_executable(test-aes
    test_aes.cpp
)

target_include_directories(test-aes
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-aes
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-aes
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-aes COMMAND test-aes)

add_executable(test-child
    test_child.cpp
)

add_executable(test-checksum
    test_checksum.cpp
)

target_include_directories(test-checksum
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-checksum
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-checksum
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-checksum COMMAND test-checksum)


target_include_directories(test-child
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-child
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-child
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-child COMMAND test-child)

add_executable(test-child-table
    test_child_table.cpp
)

target_include_directories(test-child-table
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-child-table
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-child-table
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-child-table COMMAND test-child-table)

add_executable(test-cmd-line-parser
    test_cmd_line_parser.cpp
)

target_include_directories(test-cmd-line-parser
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-cmd-line-parser
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-cmd-line-parser
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-cmd-line-parser COMMAND test-cmd-line-parser)

add_executable(test-dns
    test_dns.cpp
)

target_include_directories(test-dns
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-dns
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-dns
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-dns COMMAND test-dns)

add_executable(test-ecdsa
    test_ecdsa.cpp
)

target_include_directories(test-ecdsa
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-ecdsa
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-ecdsa
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-ecdsa COMMAND test-ecdsa)


add_executable(test-flash
    test_flash.cpp
)

target_include_directories(test-flash
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-flash
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-flash
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-flash COMMAND test-flash)

add_executable(test-heap
    test_heap.cpp
)

target_include_directories(test-heap
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-heap
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-heap
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-heap COMMAND test-heap)

add_executable(test-hkdf-sha256
    ${COMMON_SOURCES}
    test_hkdf_sha256.cpp
)

target_include_directories(test-hkdf-sha256
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_definitions(test-hkdf-sha256
    PRIVATE
        ${OT_PRIVATE_DEFINES}
)

target_compile_options(test-hkdf-sha256
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-hkdf-sha256
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-hkdf-sha256 COMMAND test-hkdf-sha256)

add_executable(test-hmac-sha256
    test_hmac_sha256.cpp
)

target_include_directories(test-hmac-sha256
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-hmac-sha256
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-hmac-sha256
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-hmac-sha256 COMMAND test-hmac-sha256)

add_executable(test-ip-address
    test_ip_address.cpp
)

target_include_directories(test-ip-address
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-ip-address
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-ip-address
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-ip-address COMMAND test-ip-address)

add_executable(test-link-quality
    test_link_quality.cpp
)

target_include_directories(test-link-quality
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-link-quality
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-link-quality
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-link-quality COMMAND test-link-quality)

add_executable(test-linked-list
    test_linked_list.cpp
)

target_include_directories(test-linked-list
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-linked-list
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-linked-list
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-linked-list COMMAND test-linked-list)

add_executable(test-lookup-table
    test_lookup_table.cpp
)

target_include_directories(test-lookup-table
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-lookup-table
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-lookup-table
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-lookup-table COMMAND test-lookup-table)

add_executable(test-lowpan
    test_lowpan.cpp
)

target_include_directories(test-lowpan
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-lowpan
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-lowpan
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-lowpan COMMAND test-lowpan)

add_executable(test-mac-frame
    test_mac_frame.cpp
)

target_include_directories(test-mac-frame
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-mac-frame
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-mac-frame
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-mac-frame COMMAND test-mac-frame)

add_executable(test-macros
    test_macros.cpp
)

target_include_directories(test-macros
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-macros
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-macros
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-macros COMMAND test-macros)

add_executable(test-message
    test_message.cpp
)

target_include_directories(test-message
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-message
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-message
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-message COMMAND test-message)

add_executable(test-message-queue
    test_message_queue.cpp
)

target_include_directories(test-message-queue
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-message-queue
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-message-queue
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-message-queue COMMAND test-message-queue)

add_executable(test-multicast-listeners-table
    test_multicast_listeners_table.cpp
)

target_include_directories(test-multicast-listeners-table
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-multicast-listeners-table
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-multicast-listeners-table
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-multicast-listeners-table COMMAND test-multicast-listeners-table)

add_executable(test-ndproxy-table
    test_ndproxy_table.cpp
)

target_include_directories(test-ndproxy-table
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-ndproxy-table
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)


target_link_libraries(test-ndproxy-table
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-ndproxy-table COMMAND test-ndproxy-table)


add_executable(test-netif
    test_netif.cpp
)

target_include_directories(test-netif
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-netif
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-netif
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-netif COMMAND test-netif)

add_executable(test-network-data
    test_network_data.cpp
)

target_include_directories(test-network-data
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-network-data
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-network-data
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-network-data COMMAND test-network-data)

add_executable(test-pool
    test_pool.cpp
)

target_include_directories(test-pool
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-pool
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-pool
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-pool COMMAND test-pool)

add_executable(test-priority-queue
    test_priority_queue.cpp
)

target_include_directories(test-priority-queue
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-priority-queue
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-priority-queue
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-priority-queue COMMAND test-priority-queue)

add_executable(test-pskc
    test_pskc.cpp
)

target_include_directories(test-pskc
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-pskc
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-pskc
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-pskc COMMAND test-pskc)

add_executable(test-steering-data
    test_steering_data.cpp
)

target_include_directories(test-steering-data
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-steering-data
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-steering-data
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-steering-data COMMAND test-steering-data)

add_executable(test-string
    test_string.cpp
)

target_include_directories(test-string
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-string
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-string
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-string COMMAND test-string)

add_executable(test-timer
    test_timer.cpp
)

target_include_directories(test-timer
    PRIVATE
        ${COMMON_INCLUDES}
)

target_compile_options(test-timer
    PRIVATE
        ${COMMON_COMPILE_OPTIONS}
)

target_link_libraries(test-timer
    PRIVATE
        ${COMMON_LIBS}
)

add_test(NAME test-timer COMMAND test-timer)

set_target_properties(
    test-platform
    test-aes
    test-checksum
    test-child
    test-child-table
    test-cmd-line-parser
    test-dns
    test-ecdsa
    test-flash
    test-heap
    test-hkdf-sha256
    test-hmac-sha256
    test-ip-address
    test-link-quality
    test-linked-list
    test-lookup-table
    test-lowpan
    test-mac-frame
    test-macros
    test-message
    test-message-queue
    test-multicast-listeners-table
    test-ndproxy-table
    test-netif
    test-network-data
    test-pool
    test-priority-queue
    test-pskc
    test-steering-data
    test-string
    test-timer
    PROPERTIES
        C_STANDARD 99
        CXX_STANDARD 11
)
