diff --git a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/List.test.ets b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/List.test.ets index c3c7b5e55b6a32c474d9ac7a90fe44f60f17c838..49cea20c203395c60022b26c78cdaf30e7610665 100644 --- a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/List.test.ets +++ b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/List.test.ets @@ -15,9 +15,11 @@ import pasteBoardJEtsunitTest from './PasteBoardEtsunitTest'; import pasteBoardTest from './PasteBoard.test.ets'; -import pasteBoardSupportBinaryDataTest from './PasteBoardSupportBinaryData.test'; +import pasteBoardRecordTest from './PasteBoardRecord.test.ets' +import pasteBoardSystemPasteBoardTest from './PasteBoardSystemPasteBoard.test.ets' export default function testsuite() { - pasteBoardSupportBinaryDataTest() pasteBoardJEtsunitTest() + pasteBoardSystemPasteBoardTest() pasteBoardTest() + pasteBoardRecordTest() } \ No newline at end of file diff --git a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoard.test.ets b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoard.test.ets index ef9757805211d02384abea7e1743b5e243d76638..1bc42b6cf924609448833bc1920f3195e60c0c4d 100644 --- a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoard.test.ets +++ b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoard.test.ets @@ -17,12 +17,31 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' import pasteboard from '@ohos.pasteboard' import image from '@ohos.multimedia.image'; -const color = new ArrayBuffer(96); -let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } +let opt = { + size: { height: 3, width: 5 }, + pixelFormat: 3, + editable: true, + alphaType: 1, + scaleMode: 1 +} + +let error = undefined + +const color = new ArrayBuffer(128); + +const WANT = { + bundleName: "com.acts.distributeddatamgr.pasteboardtest", + abilityName: "com.acts.distributeddatamgr.pasteboardtest.MainAbility" +}; + +const ARRAY_BUFFER = new ArrayBuffer(256) export default function pasteBoardTest(){ describe('pasteBoardTest', function() { console.info('start################################start'); - + + beforeEach(function() { + error = undefined; + }) /** * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_TEST_1100 * @tc.name Adds one record(s) @@ -110,5 +129,667 @@ export default function pasteBoardTest(){ }) done(); }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0100 + * @tc.name setProperty + * @tc.desc Test pasteBoard setProperty error,type of parameter "property" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0100 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + function setProperty(property){ + pasteData.setProperty(property) + } + try{ + setProperty("property"); + }catch(err){ + console.info("Set property error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0200 + * @tc.name setProperty + * @tc.desc Test pasteBoard setProperty error,parameter "property" is null; + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0200 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + try{ + pasteData.setProperty(null); + }catch(err){ + console.info("Set property error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0300 + * @tc.name setProperty + * @tc.desc Test pasteBoard setProperty error without parameters + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0300 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + function setProperty(func, property){ + func() + } + try{ + setProperty(pasteData.setProperty,"prop"); + }catch(err){ + console.info("Set property error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETPROPERTY_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0100 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast string record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0100 start") + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + await pasteDataRecord.convertToTextV9((err, data) => { + if(err != null){ + console.info("Cast string record to text error, error message is: " + err) + expect(false).assertTrue(); + }else{ + console.info("Cast string record to text success,result is: " + data) + expect(data).assertEqual("valueType") + } + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0200 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast pixelMap record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0200 start") + let pasteDataRecord =undefined; + await image.createPixelMap(color, opt).then((pixelMap) => { + pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_PIXELMAP,pixelMap); + }) + await pasteDataRecord.convertToTextV9((err, data) => { + if(err != null){ + console.info("Cast pixelMap record to text error, error message is: " + err) + expect(false).assertTrue(); + }else{ + console.info("Cast pixelMap record to text success,result is: " + data) + expect(data).assertEqual("") + } + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0300 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast want record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0300 start") + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_WANT,WANT) + await pasteDataRecord.convertToTextV9((err, data) => { + if(err != null){ + console.info("Cast want record to text error, error message is: " + err) + expect(false).assertTrue(); + }else{ + console.info("Cast want record to text success,result is: " + data) + expect(data).assertEqual("") + } + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0400 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast arrayBuffer record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0400 start") + let pasteDataRecord = pasteboard.createRecord("ArrayBuffer",ARRAY_BUFFER) + await pasteDataRecord.convertToTextV9((err, data) => { + if(err != null){ + console.info("Cast arrayBuffer record to text error, error message is: " + err) + expect(false).assertTrue(); + }else{ + console.info("Cast arrayBuffer record to text success,result is: " + data) + expect(data).assertEqual("") + } + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0500 + * @tc.name convertToTextV9 + * @tc.desc Cast arrayBuffer record to text failed, + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0500', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0500 start") + let pasteDataRecord = pasteboard.createRecord("string",ARRAY_BUFFER) + function convert(callBack){ + pasteDataRecord.convertToTextV9(callBack) + } + try{ + convert("callback") + }catch(err){ + console.info("Cast string record to text error, error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_CALLBACK_0500 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0100 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast string record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0100 start") + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + await pasteDataRecord.convertToTextV9().then((data) => { + console.info("Cast string record to text success,result is: " + data) + expect(data).assertEqual("valueType") + }).catch((err) => { + console.info("Cast string record to text error, error message is: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0200 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast pixelMap record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0200 start") + let pasteDataRecord =undefined; + await image.createPixelMap(color, opt).then((pixelMap) => { + pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_PIXELMAP,pixelMap); + }) + await pasteDataRecord.convertToTextV9().then((data) => { + console.info("Cast pixelMap record to text success,result is: " + data) + expect(data).assertEqual("") + }).catch((err) => { + console.info("Cast pixelMap record to text error, error message is: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0300 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast want record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0300 start") + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_WANT,WANT) + await pasteDataRecord.convertToTextV9().then((data) => { + console.info("Cast want record to text success,result is: " + data) + expect(data).assertEqual("") + }).catch(err => { + console.info("Cast want record to text error, error message is: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0400 + * @tc.name convertToTextV9 + * @tc.desc Successfully cast arrayBuffer record to text + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0400 start") + let pasteDataRecord = pasteboard.createRecord("ArrayBuffer",ARRAY_BUFFER) + await pasteDataRecord.convertToTextV9().then((data) => { + console.info("Cast arrayBuffer record to text success,result is: " + data) + expect(data).assertEqual("") + }).catch(err => { + console.info("Cast arrayBuffer record to text error, error message is: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CONVERTTOTEXTV9_PROMISE_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0100 + * @tc.name getRecord + * @tc.desc Get specified record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0100 start") + var uri = "www.baidu.com" + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI,uri) + expect(pasteData.getRecord(0).uri).assertEqual(uri) + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0200 + * @tc.name getRecord + * @tc.desc Get specified record failed,type of parameter "index" is string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0200 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + function getRecord(index){ + pasteData.getRecord(index) + } + try{ + getRecord("0") + }catch(err){ + console.info("Get specified record failed,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0300 + * @tc.name getRecord + * @tc.desc Get specified record failed,index out of range + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0300 start") + let pasteData = pasteboard.createData("arraybuffer",ARRAY_BUFFER) + try{ + pasteData.getRecord(1) + }catch(err){ + console.info("Get specified record failed,error code is: " + err.code) + error = err + expect(err.code).assertEqual("12900001") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETRECORDAT_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0100 + * @tc.name hasType + * @tc.desc Check whether the pasteData contains the specified data type success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0100 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + let result = pasteData.hasType("string") + expect(result).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0200 + * @tc.name hasType + * @tc.desc Check whether the pasteData contains the specified data type success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0200 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + let result = pasteData.hasType("arrayBuffer") + expect(result).assertEqual(false); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0300 + * @tc.name hasType + * @tc.desc Check whether the pasteData contains the specified data type failed,type of parameter "mimeType" is number + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0300 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + let result + function check(mimeType){ + pasteData.hasType(mimeType) + } + try{ + check(0) + }catch(err){ + console.info("Check fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0400 + * @tc.name hasType + * @tc.desc Check whether the pasteData contains the specified data type failed without parameters + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0400 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + let result + function check(func,mimeType){ + func() + } + try{ + check(pasteData.hasType,"string") + }catch(err){ + console.info("Check fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASTYPE_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0100 + * @tc.name removeRecord + * @tc.desc Remove specified record from pasteData successful + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0100 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + pasteData.removeRecord(0) + let result = pasteData.hasType("string") + expect(result == false).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0200 + * @tc.name removeRecord + * @tc.desc Remove specified record from pasteData failed,index out of range + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0200 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + try{ + pasteData.removeRecord(1) + }catch(err){ + console.info("Remove specified record fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("12900001") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0300 + * @tc.name removeRecord + * @tc.desc Remove specified record from pasteData failed,type of parameter "index" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0300 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + function remove(index){ + pasteData.removeRecord(index) + } + try{ + remove("0") + }catch(err){ + console.info("Remove specified record fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0400 + * @tc.name removeRecord + * @tc.desc Remove specified record from pasteData failed without parameters + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0400 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + function remove(func, index){ + func() + } + try{ + remove(pasteData.removeRecord,1) + }catch(err){ + console.info("Remove specified record fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REMOVERECORD_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0100 + * @tc.name replaceRecord + * @tc.desc Remove specified record from pasteData failed without parameters + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0100 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + let pasteDataRecord = pasteboard.createRecord("arrayBuffer",ARRAY_BUFFER) + pasteData.replaceRecord(0,pasteDataRecord) + let result = pasteData.hasType("arrayBuffer") + expect(result).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0200 + * @tc.name replaceRecord + * @tc.desc Remove specified record from pasteData failed,index out of range; + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0200 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + let pasteDataRecord = pasteboard.createRecord("arrayBuffer",ARRAY_BUFFER) + try{ + pasteData.replaceRecord(1,pasteDataRecord) + }catch(err){ + console.info("Replace specified record fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("12900001") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0300 + * @tc.name replaceRecord + * @tc.desc Remove specified record from pasteData failed,type of parameter "index" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0300 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + let pasteDataRecord = pasteboard.createRecord("arrayBuffer",ARRAY_BUFFER) + function replace(index, record){ + pasteData.replaceRecord(index, record) + } + try{ + replace("0",pasteDataRecord) + }catch(err){ + console.info("Replace specified record fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0400 + * @tc.name replaceRecord + * @tc.desc Remove specified record from pasteData failed,type of parameter "record" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0400 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + let pasteDataRecord = pasteboard.createRecord("arrayBuffer",ARRAY_BUFFER) + function replace(index, record){ + pasteData.replaceRecord(index, record) + } + try{ + replace(0,"pasteDataRecord") + }catch(err){ + console.info("Replace specified record fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0500 + * @tc.name replaceRecord + * @tc.desc Remove specified record from pasteData failed without parameters + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0500', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0500 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + let pasteDataRecord = pasteboard.createRecord("arrayBuffer",ARRAY_BUFFER) + function replace(func, index, record){ + func() + } + try{ + replace(pasteData.replaceRecord, 0, "record") + }catch(err){ + console.info("Replace specified record fail,error code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_REPLACERECORD_0500 end") + done(); + }) + }); -} +} \ No newline at end of file diff --git a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardRecord.test.ets b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardRecord.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..003dd19546caf2cf00d2929b8a46c49c4b0c1f89 --- /dev/null +++ b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardRecord.test.ets @@ -0,0 +1,758 @@ +/* + * Copyright (C) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import pasteboard from '@ohos.pasteboard' +import image from '@ohos.multimedia.image'; + + +let opt = { + size: { height: 3, width: 5 }, + pixelFormat: 3, + editable: true, + alphaType: 1, + scaleMode: 1 +} + +let error = undefined + +const color = new ArrayBuffer(128); + +const WANT = { + bundleName: "com.acts.distributeddatamgr.pasteboardtest", + abilityName: "com.acts.distributeddatamgr.pasteboardtest.MainAbility" +}; + +const ARRAY_BUFFER = new ArrayBuffer(256) +export default function pasteBoardRecordTest(){ + describe('pasteBoardRecordTest', function() { + console.info('start################################start'); + + beforeEach(function() { + error = undefined; + }) + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0100 + * @tc.name CreateData + * @tc.desc Test pasteBoard create pixelMap data success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0100 start") + let pasteData + await image.createPixelMap(color, opt).then((pixelMap) => { + pasteData = pasteboard.createData(pasteboard.MIMETYPE_PIXELMAP,pixelMap); + }) + let pixelMapRecord = pasteData.getPrimaryPixelMap() + expect(pixelMapRecord != null).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0200 + * @tc.name CreateData + * @tc.desc Test pasteBoard create want data success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0200 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_WANT,WANT) + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_WANT) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0300 + * @tc.name CreateData + * @tc.desc Test pasteBoard create arrayBuffer data success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0300 start") + let pasteData = pasteboard.createData("ArrayBuffer",ARRAY_BUFFER) + let hasType = pasteData.hasType("ArrayBuffer") + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0400 + * @tc.name CreateData + * @tc.desc Test pasteBoard create string data success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0400 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN,"String") + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0500 + * @tc.name CreateData + * @tc.desc Test pasteBoard create arrayBuffer data success with 1024 bit mimeType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0500', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0500 start") + var mimeType = "x".repeat(1024) + let pasteData = pasteboard.createData(mimeType,ARRAY_BUFFER) + let hasType = pasteData.hasType(mimeType) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0500 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0600 + * @tc.name CreateData + * @tc.desc Test pasteBoard create arrayBuffer data success with 512000 bit valueType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0600', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0600 start") + var valueType = undefined + for(var i; i<500; i++){ + valueType = valueType + "x".repeat(1024) + } + let pasteData = pasteboard.createData("maxLength",ARRAY_BUFFER) + let hasType = pasteData.hasType("maxLength") + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0600 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0700 + * @tc.name CreateData + * @tc.desc Test pasteBoard create uri data success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0700', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0700 start") + var uri = "www.baidu.com" + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI,uri) + expect(pasteData.getRecord(0).uri).assertEqual(uri) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0700 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0800 + * @tc.name CreateData + * @tc.desc Test pasteBoard create string data fail with 1025 bit mimeType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0800', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0800 start") + var mimeType = "x".repeat(1025) + try{ + let pasteData = pasteboard.createData(mimeType,ARRAY_BUFFER) + }catch(err){ + console.info("Create data error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0800 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0900 + * @tc.name CreateData + * @tc.desc Test pasteBoard create string data fail,type of mimeType is number + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0900', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0900 start") + function create(mimetype, valueType){ + pasteboard.createData(mimetype,valueType) + } + try{ + create(0,"String") + }catch(err){ + console.info("Create data error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_0900 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1000 + * @tc.name CreateData + * @tc.desc Test pasteBoard create string data fail,value of mimeType is null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1000', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1000 start") + try{ + let pasteData = pasteboard.createData(null,"String") + }catch(err){ + console.info("Create data error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1000 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1100 + * @tc.name CreateData + * @tc.desc Test pasteBoard create string data fail with one parameter + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1100 start") + function create(func,mimetype,valueType){ + func(mimetype) + } + try{ + create(pasteboard.createData,"String","valueType") + }catch(err){ + console.info("Create data error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATEDATA_1100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0100 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create pixelMap record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0100 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + await image.createPixelMap(color, opt).then((pixelMap) => { + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_PIXELMAP,pixelMap); + pasteData.addRecord(pasteDataRecord) + }) + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_PIXELMAP) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0200 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create want record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0200 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_WANT,WANT); + pasteData.addRecord(pasteDataRecord) + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_WANT) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0300 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create arrayBuffer record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0300 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_WANT,WANT) + let pasteDataRecord = pasteboard.createRecord("ArrayBuffer",ARRAY_BUFFER); + pasteData.addRecord(pasteDataRecord) + + let hasType = pasteData.hasType("ArrayBuffer") + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0400 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create string record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0400 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN,"stringValueType"); + pasteData.addRecord(pasteDataRecord) + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0500 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create arrayBuffer record success with 1024 bit mimeType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0500', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0500 start") + let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN,"valueType") + let pasteDataRecord = pasteboard.createRecord("x".repeat(1024),ARRAY_BUFFER); + pasteData.addRecord(pasteDataRecord) + + let hasType = pasteData.hasType("x".repeat(1024)) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0500 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0600 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create string record success with 512000 bit valueType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0600', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0600 start") + let pasteData = pasteboard.createData("arrayBuffer",ARRAY_BUFFER) + console.info("create arraybuffer data success") + var valueType = "x" + for(var i; i<500; i++){ + valueType = valueType + "x".repeat(1024) + } + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN,valueType) + pasteData.addRecord(pasteDataRecord) + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0600 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0700 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create string record fail with 1025 bit mimeType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0700', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0700 start") + var mimeType = "x".repeat(1025) + try{ + let pasteDataRecord = pasteboard.createRecord(mimeType,ARRAY_BUFFER) + }catch(err){ + console.info("Create record error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0700 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0800 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create string record fail,type of mimeType is number + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0800', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0800 start") + function create(mimetype, valueType){ + pasteboard.createRecord(mimetype,valueType) + } + try{ + create(1,"String") + }catch(err){ + console.info("Create record error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0800 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0900 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create string record fail with 512001 bit valueType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0900', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0900 start") + var valueType = undefined + for(var i; i<512001; i++){ + valueType = valueType + "x" + } + try{ + let pasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN,valueType) + }catch(err){ + console.info("Create record error, err code is: " + err.code) + error =err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_0900 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1000 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create string record fail,mimeType is null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1000', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1000 start") + try{ + let pasteDataRecord = pasteboard.createRecord(null,"String") + }catch(err){ + console.info("Create record error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1000 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1100 + * @tc.name CreateRecord + * @tc.desc Test pasteBoard create string record fail with one parameter + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1100 start") + function create(func,mimetype,valueType){ + func(mimetype) + } + try{ + create(pasteboard.createRecord, "mimeType","String") + }catch(err){ + console.info("Create record error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CREATERECORD_1100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0100 + * @tc.name AddData + * @tc.desc Test pasteBoard add pixelMap record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0100 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + await image.createPixelMap(color, opt).then((pixelMap) => { + pasteData.addRecord(pasteboard.MIMETYPE_PIXELMAP,pixelMap); + }) + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_PIXELMAP) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0200 + * @tc.name AddData + * @tc.desc Test pasteBoard add want record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0200 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + pasteData.addRecord(pasteboard.MIMETYPE_TEXT_WANT,WANT); + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_WANT) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0300 + * @tc.name AddData + * @tc.desc Test pasteBoard add arrayBuffer record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0300 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + pasteData.addRecord("ArrayBuffer",ARRAY_BUFFER); + + let hasType = pasteData.hasType("ArrayBuffer") + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0400 + * @tc.name AddData + * @tc.desc Test pasteBoard add string record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0400', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0400 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + pasteData.addRecord(pasteboard.MIMETYPE_TEXT_PLAIN,"stringValueType"); + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0400 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0500 + * @tc.name AddData + * @tc.desc Test pasteBoard add record success with 1024 bit mimeType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0500', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0500 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + pasteData.addRecord("x".repeat(1024),ARRAY_BUFFER); + + let hasType = pasteData.hasType("x".repeat(1024)) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0500 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0600 + * @tc.name AddData + * @tc.desc Test pasteBoard add 600th record success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0600', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0600 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + for(var i = 0; i <510; i++){ + pasteData.addRecord("stringRecord" + i, ARRAY_BUFFER); + } + pasteData.addRecord("stringRecord512", ARRAY_BUFFER); + let result = pasteData.hasType("stringRecord512") + expect(result).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0600 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0700 + * @tc.name AddData + * @tc.desc Test pasteBoard add record success with 512000 bit valueType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0700', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0700 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + var valueType = "x" + for(var i; i<500; i++){ + valueType = valueType + "x".repeat(1024) + } + pasteData.addRecord(pasteboard.MIMETYPE_TEXT_PLAIN,valueType) + + let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN) + expect(hasType).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0700 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0800 + * @tc.name AddData + * @tc.desc Test pasteBoard add record fail with 1025 bit mimeType + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0800', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0800 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + try{ + pasteData.addRecord("x".repeat(1025),ARRAY_BUFFER); + }catch(err){ + console.info("Add record error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + if(error == undefined){ + console.info("Add record success") + expect(false).assertTrue() + } + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0800 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0900 + * @tc.name AddData + * @tc.desc Test pasteBoard add record fail,type of mimeType is number + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0900', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0900 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + function add(mimeType,valueType){ + pasteData.addRecord(mimeType, valueType); + } + try{ + add(1,"string") + }catch(err){ + console.info("Add record error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_0900 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1100 + * @tc.name AddData + * @tc.desc Test pasteBoard add 613th record fail + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1100 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + for(var i = 0; i < 511; i++){ + pasteData.addRecord("stringRecord" + i, ARRAY_BUFFER); + } + try{ + pasteData.addRecord("stringRecord513", ARRAY_BUFFER); + }catch(err){ + console.info("Add record error, err code is: " + err.code) + expect(err.code).assertEqual("12900002") + } + let hasType = pasteData.hasType("stringRecord513") + expect(hasType == false).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1200 + * @tc.name AddData + * @tc.desc Test pasteBoard add record fail,mimeType is null + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1200 start") + let pasteData = pasteboard.createData("string",ARRAY_BUFFER) + try{ + pasteData.addRecord(null,"string"); + }catch(err){ + console.info("Add record error, err code is: " + err.code) + error = err + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_ADDRECORD_1200 end") + done(); + }) + }); +} diff --git a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardSupportBinaryData.test.ets b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardSupportBinaryData.test.ets deleted file mode 100644 index 2676c83415d666713293550a504be53a78737d05..0000000000000000000000000000000000000000 --- a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardSupportBinaryData.test.ets +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' -import pasteboard from '@ohos.pasteboard' - -export default function pasteBoardSupportBinaryDataTest(){ - describe('pasteBoardSupportBinaryDataTest', function() { - console.info('start################################start'); - - /** - * @tc.number SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0100 - * @tc.name Create pasteData use binary parameter - * @tc.desc Test pasteBoard API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 2 - */ - it('SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0100', 0, async function (done) { - console.info("SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0100 start") - var systemPasteBoard = pasteboard.getSystemPasteboard(); - await systemPasteBoard.clear().then(async () => { - var pasteData = undefined; - console.info("systemPasteBoard clear data success") - var dataUri = new ArrayBuffer(256) - pasteData = pasteboard.createData("text/uri",dataUri) - var addUri = new ArrayBuffer(128) - pasteData.addRecord("text/uri", addUri) - var recordUri = new ArrayBuffer(96) - var pasteDataRecord = pasteboard.createRecord("text/uri", recordUri) - pasteData.addRecord(pasteDataRecord) - await systemPasteBoard.setPasteData(pasteData).then(async () => { - console.info("Set pastedata success") - await systemPasteBoard.hasPasteData().then(async (data) => { - console.info("Check pastedata has data success, result: " + data) - expect(data).assertTrue(); - await systemPasteBoard.getPasteData().then(async (data) => { - console.info("Get paste data success") - expect(data.getRecordCount()).assertEqual(3) - }) - }) - }) - }) - done(); - }) - - /** - * @tc.number SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0200 - * @tc.name Create pasteData use binary parameter - * @tc.desc Test pasteBoard API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 2 - */ - it('SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0200', 0, async function (done) { - console.info("SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0200 start") - var systemPasteBoard = pasteboard.getSystemPasteboard(); - await systemPasteBoard.clear().then(async () => { - var pasteData = undefined; - console.info("systemPasteBoard clear data success") - var dataHtml = new ArrayBuffer(256) - pasteData = pasteboard.createData("text/html",dataHtml) - var addHtml = new ArrayBuffer(128) - pasteData.addRecord("text/html", addHtml) - var recordHtml = new ArrayBuffer(64) - var pasteDataRecord = pasteboard.createRecord("text/html", recordHtml) - pasteData.addRecord(pasteDataRecord) - await systemPasteBoard.setPasteData(pasteData).then(async () => { - console.info("set pastedata success") - await systemPasteBoard.hasPasteData().then(async (data) => { - console.info("Check pastedata has data success, result: " + data) - expect(data).assertTrue(); - await systemPasteBoard.getPasteData().then(async (data) => { - console.info("get paste data success") - expect(data.getRecordCount()).assertEqual(3) - }) - }) - }) - }) - done(); - }) - - /** - * @tc.number SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0300 - * @tc.name Create pasteData use binary parameter - * @tc.desc Test pasteBoard API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 2 - */ - it('SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0300', 0, async function (done) { - console.info("SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0300 start") - var systemPasteBoard = pasteboard.getSystemPasteboard(); - await systemPasteBoard.clear().then(async () => { - console.info("systemPasteBoard clear data success") - var pasteData = undefined - var pasteRecord = undefined; - - - var dataHtml = new ArrayBuffer(256) - pasteData = pasteboard.createData("x".repeat(1025),dataHtml) - expect(pasteData).assertEqual(undefined) - pasteData = pasteboard.createData("x".repeat(1024),dataHtml) - expect(pasteData != undefined).assertTrue(); - - var addHtml = new ArrayBuffer(128) - pasteData.addRecord("x".repeat(1025),dataHtml) - expect(pasteData.getRecordCount()).assertEqual(1) - pasteData.addRecord("x".repeat(1024),dataHtml) - expect(pasteData.getRecordCount()).assertEqual(2) - - var recordHtml = new ArrayBuffer(64) - pasteRecord = pasteboard.createRecord("x".repeat(1025),dataHtml) - expect(pasteRecord).assertEqual(undefined); - pasteRecord = pasteboard.createRecord("x".repeat(1024),dataHtml) - expect(pasteRecord != undefined).assertTrue();; - - pasteData.addRecord(pasteRecord) - await systemPasteBoard.setPasteData(pasteData).then(async () => { - console.info("set pastedata success") - await systemPasteBoard.hasPasteData().then(async (data) => { - console.info("Check pastedata has data success, result: " + data) - expect(data).assertTrue(); - await systemPasteBoard.getPasteData().then(async (data) => { - console.info("get paste data success") - expect(data.getRecordCount()).assertEqual(3) - }) - }) - }) - }) - done(); - }) - console.info('end################################end'); - }); -} diff --git a/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardSystemPasteBoard.test.ets b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardSystemPasteBoard.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..13783a8d1cf4f7fd3690928c22392550b098b3e6 --- /dev/null +++ b/distributeddatamgr/Pasteboardjsapitest/entry/src/main/ets/test/PasteBoardSystemPasteBoard.test.ets @@ -0,0 +1,492 @@ +/* + * Copyright (C) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import pasteboard from '@ohos.pasteboard' + +let error = undefined; + +const ARRAY_BUFFER = new ArrayBuffer(256) + +export default function pasteBoardSystemPasteBoardTest(){ + describe('pasteBoardSystemPasteBoardTest', function() { + console.info('start################################start'); + beforeEach(function() { + error = undefined; + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0100 + * @tc.name clearData + * @tc.desc Clear the data in the system pasteBoard + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData) + await systemPasteBoard.clearData(async (err, data) => { + console.info("Clear the data in the system pasteBoard finished") + }) + await systemPasteBoard.hasData().then((data) => { + expect(data).assertEqual(false); + }) + done(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0100 end") + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0200 + * @tc.name clearData + * @tc.desc Clear the data in the system pasteBoard fail,type of parameter "callback" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0200 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + function clear(callback){ + systemPasteBoard.clearData(callback) + } + try{ + clear("callback") + }catch(err){ + console.info("Clear the data in the system pasteBoard error,error code: " + err.code) + error = err; + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_CALLBACK_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_PROMISE_0100 + * @tc.name clearData + * @tc.desc Clear the data in the system pasteBoard + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_PROMISE_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_PROMISE_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData).then(async () => { + await systemPasteBoard.hasData().then(async (data) => { + expect(data).assertTrue(); + await systemPasteBoard.clearData().then(async () =>{ + console.info("Clear the data in the system pasteBoard success") + await systemPasteBoard.hasData().then((data) => { + expect(data).assertEqual(false); + }) + }).catch((err) => { + console.info("Clear the data in the system pasteBoard error,error: " + err) + expect(false).assertTrue(); + }) + }).catch(err => { + console.info("Judge whether there is data in the system pasteBoard error,error is: " + err) + expect(false).assertTrue(); + }) + }).catch(err => { + console.info("System pasteBoard set pastedata error,error: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_CLEARDATA_PROMISE_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0100 + * @tc.name getData + * @tc.desc get the pastedata from system pasteBoard success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData).then(async () => { + await systemPasteBoard.getData((err, data) => { + if(err != null){ + console.info("Get the pastedata from system pasteboard failed" + err) + expect(false).assertTrue(); + }else{ + let recordCount = data.getRecordCount() + expect(recordCount).assertEqual(1) + } + }) + }).catch(err => { + console.info("System pasteBoard set pastedata error,error: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0200 + * @tc.name getData + * @tc.desc get the pastedata from system pasteBoard fail,type of parameter "callback" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0200 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + function getData(callback){ + systemPasteBoard.getData(callback) + } + try{ + getData("callback") + }catch(err){ + console.info("Get the pastedata from system pasteBoard fail,error code: " + err.code) + error = err; + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_CALLBACK_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_PROMISE_0100 + * @tc.name getData + * @tc.desc get the pastedata from system pasteBoard success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_PROMISE_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_PROMISE_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData).then(async () => { + await systemPasteBoard.getData().then(async (data) => { + console.info("Get the pastedata from system pasteboard success") + let recordCount = data.getRecordCount() + expect(recordCount).assertEqual(1) + }).catch((err) => { + console.info("Get the pastedata from system pasteboard failed" + err) + expect(false).assertTrue(); + }) + }).catch(err => { + console.info("System pasteBoard set pastedata error,error: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_GETDATA_PROMISE_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0100 + * @tc.name hasData + * @tc.desc Determine if there is data in the system pasteboard success, result is true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData).then(async () => { + await systemPasteBoard.hasData((err, data) => { + if(err != undefined){ + console.info("Judge whether there is data in the system pasteBoard error,error is: " + err) + expect(false).assertTrue(); + }else{ + expect(data).assertTrue(); + } + }) + }).catch(err => { + console.info("System pasteBoard set pastedata error,error: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0200 + * @tc.name hasData + * @tc.desc Determine if there is data in the system pasteboard success, result is true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0200 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.clearData().then(async() => { + await systemPasteBoard.hasData((err, data) => { + if(err != undefined){ + console.info("Judge whether there is data in the system pasteBoard error,error is: " + err) + expect(false).assertTrue(); + }else{ + expect(data == false).assertTrue(); + } + }) + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0200 + * @tc.name hasData + * @tc.desc Determine if there is data in the system pasteboard fail,type of parameter "callback" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0300 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + function hasData( callback){ + systemPasteBoard.hasData(callback) + } + try{ + hasData("callback") + }catch(err){ + console.info("Judge whether there is data in the system pasteBoard error,error code: " + err.code) + error = err; + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_CALLBACK_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0100 + * @tc.name hasData + * @tc.desc Determine if there is data in the system pasteboard success, result is true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData).then(async () => { + await systemPasteBoard.hasData().then((data) => { + expect(data).assertTrue(); + }).catch(err => { + console.info("Judge whether there is data in the system pasteBoard error,error is: " + err) + expect(false).assertTrue(); + }) + }).catch(err => { + console.info("System pasteBoard set pastedata error,error: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0200 + * @tc.name hasData + * @tc.desc Determine if there is data in the system pasteboard success, result is true + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0200 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.clearData().then(async() => { + await systemPasteBoard.hasData().then((data) => { + expect( data == false).assertTrue(); + }).catch(err => { + console.info("Judge whether there is data in the system pasteBoard error,error is: " + err) + expect(false).assertTrue(); + }) + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_HASDATA_PROMISE_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0100 + * @tc.name setData + * @tc.desc Put pastedata to system pasteBoard success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData, async (err, data) =>{ + if(err != null){ + console.info("System pasteBoard set pastedata error,error: " + err) + expect(false).assertTrue(); + }else{ + await systemPasteBoard.hasData().then((data) => { + expect(data).assertTrue(); + }).catch(err => { + console.info("Judge whether there is data in the system pasteBoard error,error is: " + err) + expect(false).assertTrue(); + }) + } + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0200 + * @tc.name setData + * @tc.desc Put pastedata to system pasteBoard fail,type of parameter "pasteData" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0200 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + async function setData( pasteData, callBack){ + await systemPasteBoard.setData(pasteData, callBack) + } + try{ + await setData("pasteData", async (err, data) =>{ + if(err != null){ + console.info("System pasteBoard set pastedata error,error: " + err) + expect(err.code).assertEqual("401"); + }else{ + expect(false).assertTrue(); + } + }) + }catch(err){ + console.info("System pasteBoard set pastedata error,error: " + err) + expect(err.code).assertEqual("401"); + } + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0300 + * @tc.name setData + * @tc.desc Put pastedata to system pasteBoard fail,type of parameter "pasteData" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0300 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + function setData( pasteData, callBack){ + systemPasteBoard.setData(pasteData, callBack) + } + try{ + setData("pasteData", "callback") + }catch(err){ + console.info("Put pastedata to system pasteBoard fail,error code: " + err.code) + error = err; + expect(err.code).assertEqual("401") + } + expect(error != undefined).assertTrue(); + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_CALLBACK_0300 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0100 + * @tc.name setData + * @tc.desc Put pastedata to system pasteBoard success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0100', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0100 start") + let pasteData = pasteboard.createData('string', ARRAY_BUFFER); + let systemPasteBoard = pasteboard.getSystemPasteboard(); + await systemPasteBoard.setData(pasteData).then(async () => { + await systemPasteBoard.hasData().then((data) => { + expect(data).assertTrue(); + }).catch(err => { + console.info("Judge whether there is data in the system pasteBoard error,error is: " + err) + expect(false).assertTrue(); + }) + }).catch(err => { + console.info("System pasteBoard set pastedata error,error: " + err) + expect(false).assertTrue(); + }) + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0100 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0200 + * @tc.name setData + * @tc.desc Put pastedata to system pasteBoard fail,type of parameter "pasteData" is string + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0200', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0200 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + function setData( pasteData){ + systemPasteBoard.setData(pasteData) + } + try{ + setData("pasteData") + }catch(err){ + console.info("System pasteBoard set pastedata error,error: " + err) + expect(err.code).assertEqual("401"); + } + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0200 end") + done(); + }) + + /** + * @tc.number SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0300 + * @tc.name setData + * @tc.desc Put pastedata to system pasteBoard fail without parameters + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0300', 0, async function (done) { + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0300 start") + let systemPasteBoard = pasteboard.getSystemPasteboard(); + function setData(func, pasteData){ + func() + } + try{ + setData(systemPasteBoard.setData,"pasteData") + }catch(err){ + console.info("System pasteBoard set pastedata error,error: " + err) + expect(err.code).assertEqual("401"); + } + console.info("SUB_PASTEBOARD_FUNCTION_ETS_SETDATA_PROMISE_0300 end") + done(); + }) + }); +}