1import * as zip from '@zip.js/zip.js/dist/zip-full.min.js' 2import { MapParser } from '@/services/map_parser.js' 3 4var targetFile = new Blob() 5var mapParser 6// Please refer to system_test.map for more details. 7const systemMap = [ 8 '//system/apex/com.android.test1.apex', 9 '//system/apex/com.android.test2.apex', 10 '//system/apex/com.android.test2.apex', 11 '//system/apex/com.android.test2.apex', 12 '//system/apex/com.android.test3.apk', 13 '//system/apex/com.android.test1.apex', 14 '//system/apex/com.android.test1.apex', 15 '//system/apex/com.android.test1.apex', 16 '//system/apex/com.android.test1.apex', 17 'unknown', 18 '//init.environ.rc' 19] 20 21/** 22 * Generate a virtual Android build which only contains a .map file 23 */ 24beforeAll(async () => { 25 // web worker is not supported by zip.js, turn it off 26 zip.configure({ 27 useWebWorkers: false, 28 }) 29 // Use system_test.map as a virtual map file 30 const fs = require("fs") 31 const path = require("path") 32 const file = path.join(__dirname, "./", "system_test.map") 33 const text = fs.readFileSync(file, 'utf-8', (err, data) => data) 34 const blobWriter = new zip.BlobWriter("application/zip") 35 const writer = new zip.ZipWriter(blobWriter) 36 await writer.add("IMAGES/system_test.map", new zip.TextReader(text)) 37 await writer.close() 38 targetFile = blobWriter.getData() 39 mapParser = new MapParser(targetFile) 40 await mapParser.init() 41}) 42 43test('Initialize a map parser instance.', () => { 44 expect(mapParser.mapFiles.keys().next().value).toEqual('system_test') 45}) 46 47test('Establish a map of system file.', async () => { 48 await mapParser.add('system_test', 11) 49 expect(mapParser.maps.get('system_test')).toEqual(systemMap) 50}) 51 52test('Query the map of system file.', async () => { 53 await mapParser.add('system_test', 11) 54 var queryExtents = [] 55 for (let i = 0; i < 11; i++) 56 queryExtents.push(new Object({ 57 startBlock: i, 58 // The number of blocks does not matter, because we only query the 59 // starting block. 60 numBlocks: 0 61 })) 62 expect(mapParser.query('system_test', queryExtents)).toEqual(systemMap) 63})