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

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

# list the files to mock here
list(APPEND mock_list
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Nvm.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Heap.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_SyncQueue.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Clock.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Thread.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include/iotmi_pal_Pkcs11Operations.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_pkcs11/corePKCS11/source/include/core_pkcs11.h
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/mqtt_agent/source/include/iotmi_device_MqttAgent.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}/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}/commonDependencies/coreJSON/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/core_pkcs11/corePKCS11/source/dependency/3rdparty/pkcs11/published/2-40-errata-1
        )
#list the definitions of your mocks to control what to be included
list(APPEND mock_define_list
            ""
       )

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

# list the files you would like to test here
list(APPEND real_source_files
            ${CMAKE_CURRENT_LIST_DIR}/fake_iotmi_pal_Log.c
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/source/iotmi_device_FleetProvisioning.c
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/Fleet-Provisioning-for-AWS-IoT-embedded-sdk/source/fleet_provisioning.c
        )
# list the directories the module under test includes
list(APPEND real_include_directories
            .
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/source
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/provisionee/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/commonDependencies/Fleet-Provisioning-for-AWS-IoT-embedded-sdk/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/sdk_log/source/include/logging
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/sdk_version/source/generated_include
        )

# list the read library link libraries
list(APPEND real_link_libraries
            corejson
            corePKCS11
            coreMQTT
            iotmi::LogUtility
        )

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

# list the directories your test needs to include
list(APPEND test_include_directories
            .
            ${PROVISIONEE_MOCK_HEADER}
            ${IOTMI_EMBEDDED_C_TOP_DIR}/platform/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/provisionee/source/include
            ${IOTMI_EMBEDDED_C_TOP_DIR}/components/mqtt_agent/source/include
            ${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/coreJSON/source/include
        )

# =============================  (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}/fleet_provisioning_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}
)

target_compile_definitions(${real_name} PUBLIC
        "-DIOTMI_USE_MANAGED_INTEGRATIONS_DEVICE_LOG=0"
        "-DLIBRARY_LOG_LEVEL=4"
    )

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

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" )
