!45108 补充 XComponentController相关TDD测试用例

Merge pull request !45108 from sd_wu/tdd
This commit is contained in:
openharmony_ci 2024-10-11 01:23:52 +00:00 committed by Gitee
commit b33728d46f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 101 additions and 0 deletions

View File

@ -27,6 +27,9 @@ const char* NODEPTR_OF_UINODE = "nodePtr_";
std::shared_ptr<XComponentController> XComponentController::GetXComponentControllerFromNapiValue(
napi_env env, napi_value napiValue)
{
if (env == nullptr) {
return nullptr;
}
const auto* vm = reinterpret_cast<NativeEngine*>(env)->GetEcmaVm();
auto localRef = NapiValueToLocalValue(napiValue);
if (localRef->IsNull()) {
@ -43,6 +46,9 @@ std::shared_ptr<XComponentController> XComponentController::GetXComponentControl
XComponentControllerErrorCode XComponentController::SetSurfaceCallbackMode(
napi_env env, napi_value node, SurfaceCallbackMode mode)
{
if (env == nullptr) {
return XComponentControllerErrorCode::XCOMPONENT_CONTROLLER_BAD_PARAMETER;
}
const auto* vm = reinterpret_cast<NativeEngine*>(env)->GetEcmaVm();
auto nodeRef = NapiValueToLocalValue(node);
if (nodeRef.IsEmpty() || !nodeRef->IsObject(vm)) {

View File

@ -931,6 +931,45 @@ ohos_unittest("js_drawable_descriptor_test") {
]
}
ohos_unittest("xcomponent_controller_test") {
module_out_path = interface_test_output_path
sources = [
"$ace_root/interfaces/inner_api/xcomponent_controller/xcomponent_controller.cpp",
"xcomponent_controller_test.cpp",
]
configs = [
"$ace_root/test/unittest:ace_unittest_config",
":c_api_configs",
]
include_dirs = [
"$ace_root/frameworks/core/interfaces/arkoala",
"$ace_root/frameworks/",
"$ace_root/interfaces/native/",
"$ace_root/interfaces/native/node",
"$ace_root",
"$ace_root/interfaces/inner_api/xcomponent_controller",
]
deps = [
"$ace_root/interfaces/inner_api/xcomponent_controller:ace_xcomponent_controller",
"//third_party/googletest:gmock_main",
]
external_deps = [
"cJSON:cjson",
"c_utils:utils",
"ets_runtime:libark_jsruntime",
"hilog:libhilog",
"image_framework:image",
"image_framework:image_native",
"napi:ace_napi",
"resource_management:global_resmgr",
]
}
group("interfaces_unittest") {
testonly = true
deps = [
@ -956,5 +995,6 @@ group("interfaces_unittest") {
":ui_content_test",
":ui_event_test",
":viewport_config_test",
":xcomponent_controller_test",
]
}

View File

@ -0,0 +1,55 @@
/*
* 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 "gtest/gtest.h"
#include "interfaces/inner_api/xcomponent_controller/xcomponent_controller.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS::Ace {
class XComponentControllerTest : public testing::Test {
public:
static void SetUpTestCase() {};
static void TearDownTestCase() {};
};
/**
* @tc.name: XComponentControllerTest001
* @tc.desc: Test XComponentController::GetXComponentControllerFromNapiValue function.
* @tc.type: FUNC
*/
HWTEST_F(XComponentControllerTest, XComponentControllerTest001, TestSize.Level1)
{
napi_env__* env = nullptr;
napi_value__* value = nullptr;
auto controller = XComponentController::GetXComponentControllerFromNapiValue(env, value);
EXPECT_EQ(controller, nullptr);
}
/**
* @tc.name: XComponentControllerTest002
* @tc.desc: Test XComponentController::SetSurfaceCallbackMode function.
* @tc.type: FUNC
*/
HWTEST_F(XComponentControllerTest, XComponentControllerTest002, TestSize.Level1)
{
napi_env__* env = nullptr;
napi_value__* value = nullptr;
SurfaceCallbackMode mode = SurfaceCallbackMode::DEFAULT;
uint32_t code = XComponentController::SetSurfaceCallbackMode(env, value, mode);
EXPECT_EQ(code, 1);
}
} // namespace OHOS::Ace