From b6491a4187dcc40de7210edd799cdb95d16c8498 Mon Sep 17 00:00:00 2001 From: fuzikun Date: Tue, 14 Sep 2021 10:20:14 +0800 Subject: [PATCH 1/2] add test case Signed-off-by: fuzikun --- ohos.build | 2 + test/unittest/fbe_iudf_xattr/BUILD.gn | 33 +++++++++++ .../fbe_iudf_xattr/fbe_iudf_xattr_test.cpp | 54 ++++++++++++++++++ .../fbe_iudf_xattr/fbe_iudf_xattr_test.h | 21 +++++++ test/unittest/hwdevsl/BUILD.gn | 36 ++++++++++++ test/unittest/hwdevsl/hwdevsl_test.cpp | 55 +++++++++++++++++++ test/unittest/hwdevsl/hwdevsl_test.h | 21 +++++++ 7 files changed, 222 insertions(+) create mode 100644 test/unittest/fbe_iudf_xattr/BUILD.gn create mode 100644 test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp create mode 100644 test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.h create mode 100644 test/unittest/hwdevsl/BUILD.gn create mode 100644 test/unittest/hwdevsl/hwdevsl_test.cpp create mode 100644 test/unittest/hwdevsl/hwdevsl_test.h diff --git a/ohos.build b/ohos.build index fb8100a..72dada8 100755 --- a/ohos.build +++ b/ohos.build @@ -32,6 +32,8 @@ } ], "test_list": [ + "//base/security/dataclassification/test/unittest/fbe_iudf_xattr:fbe_iudf_xattr_test", + "//base/security/dataclassification/test/unittest/hwdevsl:hwdevsl_test" ] } } diff --git a/test/unittest/fbe_iudf_xattr/BUILD.gn b/test/unittest/fbe_iudf_xattr/BUILD.gn new file mode 100644 index 0000000..cfd6d99 --- /dev/null +++ b/test/unittest/fbe_iudf_xattr/BUILD.gn @@ -0,0 +1,33 @@ +import("//build/test.gni") +module_output_path = "dataclassification/fbe_iudf_xattr" + +config("fbe_iudf_xattr_test_config") { + visibility = [ ":*" ] + include_dirs = [ + "//base/security/dataclassification/test/unittest/fbe_iudf_xattr", + "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr/include", + "//third_party/googletest/googletest/include", + ] + cflags = [ "-DHILOG_ENABLE" ] +} + +ohos_unittest("IudfXattrTest") { + part_name = "dataclassification" + subsystem_name = "security" + module_out_path = module_output_path + + sources = [ "fbe_iudf_xattr_test.cpp" ] + + configs = [ ":fbe_iudf_xattr_test_config"] + + deps = [ + "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr:fbe_iudf_xattr" + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +group("fbe_iudf_xattr_test") { + testonly = true + deps = [ ":IudfXattrTest" ] +} \ No newline at end of file diff --git a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp b/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp new file mode 100644 index 0000000..046bf7b --- /dev/null +++ b/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp @@ -0,0 +1,54 @@ + +/* + * Copyright (C) 2021 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 "gtest/gtest.h" + +#include "fbe_iudf_xattr_test.h" +#include "fbe_sdp_policy.h" + +using namespace testing::ext; + +class IudfXattrTest : public testing::Test { +protected: + IudfXattrTest(); + ~IudfXattrTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + +private: +}; + +IudfXattrTest::IudfXattrTest() {} +IudfXattrTest::~IudfXattrTest() {} +void IudfXattrTest::SetUpTestCase() {} +void IudfXattrTest::TearDownTestCase() {} +void IudfXattrTest::SetUp() {} +void IudfXattrTest::TearDown() {} + +/** + * @tc.name: TestIsSupportIudf + * @tc.desc: Verify IsSupportIudf function + * @tc.type: FUN + */ +HWTEST_F(IudfXattrTest, TestIsSupportIudf, TestSize.Level1) +{ + bool ret; + + ret = IsSupportIudf(); + EXPECT_EQ(false, ret); +} \ No newline at end of file diff --git a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.h b/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.h new file mode 100644 index 0000000..c07f158 --- /dev/null +++ b/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef FBE_IUDF_XATTR_TEST_H +#define FBE_IUDF_XATTR_TEST_H + +int TestIsSupportIudf(void); + +#endif \ No newline at end of file diff --git a/test/unittest/hwdevsl/BUILD.gn b/test/unittest/hwdevsl/BUILD.gn new file mode 100644 index 0000000..0fb46fe --- /dev/null +++ b/test/unittest/hwdevsl/BUILD.gn @@ -0,0 +1,36 @@ +import("//build/test.gni") +module_output_path = "dataclassification/hwdevsl" + +config("hwdevsl_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "//base/security/dataclassification/test/unittest/hwdevsl", + "//base/security/dataclassification/interfaces/innerkits/hwdevsl/include/1.0", + "//third_party/googletest/googletest/include", + "utils/native/base/include", + ] + + cflags = [ "-DHILOG_ENABLE" ] +} + +ohos_unittest("HwDslTest") { + part_name = "dataclassification" + subsystem_name = "security" + module_out_path = module_output_path + + sources = [ "hwdevsl_test.cpp" ] + + configs = [ ":hwdevsl_private_config"] + + deps = [ + "//base/security/dataclassification/interfaces/innerkits/hwdevsl:hwdsl", + "//utils/native/base:utils" + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +group("hwdevsl_test") { + testonly = true + deps = [ ":HwDslTest" ] +} \ No newline at end of file diff --git a/test/unittest/hwdevsl/hwdevsl_test.cpp b/test/unittest/hwdevsl/hwdevsl_test.cpp new file mode 100644 index 0000000..b7641d1 --- /dev/null +++ b/test/unittest/hwdevsl/hwdevsl_test.cpp @@ -0,0 +1,55 @@ + +/* + * Copyright (C) 2021 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 "gtest/gtest.h" + +#include "hwdevsl_test.h" +#include "dev_slinfo_mgr.h" + +using namespace testing::ext; + +class DeviceSecurityLevelTest : public testing::Test { +protected: + DeviceSecurityLevelTest(); + ~DeviceSecurityLevelTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + +private: +}; + +DeviceSecurityLevelTest::DeviceSecurityLevelTest() {} +DeviceSecurityLevelTest::~DeviceSecurityLevelTest() {} +void DeviceSecurityLevelTest::SetUpTestCase() {} +void DeviceSecurityLevelTest::TearDownTestCase() {} +void DeviceSecurityLevelTest::SetUp() {} +void DeviceSecurityLevelTest::TearDown() {} + +/** + * @tc.name: TestOnStart + * @tc.desc: Verify DEVSL_OnStart function + * @tc.type: FUN + */ +HWTEST_F(DeviceSecurityLevelTest, TestOnStart, TestSize.Level1) +{ + int32_t ret; + + ret = DEVSL_OnStart(1); + EXPECT_EQ(DEVSL_SUCCESS, ret); + DEVSL_ToFinish(); +} \ No newline at end of file diff --git a/test/unittest/hwdevsl/hwdevsl_test.h b/test/unittest/hwdevsl/hwdevsl_test.h new file mode 100644 index 0000000..d4ec4ba --- /dev/null +++ b/test/unittest/hwdevsl/hwdevsl_test.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef Device_SEC_LEVEL_TEST_H +#define Device_SEC_LEVEL_TEST_H + +int TestOnStart(void); + +#endif \ No newline at end of file -- Gitee From d60f07e2391e9ab1e2905f4b4a51701d332b3250 Mon Sep 17 00:00:00 2001 From: fuzikun Date: Sat, 18 Sep 2021 10:54:34 +0800 Subject: [PATCH 2/2] add test case Signed-off-by: fuzikun --- test/unittest/fbe_iudf_xattr/BUILD.gn | 49 +++++++++------- .../fbe_iudf_xattr/fbe_iudf_xattr_test.cpp | 2 +- test/unittest/hwdevsl/BUILD.gn | 57 ++++++++++++------- test/unittest/hwdevsl/hwdevsl_test.cpp | 2 +- 4 files changed, 67 insertions(+), 43 deletions(-) diff --git a/test/unittest/fbe_iudf_xattr/BUILD.gn b/test/unittest/fbe_iudf_xattr/BUILD.gn index cfd6d99..4c9fe2f 100644 --- a/test/unittest/fbe_iudf_xattr/BUILD.gn +++ b/test/unittest/fbe_iudf_xattr/BUILD.gn @@ -1,33 +1,44 @@ +# Copyright (C) 2021 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") module_output_path = "dataclassification/fbe_iudf_xattr" config("fbe_iudf_xattr_test_config") { - visibility = [ ":*" ] - include_dirs = [ - "//base/security/dataclassification/test/unittest/fbe_iudf_xattr", - "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr/include", - "//third_party/googletest/googletest/include", - ] - cflags = [ "-DHILOG_ENABLE" ] + visibility = [ ":*" ] + include_dirs = [ + "//base/security/dataclassification/test/unittest/fbe_iudf_xattr", + "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr/include", + "//third_party/googletest/googletest/include", + ] + cflags = [ "-DHILOG_ENABLE" ] } ohos_unittest("IudfXattrTest") { - part_name = "dataclassification" - subsystem_name = "security" - module_out_path = module_output_path + part_name = "dataclassification" + subsystem_name = "security" + module_out_path = module_output_path - sources = [ "fbe_iudf_xattr_test.cpp" ] + sources = [ "fbe_iudf_xattr_test.cpp" ] - configs = [ ":fbe_iudf_xattr_test_config"] + configs = [ ":fbe_iudf_xattr_test_config" ] - deps = [ - "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr:fbe_iudf_xattr" - ] + deps = [ "//base/security/dataclassification/interfaces/innerkits/fbe_iudf_xattr:fbe_iudf_xattr" ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } group("fbe_iudf_xattr_test") { - testonly = true - deps = [ ":IudfXattrTest" ] -} \ No newline at end of file + testonly = true + deps = [ ":IudfXattrTest" ] +} diff --git a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp b/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp index 046bf7b..b878b9f 100644 --- a/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp +++ b/test/unittest/fbe_iudf_xattr/fbe_iudf_xattr_test.cpp @@ -45,7 +45,7 @@ void IudfXattrTest::TearDown() {} * @tc.desc: Verify IsSupportIudf function * @tc.type: FUN */ -HWTEST_F(IudfXattrTest, TestIsSupportIudf, TestSize.Level1) +HWTEST_F(IudfXattrTest, TestIsSupportIudf, TestSize.Level0) { bool ret; diff --git a/test/unittest/hwdevsl/BUILD.gn b/test/unittest/hwdevsl/BUILD.gn index 0fb46fe..821e7c5 100644 --- a/test/unittest/hwdevsl/BUILD.gn +++ b/test/unittest/hwdevsl/BUILD.gn @@ -1,36 +1,49 @@ +# Copyright (C) 2021 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") module_output_path = "dataclassification/hwdevsl" config("hwdevsl_private_config") { - visibility = [ ":*" ] - include_dirs = [ - "//base/security/dataclassification/test/unittest/hwdevsl", - "//base/security/dataclassification/interfaces/innerkits/hwdevsl/include/1.0", - "//third_party/googletest/googletest/include", - "utils/native/base/include", - ] - - cflags = [ "-DHILOG_ENABLE" ] + visibility = [ ":*" ] + include_dirs = [ + "//base/security/dataclassification/test/unittest/hwdevsl", + "//base/security/dataclassification/interfaces/innerkits/hwdevsl/include/1.0", + "//third_party/googletest/googletest/include", + "utils/native/base/include", + ] + + cflags = [ "-DHILOG_ENABLE" ] } ohos_unittest("HwDslTest") { - part_name = "dataclassification" - subsystem_name = "security" - module_out_path = module_output_path + part_name = "dataclassification" + subsystem_name = "security" + module_out_path = module_output_path - sources = [ "hwdevsl_test.cpp" ] + sources = [ "hwdevsl_test.cpp" ] - configs = [ ":hwdevsl_private_config"] + configs = [ ":hwdevsl_private_config" ] - deps = [ - "//base/security/dataclassification/interfaces/innerkits/hwdevsl:hwdsl", - "//utils/native/base:utils" - ] + deps = [ + "//base/security/dataclassification/interfaces/innerkits/hwdevsl:hwdsl", + "//utils/native/base:utils", + ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } group("hwdevsl_test") { - testonly = true - deps = [ ":HwDslTest" ] -} \ No newline at end of file + testonly = true + deps = [ ":HwDslTest" ] +} diff --git a/test/unittest/hwdevsl/hwdevsl_test.cpp b/test/unittest/hwdevsl/hwdevsl_test.cpp index b7641d1..dee67e2 100644 --- a/test/unittest/hwdevsl/hwdevsl_test.cpp +++ b/test/unittest/hwdevsl/hwdevsl_test.cpp @@ -45,7 +45,7 @@ void DeviceSecurityLevelTest::TearDown() {} * @tc.desc: Verify DEVSL_OnStart function * @tc.type: FUN */ -HWTEST_F(DeviceSecurityLevelTest, TestOnStart, TestSize.Level1) +HWTEST_F(DeviceSecurityLevelTest, TestOnStart, TestSize.Level0) { int32_t ret; -- Gitee