add mock

Signed-off-by: wplan1 <wangpeng163@huawei.com>
This commit is contained in:
wplan1
2022-03-14 17:00:22 +08:00
committed by wpgavin
parent 1c2f030934
commit bfe0e31938
@@ -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
};
}