/*

 * Copyright (c) 2025 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */

#include <nweb_hisysevent.h>



#include <gtest/gtest.h>



#include "arkweb_utils.h"



namespace OHOS::NWeb {



class NWebHiSysEventTest : public ::testing::Test {

public:

    void SetUp() override {}

    void TearDown() override {}

};



TEST_F(NWebHiSysEventTest, ReportCreateWebInstanceTime)

{

    uint32_t nwebId = 123;

    int64_t useTime = 1000;



    int result = EventReport::ReportCreateWebInstanceTime(nwebId, useTime);

    EXPECT_EQ(result, 0);



    OHOS::ArkWeb::SetBundleNameInner("test");

    OHOS::ArkWeb::SetApiVersionInner("test");

    result = EventReport::ReportCreateWebInstanceTime(nwebId, useTime);

    EXPECT_EQ(result, 0);



    result = EventReport::ReportCreateWebInstanceTime(nwebId, useTime);

    EXPECT_EQ(result, 0);

}



TEST_F(NWebHiSysEventTest, ReportMSDPError)

{

    std::string eventType = "TEST_EVENT";

    std::string errorType = "TEST_ERROR";

    std::string errorInfo = "Test error info";

    std::string nodePath = "/test/node/path";



    // Test with nodePath

    int result = EventReport::ReportMSDPError(eventType, errorType, errorInfo, nodePath);

    EXPECT_EQ(result, 0);



    // Test without nodePath (default empty)

    result = EventReport::ReportMSDPError(eventType, errorType, errorInfo);

    EXPECT_EQ(result, 0);



    OHOS::ArkWeb::SetBundleNameInner("test");

    OHOS::ArkWeb::SetApiVersionInner("test");



    // Test with nodePath again

    result = EventReport::ReportMSDPError(eventType, errorType, errorInfo, nodePath);

    EXPECT_EQ(result, 0);



    // Test without nodePath again

    result = EventReport::ReportMSDPError(eventType, errorType, errorInfo);

    EXPECT_EQ(result, 0);

}

}