Merge "Add test to the MapParser class in OTA_analyzer."

This commit is contained in:
Treehugger Robot
2021-08-18 18:58:09 +00:00
committed by Gerrit Code Review
3 changed files with 76 additions and 1 deletions

View File

@@ -1,6 +1,14 @@
const defaults = require('jest-config')
module.exports = {
preset: '@vue/cli-plugin-unit-jest',
transform: {
'^.+\\.vue$': 'vue-jest'
},
globals: {
...defaults.globals,
crypto: require('crypto'),
TextEncoder: require('util').TextEncoder,
TextDecoder: require('util').TextDecoder,
}
}
}

View File

@@ -0,0 +1,63 @@
import * as zip from '@zip.js/zip.js/dist/zip-full.min.js'
import { MapParser } from '@/services/map_parser.js'
var targetFile = new Blob()
var mapParser
// Please refer to system_test.map for more details.
const systemMap = [
'//system/apex/com.android.test1.apex',
'//system/apex/com.android.test2.apex',
'//system/apex/com.android.test2.apex',
'//system/apex/com.android.test2.apex',
'//system/apex/com.android.test3.apk',
'//system/apex/com.android.test1.apex',
'//system/apex/com.android.test1.apex',
'//system/apex/com.android.test1.apex',
'//system/apex/com.android.test1.apex',
'unknown',
'//init.environ.rc'
]
/**
* Generate a virtual Android build which only contains a .map file
*/
beforeAll(async () => {
// web worker is not supported by zip.js, turn it off
zip.configure({
useWebWorkers: false,
})
// Use system_test.map as a virtual map file
const fs = require("fs")
const path = require("path")
const file = path.join(__dirname, "./", "system_test.map")
const text = fs.readFileSync(file, 'utf-8', (err, data) => data)
const blobWriter = new zip.BlobWriter("application/zip")
const writer = new zip.ZipWriter(blobWriter)
await writer.add("IMAGES/system_test.map", new zip.TextReader(text))
await writer.close()
targetFile = blobWriter.getData()
mapParser = new MapParser(targetFile)
await mapParser.init()
})
test('Initialize a map parser instance.', () => {
expect(mapParser.mapFiles.keys().next().value).toEqual('system_test')
})
test('Establish a map of system file.', async () => {
await mapParser.add('system_test', 11)
expect(mapParser.maps.get('system_test')).toEqual(systemMap)
})
test('Query the map of system file.', async () => {
await mapParser.add('system_test', 11)
var queryExtents = []
for (let i = 0; i < 11; i++)
queryExtents.push(new Object({
startBlock: i,
// The number of blocks does not matter, because we only query the
// starting block.
numBlocks: 0
}))
expect(mapParser.query('system_test', queryExtents)).toEqual(systemMap)
})

View File

@@ -0,0 +1,4 @@
//init.environ.rc 10
//system/apex/com.android.test1.apex 5-6 0 0 7-8
//system/apex/com.android.test2.apex 1-3
//system/apex/com.android.test3.apk 4