-- Copyright (c) 2026 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_handler_eth = require 'bma.handles.handler_eth'
local json = require 'cjson'

TEST_handler_eth= {}

function TEST_handler_eth:test_update_network_port_linkstatus()
    local port = {}
    local data = {}
    local oem_huawei = {}

    port.update_ipv6_default_gateway = function()
    end
    port.set_link_status_numeric = function()
    end
    local c_update_physical_port_to_bridge_and_bonding = c_handler_eth.update_physical_port_to_bridge_and_bonding
    c_handler_eth.update_physical_port_to_bridge_and_bonding = function()
    end

    data.FullDuplex = json.null
    data.AutoNeg = json.null
    port.NetDevFuncType = 32
    pcall(function()
        c_handler_eth:update_network_port(port, data, oem_huawei)
    end)
    lu.assertEquals(port.FullDuplex, 255)
    lu.assertEquals(port.AutoSpeedNegotiation, 255)

    data.FullDuplex = true
    data.AutoNeg = true
    port.NetDevFuncType = 32
    pcall(function()
        c_handler_eth:update_network_port(port, data, oem_huawei)
    end)
    lu.assertEquals(port.FullDuplex, 1)
    lu.assertEquals(port.AutoSpeedNegotiation, 1)

    c_handler_eth.update_physical_port_to_bridge_and_bonding = c_update_physical_port_to_bridge_and_bonding
end