-- Copyright (c) 2024 Huawei Technologies Co., Ltd.
-- openUBMC is licensed under Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
-- EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
-- MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
-- See the Mulan PSL v2 for more details.

local lu = require 'luaunit'
local c_optical_module = require 'device.class.optical_module'

TEST_optical_module_dtor = {}

function TEST_optical_module_dtor:test_dtor_when_tasks_is_nil()
    local original_tasks = c_optical_module.tasks
    c_optical_module.tasks = nil
    c_optical_module:dtor()
    lu.assertIsNil(c_optical_module.tasks)
    c_optical_module.tasks = original_tasks
end

function TEST_optical_module_dtor:test_dtor_when_tasks_exists()
    local original_tasks = c_optical_module.tasks
    local stop_all_called = false
    local mock_tasks = {
        stop_all = function()
            stop_all_called = true
        end
    }
    c_optical_module.tasks = mock_tasks
    c_optical_module:dtor()
    lu.assertTrue(stop_all_called)
    lu.assertEquals(c_optical_module.tasks, mock_tasks)
    c_optical_module.tasks = original_tasks
end

return TEST_optical_module_dtor
