mirror of
https://gitee.com/openharmony/msdp_device_status
synced 2024-11-30 11:11:06 +00:00
add test
Signed-off-by: hellohyh001 <huiyuehong@huawei.com>
This commit is contained in:
parent
3e1e7b0fb1
commit
227ccb65ab
3
BUILD.gn
3
BUILD.gn
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
# Copyright (c) 2022-2024 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
|
||||
@ -40,6 +40,7 @@ group("device_status_tests") {
|
||||
"intention/common/channel:intention_channel_test",
|
||||
"services/native/test:devicestatussrv_test",
|
||||
"test/fuzztest:device_status_fuzztest",
|
||||
"test/unittest:device_status_unittest",
|
||||
]
|
||||
|
||||
if (fusion_rust_enabled) {
|
||||
|
21
test/unittest/BUILD.gn
Normal file
21
test/unittest/BUILD.gn
Normal file
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("../../device_status.gni")
|
||||
|
||||
group("device_status_unittest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
|
||||
deps += [ "utils:UtilityTest" ]
|
||||
}
|
53
test/unittest/utils/BUILD.gn
Normal file
53
test/unittest/utils/BUILD.gn
Normal file
@ -0,0 +1,53 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("../../../device_status.gni")
|
||||
|
||||
module_output_path = "${device_status_part_name}/unit_out"
|
||||
|
||||
ohos_unittest("UtilityTest") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
module_out_path = module_output_path
|
||||
include_dirs = [
|
||||
"${device_status_interfaces_path}/innerkits/interaction/include",
|
||||
"${device_status_utils_path}/include",
|
||||
]
|
||||
|
||||
defines = []
|
||||
|
||||
sources = [ "src/utility_test.cpp" ]
|
||||
|
||||
configs = []
|
||||
|
||||
deps = [ "${device_status_utils_path}:devicestatus_util" ]
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = []
|
||||
if (build_variant == "root" && root_perf_main != "root_main") {
|
||||
deps += [ ":UtilityTest" ]
|
||||
}
|
||||
}
|
241
test/unittest/utils/src/utility_test.cpp
Normal file
241
test/unittest/utils/src/utility_test.cpp
Normal file
@ -0,0 +1,241 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <future>
|
||||
#include <optional>
|
||||
#include <unistd.h>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "devicestatus_define.h"
|
||||
#include "devicestatus_errors.h"
|
||||
#include "utility.h"
|
||||
|
||||
#undef LOG_TAG
|
||||
#define LOG_TAG "UtilityTest"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Msdp {
|
||||
namespace DeviceStatus {
|
||||
using namespace testing::ext;
|
||||
namespace {
|
||||
constexpr int32_t TIME_WAIT_FOR_OP_MS { 20 };
|
||||
} // namespace
|
||||
|
||||
class UtilityTest : public testing::Test {
|
||||
public:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase(void);
|
||||
};
|
||||
|
||||
void UtilityTest::SetUpTestCase() {}
|
||||
|
||||
void UtilityTest::TearDownTestCase() {}
|
||||
|
||||
void UtilityTest::SetUp() {}
|
||||
|
||||
void UtilityTest::TearDown()
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP_MS));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_001
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_001, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "0";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_002
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_002, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "123";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_003
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_003, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = " 0";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_004
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_004, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "-0";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_005
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_005, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "-1";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_006
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_006, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "-10";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_007
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_007, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "123";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_008
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_008, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "-123";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_009
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_009, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "0123";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_010
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_010, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "A01";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_011
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_011, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = "A-10";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_012
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_012, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = " 123A";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UtityTest_IsInteger_013
|
||||
* @tc.desc: Checks whether a string is an integer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(UtilityTest, UtityTest_IsInteger_013, TestSize.Level1)
|
||||
{
|
||||
CALL_TEST_DEBUG;
|
||||
std::string target = " 123 A";
|
||||
bool ret = Utility::IsInteger(target);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
} // namespace DeviceStatus
|
||||
} // namespace Msdp
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user