From 49d3664c46c2a023b7ad07a8525c069dcb83f5cb Mon Sep 17 00:00:00 2001 From: wplan1 Date: Mon, 14 Mar 2022 17:00:22 +0800 Subject: [PATCH] add mock Signed-off-by: wplan1 --- .../extend/systemplugin/resourceManager.js | 76 ++++++++----------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/runtime/main/extend/systemplugin/resourceManager.js b/runtime/main/extend/systemplugin/resourceManager.js index 2d0ee701..d6614b94 100644 --- a/runtime/main/extend/systemplugin/resourceManager.js +++ b/runtime/main/extend/systemplugin/resourceManager.js @@ -17,12 +17,12 @@ export function mockResourceManager() { function Configuration(direction, locale) { this.direction = direction; this.locale = locale; -}; +} function DeviceCapability(screenDensity, deviceType) { this.screenDensity = screenDensity; this.deviceType = deviceType; -}; +} function ResourceManager(mgrId, module) { var resMgrId = mgrId; @@ -56,20 +56,6 @@ function ResourceManager(mgrId, module) { } } - this.getJsonConfig = getJsonConfig; - async function getJsonConfig(resId, callback) { - var data = {"data" : { "name": "mock string1"} }; - console.warn("ResourceManager.getJsonConfig interface mocked in the Previewer." + - " How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, null, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } - } - this.getMedia = getMedia; async function getMedia(resId, callback) { var data = "mock media data"; @@ -142,7 +128,7 @@ function ResourceManager(mgrId, module) { this.release = release; async function release(callback) { - console.warn("ResourceManager.getJsonConfig interface mocked in the Previewer. " + + console.warn("ResourceManager.release interface mocked in the Previewer. " + "How this interface works on the Previewer may be different from that on a real device.") } @@ -159,6 +145,34 @@ function ResourceManager(mgrId, module) { }) } } + + this.getRawFileDescriptor = getRawFileDescriptor; + async function getRawFileDescriptor(path, callback) { + var data = "mock raw file descriptor"; + console.warn("ResourceManager.getRawFileDescriptor interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } + + this.closeRawFileDescriptor = closeRawFileDescriptor; + async function closeRawFileDescriptor(path, callback) { + var data = "mock close raw file descriptor"; + console.warn("ResourceManager.closeRawFileDescriptor interface mocked in the Previewer. " + + "How this interface works on the Previewer may be different from that on a real device.") + if (typeof callback === 'function') { + callback.call(this, null, data); + } else { + return new Promise((resolve) => { + resolve(data); + }) + } + } } var resourceManager = { @@ -183,34 +197,10 @@ var resourceManager = { resolve(data); }) } - }, - getAResourceManager: async function getAResourceManager(optBundleName, optCallback) { - let bundleName = ''; - let callback; - if (typeof optCallback == 'function') { - bundleName = optBundleName ? optBundleName : ''; - callback = optCallback; - } else if (typeof optBundleName == 'function') { - callback = optBundleName; - } else { - bundleName = optBundleName ? optBundleName : ''; - } - - let data = new ResourceManager(1, null); - console.warn("ResourceManager.getAResourceManager interface mocked in the Previewer. " + - "How this interface works on the Previewer may be different from that on a real device.") - if (typeof callback === 'function') { - callback.call(this, 1, data); - } else { - return new Promise((resolve) => { - resolve(data); - }) - } } }; global.systemplugin.resourceManager = { - getResourceManager: resourceManager.getResourceManager, - getAResourceManager: resourceManager.getAResourceManager -}; + getResourceManager: resourceManager.getResourceManager }; +}