From 318371facfd78d03c639f9a94de7aea66a6397de Mon Sep 17 00:00:00 2001 From: yanglifeng1217 Date: Sun, 25 Jun 2023 16:04:18 +0800 Subject: [PATCH] Signed-off-by: yanglifeng1217 --- .../entry/src/main/ets/test/UDMF.test.ets | 5 + .../main/ets/test/UDMFApiCallback.test.ets | 431 +++++++------- .../src/main/ets/test/UDMFApiPromise.test.ets | 537 +++++++++--------- 3 files changed, 480 insertions(+), 493 deletions(-) diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMF.test.ets b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMF.test.ets index bd59c0c48..c1842b4f7 100644 --- a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMF.test.ets +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMF.test.ets @@ -132,6 +132,11 @@ export default function UDMFApiTest() { applicationDefinedRecord.applicationDefinedType = 'applicationDefinedType'; applicationDefinedRecord.rawData = u8Array; + let summary = new UDMF.Summary; + let records1 = summary.summary; + console.info("ttt " + records1); + let records2 = summary.totalSize; + /** * @tc.number SUB_DistributedData_Udmf_API001 * @tc.name CreateData diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiCallback.test.ets b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiCallback.test.ets index e1e0761db..f1172f235 100644 --- a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiCallback.test.ets +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiCallback.test.ets @@ -24,7 +24,7 @@ export default function UDMFApiCallback() { beforeEach(async function () { console.info(TAG + "beforeEach") let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; await UDMF.deleteData(options).then((data) => { let size = data.length; @@ -53,15 +53,15 @@ export default function UDMFApiCallback() { expect(err === undefined).assertFail(); done(); } else { - console.error(TAG, `Failed to insertData0100 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); } }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0100 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -85,15 +85,15 @@ export default function UDMFApiCallback() { expect(err === undefined).assertFail(); done(); } else { - console.error(TAG, `Failed to insertData0200 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); } }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0200 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -117,15 +117,15 @@ export default function UDMFApiCallback() { expect(err === undefined).assertFail(); done(); } else { - console.error(TAG, `Failed to insertData0300 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); } }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0300 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -150,15 +150,15 @@ export default function UDMFApiCallback() { expect(err === undefined).assertFail(); done(); } else { - console.error(TAG, `Failed to insertData0400 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); } }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0400 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -182,15 +182,15 @@ export default function UDMFApiCallback() { expect(err === undefined).assertFail(); done(); } else { - console.error(TAG, `Failed to insertData0500 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); } }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0500 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -202,7 +202,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_InsertData_Callback_0600', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -232,29 +232,29 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_UpdateData_Callback_0100', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try{ UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); - return; + if (e !== undefined) { + console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); + UDMF.updateData({key: data}, unifiedData, function (err, ret) { + if (err === undefined) { + console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); + expect(err === undefined).assertTrue() + done(); + } else { + console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); } - console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); - UDMF.updateData({key: data}, unifiedData, function (err, ret) { - if (err === undefined) { - console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); - expect(err === undefined).assertTrue() - done(); - } else { - console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); - } - }); + }); }); }catch(error){ console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -270,32 +270,38 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_UpdateData_Callback_0200', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); - return; - } - console.info(TAG + `insertData0200 success; data = ${data}, options = ${options}`); + if (e !== undefined) { + console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0200 success; data = ${data}, options = ${options}`); + try{ UDMF.updateData({key: undefined}, unifiedData, function (err, ret) { if (err === undefined) { console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); expect(err !== null).assertFail() done(); } else { - console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); } }); + }catch(errInfo){ + console.info(`UpdateData failed. code is ${errInfo.code},message is ${errInfo.message} `); + expect(errInfo.code).assertEqual('401'); + done(); + } }); } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); + console.info(`UpdateData1 failed. code is ${error.code},message is ${error.message} `); expect(error !== null).assertFail(); done(); } @@ -308,18 +314,19 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_UpdateData_Callback_0300', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); - return; - } - console.info(TAG + `insertData0300 success; data = ${data}, options = ${options}`); + if (e !== undefined) { + console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0300 success; data = ${data}, options = ${options}`); + try{ UDMF.updateData({key: null}, unifiedData, function (err, ret) { if (err === undefined) { console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); @@ -327,10 +334,16 @@ export default function UDMFApiCallback() { done(); } else { console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + expect(err !== null).assertFail() done(); } }); + }catch(errInfo){ + console.info(`UpdateData failed. code is ${errInfo.code},message is ${errInfo.message} `); + expect(errInfo.code).assertEqual('401'); + done(); + } + }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -344,45 +357,10 @@ export default function UDMFApiCallback() { * @tc.name UDMF insertData callback interface test * @tc.desc UDMF insertData callback interface test. */ - it('SUB_DDM_UDMF_UpdateData_Callback_0400', 0, function (done) { - let options = { - intention: undefined - } - let plainText = new UDMF.PlainText(); - plainText.textContent = "hello world!"; - let unifiedData = new UDMF.UnifiedData(plainText); - try { - UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(TAG + `insertData0400 fail, code is ${e.code},message is ${e.message}`); - } - UDMF.updateData({key: data}, unifiedData, function (err, ret) { - if (err === undefined) { - console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); - expect(err !== null).assertFail() - done(); - } else { - console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); - } - }); - }); - } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); - done(); - } - }) - /** - * @tc.number SUB_DDM_UDMF_UpdateData_Callback_0500 - * @tc.name UDMF updateData callback interface test - * @tc.desc UDMF updateData callback interface test. - */ - it('SUB_DDM_UDMF_UpdateData_Callback_0500', 0, function (done) { + it('SUB_DDM_UDMF_UpdateData_Callback_0400', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: undefined } let plainText = new UDMF.PlainText(); @@ -421,40 +399,40 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_QueryData_Callback_0100', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); - return; - } - console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); - UDMF.queryData(options, function (err, ret) { - if (err === undefined) { - let size = ret.length; - console.info(TAG, ` data.size = ${size}`); - for (var i = 0; i < size; i++) { - let records = ret[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); - } + if (e !== undefined) { + console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); + UDMF.queryData(options, function (err, ret) { + if (err === undefined) { + let size = ret.length; + console.info(TAG, ` data.size = ${size}`); + for (var i = 0; i < size; i++) { + let records = ret[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - } else { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); } - }); + expect(size).assertEqual(1); + done(); + } else { + console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); + } + }); }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -470,40 +448,40 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_QueryData_Callback_0200', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); - return; - } - console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); - UDMF.queryData({key: data}, function (err, ret) { - if (err === undefined) { - let size = ret.length; - console.info(TAG, ` data.size = ${size}`); - for (var i = 0; i < size; i++) { - let records = ret[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); - } + if (e !== undefined) { + console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); + UDMF.queryData({key: data}, function (err, ret) { + if (err === undefined) { + let size = ret.length; + console.info(TAG, ` data.size = ${size}`); + for (var i = 0; i < size; i++) { + let records = ret[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - } else { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); } - }); + expect(size).assertEqual(1); + done(); + } else { + console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); + } + }); }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -519,44 +497,44 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_QueryData_Callback_0300', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(options1, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); - return; - } - console.info(TAG + `insertData0100 success; data = ${data}, options = ${options1}`); - let options2 = { - intention: UDMF.Intention.SUPER_HUB, - key: data - }; - UDMF.queryData(options2, function (err, ret) { - if (err === undefined) { - let size = ret.length; - console.info(TAG, ` data.size = ${size}`); - for (var i = 0; i < size; i++) { - let records = ret[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); - } + if (e !== undefined) { + console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0100 success; data = ${data}, options = ${options1}`); + let options2 = { + intention: UDMF.Intention.DATA_HUB, + key: data + }; + UDMF.queryData(options2, function (err, ret) { + if (err === undefined) { + let size = ret.length; + console.info(TAG, ` data.size = ${size}`); + for (var i = 0; i < size; i++) { + let records = ret[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - } else { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); } - }); + expect(size).assertEqual(1); + done(); + } else { + console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); + } + }); }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -572,7 +550,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_QueryData_Callback_0400', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -585,31 +563,37 @@ export default function UDMFApiCallback() { } console.info(TAG + `insertData0400 success; data = ${data}, options = ${options1}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: 'data' }; - UDMF.queryData(options2, function (err, ret) { - if (err === undefined) { - let size = ret.length; - console.info(TAG, ` data.size = ${size}`); - for (var i = 0; i < size; i++) { - let records = ret[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); + try{ + UDMF.queryData(options2, function (err, ret) { + if (err === undefined) { + let size = ret.length; + console.info(TAG, ` data.size = ${size}`); + for (var i = 0; i < size; i++) { + let records = ret[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); + } } } + expect(err === undefined).assertFail(); + done(); + } else { + console.info(`Failed to queryData code is ${err.code},message is ${err.message} `); + expect(err.code === 401).assertFail(); + done(); } - expect(err === undefined).assertFail(); - done(); - } else { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); - } - }); + }); + }catch(errorInfo){ + console.info(`Failed to queryData. code is ${errorInfo.code},message is ${errorInfo.message} `); + expect(errorInfo.code).assertEqual('401'); + done(); + } }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -625,7 +609,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_QueryData_Callback_0500', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -638,7 +622,7 @@ export default function UDMFApiCallback() { } console.info(TAG + `insertData0500 success; data = ${data}, options = ${options1}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: undefined }; UDMF.queryData(options2, function (err, ret) { @@ -678,7 +662,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_DeleteData_Callback_0100', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -734,7 +718,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_DeleteData_Callback_0200', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -790,7 +774,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_DeleteData_Callback_0300', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -809,7 +793,7 @@ export default function UDMFApiCallback() { } console.info(TAG, ` queryData size = ${ret.length}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: data }; UDMF.deleteData(options2, function (err, row) { @@ -850,7 +834,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_DeleteData_Callback_0400', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -869,31 +853,38 @@ export default function UDMFApiCallback() { } console.info(TAG, ` queryData size = ${ret.length}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: 'data' }; - UDMF.deleteData(options2, function (err, row) { - if (err == undefined) { - let size = row.length; - console.info(TAG, ` deleteData size = ${size}`); - for (var i = 0; i < size; i++) { - let records = row[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); + try{ + UDMF.deleteData(options2, function (err, row) { + if (err == undefined) { + let size = row.length; + console.info(TAG, ` deleteData size = ${size}`); + for (var i = 0; i < size; i++) { + let records = row[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); + } } } + expect(err !== null).assertFail(); + done(); + } else { + console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); + expect(err.code === 401).assertFail(); + done(); } - expect(err !== null).assertFail(); - done(); - } else { - console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); - } - }); + }); + }catch(error){ + console.info(`Failed to deleteData. code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); + done(); + } + }); }); } catch (error) { @@ -910,7 +901,7 @@ export default function UDMFApiCallback() { */ it('SUB_DDM_UDMF_DeleteData_Callback_0300', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -929,7 +920,7 @@ export default function UDMFApiCallback() { } console.info(TAG, ` queryData size = ${ret.length}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: undefined }; UDMF.deleteData(options2, function (err, row) { diff --git a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiPromise.test.ets b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiPromise.test.ets index 179c45541..18995c5de 100644 --- a/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiPromise.test.ets +++ b/distributeddatamgr/UDMFtest/UDMFtest/entry/src/main/ets/test/UDMFApiPromise.test.ets @@ -24,7 +24,7 @@ export default function UDMFApiPromise() { beforeEach(async function () { console.info(TAG + "beforeEach") let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; await UDMF.deleteData(options).then((data) => { let size = data.length; @@ -48,18 +48,18 @@ export default function UDMFApiPromise() { let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(Options, unifiedData).then((data) => { - console.info(TAG + `data = ${data}, options = ${Options}`); - expect().assertFail(); - done(); + console.info(TAG + `data = ${data}, options = ${Options}`); + expect().assertFail(); + done(); }).catch((err) => { - console.error(TAG, `Failed to insertData0100 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); - }) + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); + }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0100 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -78,18 +78,18 @@ export default function UDMFApiPromise() { let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(Options, unifiedData).then((data) => { - console.info(TAG + `data = ${data}, options = ${Options}`); - expect().assertFail(); - done(); - }).catch((err) => { - console.error(TAG, `Failed to insertData0200 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); - }) + console.info(TAG + `data = ${data}, options = ${Options}`); + expect().assertFail(); + done(); + }).catch((err) => { + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); + }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0200 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -108,18 +108,18 @@ export default function UDMFApiPromise() { let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(Options, unifiedData).then((data) => { - console.info(TAG + `data = ${data}, options = ${Options}`); - expect().assertFail(); - done(); - }).catch((err) => { - console.error(TAG, `Failed to insertData0300 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); + console.info(TAG + `data = ${data}, options = ${Options}`); + expect().assertFail(); + done(); + }).catch((err) => { + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0300 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -139,18 +139,18 @@ export default function UDMFApiPromise() { let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(Options, unifiedData).then((data) => { - console.info(TAG + `data = ${data}, options = ${Options}`); - expect().assertFail(); - done(); - }).catch((err) => { - console.error(TAG, `Failed to insertData0400 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); + console.info(TAG + `data = ${data}, options = ${Options}`); + expect().assertFail(); + done(); + }).catch((err) => { + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0400 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -169,18 +169,18 @@ export default function UDMFApiPromise() { let unifiedData = new UDMF.UnifiedData(plainText); try { UDMF.insertData(Options, unifiedData).then((data) => { - console.info(TAG + `data = ${data}, options = ${Options}`); - expect().assertFail(); - done(); - }).catch((err) => { - console.error(TAG, `Failed to insertData0500 code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); + console.info(TAG + `data = ${data}, options = ${Options}`); + expect().assertFail(); + done(); + }).catch((err) => { + console.error(TAG, `Failed, code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }) } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); + console.error(TAG, `Failed to insertData0500 code is ${error.code},message is ${error.message} `); + expect(error.code).assertEqual('401'); done(); } }) @@ -192,20 +192,20 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_InsertData_Promise_0600', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try{ UDMF.insertData(options, unifiedData).then((data) => { - console.info(TAG + `data = ${data}, options = ${options}`); - expect(data !== null).assertTrue(); - done() - }).catch((err) => { - console.error(TAG, `Failed to insertData0600 code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); + console.info(TAG + `data = ${data}, options = ${options}`); + expect(data !== null).assertTrue(); + done() + }).catch((err) => { + console.error(TAG, `Failed to insertData0600 code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }); }catch(error){ console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -220,27 +220,27 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_UpdateData_Promise_0100', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; let unifiedData = new UDMF.UnifiedData(plainText); try{ UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); - return; - } - console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); - UDMF.updateData({key: data}, unifiedData).then((ret) => { - console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); - expect(ret !== null).assertTrue(); - done(); - }).catch((err) => { - console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); - }); + if (e !== undefined) { + console.info(TAG, ` Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); + UDMF.updateData({key: data}, unifiedData).then((ret) => { + console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); + expect(ret !== null).assertTrue(); + done(); + }).catch((err) => { + console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); + }); }); }catch(error){ @@ -257,7 +257,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_UpdateData_Promise_0200', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -269,15 +269,21 @@ export default function UDMFApiPromise() { return; } console.info(TAG + `insertData0200 success; data = ${data}, options = ${options}`); - UDMF.updateData({key: undefined}, unifiedData).then((ret) => { + try{ + UDMF.updateData({key: undefined}, unifiedData).then((ret) => { console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); expect().assertFail() done(); }).catch((err) => { - console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.info(`UpdateData1111 failed. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); - }); + }); + }catch(errInfo){ + console.info(`UpdateData2222 failed. code is ${errInfo.code},message is ${errInfo.message} `); + expect(errInfo.code).assertEqual('401'); + done(); + } }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -293,7 +299,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_UpdateData_Promise_0300', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB } let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -305,15 +311,22 @@ export default function UDMFApiPromise() { return; } console.info(TAG + `insertData0300 success; data = ${data}, options = ${options}`); - UDMF.updateData({key: null}, unifiedData).then((ret) => { + try{ + UDMF.updateData({key: null}, unifiedData).then((ret) => { console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); expect().assertFail() done(); }).catch((err) => { console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + expect(err !== null).assertFail(); done(); - }); + }); + }catch(errInfo){ + console.info(`UpdateData failed. code is ${errInfo.code},message is ${errInfo.message} `); + expect(errInfo.code).assertEqual('401'); + done(); + } + }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -327,43 +340,10 @@ export default function UDMFApiPromise() { * @tc.name UDMF insertData promise interface test * @tc.desc UDMF insertData promise interface test. */ - it('SUB_DDM_UDMF_UpdateData_Promise_0400', 0, function (done) { - let options = { - intention: undefined - } - let plainText = new UDMF.PlainText(); - plainText.textContent = "hello world!"; - let unifiedData = new UDMF.UnifiedData(plainText); - try { - UDMF.insertData(options, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(TAG + `insertData0400 fail, code is ${e.code},message is ${e.message}`); - } - UDMF.updateData({key: data}, unifiedData).then((ret) => { - console.info(TAG + `updateData success; data = ${ret}, options = ${options}`); - expect().assertFail() - done(); - }).catch((err) => { - console.info(`UpdateData failed. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); - }); - }); - } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); - done(); - } - }) - /** - * @tc.number SUB_DDM_UDMF_UpdateData_Promise_0500 - * @tc.name UDMF updateData promise interface test - * @tc.desc UDMF updateData promise interface test. - */ - it('SUB_DDM_UDMF_UpdateData_Promise_0500', 0, function (done) { + it('SUB_DDM_UDMF_UpdateData_Promise_0400', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: undefined } let plainText = new UDMF.PlainText(); @@ -385,7 +365,6 @@ export default function UDMFApiPromise() { expect(err !== null).assertFail(); done(); }); - }); }catch(error){ console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -401,7 +380,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_QueryData_Promise_0100', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -414,24 +393,24 @@ export default function UDMFApiPromise() { } console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); UDMF.queryData(options).then((ret) => { - let size = ret.length; - console.info(TAG, ` data.size = ${size}`); - for (var i = 0; i < size; i++) { - let records = ret[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); - } + let size = ret.length; + console.info(TAG, ` data.size = ${size}`); + for (var i = 0; i < size; i++) { + let records = ret[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - }).catch((err) => { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); + } + expect(size).assertEqual(1); + done(); + }).catch((err) => { + console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }); }); } catch (error) { @@ -448,7 +427,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_QueryData_Promise_0200', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -461,24 +440,24 @@ export default function UDMFApiPromise() { } console.info(TAG + `insertData0100 success; data = ${data}, options = ${options}`); UDMF.queryData({key: data}).then((ret) => { - let size = ret.length; - console.info(TAG, ` data.size = ${size}`); - for (var i = 0; i < size; i++) { - let records = ret[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); - } + let size = ret.length; + console.info(TAG, ` data.size = ${size}`); + for (var i = 0; i < size; i++) { + let records = ret[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - }).catch((err) => { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); + } + expect(size).assertEqual(1); + done(); + }).catch((err) => { + console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }); }); } catch (error) { @@ -495,7 +474,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_QueryData_Promise_0300', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -508,28 +487,28 @@ export default function UDMFApiPromise() { } console.info(TAG + `insertData0100 success; data = ${data}, options = ${options1}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: data }; UDMF.queryData(options2).then((ret) => { - let size = ret.length; - console.info(TAG, ` data.size = ${size}`); - for (var i = 0; i < size; i++) { - let records = ret[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); - } + let size = ret.length; + console.info(TAG, ` data.size = ${size}`); + for (var i = 0; i < size; i++) { + let records = ret[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` queryData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - }).catch((err) => { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); + } + expect(size).assertEqual(1); + done(); + }).catch((err) => { + console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }); }); } catch (error) { @@ -546,7 +525,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_QueryData_Promise_0400', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -559,10 +538,11 @@ export default function UDMFApiPromise() { } console.info(TAG + `insertData0400 success; data = ${data}, options = ${options1}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: 'data' }; - UDMF.queryData(options2).then((ret) => { + try{ + UDMF.queryData(options2).then((ret) => { let size = ret.length; console.info(TAG, ` data.size = ${size}`); for (var i = 0; i < size; i++) { @@ -578,10 +558,15 @@ export default function UDMFApiPromise() { expect().assertFail(); done(); }).catch((err) => { - console.info(`Failed to queryData. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); + console.info(`Failed. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); done(); - }); + }); + }catch(errInfo){ + console.info(`Failed to queryData. code is ${errInfo.code},message is ${errInfo.message} `); + expect(errInfo.code).assertEqual('401'); + done(); + } }); } catch (error) { console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); @@ -597,7 +582,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_QueryData_Promise_0500', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -610,7 +595,7 @@ export default function UDMFApiPromise() { } console.info(TAG + `insertData0500 success; data = ${data}, options = ${options1}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: undefined }; UDMF.queryData(options2).then((ret) => { @@ -648,7 +633,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_DeleteData_Promise_0100', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -667,24 +652,24 @@ export default function UDMFApiPromise() { } console.info(TAG, ` queryData size = ${ret.length}`); UDMF.deleteData(options).then((row) => { - let size = row.length; - console.info(TAG, ` deleteData size = ${size}`); - for (var i = 0; i < size; i++) { - let records = row[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); - } + let size = row.length; + console.info(TAG, ` deleteData size = ${size}`); + for (var i = 0; i < size; i++) { + let records = row[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - }).catch((err) => { - console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); + } + expect(size).assertEqual(1); + done(); + }).catch((err) => { + console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }); }); }); @@ -702,7 +687,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_DeleteData_Promise_0200', 0, function (done) { let options = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -721,24 +706,24 @@ export default function UDMFApiPromise() { } console.info(TAG, ` queryData size = ${ret.length}`); UDMF.deleteData({key: data}).then((row) => { - let size = row.length; - console.info(TAG, ` deleteData size = ${size}`); - for (var i = 0; i < size; i++) { - let records = row[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); - } + let size = row.length; + console.info(TAG, ` deleteData size = ${size}`); + for (var i = 0; i < size; i++) { + let records = row[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); } } - expect(size).assertEqual(1); - done(); - }).catch((err) => { - console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); - expect(err !== null).assertFail(); - done(); + } + expect(size).assertEqual(1); + done(); + }).catch((err) => { + console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); }); }); }); @@ -756,7 +741,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_DeleteData_Promise_0300', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -775,10 +760,69 @@ export default function UDMFApiPromise() { } console.info(TAG, ` queryData size = ${ret.length}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: data }; UDMF.deleteData(options2).then((row) => { + let size = row.length; + console.info(TAG, ` deleteData size = ${size}`); + for (var i = 0; i < size; i++) { + let records = row[i].getRecords(); + let size = records.length; + for (var j = 0; j < size; j++) { + if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { + let text = (records[j]); + console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); + } + } + } + expect(size).assertEqual(1); + done(); + }).catch((err) => { + console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); + expect(err !== null).assertFail(); + done(); + }); + }); + }); + } catch (error) { + console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); + expect(error !== null).assertFail(); + done(); + } + }) + + /** + * @tc.number SUB_DDM_UDMF_DeleteData_Promise_0400 + * @tc.name UDMF deleteData promise interface test + * @tc.desc UDMF deleteData promise interface test. + */ + it('SUB_DDM_UDMF_DeleteData_Promise_0400', 0, function (done) { + let options1 = { + intention: UDMF.Intention.DATA_HUB + }; + let plainText = new UDMF.PlainText(); + plainText.textContent = "hello world!"; + let unifiedData = new UDMF.UnifiedData(plainText); + try { + UDMF.insertData(options1, unifiedData, function (e, data) { + if (e !== undefined) { + console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); + return; + } + console.info(TAG + `insertData0100 success; data = ${data}, options = ${options1}`); + UDMF.queryData(options1, function (errInfo, ret) { + if (errInfo !== undefined) { + console.info(`Failed to queryData. code is ${errInfo.code},message is ${errInfo.message} `); + return; + } + console.info(TAG, ` queryData size = ${ret.length}`); + let options2 = { + intention: UDMF.Intention.DATA_HUB, + key: 'data' + }; + try{ + UDMF.deleteData(options2).then((row) => { let size = row.length; console.info(TAG, ` deleteData size = ${size}`); for (var i = 0; i < size; i++) { @@ -791,13 +835,18 @@ export default function UDMFApiPromise() { } } } - expect(size).assertEqual(1); + expect().assertFail(); done(); }).catch((err) => { console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); expect(err !== null).assertFail(); done(); - }); + }); + }catch(errInfo){ + console.info(`Failed to deleteData. code is ${errInfo.code},message is ${errInfo.message} `); + expect(errInfo.code).assertEqual('401'); + done(); + } }); }); } catch (error) { @@ -807,64 +856,6 @@ export default function UDMFApiPromise() { } }) - /** - * @tc.number SUB_DDM_UDMF_DeleteData_Promise_0400 - * @tc.name UDMF deleteData promise interface test - * @tc.desc UDMF deleteData promise interface test. - */ - it('SUB_DDM_UDMF_DeleteData_Promise_0400', 0, function (done) { - let options1 = { - intention: UDMF.Intention.SUPER_HUB - }; - let plainText = new UDMF.PlainText(); - plainText.textContent = "hello world!"; - let unifiedData = new UDMF.UnifiedData(plainText); - try { - UDMF.insertData(options1, unifiedData, function (e, data) { - if (e !== undefined) { - console.info(`Failed to insertData. code is ${e.code},message is ${e.message} `); - return; - } - console.info(TAG + `insertData0100 success; data = ${data}, options = ${options1}`); - UDMF.queryData(options1, function (errInfo, ret) { - if (errInfo !== undefined) { - console.info(`Failed to queryData. code is ${errInfo.code},message is ${errInfo.message} `); - return; - } - console.info(TAG, ` queryData size = ${ret.length}`); - let options2 = { - intention: UDMF.Intention.SUPER_HUB, - key: 'data' - }; - UDMF.deleteData(options2).then((row) => { - let size = row.length; - console.info(TAG, ` deleteData size = ${size}`); - for (var i = 0; i < size; i++) { - let records = row[i].getRecords(); - let size = records.length; - for (var j = 0; j < size; j++) { - if (records[j].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) { - let text = (records[j]); - console.info(TAG, ` deleteData.result = ${i + 1}.${text.textContent}`); - } - } - } - expect().assertFail(); - done(); - }).catch((err) => { - console.info(`Failed to deleteData. code is ${err.code},message is ${err.message} `); - expect(err.code).assertEqual('401'); - done(); - }); - }); - }); - } catch (error) { - console.error(TAG, `Failed, code is ${error.code},message is ${error.message} `); - expect(error !== null).assertFail(); - done(); - } - }) - /** * @tc.number SUB_DDM_UDMF_DeleteData_Promise_0500 * @tc.name UDMF deleteData promise interface test @@ -872,7 +863,7 @@ export default function UDMFApiPromise() { */ it('SUB_DDM_UDMF_DeleteData_Promise_0500', 0, function (done) { let options1 = { - intention: UDMF.Intention.SUPER_HUB + intention: UDMF.Intention.DATA_HUB }; let plainText = new UDMF.PlainText(); plainText.textContent = "hello world!"; @@ -891,7 +882,7 @@ export default function UDMFApiPromise() { } console.info(TAG, ` queryData size = ${ret.length}`); let options2 = { - intention: UDMF.Intention.SUPER_HUB, + intention: UDMF.Intention.DATA_HUB, key: undefined }; UDMF.deleteData(options2).then((row) => { -- GitLab