1/* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the 'License'); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an 'AS IS' BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import pasteboard from '@ohos.pasteboard'; 16import { beforeEach, describe, expect, it } from '@ohos/hypium'; 17 18let error: ESObject = undefined 19let tag = "PASTEBOARDSYNC--------------------" 20 21export default function pasteboardSyncTest() { 22 describe("pasteboardSyncTest", () => { 23 console.info("start#############################start") 24 beforeEach(() => { 25 error = undefined 26 }) 27 28 /** 29 * @tc.number SUB_Pasteboard_Local_SDK_PasteboardSync_0100 30 * @tc.name clearDataSync interface test 31 * @tc.desc Test clearDataSync when systemPasteBoard has data 32 */ 33 it("SUB_Pasteboard_Local_SDK_PasteboardSync_0100", 0, () => { 34 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0100 ---------start") 35 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, "pasteboard"); 36 let systemPasteBoard = pasteboard.getSystemPasteboard(); 37 38 systemPasteBoard.setDataSync(pasteData); 39 expect(systemPasteBoard.hasDataSync()).assertEqual(true); 40 console.info(tag + "Succeeded in setting PasteData"); 41 42 systemPasteBoard.clearDataSync(); 43 44 let result = systemPasteBoard.hasDataSync(); 45 console.info(tag + `Succeed in checking the PasteBoard. Result: ${result}`) 46 expect(result).assertEqual(false); 47 console.info(tag + "Clear the data in the system PasteBoard finished") 48 49 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0100 ---------end") 50 }) 51 52 53 /** 54 * @tc.number SUB_Pasteboard_Local_SDK_PasteboardSync_0200 55 * @tc.name setDataSync interface test 56 * @tc.desc Test setDataSync in systemPasteBoard 57 */ 58 it("SUB_Pasteboard_Local_SDK_PasteboardSync_0200", 0, () => { 59 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0200 ---------start") 60 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, "pasteboard"); 61 let systemPasteBoard = pasteboard.getSystemPasteboard(); 62 63 console.info(tag + `${systemPasteBoard}`); 64 systemPasteBoard.setDataSync(pasteData); 65 console.info(tag + "Succeeded in setting PasteData"); 66 let result = systemPasteBoard.getDataSync(); 67 68 console.info(tag + `Get the pasteboard from system PasteBoard success. Result: ${result}`) 69 expect(result.getPrimaryText()).assertEqual("pasteboard"); 70 71 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0200 ---------end") 72 }) 73 74 75 /** 76 * @tc.number SUB_Pasteboard_Local_SDK_PasteboardSync_0300 77 * @tc.name setDataSync interface test 78 * @tc.desc Test setDataSync when parameter is null 79 */ 80 it("SUB_Pasteboard_Local_SDK_PasteboardSync_0300", 0, () => { 81 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0300 ---------start") 82 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, "pasteboard"); 83 let systemPasteBoard = pasteboard.getSystemPasteboard(); 84 85 console.info(tag + `${systemPasteBoard}`) 86 try { 87 systemPasteBoard.setDataSync(null); 88 expect().assertFail() 89 console.info(tag + "Succeeded in setting PasteData"); 90 } catch (err) { 91 expect(err.code == 401).assertTrue(); 92 } 93 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0300 ---------end") 94 }) 95 96 /** 97 * @tc.number SUB_Pasteboard_Local_SDK_PasteboardSync_0400 98 * @tc.name setDataSync interface test 99 * @tc.desc Test setDataSync parameter is undefined 100 */ 101 it("SUB_Pasteboard_Local_SDK_PasteboardSync_0400", 0, () => { 102 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0400 ---------start") 103 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, "pasteboard"); 104 let systemPasteBoard = pasteboard.getSystemPasteboard(); 105 106 console.info(tag + `${systemPasteBoard}`); 107 try { 108 systemPasteBoard.setDataSync(undefined); 109 expect().assertFail() 110 console.info(tag + "Succeeded in setting PasteData"); 111 } catch (err) { 112 expect(err.code == 401).assertTrue(); 113 } 114 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0400 ---------end") 115 }) 116 117 118 /** 119 * @tc.number SUB_Pasteboard_Local_SDK_PasteboardSync_0500 120 * @tc.name getDataSync interface test 121 * @tc.desc Test getDataSync when setDataSync in systemPasteBoard 122 */ 123 it("SUB_Pasteboard_Local_SDK_PasteboardSync_0500", 0, () => { 124 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0500 ---------start") 125 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, "pasteboard"); 126 let systemPasteBoard = pasteboard.getSystemPasteboard(); 127 128 systemPasteBoard.setData(pasteData); 129 console.info(tag + "Succeeded in setting PasteData"); 130 131 let resultFlg = systemPasteBoard.hasDataSync(); 132 expect(resultFlg).assertTrue(); 133 134 let resultText = systemPasteBoard.getDataSync().getPrimaryText(); 135 expect(resultText).assertEqual("pasteboard"); 136 console.info(tag + `Get the pasteboard from system PasteBoard success. Result: ${resultText}`) 137 138 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0500 ---------end") 139 }) 140 141 /** 142 * @tc.number SUB_Pasteboard_Local_SDK_PasteboardSync_0600 143 * @tc.name hasDataSync interface test 144 * @tc.desc Test hasDataSync when systemPasteBoard has parameter 145 */ 146 it("SUB_Pasteboard_Local_SDK_PasteboardSync_0600", 0, () => { 147 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0600 ---------start") 148 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, "pasteboard"); 149 let systemPasteBoard = pasteboard.getSystemPasteboard(); 150 151 systemPasteBoard.setDataSync(pasteData); 152 console.info(tag + "Succeeded in setting PasteData"); 153 let result = systemPasteBoard.hasDataSync(); 154 expect(result).assertTrue(); 155 console.info(tag + `Succeed in checking the PasteBoard. Result: ${result}`); 156 ; 157 158 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0600 ---------end"); 159 160 }) 161 162 /** 163 * @tc.number SUB_Pasteboard_Local_SDK_PasteboardSync_0700 164 * @tc.name hasDataSync interface test 165 * @tc.desc Test hasDataSync when systemPasteBoard is null 166 */ 167 it("SUB_Pasteboard_Local_SDK_PasteboardSync_0700", 0, () => { 168 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0700 ---------start") 169 let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, ""); 170 let systemPasteBoard = pasteboard.getSystemPasteboard(); 171 systemPasteBoard.clearDataSync(); 172 let result = systemPasteBoard.hasDataSync(); 173 expect(result).assertEqual(false); 174 console.info(tag + `Succeed in checking the PasteBoard. Result: ${result}`) 175 176 console.info(tag + "SUB_Pasteboard_Local_SDK_PasteboardSync_0700 ---------end") 177 178 }) 179 180 }) 181}