mirror of
https://gitee.com/openharmony/napi_generator
synced 2025-02-12 04:30:36 +00:00
commit
7421d99c92
@ -22,8 +22,24 @@
|
||||
"onCommand:extension.h2hdf"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"l10n":"./l10n",
|
||||
"l10n": "./l10n",
|
||||
"contributes": {
|
||||
"configuration": {
|
||||
"type": "object",
|
||||
"title": "YourExtensionConfiguration",
|
||||
"properties": {
|
||||
"napiExtension.outSetting": {
|
||||
"type": "string",
|
||||
"default": "./",
|
||||
"description": "description of outpath"
|
||||
},
|
||||
"testReport.canOutput": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "description of output flag"
|
||||
}
|
||||
}
|
||||
},
|
||||
"commands": [
|
||||
{
|
||||
"command": "extension.h2dts",
|
||||
@ -38,28 +54,27 @@
|
||||
"title": "%extension.dts2cpp.title%"
|
||||
},
|
||||
{
|
||||
"command": "extension.h2sa",
|
||||
"title": "%extension.h2sa.title%"
|
||||
"command": "extension.h2sa",
|
||||
"title": "%extension.h2sa.title%"
|
||||
},
|
||||
{
|
||||
"command": "extension.h2hdf",
|
||||
"title": "%extension.h2hdf.title%"
|
||||
|
||||
"command": "extension.h2hdf",
|
||||
"title": "%extension.h2hdf.title%"
|
||||
},
|
||||
{
|
||||
{
|
||||
"command": "extension.ohcrosscompile",
|
||||
"title": "%extension.ohcrosscompile.title%"
|
||||
},
|
||||
{
|
||||
"command": "extension.ohGenerator",
|
||||
"title": "%extension.ohGenerator.title%"
|
||||
{
|
||||
"command": "extension.ohGenerator",
|
||||
"title": "%extension.ohGenerator.title%"
|
||||
}
|
||||
],
|
||||
"viewsWelcome": [
|
||||
{
|
||||
"view": "workbench.explorer.emptyView",
|
||||
"contents": "%Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)%"
|
||||
}
|
||||
{
|
||||
"view": "workbench.explorer.emptyView",
|
||||
"contents": "%Generate NAPI definition code and framework code for OpenHarmony. \n[OHGenerator](command:extension.ohGenerator)%"
|
||||
}
|
||||
],
|
||||
"submenus": [
|
||||
{
|
||||
@ -70,14 +85,14 @@
|
||||
"menus": {
|
||||
"gen-menulist": [
|
||||
{
|
||||
"command": "extension.h2sa",
|
||||
"when": "resourceExtname == .h",
|
||||
"group": "2_workspace"
|
||||
"command": "extension.h2sa",
|
||||
"when": "resourceExtname == .h",
|
||||
"group": "2_workspace"
|
||||
},
|
||||
{
|
||||
"command": "extension.h2hdf",
|
||||
"when": "resourceExtname == .h",
|
||||
"group": "2_workspace"
|
||||
"command": "extension.h2hdf",
|
||||
"when": "resourceExtname == .h",
|
||||
"group": "2_workspace"
|
||||
},
|
||||
{
|
||||
"command": "extension.h2dts",
|
||||
@ -109,78 +124,78 @@
|
||||
]
|
||||
},
|
||||
"snippets": [
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_class_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_thread_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_asyncwork_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_promise_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_callback_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_enum_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_struct_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_variable_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_external_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_error_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_function_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_class_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_struct_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_enum_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_callback_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_promise_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_thread_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_value_snippets.json"
|
||||
}
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_class_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_thread_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_asyncwork_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_promise_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_callback_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_enum_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_struct_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_variable_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_external_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/napi_error_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_function_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_class_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_struct_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_enum_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_callback_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_promise_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_thread_snippets.json"
|
||||
},
|
||||
{
|
||||
"language": "cpp",
|
||||
"path": "./snippets/aki_value_snippets.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
@ -192,23 +207,24 @@
|
||||
"test": "node ./out/test/runTest.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/mocha": "^5.2.6",
|
||||
"@types/node": "^16.17.0",
|
||||
"@types/tar": "^6.1.13",
|
||||
"@types/vscode": "^1.73.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.30.0",
|
||||
"@typescript-eslint/parser": "^5.30.0",
|
||||
"@vscode/test-electron": "^1.6.1",
|
||||
"glob": "^7.1.4",
|
||||
"mocha": "^6.1.4",
|
||||
"source-map-support": "^0.5.12",
|
||||
"eslint": "^8.13.0"
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/mocha": "^5.2.6",
|
||||
"@types/node": "^16.17.0",
|
||||
"@types/tar": "^6.1.13",
|
||||
"@types/vscode": "^1.73.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.30.0",
|
||||
"@typescript-eslint/parser": "^5.30.0",
|
||||
"@vscode/test-electron": "^1.6.1",
|
||||
"eslint": "^8.13.0",
|
||||
"glob": "^7.1.4",
|
||||
"mocha": "^6.1.4",
|
||||
"mocha-junit-reporter": "^2.2.1",
|
||||
"source-map-support": "^0.5.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"vsce": "^2.15.0",
|
||||
"@vscode/l10n": "^0.0.10",
|
||||
"tar": "^7.4.3",
|
||||
"typescript": "^4.7.2",
|
||||
"@vscode/l10n": "^0.0.10",
|
||||
"tar": "^7.4.3"
|
||||
"vsce": "^2.15.0"
|
||||
}
|
||||
}
|
||||
|
28
src/vscode_plugin/src/common/conf.ts
Normal file
28
src/vscode_plugin/src/common/conf.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const vscode = require("vscode");
|
||||
|
||||
export function getOutputPath(): string {
|
||||
const config = vscode.workspace.getConfiguration('napiExtension');
|
||||
const outSetting = config.get("outSetting");
|
||||
return outSetting;
|
||||
}
|
||||
|
||||
export function getReportConf(): string {
|
||||
const config = vscode.workspace.getConfiguration('testReport');
|
||||
const outSetting = config.get("canOutput");
|
||||
return outSetting;
|
||||
}
|
22
src/vscode_plugin/src/common/file.ts
Normal file
22
src/vscode_plugin/src/common/file.ts
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const vscode = require("vscode");
|
||||
|
||||
export function getOutputPath(): string {
|
||||
const config = vscode.workspace.getConfiguration('napiExtension');
|
||||
const outSetting = config.get("outSetting");
|
||||
return outSetting;
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
export function replaceAll(s: string, sfrom: string, sto: any) {
|
||||
console.log('[replaceall] s:'+s+' sfrom:'+sfrom+' sto:'+sto);
|
||||
// console.log('[replaceall] s:'+s+' sfrom:'+sfrom+' sto:'+sto);
|
||||
if (s && sfrom && sto) {
|
||||
while (s.indexOf(sfrom) >= 0) {
|
||||
s = s.replace(sfrom, sto);
|
||||
|
@ -17,10 +17,10 @@ import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { DirTemp, HdfRootInfo } from "./datatype";
|
||||
import { hdf_version_map } from '../template/hdf/hdfdir';
|
||||
import { genIdlFile } from './genidlfile';
|
||||
import { genServiceHFile } from './genservicehfile';
|
||||
import { genServiceCppFile } from './genservicecppfile';
|
||||
import { genHdfCommonFile } from './genCommonFile';
|
||||
import { genIdlFile } from './tools/genidlfile';
|
||||
import { genServiceHFile } from './tools/genservicehfile';
|
||||
import { genServiceCppFile } from './tools/genservicecppfile';
|
||||
import { genHdfCommonFile } from './tools/gencommonfile';
|
||||
|
||||
const fileHandlers: { [key: string]: Function } = {
|
||||
'I[marcoName]Interface.idl': genIdlFile,
|
||||
|
@ -18,15 +18,15 @@ import { sa_version_map } from '../template/sa/sadir';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import { DirTemp, ServiceRootInfo } from './datatype';
|
||||
import { genProxyHFile } from './genproxyhfile';
|
||||
import { genProxyCppFile } from './genproxycppfile';
|
||||
import { genSaHFile } from './gensahfile';
|
||||
import { genSaCppFile } from './gensacppfile';
|
||||
import { genIServiceHFile } from './geniservicehfile';
|
||||
import { genStubHFile } from './genstubhfile';
|
||||
import { genStubCppFile } from './genstubcppfile';
|
||||
import { genClientCppFile } from './genclientcppfile';
|
||||
import { genSaCommonFile } from './genCommonFile';
|
||||
import { genProxyHFile } from './tools/genproxyhfile';
|
||||
import { genProxyCppFile } from './tools/genproxycppfile';
|
||||
import { genSaHFile } from './tools/gensahfile';
|
||||
import { genSaCppFile } from './tools/gensacppfile';
|
||||
import { genIServiceHFile } from './tools/geniservicehfile';
|
||||
import { genStubHFile } from './tools/genstubhfile';
|
||||
import { genStubCppFile } from './tools/genstubcppfile';
|
||||
import { genClientCppFile } from './tools/genclientcppfile';
|
||||
import { genSaCommonFile } from './tools/gencommonfile';
|
||||
|
||||
const fileHandlers: { [key: string]: Function } = {
|
||||
'[serviceName]_service_proxy.h': genProxyHFile,
|
||||
|
@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { replaceAll, getTab } from '../common/tool';
|
||||
import { replaceAll, getTab } from '../../common/tool';
|
||||
import * as fs from 'fs';
|
||||
import { format } from 'util'
|
||||
import { FuncObj, ParamObj, ServiceRootInfo } from './datatype';
|
||||
import { FuncObj, ParamObj, ServiceRootInfo } from '../datatype';
|
||||
|
||||
function getClientFuncParamStr(params: ParamObj[]) {
|
||||
let paramStr = '';
|
||||
@ -28,8 +28,7 @@ function getClientFuncParamStr(params: ParamObj[]) {
|
||||
return paramStr;
|
||||
}
|
||||
|
||||
// 生成xxx_client.cpp
|
||||
export function genClientCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenClientCppFile(rootInfo: ServiceRootInfo, fileContent: string): string {
|
||||
let clientFuncCpp = '';
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
let funcTab = getTab(1);
|
||||
@ -42,5 +41,11 @@ export function genClientCppFile(rootInfo: ServiceRootInfo, filePath: string, fi
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', rootInfo.serviceName.toUpperCase());
|
||||
fileContent = replaceAll(fileContent, '[lowServiceName]', rootInfo.serviceName.toLowerCase());
|
||||
fileContent = replaceAll(fileContent, '[clientFuncInvoke]', clientFuncCpp);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
// 生成xxx_client.cpp
|
||||
export function genClientCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -14,8 +14,8 @@
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { HdfRootInfo, ServiceRootInfo } from "./datatype";
|
||||
import { replaceAll } from '../common/tool';
|
||||
import { HdfRootInfo, ServiceRootInfo } from "../datatype";
|
||||
import { replaceAll } from '../../common/tool';
|
||||
|
||||
// 生成sa非特殊处理的文件, 如xxx.cfg
|
||||
export function genSaCommonFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getTab } from '../common/tool';
|
||||
import { getReg, match } from '../common/re';
|
||||
import { getTab } from '../../common/tool';
|
||||
import { getReg, match } from '../../common/re';
|
||||
import { format } from 'util'
|
||||
import { FuncObj, ParamObj } from './datatype';
|
||||
import { transferMap } from '../template/functypemap_template'
|
||||
import { FuncObj, ParamObj } from '../datatype';
|
||||
import { transferMap } from '../../template/functypemap_template'
|
||||
|
||||
export function getFuncParamStr(params: ParamObj[]) {
|
||||
let paramStr = '';
|
||||
@ -51,12 +51,12 @@ const TYPE_DEF_MAP = new Map(
|
||||
['long long', 'double'], ['long double', 'double'], ['std::string', 'string']
|
||||
]);
|
||||
|
||||
function getParcelType(srcType: string) {
|
||||
export function getParcelType(srcType: string) {
|
||||
let parcelType = TYPE_DEF_MAP.get(srcType);
|
||||
return parcelType === undefined ? srcType : parcelType;
|
||||
}
|
||||
|
||||
function getTransferContent(parcelVecType: string, isWrite: number) {
|
||||
export function getTransferContent(parcelVecType: string, isWrite: number) {
|
||||
let rwFunc = '';
|
||||
for (let index = 0; index < transferMap.length; index++) {
|
||||
if (parcelVecType === transferMap[index].fromType) {
|
@ -14,25 +14,26 @@
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { FuncObj, HdfRootInfo } from "./datatype";
|
||||
import { idlTransferType } from '../template/functypemap_template';
|
||||
import { FuncObj, HdfRootInfo } from "../datatype";
|
||||
import { idlTransferType } from '../../template/functypemap_template';
|
||||
import { format } from 'util';
|
||||
import { getTab, replaceAll } from '../common/tool';
|
||||
import { getTab, replaceAll } from '../../common/tool';
|
||||
|
||||
// 常用类型转换表, 将C语言常见类型(key)转换为remote data读写函数使用的类型(value)
|
||||
// 例如 ErrCode 类型在框架中的系统原型为int类型,这里映射成int32_t,
|
||||
// 因为int32_t类型在 DATA_W_MAP/DATA_R_MAP 表中有对应的读写数据方法(WriteInt32/ReadInt32)
|
||||
const TYPE_DEF_MAP = new Map(
|
||||
[['std::string', 'string'], ['char *', 'string']
|
||||
const TYPE_DEF_MAP = new Map([
|
||||
['std::string', 'string'],
|
||||
['char *', 'string']
|
||||
]);
|
||||
|
||||
function getParcelType(srcType: string) {
|
||||
export function getParcelType(srcType: string) {
|
||||
let parcelType = TYPE_DEF_MAP.get(srcType);
|
||||
return parcelType === undefined ? srcType : parcelType;
|
||||
}
|
||||
|
||||
// idlTransferType
|
||||
function getIdlType(cType: string) {
|
||||
export function getIdlType(cType: string) {
|
||||
let rawType = getParcelType(cType);
|
||||
for (let index = 0; index < idlTransferType.length; index++) {
|
||||
if (rawType === idlTransferType[index].fromType) {
|
||||
@ -42,7 +43,7 @@ function getIdlType(cType: string) {
|
||||
return cType;
|
||||
}
|
||||
|
||||
function isReturn(type: string) {
|
||||
export function isReturn(type: string) {
|
||||
if (type) {
|
||||
if (type.indexOf('&')>0 || type.indexOf('**')>0) {
|
||||
return true;
|
||||
@ -51,7 +52,7 @@ function isReturn(type: string) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function getIdlFuncParamStr(funcObj: FuncObj) {
|
||||
export function getIdlFuncParamStr(funcObj: FuncObj) {
|
||||
let idlParams = '';
|
||||
for (let i = 0; i < funcObj.parameters.length; ++i) {
|
||||
let type = getIdlType(funcObj.parameters[i].type);
|
||||
@ -73,8 +74,7 @@ function getIdlFuncParamStr(funcObj: FuncObj) {
|
||||
return idlParams;
|
||||
}
|
||||
|
||||
// 每个方法一个文件
|
||||
export function genIdlFile(rootInfo: HdfRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenIdlFile(rootInfo: HdfRootInfo, fileContent: string): string {
|
||||
let funcTab = getTab(1);
|
||||
let idlFuncDefine = '';
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
@ -89,5 +89,11 @@ export function genIdlFile(rootInfo: HdfRootInfo, filePath: string, fileContent:
|
||||
fileContent = replaceAll(fileContent, '[driverName]', rootInfo.driverName);
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', marcoName);
|
||||
fileContent = replaceAll(fileContent, '[idlFunDeclare]', idlFuncDefine);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
// 每个方法一个文件
|
||||
export function genIdlFile(rootInfo: HdfRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenIdlFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -13,13 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { replaceAll, getTab } from '../common/tool';
|
||||
import { replaceAll, getTab } from '../../common/tool';
|
||||
import * as fs from 'fs';
|
||||
import { format } from 'util'
|
||||
import { FuncObj, ServiceRootInfo } from './datatype';
|
||||
import { getFuncParamStr } from './genCommonFunc';
|
||||
import { FuncObj, ServiceRootInfo } from '../datatype';
|
||||
import { getFuncParamStr } from '../tools/gencommonfunc';
|
||||
|
||||
export function genIServiceHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenIServiceHFile(rootInfo: ServiceRootInfo, fileContent: string): string {
|
||||
let iServiceFuncH = '';
|
||||
let funcEnumStr = '';
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
@ -37,5 +37,10 @@ export function genIServiceHFile(rootInfo: ServiceRootInfo, filePath: string, fi
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', rootInfo.serviceName.toUpperCase());
|
||||
fileContent = replaceAll(fileContent, '[funcEnum]', funcEnumStr);
|
||||
fileContent = replaceAll(fileContent, '[iServiceHFunctions]', iServiceFuncH);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
export function genIServiceHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenIServiceHFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -13,14 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getTab, replaceAll } from '../common/tool';
|
||||
import { getTab, replaceAll } from '../../common/tool';
|
||||
import * as fs from 'fs';
|
||||
import { format } from 'util'
|
||||
import { FuncObj, ParamObj, ServiceRootInfo } from './datatype';
|
||||
import { genRead, genWrite, getFuncParamStr } from './genCommonFunc';
|
||||
import { proxyFuncTemplate } from '../template/func_template';
|
||||
import { FuncObj, ParamObj, ServiceRootInfo } from '../datatype';
|
||||
import { genRead, genWrite, getFuncParamStr } from '../tools/gencommonfunc';
|
||||
import { proxyFuncTemplate } from '../../template/func_template';
|
||||
|
||||
function genProxyFunc(funcInfo: FuncObj, className: string, paramStr: string, funcEnum: string) {
|
||||
export function genProxyFunc(funcInfo: FuncObj, className: string, paramStr: string, funcEnum: string) {
|
||||
let proxyFunc = replaceAll(proxyFuncTemplate, '[serviceName]', className);
|
||||
proxyFunc = replaceAll(proxyFunc, '[funcName]', funcInfo.name);
|
||||
proxyFunc = replaceAll(proxyFunc, '[params]', paramStr);
|
||||
@ -54,8 +54,7 @@ function genProxyFunc(funcInfo: FuncObj, className: string, paramStr: string, fu
|
||||
return proxyFunc;
|
||||
}
|
||||
|
||||
// 生成 xxx_service_proxy.cpp
|
||||
export function genProxyCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenProxyCppFile(rootInfo: ServiceRootInfo, fileContent: string) {
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
let proxyFuncCpp = '';
|
||||
for (let i = 0; i < funcList.length; ++i) {
|
||||
@ -68,5 +67,11 @@ export function genProxyCppFile(rootInfo: ServiceRootInfo, filePath: string, fil
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', rootInfo.serviceName.toUpperCase());
|
||||
fileContent = replaceAll(fileContent, '[lowServiceName]', rootInfo.serviceName.toLowerCase());
|
||||
fileContent = replaceAll(fileContent, '[remoteFuncImpl]', proxyFuncCpp);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
// 生成 xxx_service_proxy.cpp
|
||||
export function genProxyCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenProxyCppFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -13,18 +13,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { replaceAll } from '../common/tool';
|
||||
import { replaceAll } from '../../common/tool';
|
||||
import * as fs from 'fs';
|
||||
import { FuncObj, ServiceRootInfo } from './datatype';
|
||||
import { genDeclareContent } from './genCommonFunc';
|
||||
import { FuncObj, ServiceRootInfo } from '../datatype';
|
||||
import { genDeclareContent } from './gencommonfunc';
|
||||
|
||||
// 生成 xxx_service_proxy.h
|
||||
export function genProxyHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenProxyHFile(rootInfo: ServiceRootInfo, fileContent: string): string {
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
let proxyFuncHContent = genDeclareContent(funcList);
|
||||
fileContent = replaceAll(fileContent, '[serviceName]', rootInfo.serviceName);
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', rootInfo.serviceName.toUpperCase());
|
||||
fileContent = replaceAll(fileContent, '[lowServiceName]', rootInfo.serviceName.toLowerCase());
|
||||
fileContent = replaceAll(fileContent, '[proxyHFunctions]', proxyFuncHContent);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
// 生成 xxx_service_proxy.h
|
||||
export function genProxyHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenProxyHFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -13,16 +13,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { replaceAll } from '../common/tool';
|
||||
import { replaceAll } from '../../common/tool';
|
||||
const numericTypes = ['short', 'int', 'long', 'long long', 'float', 'double'];
|
||||
const boolType = ['bool'];
|
||||
const charType = ['char', 'string'];
|
||||
import { serviceFuncImplTemplate } from '../template/func_template';
|
||||
import { serviceFuncImplTemplate } from '../../template/func_template';
|
||||
import * as fs from 'fs';
|
||||
import { FuncObj, ServiceRootInfo } from './datatype';
|
||||
import { getFuncParamStr } from './genCommonFunc';
|
||||
import { FuncObj, ServiceRootInfo } from '../datatype';
|
||||
import { getFuncParamStr } from './gencommonfunc';
|
||||
|
||||
function genServiceFunc(funcInfo: FuncObj, className: string, paramStr: string) {
|
||||
export function genServiceFunc(funcInfo: FuncObj, className: string, paramStr: string) {
|
||||
let serviceFunc = replaceAll(serviceFuncImplTemplate, '[retType]', funcInfo.returns);
|
||||
// 根据类型初始化返回值
|
||||
let initRetvalue;
|
||||
@ -48,8 +48,7 @@ function genServiceFunc(funcInfo: FuncObj, className: string, paramStr: string)
|
||||
return serviceFunc;
|
||||
}
|
||||
|
||||
// 生成 xxx_service.cpp
|
||||
export function genSaCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenSaCppFile(rootInfo: ServiceRootInfo, fileContent: string): string {
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
let serviceFuncCpp = '';
|
||||
for (let i = 0; i < funcList.length; ++i) {
|
||||
@ -60,5 +59,11 @@ export function genSaCppFile(rootInfo: ServiceRootInfo, filePath: string, fileCo
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', rootInfo.serviceName.toUpperCase());
|
||||
fileContent = replaceAll(fileContent, '[lowServiceName]', rootInfo.serviceName.toLowerCase());
|
||||
fileContent = replaceAll(fileContent, '[serviceFuncImpl]', serviceFuncCpp);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
// 生成 xxx_service.cpp
|
||||
export function genSaCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenSaCppFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -13,18 +13,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { replaceAll } from '../common/tool';
|
||||
import { replaceAll } from '../../common/tool';
|
||||
import * as fs from 'fs';
|
||||
import { FuncObj, ServiceRootInfo } from './datatype';
|
||||
import { genDeclareContent } from './genCommonFunc';
|
||||
import { FuncObj, ServiceRootInfo } from '../datatype';
|
||||
import { genDeclareContent } from './gencommonfunc';
|
||||
|
||||
// 生成 xxx_service.h
|
||||
export function genSaHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenSaHFile(rootInfo: ServiceRootInfo, fileContent: string): string {
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
let saFuncHContent = genDeclareContent(funcList);
|
||||
fileContent = replaceAll(fileContent, '[serviceName]', rootInfo.serviceName);
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', rootInfo.serviceName.toUpperCase());
|
||||
fileContent = replaceAll(fileContent, '[lowServiceName]', rootInfo.serviceName.toLowerCase());
|
||||
fileContent = replaceAll(fileContent, '[serviceHFunctions]', saFuncHContent);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
// 生成 xxx_service.h
|
||||
export function genSaHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenSaHFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -14,12 +14,12 @@
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { FuncObj, HdfRootInfo } from "./datatype";
|
||||
import { replaceAll } from '../common/tool';
|
||||
import { FuncObj, HdfRootInfo } from "../datatype";
|
||||
import { replaceAll } from '../../common/tool';
|
||||
import { getServiceFuncParamStr } from './genservicehfile';
|
||||
import { hdiServiceFuncTemplate } from '../template/func_template';
|
||||
import { hdiServiceFuncTemplate } from '../../template/func_template';
|
||||
|
||||
export function genServiceCppFile(rootInfo: HdfRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenServiceCppFile(rootInfo: HdfRootInfo, fileContent: string): string {
|
||||
let hdiServiceFuncCpp = '';
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
let upperName = rootInfo.driverName.substring(0, 1).toLocaleUpperCase();
|
||||
@ -34,5 +34,10 @@ export function genServiceCppFile(rootInfo: HdfRootInfo, filePath: string, fileC
|
||||
fileContent = replaceAll(fileContent, '[driverName]', rootInfo.driverName);
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', marcoName);
|
||||
fileContent = replaceAll(fileContent, '[serviceFuncListImpl]', hdiServiceFuncCpp);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
export function genServiceCppFile(rootInfo: HdfRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenServiceCppFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -14,9 +14,9 @@
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import { FuncObj, HdfRootInfo } from "./datatype";
|
||||
import { FuncObj, HdfRootInfo } from "../datatype";
|
||||
import { format } from 'util';
|
||||
import { getTab, replaceAll } from '../common/tool';
|
||||
import { getTab, replaceAll } from '../../common/tool';
|
||||
|
||||
// 干脆这个用来表示hdf的service.h算了, 暂时先把hdf和sa的分开
|
||||
|
||||
@ -41,7 +41,7 @@ export function getServiceFuncParamStr(funcObj: FuncObj) {
|
||||
return paramStr;
|
||||
}
|
||||
|
||||
export function genServiceHFile(rootInfo: HdfRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenServiceHFile(rootInfo: HdfRootInfo, fileContent: string): string {
|
||||
let hdiServiceFuncH = '';
|
||||
let funcTab = getTab(1);
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
@ -58,5 +58,10 @@ export function genServiceHFile(rootInfo: HdfRootInfo, filePath: string, fileCon
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', marcoName);
|
||||
fileContent = replaceAll(fileContent, '[driverUpperName]', upperDriverName);
|
||||
fileContent = replaceAll(fileContent, '[serviceFuncDeclare]', hdiServiceFuncH);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
export function genServiceHFile(rootInfo: HdfRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenServiceHFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -13,12 +13,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { replaceAll, getTab } from '../common/tool';
|
||||
import { stubInnerFuncTemplate } from '../template/func_template';
|
||||
import { replaceAll, getTab } from '../../common/tool';
|
||||
import { stubInnerFuncTemplate } from '../../template/func_template';
|
||||
import * as fs from 'fs';
|
||||
import { format } from 'util'
|
||||
import { FuncObj, ServiceRootInfo } from './datatype';
|
||||
import { genRead, genWrite } from './genCommonFunc';
|
||||
import { FuncObj, ServiceRootInfo } from '../datatype';
|
||||
import { genRead, genWrite } from './gencommonfunc';
|
||||
|
||||
function genStubInnerFunc(funcInfo: FuncObj, className: string) {
|
||||
let innerFunc = replaceAll(stubInnerFuncTemplate, '[serviceName]', className);
|
||||
@ -67,8 +67,7 @@ function genStubInnerFunc(funcInfo: FuncObj, className: string) {
|
||||
return innerFunc;
|
||||
}
|
||||
|
||||
// 生成 xxx_service_stub.cpp
|
||||
export function genStubCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenStubCppFile(rootInfo: ServiceRootInfo, fileContent: string): string {
|
||||
let stubInnerFuncMap = '';
|
||||
let stubInnerFuncCpp = '';
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
@ -81,5 +80,11 @@ export function genStubCppFile(rootInfo: ServiceRootInfo, filePath: string, file
|
||||
fileContent = replaceAll(fileContent, '[lowServiceName]', rootInfo.serviceName.toLowerCase());
|
||||
fileContent = replaceAll(fileContent, '[innerFuncMap]', stubInnerFuncMap);
|
||||
fileContent = replaceAll(fileContent, '[innerFuncImpl]', stubInnerFuncCpp);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
// 生成 xxx_service_stub.cpp
|
||||
export function genStubCppFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenStubCppFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -13,13 +13,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { replaceAll, getTab } from '../common/tool';
|
||||
import { replaceAll, getTab } from '../../common/tool';
|
||||
import * as fs from 'fs';
|
||||
import { format } from 'util'
|
||||
import { FuncObj, ServiceRootInfo } from './datatype';
|
||||
import { FuncObj, ServiceRootInfo } from '../datatype';
|
||||
|
||||
// 生成 xxx_service_stub.h
|
||||
export function genStubHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
export function doGenStubHFile(rootInfo: ServiceRootInfo, fileContent: string): string {
|
||||
let stubInnerFuncH = '';
|
||||
let funcList: FuncObj[] = rootInfo.funcs;
|
||||
let funcTab = getTab(1);
|
||||
@ -32,5 +31,10 @@ export function genStubHFile(rootInfo: ServiceRootInfo, filePath: string, fileCo
|
||||
fileContent = replaceAll(fileContent, '[marcoName]', rootInfo.serviceName.toUpperCase());
|
||||
fileContent = replaceAll(fileContent, '[lowServiceName]', rootInfo.serviceName.toLowerCase());
|
||||
fileContent = replaceAll(fileContent, '[innerFuncDef]', stubInnerFuncH);
|
||||
return fileContent;
|
||||
}
|
||||
// 生成 xxx_service_stub.h
|
||||
export function genStubHFile(rootInfo: ServiceRootInfo, filePath: string, fileContent: string) {
|
||||
fileContent = doGenStubHFile(rootInfo, fileContent);
|
||||
fs.writeFileSync(filePath, fileContent);
|
||||
}
|
@ -20,7 +20,7 @@ import { ParamObj, FuncObj, StructObj, ClassObj, EnumObj, UnionObj, ParseObj } f
|
||||
|
||||
import fs = require('fs');
|
||||
|
||||
function parseEnum(data: string) {
|
||||
export function parseEnum(data: string) {
|
||||
// 使用正则表达式提取枚举定义
|
||||
const enumRegex = /typedef\s+enum\s+(\w*)\s*{([^}]*)}\s*(\w+);|enum\s+(\w+)\s*{([^}]*)}\s*;/g;
|
||||
const enums: EnumObj[] = [];
|
||||
@ -43,7 +43,7 @@ function parseEnum(data: string) {
|
||||
return enums;
|
||||
}
|
||||
|
||||
function parseUnion(data: string) {
|
||||
export function parseUnion(data: string) {
|
||||
// 使用正则表达式提取联合体定义
|
||||
const unionRegex = /typedef\s+union\s*(\w*)\s*{([^}]*)}\s*(\w+)\s*;|union\s+(\w+)\s*{([^}]*)}\s*;/g;
|
||||
const unions: UnionObj[] = [];
|
||||
@ -91,7 +91,7 @@ function parseUnion(data: string) {
|
||||
return unions;
|
||||
}
|
||||
|
||||
function parseStruct(data: string) {
|
||||
export function parseStruct(data: string) {
|
||||
// 使用正则表达式提取结构体定义
|
||||
// const structRegex = /typedef\s+struct\s+(\w+)\s*{([^}]*)}\s*(\w+);/g;
|
||||
// const structRegex = /(\btypedef\b\s+)?struct\s+\w*\s*{([^}]*)}\s*(\w+);/g;
|
||||
@ -138,7 +138,7 @@ function parseStruct(data: string) {
|
||||
return structs;
|
||||
}
|
||||
// /^(const\s+)?([\w\s*]+)\s+(\w+)(?:\[(\d+)\])?$/
|
||||
function parseParameters(members: string[]): ParamObj[] {
|
||||
export function parseParameters(members: string[]): ParamObj[] {
|
||||
// const memberRegex = /^(const\s+)?([\w\s*]+)\s+(\w+)(?:\[(\d+)\])?$/;
|
||||
const memberRegex = /^(const\s+)?([\w\s*]+)\s+(\w+)(?:\[(\d*)\])?$/;
|
||||
// console.info(` parseParameters members: ${JSON.stringify(members)}`);
|
||||
@ -157,7 +157,7 @@ function parseParameters(members: string[]): ParamObj[] {
|
||||
}).filter((m): m is ParamObj => m !== null);
|
||||
}
|
||||
|
||||
function parseMembers(members: string[]): ParamObj[] {
|
||||
export function parseMembers(members: string[]): ParamObj[] {
|
||||
const memberRegex = /(?:public:|private:)?\s*(\w+(?:\s+\w+)?)\s+(\w+)(?:\[(\d+)\])?/;
|
||||
// console.info(` parseMembers members: ${JSON.stringify(members)}`);
|
||||
return members.map(member => {
|
||||
@ -174,7 +174,7 @@ function parseMembers(members: string[]): ParamObj[] {
|
||||
}).filter((m): m is ParamObj => m !== null);
|
||||
}
|
||||
|
||||
function parseMethods(functions: string[]): FuncObj[] {
|
||||
export function parseMethods(functions: string[]): FuncObj[] {
|
||||
const functionRegex = /^(\w[\w\s]*\*?)\s+(\w+)\((.*?)\)$/;
|
||||
// 正则表达式匹配返回值、函数名和参数
|
||||
// const functionRegex = /(\w+)\s+(\w+)\(([^)]*)\)/;
|
||||
@ -196,7 +196,7 @@ function parseMethods(functions: string[]): FuncObj[] {
|
||||
}).filter((f): f is FuncObj => f !== null);
|
||||
}
|
||||
|
||||
function parseClass(data: string) {
|
||||
export function parseClass(data: string) {
|
||||
// 使用正则表达式提取类定义
|
||||
const classRegex = /class\s+(\w+)\s*{([^}]*)}/g;
|
||||
const classes: ClassObj[] = []
|
||||
@ -241,7 +241,7 @@ function parseClass(data: string) {
|
||||
return classes;
|
||||
}
|
||||
|
||||
function parseFunctionOld(data: string) {
|
||||
export function parseFunctionOld(data: string) {
|
||||
// 使用正则表达式提取函数定义
|
||||
const functionRegex1 = /([a-zA-Z_]\w*\s+)+([*a-zA-Z_]\w+)\s*\(([^)]*)\)\s*(?={|;)/g;
|
||||
const functionRegex2 = /(\w+\s*\(.*?\)\s+)(\w+)\s*\((.*?)\);\s*/g;
|
||||
@ -326,7 +326,7 @@ function parseFunctionOld(data: string) {
|
||||
// }
|
||||
}
|
||||
|
||||
function parseFunction(data: string): FuncObj[] {
|
||||
export function parseFunction(data: string): FuncObj[] {
|
||||
// const funcRegex = /^(static\s+)?(const\s+)?([\w\s\[\]*]+)\s+(\w+)\s*\(([^)]*)\);/gm;
|
||||
const funcRegex = /(?:typedef\s+([\w\s\[\]*]+)\s+\(\*\s*(\w+)\)\s*\(([^)]*)\);|^(static\s+)?(const\s+)?([\w\s\[\]*]+)\s+(\w+)\s*\(([^)]*)\);)/gm
|
||||
const functions: FuncObj[] = []
|
||||
|
@ -52,7 +52,7 @@ const OBJECT_TYPE = 180;
|
||||
|
||||
let gchecker: ts.TypeChecker;
|
||||
|
||||
function getTypeAliasSubtypes(typeAlias: ts.TypeAliasDeclaration, list: ParamObj[]) {
|
||||
export function getTypeAliasSubtypes(typeAlias: ts.TypeAliasDeclaration, list: ParamObj[]) {
|
||||
// 检查类型是否为类型节点
|
||||
const typeNode = typeAlias.type;
|
||||
// console.log('getTypeAliasSubtypes');
|
||||
@ -90,7 +90,7 @@ function getTypeAliasSubtypes(typeAlias: ts.TypeAliasDeclaration, list: ParamObj
|
||||
return [];
|
||||
}
|
||||
|
||||
function getParamType(paramType: any) {
|
||||
export function getParamType(paramType: any) {
|
||||
if (paramType === undefined) {
|
||||
return 'void';
|
||||
}
|
||||
|
62
src/vscode_plugin/src/test/readme.md
Normal file
62
src/vscode_plugin/src/test/readme.md
Normal file
@ -0,0 +1,62 @@
|
||||
### Run test
|
||||
|
||||
1. Modify launch.json
|
||||
|
||||
```json
|
||||
//add test config
|
||||
{
|
||||
"name": "Run Extension Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||
],
|
||||
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
|
||||
"preLaunchTask": "npm: watch"
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
2. start the test by using “F5”
|
||||
|
||||
|
||||
|
||||
3. get result in output of "debug console(调试控制台)"
|
||||
|
||||
|
||||
|
||||
4. add testcase: following test-files in "test\suit"
|
||||
|
||||
| test-dir | test-target | testcase | result | tester |
|
||||
| --------- | ----------------- | -------- | ------ | ------ |
|
||||
| common | re | | | zmh |
|
||||
| common | tool | | | hrt |
|
||||
| gen/tools | genclientcppfile | | | |
|
||||
| | gencommonfile | | | |
|
||||
| | gencommonfunc | | | |
|
||||
| | genidlfile | | | |
|
||||
| | geniservicehfile | | | |
|
||||
| | genproxycppfile | | | |
|
||||
| | genproxyhfile | | | |
|
||||
| | gensacppfile | | | |
|
||||
| | gensahfile | | | |
|
||||
| | genservicecppfile | | | |
|
||||
| | genservicehfile | | | |
|
||||
| | genstubcppfile | | | |
|
||||
| | genstubhfile | | | |
|
||||
| gen | gencpp | | | |
|
||||
| | gendts | | | |
|
||||
| | gendtscpp | | | |
|
||||
| | genhdf | | | |
|
||||
| | gensa | | | |
|
||||
| | gentest | | | |
|
||||
| parse | parsec | | | |
|
||||
| | parsets | | | |
|
||||
|
||||
|
||||
|
||||
5. test report
|
@ -18,7 +18,7 @@ import * as assert from 'assert';
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
import * as tools from '../../common/tool'
|
||||
import * as tools from '../../../common/tool'
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('Common_Tool_Test_Suite', () => {
|
||||
@ -28,6 +28,7 @@ suite('Common_Tool_Test_Suite', () => {
|
||||
test('replaceall_test_1', () => {
|
||||
let resultStr = tools.replaceAll('hello_world', 'or', 'er');
|
||||
assert.strictEqual(resultStr, 'hello_werld');
|
||||
|
||||
resultStr = tools.replaceAll('hello_world', 'l', 'r');
|
||||
assert.strictEqual(resultStr, 'herro_worrd');
|
||||
});
|
65
src/vscode_plugin/src/test/suite/gen/genidlfile.test.ts
Normal file
65
src/vscode_plugin/src/test/suite/gen/genidlfile.test.ts
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
import * as genIdlFile from '../../../gen/tools/genidlfile'
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('GenIdl_file_Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
//1, 测试 parseEnum 一般情况
|
||||
test('getParcelType_test_1', () => {
|
||||
let resStr = genIdlFile.getParcelType('');
|
||||
assert.strictEqual(resStr, resStr);
|
||||
|
||||
resStr = genIdlFile.getParcelType('std::string');
|
||||
assert.strictEqual(resStr, 'string');
|
||||
});
|
||||
|
||||
//2, 测试边界情况
|
||||
test('getParcelType_test_2', () => {
|
||||
let resStr = genIdlFile.getParcelType('std::string');
|
||||
assert.strictEqual(resStr, 'string');
|
||||
|
||||
resStr = genIdlFile.getParcelType('char *');
|
||||
assert.strictEqual(resStr, 'string');
|
||||
|
||||
resStr = genIdlFile.getParcelType('char *');
|
||||
assert.strictEqual(resStr, resStr);
|
||||
});
|
||||
|
||||
//3, 测试异常情况
|
||||
test('getParcelType_test_3', () => {
|
||||
let resStr = genIdlFile.getParcelType('');
|
||||
assert.strictEqual(resStr, '');
|
||||
|
||||
resStr = genIdlFile.getParcelType('string');
|
||||
assert.strictEqual(resStr, 'string');
|
||||
|
||||
resStr = genIdlFile.getParcelType('char*');
|
||||
assert.strictEqual(resStr, 'char*');
|
||||
});
|
||||
|
||||
//4, 测试错误情况
|
||||
test('getParcelType_test_4', () => {
|
||||
let resStr = genIdlFile.getParcelType('');
|
||||
assert.strictEqual(resStr, '');
|
||||
});
|
||||
});
|
@ -16,6 +16,7 @@
|
||||
import * as path from 'path';
|
||||
import * as Mocha from 'mocha';
|
||||
import * as glob from 'glob';
|
||||
import { getOutputPath, getReportConf } from '../../common/conf';
|
||||
|
||||
export function run(): Promise<void> {
|
||||
// Create the mocha test
|
||||
@ -23,6 +24,13 @@ export function run(): Promise<void> {
|
||||
ui: 'tdd'
|
||||
});
|
||||
mocha.useColors(true);
|
||||
|
||||
let reportTestResult = getReportConf();
|
||||
if (reportTestResult) {
|
||||
let outpath = getOutputPath();
|
||||
outpath = outpath + 'testres.xunit.xml';
|
||||
mocha.reporter('xunit', { output: outpath });
|
||||
}
|
||||
|
||||
const testsRoot = path.resolve(__dirname, '..');
|
||||
|
||||
|
63
src/vscode_plugin/src/test/suite/parse/parsec.test.ts
Normal file
63
src/vscode_plugin/src/test/suite/parse/parsec.test.ts
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
import * as parsec from '../../../parse/parsec'
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('Parse_C_Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
//1, 测试 parseEnum 一般情况
|
||||
test('parseEnum_test_1', () => {
|
||||
let enumObjList = parsec.parseEnum('hello_world');
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
});
|
||||
|
||||
//2, 测试边界情况
|
||||
test('parseEnum_test_2', () => {
|
||||
let enumObjList = parsec.parseEnum('enum { ENUM_1 }');
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
|
||||
enumObjList = parsec.parseEnum('enum { ENUM_1, ENUM_2 }');
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
|
||||
enumObjList = parsec.parseEnum('enum { ENUM_1, ENUM_2 }; enum { ENUM_10, ENUM_20 };');
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
});
|
||||
|
||||
//3, 测试异常情况
|
||||
test('parseEnum_test_3', () => {
|
||||
let teststr: string = '';
|
||||
let enumObjList = parsec.parseEnum(teststr);
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
|
||||
enumObjList = parsec.parseEnum('enum');
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
|
||||
enumObjList = parsec.parseEnum('enum { ENUM_1, ENUM_1 }');
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
});
|
||||
|
||||
//4, 测试错误情况
|
||||
test('replaceall_test_4', () => {
|
||||
let enumObjList = parsec.parseEnum('');
|
||||
assert.strictEqual(enumObjList.length, 0);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user