/*
 * Copyright (c) 2026 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 <optional>

#include "gtest/gtest.h"

#include "selection_common.h"

namespace OHOS {
namespace SelectionFwk {

using namespace testing::ext;

class SelectionCommonTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp();
    void TearDown();
};

void SelectionCommonTest::SetUpTestCase()
{
    std::cout << "SelectionCommonTest SetUpTestCase" << std::endl;
}

void SelectionCommonTest::TearDownTestCase()
{
    std::cout << "SelectionCommonTest TearDownTestCase" << std::endl;
}

void SelectionCommonTest::SetUp()
{
    std::cout << "SelectionCommonTest SetUp" << std::endl;
}

void SelectionCommonTest::TearDown()
{
    std::cout << "SelectionCommonTest TearDown" << std::endl;
}

/**
 * @tc.name: SelectionCommon003
 * @tc.desc: test IsNumber method with characters
 * @tc.type: FUNC
 */
HWTEST_F(SelectionCommonTest, SelectionCommon003, TestSize.Level0)
{
    std::string str;
    ASSERT_FALSE(IsNumber(str));
    ASSERT_FALSE(IsNumber("+"));
    ASSERT_FALSE(IsNumber("-"));
    ASSERT_FALSE(IsNumber("100a"));
    ASSERT_TRUE(IsNumber("100"));
}


/**
 * @tc.name: SelectionCommon004
 * @tc.desc: test ParseAppInfo method with strings
 * @tc.type: FUNC
 */
HWTEST_F(SelectionCommonTest, SelectionCommon004, TestSize.Level0)
{
    ASSERT_EQ(ParseAppInfo("a"), std::nullopt);
    ASSERT_EQ(ParseAppInfo("a/"), std::nullopt);
    ASSERT_EQ(ParseAppInfo("/a"), std::nullopt);
    std::string appInfoStr = "a/b";
    auto appInfo = ParseAppInfo(appInfoStr);
    ASSERT_NE(appInfo, std::nullopt);
    ASSERT_EQ(std::get<0>(appInfo.value()), "a");
    ASSERT_EQ(std::get<1>(appInfo.value()), "b");
}

/**
 * @tc.name: SelectionCommon005
 * @tc.desc: test operator==
 * @tc.type: FUNC
 */
HWTEST_F(SelectionCommonTest, SelectionCommon005, TestSize.Level0)
{
    AbilityRuntimeInfo abilityInfo{101, "a", "b"};
    AbilityRuntimeInfo &abilityInfo2 = abilityInfo;
    ASSERT_TRUE(abilityInfo == abilityInfo2);

    AbilityRuntimeInfo abilityInfo3{101, "c", "d"};
    ASSERT_FALSE(abilityInfo == abilityInfo3);

    AbilityRuntimeInfo abilityInfo4{101, "a", "d"};
    ASSERT_FALSE(abilityInfo == abilityInfo4);

    AbilityRuntimeInfo abilityInfo5{101, "a", "b"};
    ASSERT_TRUE(abilityInfo == abilityInfo5);
}
}
}