style: add enum input validation

Signed-off-by: gou-jingjing <goujingjing@kaihong.com>
This commit is contained in:
gou-jingjing 2024-02-29 17:47:08 +08:00
parent 4853a9b313
commit 229514d470
12 changed files with 213 additions and 127 deletions

View File

@ -79,6 +79,7 @@ function getFuncParaType(v, interfaceName, data, results) {
let index = enumIndex(parameter, results)
if (results.enum[index].body.enumValueType === EnumValueType.ENUM_VALUE_TYPE_NUMBER) {
v["type"] = v["type"].replace(parameter, "NUMBER_TYPE_" + NumberIncrease.getAndIncrease())
v["realType"] = v["type"]
} else if (results.enum[index].body.enumValueType === EnumValueType.ENUM_VALUE_TYPE_STRING) {
v["type"] = v["type"].replace(parameter, "string")
} else {
@ -95,6 +96,7 @@ function getFuncParaType(v, interfaceName, data, results) {
if (parameter.indexOf("number") >= 0) {
v["type"] = v["type"].replace("number", "NUMBER_TYPE_" + NumberIncrease.getAndIncrease())
v["realType"] = v["type"]
}
// type的处理
@ -249,7 +251,7 @@ function analyzeFunction(data, isStatic, name, values, ret, results, interfaceNa
let paramAsync = paramType.substring(14, paramType.length - 1)
paramType = paramType.replace(paramAsync, paramTypeVal);
}
values.push({name: "promise", optional: false, type: paramType})
values.push({name: "promise", optional: false, type: paramType, realType: paramType})
ret = "void" // 返回值由Promise改为void与AsyncCallback接口保持一致
}
for (let j in values) {

View File

@ -84,6 +84,7 @@ function analyzeInterface(data, rsltInterface = null, results, interfaceName = '
result.value.push({
name: valueName,
type: valueType,
realType: valueType,
optional: optionalFlag
})
}

View File

@ -103,7 +103,7 @@ function analyzeParams(funcName, values) {
checkParamOk = false;
}
if (checkParamOk) {
result.push({ "name": re.getReg(v, matchs.regs[1]), "type": type, "optional": optionalFlag})
result.push({ "name": re.getReg(v, matchs.regs[1]), "type": type, "optional": optionalFlag, "realType": type})
if (type.indexOf("AsyncCallback") >= 0) {
funcType = FuncType.ASYNC
}

View File

@ -15,10 +15,11 @@
const re = require("../tools/re");
const { EnumValueType, getLogErrInfo } = require("../tools/common");
const { NapiLog } = require("../tools/NapiLog");
function generateEnum(name, data) {
function generateEnum(name, data, inNamespace, nameSpaceName, toolNamespace) {
let implH = ""
let implCpp = ""
let midInitEnum = ""
let midInitEnumDefine = ""
if (data.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
implH = `\nclass %s {\npublic:\n`.format(name, implH)
@ -30,28 +31,29 @@ function generateEnum(name, data) {
}
for (let i in data.element) {
let v = data.element[i]
if(midInitEnum == "") {
midInitEnum += ' std::map<const char *, std::any> enumMap%s;\n'.format(name)
if(midInitEnumDefine == "") {
midInitEnumDefine += 'std::map<const char *, std::any> enumMap%s;\n'.format(name)
}
if (data.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
implH += ` static const std::string %s;\n`.format(v.name)
implCpp += `\nconst std::string %s::%s = "%s";\n`.format(name, v.name, v.value)
midInitEnum += ' enumMap%s["%s"] = "%s";\n'.format(name, v.name, v.value)
midInitEnum += ' %s%s::%senumMap%s["%s"] = "%s";\n'.format(inNamespace, nameSpaceName, toolNamespace, name, v.name, v.value)
} else {
if (v.value == '') {
v.value = 0
}
implH += ` %s = %s,\n`.format(v.name, v.value)
midInitEnum += ' enumMap%s["%s"] = %s;\n'.format(name, v.name, v.value)
midInitEnum += ' %s%s::%senumMap%s["%s"] = %s;\n'.format(inNamespace, nameSpaceName, toolNamespace, name, v.name, v.value)
}
}
midInitEnum += ' pxt->CreateEnumObject("%s", enumMap%s);\n'.format(name, name)
midInitEnum += ' pxt->CreateEnumObject("%s", %s%s::%senumMap%s);\n'.format(name, inNamespace, nameSpaceName, toolNamespace, name)
implH += `};\n`
let result = {
implH: implH,
implCpp: implCpp,
midInitEnum: midInitEnum
midInitEnum: midInitEnum,
midInitEnumDefine: midInitEnumDefine
}
return result
}

View File

@ -100,17 +100,18 @@ function genExtendsRelation(data) {
//生成module_middle.cpp、module.h、module.cpp
function generateNamespace(name, data, inNamespace = "") {
let namespaceResult = { implH: "", implCpp: "", middleFunc: "", middleInit: "", declarationH: "", middleH: "" }
let namespaceResult = { implH: "", implCpp: "", middleFunc: "", middleInit: "", declarationH: "", middleH: "", middleInitEnumDef: "" }
namespaceResult.middleInit += formatMiddleInit(inNamespace, name)
genExtendsRelation(data)
InterfaceList.push(data.interface)
TypeList.push(data.type)
EnumList.push(data.enum)
CallFunctionList.push(data.callFunction)
enumNamespaceFunction(data, namespaceResult);
let toolNamespace = getToolNamespaceFunc(inNamespace, name);
enumNamespaceFunction(data, namespaceResult, inNamespace, name, toolNamespace);
for (let i in data.type) {
let ii = data.type[i]
let result = generateType(ii.name, ii.body, inNamespace + name + "::")
let result = generateType(ii.name, ii.body, inNamespace + name + "::",inNamespace, name, toolNamespace)
namespaceResult = getNamespaceResult(result, namespaceResult)
}
for (let i in data.interface) {
@ -145,7 +146,7 @@ function generateNamespace(name, data, inNamespace = "") {
flag = true;
}
return generateResult(name, namespaceResult.implH, namespaceResult.implCpp, namespaceResult.middleFunc,
namespaceResult.middleInit, namespaceResult.middleH, flag)
namespaceResult.middleInit, namespaceResult.middleH, namespaceResult.middleInitEnumDef, flag)
}
function genNamespaceFunc(data, i, namespaceResult, inNamespace, name) {
@ -180,11 +181,12 @@ function getToolNamespaceFunc(inNamespace, name) {
return toolNamespace;
}
function enumNamespaceFunction(data, namespaceResult) {
let result = generateEnumResult(data);
function enumNamespaceFunction(data, namespaceResult, inNamespace, nameSpaceName, toolNamespace) {
let result = generateEnumResult(data, inNamespace, nameSpaceName, toolNamespace);
namespaceResult.implH += result.implH;
namespaceResult.implCpp += result.implCpp;
namespaceResult.middleInit += result.middleInit;
namespaceResult.middleInitEnumDef += result.midInitEnumDefine
}
function getNamespaceResult(subResult, returnResult) {
@ -195,33 +197,40 @@ function getNamespaceResult(subResult, returnResult) {
returnResult.declarationH += subResult.declarationH
returnResult.middleH += subResult.middleH
if (subResult.midInitEnumDefine !== undefined) {
returnResult.middleInitEnumDef += subResult.midInitEnumDefine
}
return returnResult
}
function generateEnumResult(data) {
function generateEnumResult(data, inNamespace, nameSpaceName, toolNamespace) {
let resultEnum = {
implH: "",
implCpp: "",
middleInit: ""
middleInit: "",
midInitEnumDefine: ""
}
for (let i in data.enum) {
let enumm = data.enum[i]
let result = generateEnum(enumm.name, enumm.body)
let result = generateEnum(enumm.name, enumm.body, inNamespace, nameSpaceName, toolNamespace)
resultEnum.implH += result.implH
resultEnum.implCpp += result.implCpp
resultEnum.middleInit += result.midInitEnum
resultEnum.midInitEnumDefine += result.midInitEnumDefine
}
return resultEnum
}
function generateResult(name, implH, implCpp, middleFunc, middleInit, middleH, flag) {
function generateResult(name, implH, implCpp, middleFunc, middleInit, middleH, middleInitEnumDef, flag) {
let result
let middleEnumDefine = middleInitEnumDef.indexOf('undefined') >= 0? '' : middleInitEnumDef
if (flag) {
result = {
implH: `\nnamespace %s {\nnamespace %s_interface {%s\n}\n}`.format(name, name, implH),
implCpp: `\nnamespace %s {\nnamespace %s_interface {%s\n}\n}`.format(name, name, implCpp),
middleBody: `\nnamespace %s {\nnamespace %s_interface {%s\n}\n}`.format(name, name, middleFunc),
middleBody: `\nnamespace %s {\nnamespace %s_interface {\n%s%s\n}\n}`.format(name, name, middleEnumDefine, middleFunc),
middleInit: middleInit,
middleH: `\nnamespace %s {\nnamespace %s_interface {%s\n}\n}`.format(name, name, middleH)
}
@ -229,7 +238,7 @@ function generateResult(name, implH, implCpp, middleFunc, middleInit, middleH, f
result = {
implH: `\nnamespace %s {%s\n}`.format(name, implH),
implCpp: `\nnamespace %s {%s}`.format(name, implCpp),
middleBody: `\nnamespace %s {%s}`.format(name, middleFunc),
middleBody: `\nnamespace %s {\n%s%s}`.format(name, middleEnumDefine, middleFunc),
middleInit: middleInit,
middleH: `\nnamespace %s {%s\n}`.format(name, middleH)
}

View File

@ -76,14 +76,34 @@ function jsToC(dest, napiVn, type, enumType = 0, optional) {
if (type.indexOf("|") >= 0) {
return unionTempleteFunc(dest, napiVn, type, optional)
} else if (type === "string") {
if (napiVn.indexOf("GetValueProperty") >= 0) {
let lt = LenIncrease.getAndIncrease()
return `napi_value tnv%d = %s;\n if (tnv%d != nullptr) {pxt->SwapJs2CUtf8(tnv%d, %s);}\n`
.format(lt, napiVn, lt, lt, dest)
} else {
return "pxt->SwapJs2CUtf8(%s, %s);".format(napiVn, dest)
}
} else if (type.substring(type.length - 2) === "[]") {
let verifyEnumValue = '';
let strlt = LenIncrease.getAndIncrease()
if (enumType) {
// 对枚举是string的值做校验
verifyEnumValue = `
bool isStrValueInMap%s = false;
for (const auto& pair : enumMap%s) {
const char* charPtr = std::any_cast<const char*>(pair.second);
std::string value = charPtr;
if (value == %s) {
isStrValueInMap%s = true;
break;
}
}
if (!isStrValueInMap%s) {
napi_throw_error(env, nullptr, "enum value is wrong!");
return nullptr;
}`.format(strlt, enumType, dest, strlt, strlt)
}
if (napiVn.indexOf("GetValueProperty") >= 0) {
let lt = LenIncrease.getAndIncrease()
return `napi_value tnv%d = %s;\n if (tnv%d != nullptr) {pxt->SwapJs2CUtf8(tnv%d, %s);}\n`
.format(lt, napiVn, lt, lt, dest)
} else {
return "pxt->SwapJs2CUtf8(%s, %s);".format(napiVn, dest) + verifyEnumValue
}
} else if (type.substring(type.length - 2) === "[]") {
return arrTemplete(dest, napiVn, type);
} else if (type.substring(0, 12) === "NUMBER_TYPE_") {
return numTempleteFunc (enumType, napiVn, type, dest);
@ -298,13 +318,29 @@ function arrTemplete(dest, napiVn, type) {
function numTempleteFunc(enumType, napiVn, type, dest) {
if (enumType) {
let strlt = LenIncrease.getAndIncrease()
// 对传入的枚举值做校验
let verifyEnumValue = `
bool isValueInMap%s = false;
for (const auto& pair : enumMap%s) {
int value = std::any_cast<int>(pair.second);
if (value == (int)%s) {
isValueInMap%s = true;
break;
}
}
if (!isValueInMap%s) {
napi_throw_error(env, nullptr, "enum value is wrong!");
return nullptr;
}`.format(strlt, enumType, dest, strlt, strlt)
if (napiVn.indexOf("GetValueProperty") >= 0) {
let lt = LenIncrease.getAndIncrease()
return `napi_value tnv%d = %s;\n if (tnv%d != nullptr) {NUMBER_JS_2_C_ENUM(tnv%d, %s, %s, %s);}\n`
.format(lt, napiVn, lt, lt, type, dest, enumType)
return `napi_value tnv%d = %s;\n if (tnv%d != nullptr) {NUMBER_JS_2_C_ENUM(tnv%d, %s, %s, %s);}\n`
.format(lt, napiVn, lt, lt, type, dest, enumType) + verifyEnumValue
} else {
return `NUMBER_JS_2_C_ENUM(%s, %s, %s, %s);`.format(napiVn, type, dest, enumType)
}
return `NUMBER_JS_2_C_ENUM(%s, %s, %s, %s);`.format(napiVn, type, dest, enumType) + verifyEnumValue
}
} else {
if (napiVn.indexOf("GetValueProperty") >= 0) {
let lt = LenIncrease.getAndIncrease()
@ -877,7 +913,11 @@ function isArrayType(type) {
}
function getValueCheckout(funcValue, param, inParamName, p, cType) {
let valueCheckout = jsToC(inParamName, "pxt->GetArgv(%d)".format(getConstNum(p)), funcValue.type) + "\n "
let enumType = 0;
if (funcValue.type !== funcValue.realType) {
enumType = funcValue.realType;
}
let valueCheckout = jsToC(inParamName, "pxt->GetArgv(%d)".format(getConstNum(p)), funcValue.type, enumType) + "\n "
if (funcValue.optional) {
valueCheckout = "if (pxt->GetArgc() > %d) {\n vio->in%d = new %s;\n "
.format(getConstNum(p), p, cType) + valueCheckout + "}\n "
@ -894,7 +934,21 @@ function paramGenerateUnion(type, param, p, name) {
param.valueDefine += "%sstd::any &%s".format(param.valueDefine.length > 0 ? ", " : "", name)
}
function isEnumTypeFunc(cType, funcValue) {
if (cType !== funcValue.realType && funcValue.type !== funcValue.realType && funcValue.type !== "string") {
return true;
} else {
return false;
}
}
function paramGenerateCommon(p, cType, funcValue, param, modifiers, inParamName) {
// string类型和number类型枚举处理时才走该分支
if (isEnumTypeFunc(cType, funcValue)) {
cType = funcValue.realType
}
param.valueIn += funcValue.optional ? "\n %s* in%d = nullptr;".format(cType, p)
: "\n %s in%d;".format(cType, p)
if (TypeList.getValue(cType)) {

View File

@ -18,13 +18,14 @@ const { NapiLog } = require("../tools/NapiLog");
const { addUniqObj2List } = require("../tools/tool");
const re = require("../tools/re");
function getHDefineOfType(data, name, type, variable) {
function getHDefineOfType(data, name, type, variable, inNamespace, nameSpaceName, toolNamespace) {
if (typeof(type) === 'object') {
// 字符常量转化
let result = generateTypeEnum(name, data)
let result = generateTypeEnum(name, data, inNamespace, nameSpaceName, toolNamespace)
variable.hDefine += result.implH
variable.cppDefine += result.implCpp
variable.middleInitDefine += result.midInitEnum
variable.midInitEnumDefine += result.midInitEnumDefine
} else if (type.indexOf("|") >= 0) {
variable.hDefine += "\n typedef std::any %s;".format(name)
} else if (type == "string") {
@ -43,27 +44,29 @@ function getHDefineOfType(data, name, type, variable) {
}
}
function generateTypeEnum(name, data) {
function generateTypeEnum(name, data, inNamespace, nameSpaceName, toolNamespace) {
let implH = ""
let implCpp = ""
let midInitEnum = ""
let midInitEnumDefine = ""
implH = `\nclass %s {\npublic:\n`.format(name, implH)
for (let i in data.element) {
let v = data.element[i]
if(midInitEnum == "") {
midInitEnum += ' std::map<const char *, std::any> enumMap%s;\n'.format(name)
if(midInitEnumDefine == "") {
midInitEnumDefine += 'std::map<const char *, std::any> enumMap%s;\n'.format(name)
}
implH += ` static const std::string %s;\n`.format(v.name)
implCpp += `\nconst std::string %s::%s = "%s";\n`.format(name, v.name, v.value)
midInitEnum += ' enumMap%s["%s"] = "%s";\n'.format(name, v.name, v.value)
implCpp += `\nconst std::string %s::%s = "%s";\n`.format(name, v.name, v.value)
midInitEnum += ' %s%s::%senumMap%s["%s"] = "%s";\n'.format(inNamespace, nameSpaceName, toolNamespace, name, v.name, v.value)
}
midInitEnum += ' pxt->CreateEnumObject("%s", enumMap%s);\n'.format(name, name)
midInitEnum += ' pxt->CreateEnumObject("%s", %s%s::%senumMap%s);\n'.format(name, inNamespace, nameSpaceName, toolNamespace, name)
implH += `};\n`
let result = {
implH: implH,
implCpp: implCpp,
midInitEnum: midInitEnum
midInitEnum: midInitEnum,
midInitEnumDefine: midInitEnumDefine
}
return result
}
@ -211,19 +214,21 @@ function getSelfNs(inNamespace) {
return selfNs
}
function generateType(name, data, inNamespace) {
function generateType(name, data, inNamespace, inNameSpaceEnum, nameSpaceName, toolNamespace) {
let result = {
implH: '',
implCpp: '',
middleBody: '',
middleInit: '',
declarationH:'',
middleH: ''
middleH: '',
midInitEnumDefine: ''
}
let resultConnect = connectResult(name, data)
let resultConnect = connectResult(name, data, inNameSpaceEnum, nameSpaceName, toolNamespace)
let implH = resultConnect[1]
let implCpp = resultConnect[2]
let middleInit = resultConnect[3]
let midInitEnumDefine = resultConnect[4]
let selfNs = ""
selfNs = getSelfNs(inNamespace);
if (implH.indexOf("typedef") > 0) {
@ -233,7 +238,8 @@ function generateType(name, data, inNamespace) {
middleBody: '',
middleInit: middleInit,
declarationH:'',
middleH: ''
middleH: '',
midInitEnumDefine: midInitEnumDefine
}
} else if (implCpp !== '' && middleInit !== '') {
result = {
@ -242,7 +248,8 @@ function generateType(name, data, inNamespace) {
middleBody: '',
middleInit: middleInit,
declarationH:'',
middleH: ''
middleH: '',
midInitEnumDefine: midInitEnumDefine
}
} else {
result = {
@ -255,7 +262,8 @@ function generateType(name, data, inNamespace) {
middleInit: middleInit,
declarationH: `
struct %s;\r`.format(name),
middleH: ''
middleH: '',
midInitEnumDefine: ''
}
}
return result
@ -268,15 +276,17 @@ function getAllPropties(interfaceBody, properties) {
}
}
function connectResult(name, data) {
function connectResult(name, data, inNamespace, nameSpaceName, toolNamespace) {
let implH = ""
let implCpp = ""
let middleFunc = ""
let middleInit = ""
let midInitEnumDefine = ""
let variable = {
hDefine: "",
cppDefine: "",
middleInitDefine: ""
middleInitDefine: "",
midInitEnumDefine: ""
}
if (Object.prototype.hasOwnProperty.call(data, "value")) {
data.allProperties = {values:[]}
@ -287,12 +297,13 @@ function connectResult(name, data) {
}
} else {
let type = data
getHDefineOfType(data, name, type, variable)
getHDefineOfType(data, name, type, variable, inNamespace, nameSpaceName, toolNamespace)
}
implH += variable.hDefine
implCpp += variable.cppDefine
middleInit += variable.middleInitDefine
return [middleFunc, implH, implCpp, middleInit]
midInitEnumDefine += variable.midInitEnumDefine
return [middleFunc, implH, implCpp, middleInit, midInitEnumDefine]
}
module.exports = {

View File

@ -46,6 +46,12 @@ declare namespace napitest {
STATE_TEST_END,
}
export enum HttpStatus {
STATUS0 = 0,
STATUS1 = 500,
STATUS2 = 503,
}
function fun1(v0: string, v1: GrantStatus): GrantStatus;
function fun2(v0: number, v1: LaunchReason): LaunchReason;
function fun3(v0: string, v1: Action): Action;
@ -57,6 +63,7 @@ declare namespace napitest {
function fun9(v0: PlayingTest): string;
function fun10(v: TestStatus): string;
function fun11(v: EnumString): string;
function fun12(v: HttpStatus): number;
//function fun10(v: TestStatus): string;
/*function fun7(v0: LaunchReason[], v1: LaunchReason): number;*/

View File

@ -107,4 +107,75 @@ describe('enum second part', function () {
let ret = test.fun11(test.EnumString.ENUM_SEARCH);
assert.strictEqual(ret, '');
})
});
// function fun12(v: HttpStatus): number;
it('test fun12', function () {
let ret = test.fun12(test.HttpStatus.STATUS0);
assert.strictEqual(ret, 0);
});
});
// Èë²ÎÒì³£²âÊÔ
describe('enum third part', function () {
// function fun1(v0: string, v1: GrantStatus): GrantStatus;
it('test fun1 exception ', function () {
let ret2 = false;
try {
let ret = fun1('aaaa', "bbbb");
} catch (err) {
ret2 = true;
console.info("err: "+ err)
}
assert.strictEqual(ret2, true)
});
// function fun2(v0: number, v1: LaunchReason): LaunchReason;
it('test fun2 exception', function () {
let ret3 = false;
try {
let ret = fun2(18, 9);
} catch (err) {
ret3 = true;
console.info("err: "+ err)
}
assert.strictEqual(ret3, true)
});
// function fun3(v0: string, v1: Action): Action;
it('test fun3 exception', function () {
let ret2 = false;
try {
let ret = fun3('ggg', 'ccc');
} catch (err) {
ret2 = true;
console.info("err: "+ err)
}
assert.strictEqual(ret2, true)
});
// function fun4(v0: number, v1: PlayingState): PlayingState;
it('test fun4 exception', function () {
let ret3 = false;
try {
let ret = fun4(18, 8);
} catch (err) {
ret3 = true;
console.info("err: "+ err)
}
assert.strictEqual(ret3, true)
});
// function fun12(v: HttpStatus): number;
it('test fun12 exception', function () {
let ret3 = false;
try {
let ret = test.fun12(2);
} catch (err) {
ret3 = true;
console.info("err: "+ err)
}
assert.strictEqual(ret3, true)
});
})

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { getProperties, enumParamFunc, NodeSayHello, NodeSayHi } = require("./out/build/Release/napitest")
const { getProperties, enumParamFunc, NodeSayHello, NodeSayHi, WindowType } = require("./out/build/Release/napitest")
const test = require("./out/build/Release/napitest")
var assert = require("assert");
const { consumers } = require("stream");
@ -54,7 +54,7 @@ describe('test_Class', function () {
describe('test_Function', function () {
it('test enumParamFunc', function () {
// function enumParamFunc(v0: boolean, v1: WindowType): number;
let ret = enumParamFunc(true, 12);
let ret = enumParamFunc(true, WindowType.TYPE_APP);
assert.strictEqual(ret, 0);
});
});

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2022 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 { Callback } from './../basic';
declare namespace napitest {
export enum HttpStatus {
STATUS0 = 0,
STATUS1 = 500,
STATUS2 = 503,
}
function fun1(v1: HttpStatus): number;
export enum GrantStatus {
PERMISSION_DEFAULT = "ADMIN",
PERMISSION_DENIED = "NORMAL",
PERMISSION_GRANTED = "GUEST",
}
function fun2(v1: GrantStatus): number;
/*function fun3(reason: string, callback: Callback<HttpStatus>): void;
*/
}
export default napitest;

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2022 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 { fun1, fun2, fun3 } = require("./out/build/Release/napitest")
const test = require("./out/build/Release/napitest")
var assert = require("assert");
describe('String', function () {
// function fun1(v1: HttpStatus): number;
it('test fun1', function () {
let ret = test.fun1(test.HttpStatus.STATUS0);
assert.strictEqual(ret, 0);
});
// function fun2(v1: GrantStatus): number;
it('test fun2', function () {
let ret = test.fun2(test.GrantStatus.PERMISSION_DEFAULT);
assert.strictEqual(ret, 0);
});
});