# ====================  Define your project name (edit) ========================
set(project_name "iotmi_wss")

# Include BackoffAlgorithm paths
set( BACKOFF_ALGORITHM_DIR ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/backoff_algorithm )
include( ${BACKOFF_ALGORITHM_DIR}/backoffAlgorithmFilePaths.cmake )

# =====================  Create your mock here  (edit)  ========================

# list the files to mock here
list(APPEND mock_list
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Wifi.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Crypto.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_NetworkTransport.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_SyncQueue.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_SyncEvent.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Thread.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Mutex.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/mqtt_agent/source/include/iotmi_device_MqttAgent.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_pkcs11/corePKCS11/source/include/core_pkcs11.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/src/private/iotmi_device_message_builders.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Clock.h
            ${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS}/backoff_algorithm.h
        )
# list the directories your mocks need
list(APPEND mock_include_list
            ${CMAKE_CURRENT_LIST_DIR}
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/common/mbedtls/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/posix/network-transport/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_pkcs11/corePKCS11/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_mqtt/coreMQTT/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_mqtt/coreMQTT/source/interface
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/mqtt_agent/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/sdk_log/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_pkcs11/corePKCS11/source/dependency/3rdparty/pkcs11/published/2-40-errata-1
            ${IOTMI_EMBEDDED_C_TOP_DIR}/src/private
            ${IOTMI_EMBEDDED_C_TOP_DIR}/include
            ${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS}
        )
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
            "IOTMI_USE_WSS_PROVISIONEE=1"
       )

# ================= Create the library under test here (edit) ==================

# list the files you would like to test here
list(APPEND real_source_files
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/wss/source/iotmi_wss.c
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/wss/source/iotmi_wss_FlowControl.c
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/wss/source/iotmi_wss_Steps.c
            ${IOTMI_EMBEDDED_C_TOP_DIR}/src/iotmi_string_utils.c
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/posix/source/iotmi_pal_Heap.c
        )
# list the directories the module under test includes
list(APPEND real_include_directories
            .
            ${IOTMI_EMBEDDED_C_TOP_DIR}/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/src
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/common/mbedtls/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/posix/network-transport/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/wss/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/wss/source
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/mqtt_agent/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/sdk_log/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/sdk_log/source/include/logging
        )

# list the read library link libraries
list(APPEND real_link_libraries
            iotmi::DataModelHandler
            corePKCS11
            coreMQTT
            cjson
        )

# =====================  Create UnitTest Code here (edit)  =====================

# list the directories your test needs to include
list(APPEND test_include_directories
            .
            ${WSS_MOCK_HEADER}
            ${IOTMI_EMBEDDED_C_TOP_DIR}/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/src
            ${IOTMI_EMBEDDED_C_TOP_DIR}/src/private
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/common/mbedtls/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/posix/network-transport/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/wss/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/wss/source
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/mqtt_agent/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/sdk_log/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/sdk_log/source/include/logging
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_pkcs11/corePKCS11/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_pkcs11/corePKCS11/source/dependency/3rdparty/pkcs11/published/2-40-errata-1
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_mqtt/coreMQTT/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_mqtt/coreMQTT/source/interface
            ${BACKOFF_ALGORITHM_INCLUDE_PUBLIC_DIRS}
        )

# =============================  (end edit)  ===================================

set(mock_name "${project_name}_mock")
set(real_name "${project_name}_real")

create_mock_list(${mock_name}
                "${mock_list}"
                "${CMAKE_CURRENT_SOURCE_DIR}/wss_ut_config.yml"
                "${mock_include_list}"
                "${mock_define_list}"
        )

create_real_library(${real_name}
                    "${real_source_files}"
                    "${real_include_directories}"
                    ""
        )

target_link_libraries( ${real_name}
    PRIVATE
        ${mock_name}
        ${real_link_libraries}
    PUBLIC
        cjson
)

list(APPEND ${project_name}_utest_link_list
            -l${mock_name}
            lib${real_name}.a
            cjson
        )

list(APPEND ${project_name}_utest_dep_list
            ${real_name}
        )

set(utest_name "${project_name}_utest")
set(utest_source "${project_name}_utest.c")
create_test(${utest_name}
            ${utest_source}
            "${${project_name}_utest_link_list}"
            "${${project_name}_utest_dep_list}"
            "${test_include_directories}"
        )

set_target_properties(${utest_name} PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests/unit-test" )

# Add WSS define to test target
target_compile_definitions(${utest_name} PRIVATE IOTMI_USE_WSS_PROVISIONEE=1)
