Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
c3873fb4
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c3873fb4
编写于
3月 23, 2022
作者:
O
openharmony_ci
提交者:
Gitee
3月 23, 2022
浏览文件
操作
浏览文件
下载
差异文件
!2711 add battery common event test case
Merge pull request !2711 from zhaoruiyuan/master
上级
b8c94c3a
79d04b7e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
792 addition
and
4 deletion
+792
-4
powermgr/powermgrbattery/src/main/js/default/test/List.test.js
...mgr/powermgrbattery/src/main/js/default/test/List.test.js
+2
-1
powermgr/powermgrbattery/src/main/js/default/test/battery_common_event.test.js
...ery/src/main/js/default/test/battery_common_event.test.js
+392
-0
powermgr/powermgrbattery_rk3568/src/main/js/default/test/List.test.js
...ermgrbattery_rk3568/src/main/js/default/test/List.test.js
+2
-1
powermgr/powermgrbattery_rk3568/src/main/js/default/test/battery_common_event.test.js
...568/src/main/js/default/test/battery_common_event.test.js
+392
-0
powermgr/powermgrthermal/src/main/js/default/test/thermal_performance.test.js
...rmal/src/main/js/default/test/thermal_performance.test.js
+4
-2
未找到文件。
powermgr/powermgrbattery/src/main/js/default/test/List.test.js
浏览文件 @
c3873fb4
...
...
@@ -13,4 +13,5 @@
* limitations under the License.
*/
require
(
'
./battery_unit.test.js
'
)
require
(
'
./power_manager_running_lock.test.js
'
)
\ No newline at end of file
require
(
'
./battery_common_event.test.js
'
)
require
(
'
./power_manager_running_lock.test.js
'
)
powermgr/powermgrbattery/src/main/js/default/test/battery_common_event.test.js
0 → 100644
浏览文件 @
c3873fb4
/*
* Copyright (C) 2022 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
commonEvent
from
'
@ohos.commonEvent
'
;
describe
(
'
appInfoTest
'
,
function
()
{
console
.
log
(
"
*************Battery commonEvent Test Begin*************
"
);
/**
* @tc.number BatteryCommonEventTest_001
* @tc.name subscribe battery changed common event
* @tc.desc battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_001
'
,
0
,
function
(
done
)
{
createBatteryChangedSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_002
* @tc.name subscribe battery okay common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_002
'
,
0
,
function
(
done
)
{
createBatteryOkaySubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_003
* @tc.name subscribe battery low common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_003
'
,
0
,
function
(
done
)
{
createBatteryLowSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_004
* @tc.name subscribe power connected common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_004
'
,
0
,
function
(
done
)
{
createBatteryPowerConnectedSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_005
* @tc.name subscribe power disconnected common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_005
'
,
0
,
function
(
done
)
{
createBatteryPowerDisconnectedSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_006
* @tc.name subscribe battery charging common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_006
'
,
0
,
function
(
done
)
{
createBatteryChargingSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_007
* @tc.name subscribe battery discharging common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_007
'
,
0
,
function
(
done
)
{
createBatteryDischargingSubscriber
();
done
();
})
console
.
log
(
"
*************Battery commonEvent Test End*************
"
);
})
function
createBatteryChangedSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_BATTERY_CHANGED
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryChangedSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe battery_changed begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
capacity
=
commonEventData
.
parameters
[
'
0
'
];
console
.
info
(
"
capacity is:
"
+
capacity
);
expect
(
capacity
>=
0
&&
capacity
<=
100
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryOkaySubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_BATTERY_OKAY
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryOkaySubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe battery_okay begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
capacity
=
commonEventData
.
parameters
[
'
0
'
];
console
.
info
(
"
capacity is:
"
+
capacity
);
expect
(
capacity
>=
0
&&
capacity
<=
100
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryLowSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_BATTERY_LOW
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryLowSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe battery_low begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
capacity
=
commonEventData
.
parameters
[
'
0
'
];
console
.
info
(
"
capacity is:
"
+
capacity
);
expect
(
capacity
>=
0
&&
capacity
<=
100
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryPowerConnectedSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_POWER_CONNECTED
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryPowerConnectedSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe power_connected begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
pluggedType
=
commonEventData
.
parameters
[
'
4
'
];
console
.
info
(
"
pluggedType is:
"
+
pluggedType
);
expect
(
pluggedType
>=
0
&&
pluggedType
<=
4
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryPowerDisconnectedSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_POWER_DISCONNECTED
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryPowerDisconnectedSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe power_disconnected begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
pluggedType
=
commonEventData
.
parameters
[
'
4
'
];
console
.
info
(
"
pluggedType is:
"
+
pluggedType
);
expect
(
pluggedType
>=
0
&&
pluggedType
<=
4
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryChargingSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_CHARGING
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryChargingSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe charging begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
chargeState
=
commonEventData
.
parameters
[
'
7
'
];
console
.
info
(
"
chargeState is:
"
+
chargeState
);
expect
(
chargeState
>=
0
&&
chargeState
<=
10
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryDischargingSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_DISCHARGING
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryDischargingSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe discharging begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
chargeState
=
commonEventData
.
parameters
[
'
7
'
];
console
.
info
(
"
chargeState is:
"
+
chargeState
);
expect
(
chargeState
>=
0
&&
chargeState
<=
10
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
powermgr/powermgrbattery_rk3568/src/main/js/default/test/List.test.js
浏览文件 @
c3873fb4
...
...
@@ -13,4 +13,5 @@
* limitations under the License.
*/
require
(
'
./battery_unit.test.js
'
)
require
(
'
./power_manager_running_lock.test.js
'
)
\ No newline at end of file
require
(
'
./battery_common_event.test.js
'
)
require
(
'
./power_manager_running_lock.test.js
'
)
powermgr/powermgrbattery_rk3568/src/main/js/default/test/battery_common_event.test.js
0 → 100644
浏览文件 @
c3873fb4
/*
* Copyright (C) 2022 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
commonEvent
from
'
@ohos.commonEvent
'
;
describe
(
'
appInfoTest
'
,
function
()
{
console
.
log
(
"
*************Battery commonEvent Test Begin*************
"
);
/**
* @tc.number BatteryCommonEventTest_001
* @tc.name subscribe battery changed common event
* @tc.desc battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_001
'
,
0
,
function
(
done
)
{
createBatteryChangedSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_002
* @tc.name subscribe battery okay common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_002
'
,
0
,
function
(
done
)
{
createBatteryOkaySubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_003
* @tc.name subscribe battery low common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_003
'
,
0
,
function
(
done
)
{
createBatteryLowSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_004
* @tc.name subscribe power connected common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_004
'
,
0
,
function
(
done
)
{
createBatteryPowerConnectedSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_005
* @tc.name subscribe power disconnected common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_005
'
,
0
,
function
(
done
)
{
createBatteryPowerDisconnectedSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_006
* @tc.name subscribe battery charging common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_006
'
,
0
,
function
(
done
)
{
createBatteryChargingSubscriber
();
done
();
})
/**
* @tc.number BatteryCommonEventTest_007
* @tc.name subscribe battery discharging common event
* @tc.desc Battery acquisition kit
*/
it
(
'
BatteryCommonEventTest_007
'
,
0
,
function
(
done
)
{
createBatteryDischargingSubscriber
();
done
();
})
console
.
log
(
"
*************Battery commonEvent Test End*************
"
);
})
function
createBatteryChangedSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_BATTERY_CHANGED
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryChangedSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe battery_changed begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
capacity
=
commonEventData
.
parameters
[
'
0
'
];
console
.
info
(
"
capacity is:
"
+
capacity
);
expect
(
capacity
>=
0
&&
capacity
<=
100
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryOkaySubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_BATTERY_OKAY
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryOkaySubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe battery_okay begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
capacity
=
commonEventData
.
parameters
[
'
0
'
];
console
.
info
(
"
capacity is:
"
+
capacity
);
expect
(
capacity
>=
0
&&
capacity
<=
100
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryLowSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_BATTERY_LOW
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryLowSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe battery_low begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
capacity
=
commonEventData
.
parameters
[
'
0
'
];
console
.
info
(
"
capacity is:
"
+
capacity
);
expect
(
capacity
>=
0
&&
capacity
<=
100
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryPowerConnectedSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_POWER_CONNECTED
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryPowerConnectedSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe power_connected begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
pluggedType
=
commonEventData
.
parameters
[
'
4
'
];
console
.
info
(
"
pluggedType is:
"
+
pluggedType
);
expect
(
pluggedType
>=
0
&&
pluggedType
<=
4
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryPowerDisconnectedSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_POWER_DISCONNECTED
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryPowerDisconnectedSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe power_disconnected begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
pluggedType
=
commonEventData
.
parameters
[
'
4
'
];
console
.
info
(
"
pluggedType is:
"
+
pluggedType
);
expect
(
pluggedType
>=
0
&&
pluggedType
<=
4
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryChargingSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_CHARGING
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryChargingSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe charging begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
chargeState
=
commonEventData
.
parameters
[
'
7
'
];
console
.
info
(
"
chargeState is:
"
+
chargeState
);
expect
(
chargeState
>=
0
&&
chargeState
<=
10
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
function
createBatteryDischargingSubscriber
()
{
var
commonEventSubscribeInfo
=
{
events
:
[
commonEvent
.
Support
.
COMMON_EVENT_DISCHARGING
],
};
commonEvent
.
createSubscriber
(
commonEventSubscribeInfo
)
.
then
(
subscriber
=>
{
console
.
info
(
'
createBatteryDischargingSubscriber success
'
);
var
mySubscriber
=
subscriber
;
console
.
log
(
subscriber
);
if
(
subscriber
==
""
||
subscriber
==
undefined
||
subscriber
==
null
)
{
console
.
info
(
"
createSubscriber failed
"
);
}
mySubscriber
.
getCode
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getCode success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getCode error because:
'
+
JSON
.
stringify
(
error
));
})
mySubscriber
.
getData
()
.
then
((
data
)
=>
{
console
.
info
(
'
Subscriber getData success :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
'
Subscriber getData error because:
'
+
JSON
.
stringify
(
error
));
})
console
.
info
(
'
subscribe discharging begin
'
);
commonEvent
.
subscribe
(
mySubscriber
,
(
error
,
commonEventData
)
=>
{
console
.
error
(
'
err code:
'
+
JSON
.
stringify
(
error
));
console
.
info
(
'
subscribe callback:
'
+
JSON
.
stringify
(
commonEventData
));
console
.
info
(
"
commonEventData event:
"
+
commonEventData
.
event
);
console
.
info
(
"
commonEventData bundleName:
"
+
commonEventData
.
bundleName
);
console
.
info
(
"
commonEventData data:
"
+
commonEventData
.
data
);
console
.
info
(
"
commonEventData parameter:
"
+
commonEventData
.
parameters
[
0
]);
var
chargeState
=
commonEventData
.
parameters
[
'
7
'
];
console
.
info
(
"
chargeState is:
"
+
chargeState
);
expect
(
chargeState
>=
0
&&
chargeState
<=
10
).
assertTrue
();
});
}).
catch
((
error
)
=>
{
console
.
error
(
'
Operation failed. Cause:
'
+
JSON
.
stringify
(
error
));
});
}
powermgr/powermgrthermal/src/main/js/default/test/thermal_performance.test.js
浏览文件 @
c3873fb4
...
...
@@ -75,10 +75,12 @@ function performanceTest3() {
it
(
'
ThermalPerformance_003
'
,
0
,
function
()
{
let
startTime
=
new
Date
().
getTime
();
for
(
let
i
=
0
;
i
<
MAXNUM
;
i
++
)
{
thermal
.
unsubscribeThermalLevel
();
thermal
.
unsubscribeThermalLevel
(()
=>
{
console
.
info
(
"
unsubscribe success.
"
);
});
}
let
waitTime
=
new
Date
().
getTime
()
-
startTime
;
let
avgTime
=
waitTime
;
//us
console
.
info
(
`ThermalPerformance_003: Promise: unsubscribeThermalLevel Wait Time :
${
waitTime
}
`
);
})
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录