/*
* -------------------------------------------------------------------------
*  This file is part of the Vision SDK project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* Vision SDK 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.
* -------------------------------------------------------------------------
* Description: DT test for the OpLoaderVstack.cpp file.
* Author: Mind SDK
* Create: 2025
* History: NA
 */

#include <gtest/gtest.h>
#include <mockcpp/mockcpp.hpp>
#include "MxBase/E2eInfer/GlobalInit/GlobalInit.h"
#include "module/ResourceManager/GlobalInit/OperationPreload/OperationLoaders/OpLoaderVstack.h"
#include "module/ResourceManager/GlobalInit/OperationPreload/OperationLoaders/JsonPtr.h"

namespace {
    using namespace MxBase;

    class OpLoaderVstackTest : public testing::Test {
    protected:
        void TearDown() override
        {
            GlobalMockObject::verify();
        }
    };

    TEST_F(OpLoaderVstackTest, Test_CheckOpCustom_OutputShapeFailed)
    {
        OpLoaderVstack* opLoaderVstack = new OpLoaderVstack();
        APP_ERROR ret = opLoaderVstack->CheckOpCustom("1", "1;1");
        EXPECT_EQ(ret, APP_ERR_COMM_INVALID_PARAM);
    }

    TEST_F(OpLoaderVstackTest, Test_CheckOpCustom_OutputDimFailed)
    {
        OpLoaderVstack* opLoaderVstack = new OpLoaderVstack();
        APP_ERROR ret = opLoaderVstack->CheckOpCustom("1", "3");
        EXPECT_EQ(ret, APP_ERR_COMM_INVALID_PARAM);
    }

    TEST_F(OpLoaderVstackTest, Test_CheckOpCustom_ShapeFailed)
    {
        OpLoaderVstack* opLoaderVstack = new OpLoaderVstack();
        APP_ERROR ret = opLoaderVstack->CheckOpCustom("3,3", "2,1");
        EXPECT_EQ(ret, APP_ERR_COMM_INVALID_PARAM);
    }

    TEST_F(OpLoaderVstackTest, Test_CheckOpCustom_DimNotMatchFailed)
    {
        OpLoaderVstack* opLoaderVstack = new OpLoaderVstack();
        APP_ERROR ret = opLoaderVstack->CheckOpCustom("3", "2,1");
        EXPECT_EQ(ret, APP_ERR_COMM_INVALID_PARAM);
    }

    TEST_F(OpLoaderVstackTest, Test_OpCreateParamAttr_GetInputShapeByIndexFailed)
    {
        OpLoaderVstack* opLoaderVstack = new OpLoaderVstack();
        aclopAttr* attr;
        JsonPtr jsonPtr;
        MOCKER_CPP(&JsonPtr::GetInputShapeByIndex).stubs().will(returnValue(1));
        APP_ERROR ret = opLoaderVstack->OpCreateParamAttr(attr, jsonPtr, 0);
        EXPECT_EQ(ret, 1);
    }
}

int main(int argc, char *argv[])
{
    MxInit();
    testing::InitGoogleTest(&argc, argv);
    int ret = RUN_ALL_TESTS();
    MxDeInit();
    return ret;
}