提交 b8da581d 编写于 作者: L lanyill

XComponent xts增加用例

Signed-off-by: Nlanyill <lanyi3@huawei.com>
上级 96678c19
......@@ -35,8 +35,14 @@ uint32_t PluginRender::xcHeight_ = 0;
uint32_t PluginRender::xcWidth_ = 0;
double PluginRender::off_x = 0;
double PluginRender::off_y = 0;
uint32_t PluginRender::toolType_ = 5;
uint32_t PluginRender::mousecallback_ = 0;
float PluginRender::tiltX_= 0;
float PluginRender::tiltY_= 0;
uint32_t PluginRender::touchType = 4;
OH_NativeXComponent_TouchEvent PluginRender::testTouchEvent_;
OH_NativeXComponent_MouseEvent PluginRender::testMouseEvent_;
OH_NativeXComponent_MouseEvent_Callback PluginRender::mouseEventcallback_;
void OnSurfaceCreatedCB(OH_NativeXComponent* component, void* window)
{
......@@ -101,7 +107,7 @@ void DispatchTouchEventCB(OH_NativeXComponent* component, void* window)
void DispatchMouseEventCB(OH_NativeXComponent* component, void* window)
{
LOGE("DispatchMouseEventCB");
LOGD("DispatchMouseEventCB");
int32_t ret;
char idStr[OH_XCOMPONENT_ID_LEN_MAX + 1] = {};
uint64_t idSize = OH_XCOMPONENT_ID_LEN_MAX + 1;
......@@ -110,6 +116,8 @@ void DispatchMouseEventCB(OH_NativeXComponent* component, void* window)
return;
}
std::string id(idStr);
auto render = PluginRender::GetInstance(id);
render->DispatchMouseEvent(component, window);
}
PluginRender::PluginRender(std::string& id)
......@@ -122,6 +130,8 @@ PluginRender::PluginRender(std::string& id)
renderCallback->OnSurfaceChanged = OnSurfaceChangedCB;
renderCallback->OnSurfaceDestroyed = OnSurfaceDestroyedCB;
renderCallback->DispatchTouchEvent = DispatchTouchEventCB;
auto renderMouseEventCallback = PluginRender::GetNXComponentMouseEventCallback();
renderMouseEventCallback->DispatchMouseEvent = DispatchMouseEventCB;
}
PluginRender* PluginRender::GetInstance(std::string& id)
......@@ -140,10 +150,17 @@ OH_NativeXComponent_Callback* PluginRender::GetNXComponentCallback()
return &PluginRender::callback_;
}
OH_NativeXComponent_MouseEvent_Callback* PluginRender::GetNXComponentMouseEventCallback()
{
return &PluginRender::mouseEventcallback_;
}
void PluginRender::SetNativeXComponent(OH_NativeXComponent* component)
{
component_ = component;
OH_NativeXComponent_RegisterCallback(component_, &PluginRender::callback_);
uint32_t mousecallback = OH_NativeXComponent_RegisterMouseEventCallback(component_, &PluginRender::mouseEventcallback_);
mousecallback_ = mousecallback;
}
void PluginRender::OnSurfaceCreated(OH_NativeXComponent* component, void* window)
......@@ -209,6 +226,19 @@ void PluginRender::DispatchTouchEvent(OH_NativeXComponent* component, void* wind
touchEvent_.touchPoints[i].id, touchEvent_.touchPoints[i].x, touchEvent_.touchPoints[i].y);
LOGE("Touch Info : screenx = %{public}f, screeny = %{public}f",
touchEvent_.touchPoints[i].screenX, touchEvent_.touchPoints[i].screenY);
OH_NativeXComponent_TouchPointToolType toolType = OH_NativeXComponent_TouchPointToolType::OH_NATIVEXCOMPONENT_TOOL_TYPE_UNKNOWN;
float tiltX = 123.0;
float tiltY = 321.0;
int32_t ret1;
int32_t ret2;
int32_t ret3;
ret1 = OH_NativeXComponent_GetTouchPointToolType(component, i, &toolType);
ret2 = OH_NativeXComponent_GetTouchPointTiltX(component, i, &tiltX);
ret3 = OH_NativeXComponent_GetTouchPointTiltY(component, i, &tiltY);
toolType_ = toolType;
tiltX_ = tiltX;
tiltY_ = tiltY;
LOGE("Touch Info : DispatchTouchEvent dots[%{public}d] toolType=%{public}u, tiltX=%{public}f, tiltY=%{public}f", i, toolType, tiltX, tiltY);
}
} else {
LOGE("Touch fail");
......@@ -230,12 +260,32 @@ napi_value PluginRender::Export(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("TestGetXComponentOffset_x", PluginRender::TestGetXComponentOffset_x),
DECLARE_NAPI_FUNCTION("TestGetXComponentOffset_y", PluginRender::TestGetXComponentOffset_y),
DECLARE_NAPI_FUNCTION("TestGetXComponent_TouchEvent", PluginRender::TestGetXComponent_TouchEvent),
DECLARE_NAPI_FUNCTION("TestGetXComponent_MouseEvent", PluginRender::TestGetXComponent_MouseEvent),
DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_tilty", PluginRender::TestGetXComponentpointtool_tilty),
DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_type", PluginRender::TestGetXComponentpointtool_type),
DECLARE_NAPI_FUNCTION("TestGetXComponentpointtool_tiltx", PluginRender::TestGetXComponentpointtool_tiltx),
DECLARE_NAPI_FUNCTION("TestGetXComponent_RegisterMouseEventCallback", PluginRender::TestGetXComponent_RegisterMouseEventCallback),
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;
}
void PluginRender::DispatchMouseEvent(OH_NativeXComponent* component, void* window)
{
LOGE("----------TestMouse Mouse Info DispatchMouseEvent 11");
int32_t ret = OH_NativeXComponent_GetMouseEvent(component, window, &mouseEvent_);
LOGE("----------TestMouse Mouse Info DispatchMouseEvent");
if (ret == OH_NATIVEXCOMPONENT_RESULT_SUCCESS) {
testMouseEvent_ = mouseEvent_;
LOGE("TestMouse Mouse Info : x = %{public}f, y = %{public}f screenx = %{public}f, screeny = %{public}f", mouseEvent_.x, mouseEvent_.y, mouseEvent_.screenX, mouseEvent_.screenY);
LOGE("TestMouse Mouse Info : action = %{public}d, button = %{public}d, time = %{public}lld", mouseEvent_.action, mouseEvent_.button, mouseEvent_.timestamp );
LOGE("TestMouse Mouse Info : action = %{public}d, button = %{public}d", mouseEvent_.action, mouseEvent_.button);
} else {
LOGE("Mouse Info fail");
}
}
napi_value PluginRender::NapiChangeShape(napi_env env, napi_callback_info info)
{
LOGE("NapiChangeShape");
......@@ -425,6 +475,39 @@ napi_value PluginRender::TestGetXComponentOffset_y(napi_env env, napi_callback_i
return output;
}
napi_value PluginRender::TestGetXComponentpointtool_tiltx(napi_env env, napi_callback_info info)
{
LOGE("xclog running PluginRender::TestGetXComponentpointtool_tiltx");
napi_value output;
NAPI_CALL(env, napi_create_double(env, tiltX_, &output));
LOGE("xclog TestGetXComponentpointtool_tiltx : %{public}f", tiltX_);
return output;
}
napi_value PluginRender::TestGetXComponentpointtool_tilty(napi_env env, napi_callback_info info)
{
LOGE("xclog running PluginRender::TestGetXComponentpointtool_tilty");
napi_value output;
NAPI_CALL(env, napi_create_double(env, tiltY_, &output));
LOGE("xclog TestGetXComponentpointtool_tilty : %{public}f", tiltY_);
return output;
}
napi_value PluginRender::TestGetXComponentpointtool_type(napi_env env, napi_callback_info info)
{
LOGE("xclog running PluginRender::TestGetXComponentpointtool_type");
napi_value output;
NAPI_CALL(env, napi_create_double(env, toolType_, &output));
LOGE("xclog TestGetXComponentpointtool_type : %{public}u", toolType_);
return output;
}
napi_value PluginRender::TestGetXComponent_TouchEvent(napi_env env, napi_callback_info info)
{
LOGE("xclog running PluginRender::TestGetXComponent_TouchEvent");
......@@ -446,6 +529,44 @@ napi_value PluginRender::TestGetXComponent_TouchEvent(napi_env env, napi_callbac
return obj;
}
napi_value PluginRender::TestGetXComponent_MouseEvent(napi_env env, napi_callback_info info)
{
LOGE("xclog running PluginRender::TestGetXComponent_MouseEvent");
napi_value surf_x;
napi_value surf_y;
napi_value t_button;
NAPI_CALL(env, napi_create_double(env, testMouseEvent_.x, &(surf_x)));
NAPI_CALL(env, napi_create_double(env, testMouseEvent_.y, &(surf_y)));
NAPI_CALL(env, napi_create_uint32(env, testMouseEvent_.button, &(t_button)));
napi_value obj;
NAPI_CALL(env, napi_create_object(env, &obj));
NAPI_CALL(env, napi_set_named_property(env, obj, "surface_X1", surf_x)); // float x
NAPI_CALL(env, napi_set_named_property(env, obj, "surface_Y1", surf_y)); // float y
NAPI_CALL(env, napi_set_named_property(env, obj, "mousebutton", t_button)); // int32_t
return obj;
}
napi_value PluginRender::TestGetXComponent_RegisterMouseEventCallback(napi_env env, napi_callback_info info)
{
LOGE("xclog running PluginRender::TestGetXComponent_RegisterMouseEventCallback");
napi_value callback_;
NAPI_CALL(env, napi_create_double(env, mousecallback_, &(callback_)));
napi_value obj;
NAPI_CALL(env, napi_create_object(env, &obj));
NAPI_CALL(env, napi_set_named_property(env, obj, "MouseCallback_", callback_)); // float x
return obj;
}
#ifdef __cplusplus
}
#endif
\ No newline at end of file
......@@ -29,6 +29,7 @@ public:
explicit PluginRender(std::string& id);
static PluginRender* GetInstance(std::string& id);
static OH_NativeXComponent_Callback* GetNXComponentCallback();
static OH_NativeXComponent_MouseEvent_Callback* GetNXComponentMouseEventCallback();
void SetNativeXComponent(OH_NativeXComponent* component);
......@@ -50,7 +51,11 @@ public:
static napi_value TestGetXComponentOffset_x(napi_env env, napi_callback_info info);
static napi_value TestGetXComponentOffset_y(napi_env env, napi_callback_info info);
static napi_value TestGetXComponent_TouchEvent(napi_env env, napi_callback_info info);
static napi_value TestGetXComponent_MouseEvent(napi_env env, napi_callback_info info);
static napi_value TestGetXComponentpointtool_tiltx(napi_env env, napi_callback_info info);
static napi_value TestGetXComponentpointtool_tilty(napi_env env, napi_callback_info info);
static napi_value TestGetXComponentpointtool_type(napi_env env, napi_callback_info info);
static napi_value TestGetXComponent_RegisterMouseEventCallback(napi_env env, napi_callback_info info);
// Callback, called by ACE XComponent
void OnSurfaceCreated(OH_NativeXComponent* component, void* window);
......@@ -68,10 +73,16 @@ public:
static uint32_t isCreated_;
static uint32_t xcHeight_;
static uint32_t xcWidth_;
static uint32_t toolType_;
static float tiltX_;
static float tiltY_;
static uint32_t mousecallback_;
static double off_x;
static double off_y;
static uint32_t touchType;
static OH_NativeXComponent_TouchEvent testTouchEvent_;
static OH_NativeXComponent_MouseEvent testMouseEvent_;
static OH_NativeXComponent_MouseEvent_Callback mouseEventcallback_;
OH_NativeXComponent* component_;
EGLCore* eglCore_;
......@@ -83,6 +94,7 @@ public:
double x_;
double y_;
OH_NativeXComponent_TouchEvent touchEvent_;
OH_NativeXComponent_MouseEvent mouseEvent_;
};
#endif // _PLUGIN_RENDER_H_
......@@ -30,6 +30,9 @@ struct XComponentTest {
@State private xcomponentWidth:number = 720;
private offset_x:double = 0.000;
private offset_y:double = 610.000;
private index:number = 0;
private callback_:number = 0;
private type_:number = 5;
private touchTypeDown:number = 0;
private touchTypeUp:number = 1;
private touchTypeMove:number = 2;
......@@ -70,6 +73,8 @@ struct XComponentTest {
globalThis.xcomponentWidth = this.xcomponentWidth;
globalThis.touchTypeDown = this.touchTypeDown;
globalThis.touchTypeUp = this.touchTypeUp;
globalThis.type_ = this.type_;
globalThis.index = this.index;
globalThis.touchTypeMove = this.touchTypeMove;
globalThis.touchTypeCancel = this.touchTypeCancel;
globalThis.offset_x = this.offset_x;
......@@ -124,6 +129,7 @@ struct XComponentTest {
globalThis.xcomponentContext2 = this.xcomponentContext2;
globalThis.xcomponentId2 = this.xcomponentId2;
globalThis.xcomponentHeight = this.xcomponentHeight;
globalThis.callback_ = this.callback_;
globalThis.xcomponentWidth = this.xcomponentWidth;
globalThis.offset_x = this.offset_x;
globalThis.offset_y = this.offset_y;
......
......@@ -200,5 +200,116 @@ export default function XComponentTestJsunit() {
}
});
/**
* @tc.number SUB_ACE_BASIC_ETS_API_0600
* @tc.name XComponentTest006
* @tc.desc aceXComponentEtsTest
*/
it('XComponentTest006', 0, async function (done) {
await Utils.sleep(1000);
console.info('xclog XComponentTest006 START');
var x_value = 340;
var y_value = 350;
//x:300 y:430左右范围是xcomponent.context2的changelayout范围
//x:300 y:150左右范围是xcomponent.context1的changeshape范围
var xcomponentContext1= globalThis.xcomponentContext1;
var insidex = globalThis.index;
if (!xcomponentContext1) {
console.error('xclog xcomponentContext null')
result = false;
} else {
result = true;
var result;
var inside_x;
var inside_y;
var button_t;
await Utils.sleep(1000);
inside_x = xcomponentContext1.TestGetXComponent_MouseEvent().surface_X1;
inside_y = xcomponentContext1.TestGetXComponent_MouseEvent().surface_Y1;
button_t = xcomponentContext1.TestGetXComponent_MouseEvent().mousebutton;
console.info('xclog ets touchEvent: surf_x1 is '+ inside_x + ', surf_y1 is '+ inside_y + ', button_t is ' + button_t );
}
expect(inside_x).assertEqual(insidex);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_API_0700
* @tc.name XComponentTest007
* @tc.desc aceXComponentEtsTest
*/
it('XComponentTest007', 0, async function (done) {
await Utils.sleep(1000);
console.info('xclog XComponentTest007 START');
var x_value = 340;
var y_value = 350;
//x:300 y:430左右范围是xcomponent.context2的changelayout范围
//x:300 y:150左右范围是xcomponent.context1的changeshape范围
var xcomponentContext2= globalThis.xcomponentContext2;
var callback_ = globalThis.callback_;
if (!xcomponentContext2) {
console.error('xclog xcomponentContext null')
tilty = false;
} else {
result = true;
var result;
var callback;
await Utils.sleep(1000);
callback = xcomponentContext2.TestGetXComponent_RegisterMouseEventCallback().MouseCallback_;
console.info('xclog ets touchEvent: callback is ' + callback );
}
expect(callback).assertEqual(callback_);
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_API_0800
* @tc.name XComponentTest008
* @tc.desc aceXComponentEtsTest
*/
it('XComponentTest008', 0, async function (done) {
await Utils.sleep(1000);
console.info('xclog XComponentTest008 START');
var x_value = 340;
var y_value = 350;
//x:300 y:430左右范围是xcomponent.context2的changelayout范围
//x:300 y:150左右范围是xcomponent.context1的changeshape范围
var xcomponentContext1= globalThis.xcomponentContext1;
var type_ = globalThis.type_;
if (!xcomponentContext1) {
console.error('xclog xcomponentContext null')
result = false;
} else {
result = true;
var result;
var tilty;
var tiltx;
var type_t;
await Utils.sleep(1000);
tilty = xcomponentContext1.TestGetXComponentpointtool_tilty();
type_t = xcomponentContext1.TestGetXComponentpointtool_type();
tiltx = xcomponentContext1.TestGetXComponentpointtool_tiltx();
console.info('xclog ets touchEvent: surf_x is '+ tiltx + ', surf_y is '+ tilty + ', type_t is ' + type_t );
}
expect(type_t).assertEqual(type_);
done();
});
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册