提交 f51ba516 编写于 作者: G gaoxi785

Update osaccount test code

Signed-off-by: Ngaoxi785 <gaoxi785@huawei.com>
上级 b0037be7
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
import osaccount from '@ohos.account.osAccount' import osaccount from '@ohos.account.osAccount'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
const TIMEOUT = 1000;
const ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR = 4587571;
describe('ActsOsAccountSystemTest', function () { describe('ActsOsAccountSystemTest', function () {
/* /*
...@@ -26,17 +28,29 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -26,17 +28,29 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>ActsOsAccountActivate_0100 start===="); console.debug("====>ActsOsAccountActivate_0100 start====");
var osAccountManager = osaccount.getAccountManager(); var osAccountManager = osaccount.getAccountManager();
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
osAccountManager.isOsAccountActived(100, (err, data)=>{ osAccountManager.isOsAccountActived(100, (err, isActived)=>{
console.debug("====>isOsAccountActived err:" + JSON.stringify(err)); console.debug("====>isOsAccountActived err:" + JSON.stringify(err));
console.debug("====>isOsAccountActived data:" + data); console.debug("====>isOsAccountActived data:" + isActived);
expect(err.code).assertEqual(0); expect(err.code).assertEqual(0);
expect(data).assertTrue(); if(isActived){
osAccountManager.activateOsAccount(100, (err)=>{ osAccountManager.activateOsAccount(100, (err)=>{
console.debug("====>activateOsAccount err:" + JSON.stringify(err)); console.debug("====>activateOsAccount err:" + JSON.stringify(err));
expect(err.code != 0).assertTrue(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_0100 end===="); console.debug("====>ActsOsAccountActivate_0100 end====");
done(); done();
}) })
}else{
osAccountManager.activateOsAccount(100, (err)=>{
console.debug("====>activateOsAccount first err:" + JSON.stringify(err));
expect(err.code).assertEqual(0);
osAccountManager.activateOsAccount(100, (err)=>{
console.debug("====>activateOsAccount second err:" + JSON.stringify(err));
expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_0100 end====");
done();
})
})
}
}) })
}); });
...@@ -49,23 +63,29 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -49,23 +63,29 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>ActsOsAccountActivate_0200 start===="); console.debug("====>ActsOsAccountActivate_0200 start====");
var osAccountManager = osaccount.getAccountManager(); var osAccountManager = osaccount.getAccountManager();
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
try{ var isActived = await osAccountManager.isOsAccountActived(100);
var isActived = await osAccountManager.isOsAccountActived(100);
}catch(err){
console.error("====>catch isOsAccountActived 0200 err:" + JSON.stringify(err));
expect().assertFail();
done();
}
console.debug("====>isOsAccountActived err:" + JSON.stringify(isActived)); console.debug("====>isOsAccountActived err:" + JSON.stringify(isActived));
expect(isActived).assertTrue(); if(isActived){
try{ try{
await osAccountManager.activateOsAccount(100);
}catch(err){
console.debug("====>catch activateOsAccount 0200 err:" + JSON.stringify(err));
expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_0200 end====");
done();
}
}else{
console.debug("====>switch to 100 user====");
await osAccountManager.activateOsAccount(100); await osAccountManager.activateOsAccount(100);
}catch(err){ try{
console.debug("====>catch activateOsAccount 0200 err:" + JSON.stringify(err)); await osAccountManager.activateOsAccount(100);
expect(err.code != 0).assertTrue(); }catch(err){
console.debug("====>ActsOsAccountActivate_0200 end===="); console.debug("====>catch activateOsAccount 0200 err:" + JSON.stringify(err));
done(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
} console.debug("====>ActsOsAccountActivate_0200 end====");
done();
}
}
}); });
/* /*
...@@ -158,7 +178,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -158,7 +178,7 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
osAccountManager.activateOsAccount(0, (err)=>{ osAccountManager.activateOsAccount(0, (err)=>{
console.debug("====>activateOsAccount to 0 user err:" + JSON.stringify(err)); console.debug("====>activateOsAccount to 0 user err:" + JSON.stringify(err));
expect(err.code != 0).assertTrue(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_0500 end===="); console.debug("====>ActsOsAccountActivate_0500 end====");
done(); done();
}) })
...@@ -177,7 +197,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -177,7 +197,7 @@ describe('ActsOsAccountSystemTest', function () {
await osAccountManager.activateOsAccount(0); await osAccountManager.activateOsAccount(0);
}catch(err){ }catch(err){
console.debug("====>activateOsAccount to 0 user err:" + JSON.stringify(err)); console.debug("====>activateOsAccount to 0 user err:" + JSON.stringify(err));
expect(err.code != 0).assertTrue(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_0600 end===="); console.debug("====>ActsOsAccountActivate_0600 end====");
done(); done();
} }
...@@ -194,7 +214,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -194,7 +214,7 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
osAccountManager.activateOsAccount(-1, (err)=>{ osAccountManager.activateOsAccount(-1, (err)=>{
console.debug("====>activateOsAccount to -1 user err:" + JSON.stringify(err)); console.debug("====>activateOsAccount to -1 user err:" + JSON.stringify(err));
expect(err.code != 0).assertTrue(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_0700 end===="); console.debug("====>ActsOsAccountActivate_0700 end====");
done(); done();
}) })
...@@ -213,7 +233,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -213,7 +233,7 @@ describe('ActsOsAccountSystemTest', function () {
await osAccountManager.activateOsAccount(-1); await osAccountManager.activateOsAccount(-1);
}catch(err){ }catch(err){
console.debug("====>activateOsAccount to -1 user err:" + JSON.stringify(err)); console.debug("====>activateOsAccount to -1 user err:" + JSON.stringify(err));
expect(err.code != 0).assertTrue(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_0800 end===="); console.debug("====>ActsOsAccountActivate_0800 end====");
done(); done();
} }
...@@ -228,12 +248,18 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -228,12 +248,18 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>ActsOsAccountActivate_0900 start===="); console.debug("====>ActsOsAccountActivate_0900 start====");
var osAccountManager = osaccount.getAccountManager(); var osAccountManager = osaccount.getAccountManager();
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
osAccountManager.activateOsAccount("Abc", (err)=>{ var localIdStr = "100";
console.debug("====>activateOsAccount to 'Abc' user err:" + JSON.stringify(err)); function funcActivateCallback(err){
expect(err.code != 0).assertTrue(); console.debug("====>error received callback====");
console.debug("====>receive activateOsAccount err: " + JSON.stringify(err));
expect().assertFail();
done();
}
osAccountManager.activateOsAccount(localIdStr, funcActivateCallback);
setTimeout(()=>{
console.debug("====>ActsOsAccountActivate_0900 end===="); console.debug("====>ActsOsAccountActivate_0900 end====");
done(); done();
}) }, TIMEOUT);
}); });
/* /*
...@@ -245,14 +271,11 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -245,14 +271,11 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>ActsOsAccountActivate_1000 start===="); console.debug("====>ActsOsAccountActivate_1000 start====");
var osAccountManager = osaccount.getAccountManager(); var osAccountManager = osaccount.getAccountManager();
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
try{ var localIdStr = "100";
await osAccountManager.activateOsAccount("Abc"); var activateResult = await osAccountManager.activateOsAccount(localIdStr);
}catch(err){ expect(activateResult).assertEqual(null);
console.debug("====>activateOsAccount to 'Abc' user err:" + JSON.stringify(err)); console.debug("====>ActsOsAccountActivate_1000 end====");
expect(err.code != 0).assertTrue(); done();
console.debug("====>ActsOsAccountActivate_1000 end====");
done();
}
}); });
/* /*
...@@ -264,12 +287,17 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -264,12 +287,17 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>ActsOsAccountActivate_1100 start===="); console.debug("====>ActsOsAccountActivate_1100 start====");
var osAccountManager = osaccount.getAccountManager(); var osAccountManager = osaccount.getAccountManager();
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
osAccountManager.activateOsAccount(undefined, (err)=>{ function funcActivateCallback(err){
console.debug("====>activateOsAccount to undefined user err:" + JSON.stringify(err)); console.debug("====>error received callback====");
expect(err.code != 0).assertTrue(); console.debug("====>receive activateOsAccount err: " + JSON.stringify(err));
expect().assertFail();
done();
}
osAccountManager.activateOsAccount(undefined, funcActivateCallback);
setTimeout(()=>{
console.debug("====>ActsOsAccountActivate_1100 end===="); console.debug("====>ActsOsAccountActivate_1100 end====");
done(); done();
}) }, TIMEOUT);
}); });
/* /*
...@@ -281,14 +309,10 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -281,14 +309,10 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>ActsOsAccountActivate_1200 start===="); console.debug("====>ActsOsAccountActivate_1200 start====");
var osAccountManager = osaccount.getAccountManager(); var osAccountManager = osaccount.getAccountManager();
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
try{ var activateResult = await osAccountManager.activateOsAccount(undefined);
await osAccountManager.activateOsAccount(undefined); expect(activateResult).assertEqual(null);
}catch(err){ console.debug("====>ActsOsAccountActivate_1200 end====");
console.debug("====>activateOsAccount to undefined user err:" + JSON.stringify(err)); done();
expect(err.code != 0).assertTrue();
console.debug("====>ActsOsAccountActivate_1200 end====");
done();
}
}); });
/* /*
...@@ -303,7 +327,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -303,7 +327,7 @@ describe('ActsOsAccountSystemTest', function () {
console.debug("====>get AccountManager finish===="); console.debug("====>get AccountManager finish====");
osAccountManager.activateOsAccount(nonExistentLocalId, (err)=>{ osAccountManager.activateOsAccount(nonExistentLocalId, (err)=>{
console.debug("====>activateOsAccount to nonexist user err:" + JSON.stringify(err)); console.debug("====>activateOsAccount to nonexist user err:" + JSON.stringify(err));
expect(err.code != 0).assertTrue(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_1300 end===="); console.debug("====>ActsOsAccountActivate_1300 end====");
done(); done();
}) })
...@@ -323,7 +347,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -323,7 +347,7 @@ describe('ActsOsAccountSystemTest', function () {
await osAccountManager.activateOsAccount(nonExistentLocalId); await osAccountManager.activateOsAccount(nonExistentLocalId);
}catch(err){ }catch(err){
console.debug("====>activateOsAccount to nonexist user err:" + JSON.stringify(err)); console.debug("====>activateOsAccount to nonexist user err:" + JSON.stringify(err));
expect(err.code != 0).assertTrue(); expect(err.code).assertEqual(ERR_OSACCOUNT_KIT_ACTIVATE_OS_ACCOUNT_ERROR);
console.debug("====>ActsOsAccountActivate_1400 end===="); console.debug("====>ActsOsAccountActivate_1400 end====");
done(); done();
} }
......
...@@ -245,7 +245,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -245,7 +245,7 @@ describe('ActsOsAccountSystemTest', function () {
/* /*
* @tc.number : ActsOsAccountOnOff_0700 * @tc.number : ActsOsAccountOnOff_0700
* @tc.name : Subscribe and unsubscribing local multi-user * @tc.name : Subscribe and unsubscribing local multi-user
* @tc.desc : Verification cannot cancel activating type not subscribed * @tc.desc : Validate subscription callback with parameter name as empty string
*/ */
it('ActsOsAccountOnOff_0700', 0, async function (done) { it('ActsOsAccountOnOff_0700', 0, async function (done) {
console.debug("====>ActsOsAccountOnOff_0700 start===="); console.debug("====>ActsOsAccountOnOff_0700 start====");
...@@ -269,7 +269,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -269,7 +269,7 @@ describe('ActsOsAccountSystemTest', function () {
expect(err.code).assertEqual(0); expect(err.code).assertEqual(0);
expect(osAccountInfo.localName).assertEqual("osAccountNameE"); expect(osAccountInfo.localName).assertEqual("osAccountNameE");
osAccountManager.activateOsAccount(localId, (err)=>{ osAccountManager.activateOsAccount(localId, (err)=>{
console.debug("====>activateOsAccount err:" + JSON.stringify(err)); console.debug("====>activateOsAccount errcode:" + JSON.stringify(err));
expect(err.code).assertEqual(0); expect(err.code).assertEqual(0);
setTimeout(()=>{ setTimeout(()=>{
osAccountManager.removeOsAccount(localId, (err)=>{ osAccountManager.removeOsAccount(localId, (err)=>{
...@@ -286,7 +286,7 @@ describe('ActsOsAccountSystemTest', function () { ...@@ -286,7 +286,7 @@ describe('ActsOsAccountSystemTest', function () {
/* /*
* @tc.number : ActsOsAccountOnOff_0800 * @tc.number : ActsOsAccountOnOff_0800
* @tc.name : Subscribe and unsubscribing local multi-user * @tc.name : Subscribe and unsubscribing local multi-user
* @tc.desc : Verification cannot cancel activating type not subscribed * @tc.desc : Validate subscription promise with parameter name as empty string
*/ */
it('ActsOsAccountOnOff_0800', 0, async function (done) { it('ActsOsAccountOnOff_0800', 0, async function (done) {
console.debug("====>ActsOsAccountOnOff_0800 start===="); console.debug("====>ActsOsAccountOnOff_0800 start====");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册