From 49232ae2b98dbeea5693da1b9606499203eed57c Mon Sep 17 00:00:00 2001 From: wangshi Date: Mon, 28 Apr 2025 16:32:28 +0800 Subject: [PATCH 1/6] add 20 types Signed-off-by: wangshi --- .../src/test/java/gen/GenAkiCppFileTest.java | 1649 ----------------- 1 file changed, 1649 deletions(-) delete mode 100644 src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest.java diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest.java deleted file mode 100644 index 53d645bf..00000000 --- a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest.java +++ /dev/null @@ -1,1649 +0,0 @@ -/* - * Copyright (c) 2025 Shenzhen Kaihong Digital. - * 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. - */ - -package gen; - -import grammar.*; -import org.junit.jupiter.api.Test; - -import java.io.File; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static utils.FileUtils.readText; - -/** - *

类名:该类用于xxx

- * description - * - * @author Administrator - * date 2025-02-28 - * @version 1.0 - * @since 2025-02-28 - */ -class GenAkiCppFileTest { - private String classContentExpect2 = "\nclass TestClass : public IPerson {\n" + - "\tpublic char* name;\n" + - "\tprivate int age;\n" + - "\tprotected char* no;\n" + - "\treadonly char* addr;\n" + - "\tconstructor();\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestClass)\n" + - "{\n" + - "\tJSBIND_CONSTRUCTOR<>();\n" + - "\tJSBIND_PROPERTY(name);\n" + - "\tJSBIND_PROPERTY(age);\n" + - "\tJSBIND_PROPERTY(no);\n" + - "\tJSBIND_PROPERTY(addr);\n" + - "};\n"; - - private String classContentExpect3 = "\nclass Employee : public Person {\n" + - "\tint empCode;\n" + - "\tauto currentUser;\n" + - "\tstatic int pi = 3.14;\n" + - "\tconstructor();\n" + - "\tvoid displayName();\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(Employee)\n" + - "{\n" + - "\tJSBIND_CONSTRUCTOR<>();\n" + - "\tJSBIND_METHOD(displayName, \"displayName\");\n" + - "\tJSBIND_PMETHOD(displayName, \"displayNamePromise\");\n" + - "\tJSBIND_PROPERTY(empCode);\n" + - "\tJSBIND_PROPERTY(currentUser);\n" + - "\tJSBIND_PROPERTY(pi);\n" + - "};\n"; - - @Test - void getInterfaceContent() { - } - - @Test - void getEnumContent1() { - EnumObj eo = new EnumObj(); - eo.setName("TestEnum"); - List ml = new CopyOnWriteArrayList<>(); - ml.add("ONE"); - ml.add("TWO"); - eo.setMemberList(ml); - List eol = new CopyOnWriteArrayList<>(); - eol.add(eo); - ParseObj po = new ParseObj(); - po.setEnumList(eol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genEnumList(po.getEnumList()); - - if (gb instanceof GenAkiCppFile gdf) { - String enumContent = gdf.getEnumContent(); - System.out.println("genEnum: " + enumContent); - String expect = "\nenum TestEnum {\n" + - "\tONE,\n" + - "\tTWO,\n" + - "};\n" + - "\n" + - "JSBIND_ENUM(TestEnum) {\n" + - "\tJSBIND_ENUM_VALUE(ONE);\n" + - "\tJSBIND_ENUM_VALUE(TWO);\n" + - "};\n"; - assertEquals(expect, enumContent); - } - } - - @Test - void getEnumContent2() { - EnumObj eo = new EnumObj(); - eo.setName("Colors"); - List ml = new CopyOnWriteArrayList<>(); - ml.add("Red"); - ml.add("Green"); - ml.add("Blue"); - eo.setMemberList(ml); - List vl = new CopyOnWriteArrayList<>(); - vl.add("RED"); - vl.add("GREEN"); - vl.add("BLUE"); - eo.setValueList(vl); - List eol = new CopyOnWriteArrayList<>(); - eol.add(eo); - ParseObj po = new ParseObj(); - po.setEnumList(eol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genEnumList(po.getEnumList()); - - if (gb instanceof GenAkiCppFile gdf) { - String enumContent = gdf.getEnumContent(); - System.out.println("genEnum: " + enumContent); - String expect = "\nenum Colors {\n" + - "\tRed = RED,\n" + - "\tGreen = GREEN,\n" + - "\tBlue = BLUE,\n" + - "};\n" + - "\n" + - "JSBIND_ENUM(Colors) {\n" + - "\tJSBIND_ENUM_VALUE(Red);\n" + - "\tJSBIND_ENUM_VALUE(Green);\n" + - "\tJSBIND_ENUM_VALUE(Blue);\n" + - "};\n"; - assertEquals(expect, enumContent); - } - } - - @Test - void getEnumContent3() { - EnumObj eo = new EnumObj(); - eo.setName("Colors"); - List ml = new CopyOnWriteArrayList<>(); - ml.add("Red"); - ml.add("Green"); - ml.add("Blue"); - eo.setMemberList(ml); - List vl = new CopyOnWriteArrayList<>(); - vl.add("\"RED\""); - vl.add("\"GREEN\""); - vl.add("\"BLUE\""); - eo.setValueList(vl); - List eol = new CopyOnWriteArrayList<>(); - eol.add(eo); - ParseObj po = new ParseObj(); - po.setEnumList(eol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genEnumList(po.getEnumList()); - - if (gb instanceof GenAkiCppFile gdf) { - String enumContent = gdf.getEnumContent(); - System.out.println("genEnum: " + enumContent); - String expect = "\nenum Colors {\n" + - "\tRed = RED,\n" + - "\tGreen = GREEN,\n" + - "\tBlue = BLUE,\n" + - "};\n" + - "\n" + - "char* colors_STR[] = {\n" + - "\t[Red] = \"RED\",\n" + - "\t[Green] = \"GREEN\",\n" + - "\t[Blue] = \"BLUE\"\n" + - "};\n" + - "\n" + - "JSBIND_ENUM(Colors) {\n" + - "\tJSBIND_ENUM_VALUE(Red);\n" + - "\tJSBIND_ENUM_VALUE(Green);\n" + - "\tJSBIND_ENUM_VALUE(Blue);\n" + - "};\n"; - assertEquals(expect, enumContent); - } - } - - @Test - void getEnumContent4() { - EnumObj eo = new EnumObj(); - eo.setName("TestEnum"); - List ml = new CopyOnWriteArrayList<>(); - ml.add("ONE"); - ml.add("TWO"); - eo.setMemberList(ml); - - EnumObj eo1 = new EnumObj(); - eo1.setName("Colors"); - List ml1 = new CopyOnWriteArrayList<>(); - ml1.add("BLACK"); - ml1.add("WHITE"); - eo1.setMemberList(ml1); - - List eol = new CopyOnWriteArrayList<>(); - eol.add(eo); - eol.add(eo1); - - ParseObj po = new ParseObj(); - po.setEnumList(eol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genEnumList(po.getEnumList()); - - if (gb instanceof GenAkiCppFile gdf) { - String enumContent = gdf.getEnumContent(); - System.out.println("genEnum: " + enumContent); - String expect = "\nenum TestEnum {\n" + - "\tONE,\n" + - "\tTWO,\n" + - "};\n" + - "\n" + - "JSBIND_ENUM(TestEnum) {\n" + - "\tJSBIND_ENUM_VALUE(ONE);\n" + - "\tJSBIND_ENUM_VALUE(TWO);\n" + - "};\n" + - "\n" + - "enum Colors {\n" + - "\tBLACK,\n" + - "\tWHITE,\n" + - "};\n" + - "\n" + - "JSBIND_ENUM(Colors) {\n" + - "\tJSBIND_ENUM_VALUE(BLACK);\n" + - "\tJSBIND_ENUM_VALUE(WHITE);\n" + - "};\n"; - assertEquals(expect, enumContent); - } - } - - @Test - void getClassContent1() { - ClassObj co = new ClassObj(); - co.setName("TestClass"); - - co.addParam("name", "string"); - co.addParam("age", "number"); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType("number"); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType("number"); - poList.add(poItem2); - - co.addFunc("add", "number", poList); - - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = "\nclass TestClass {\n" + - "\tchar* name;\n" + - "\tint age;\n" + - "\tint add(int a, int b);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestClass)\n" + - "{\n" + - "\tJSBIND_METHOD(add, \"add\");\n" + - "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + - "\tJSBIND_PROPERTY(name);\n" + - "\tJSBIND_PROPERTY(age);\n" + - "};\n"; - assertEquals(expect, classContent); - } - } - - @Test - void getClassContent2() { - ClassObj co = new ClassObj(); - co.setName("TestClass"); - List hList = new CopyOnWriteArrayList<>(); - hList.add("IPerson"); - co.setHeritageNameList(hList); - - ParamObj pa = new ParamObj(); - pa.setName("name"); - pa.setType("string"); - pa.setQualifier("public"); - co.addParam(pa); - ParamObj pa1 = new ParamObj(); - pa1.setName("age"); - pa1.setType("number"); - pa1.setQualifier("private"); - co.addParam(pa1); - ParamObj pa2 = new ParamObj(); - pa2.setName("no"); - pa2.setType("string"); - pa2.setQualifier("protected"); - co.addParam(pa2); - ParamObj pa3 = new ParamObj(); - pa3.setName("addr"); - pa3.setType("string"); - pa3.setQualifier("readonly"); - co.addParam(pa3); - - List poList = new CopyOnWriteArrayList<>(); - co.addFunc("constructor", "", poList); - - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = classContentExpect2; - assertEquals(expect, classContent); - } - } - - @Test - void getClassContent3() { - ClassObj co = new ClassObj(); - co.setName("Employee"); - List hList = new CopyOnWriteArrayList<>(); - hList.add("Person"); - co.setHeritageNameList(hList); - - ParamObj pa = new ParamObj(); - pa.setName("empCode"); - pa.setType("number"); - co.addParam(pa); - - ParamObj pa1 = new ParamObj(); - pa1.setName("currentUser"); - pa1.setType("any"); - co.addParam(pa1); - - ParamObj pa2 = new ParamObj(); - pa2.setName("pi"); - pa2.setType("number"); - pa2.setQualifier("static"); - pa2.setStrValue("3.14"); - co.addParam(pa2); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj p1 = new ParamObj(); - p1.setName("empcode"); - p1.setType("number"); - ParamObj p2 = new ParamObj(); - p2.setName("name"); - p2.setType("string"); - co.addFunc("constructor", "", poList); - List poList1 = new CopyOnWriteArrayList<>(); - co.addFunc("displayName", "void", poList1); - - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = classContentExpect3; - assertEquals(expect, classContent); - } - } - - @Test - void getClassContent4() { - ClassObj co = new ClassObj(); - co.setName("myClass"); - - List poList1 = new CopyOnWriteArrayList<>(); - FuncObj fo = new FuncObj(); - fo.setName("foo"); - fo.setRetValue("Promise"); - fo.setAccessor("public"); - fo.setType("async"); - fo.setParamList(poList1); - co.addFunc(fo); - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = "\nclass myClass {\n" + - "\tauto foo();\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(myClass)\n" + - "{\n" + - "\tJSBIND_METHOD(foo, \"foo\");\n" + - "\tJSBIND_PMETHOD(foo, \"fooPromise\");\n" + - "};\n"; - assertEquals(expect, classContent); - } - } - - @Test - void getClassContent5() { - ClassObj co = new ClassObj(); - co.setName("KeyValuePair"); - List pol = new CopyOnWriteArrayList<>(); - ParamObj pa = new ParamObj(); - pa.setName("key"); - pa.setType("T"); - pa.setQualifier("private"); - pol.add(pa); - ParamObj po1 = new ParamObj(); - po1.setName("val"); - po1.setType("U"); - po1.setQualifier("private"); - pol.add(po1); - co.setParamList(pol); - - List tmpList = new CopyOnWriteArrayList<>(); - tmpList.add("T"); - tmpList.add("U"); - co.setTempList(tmpList); - - List poList1 = new CopyOnWriteArrayList<>(); - FuncObj fo = new FuncObj(); - fo.setName("setKeyValue"); - fo.setRetValue("void"); - fo.addParam("key", "T"); - fo.addParam("val", "U"); - co.addFunc(fo); - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = "\ntemplate class KeyValuePair {\n" + - "\tprivate T key;\n" + - "\tprivate U val;\n" + - "\tvoid setKeyValue(T key, U val);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(KeyValuePair)\n" + - "{\n" + - "\tJSBIND_METHOD(setKeyValue, \"setKeyValue\");\n" + - "\tJSBIND_PMETHOD(setKeyValue, \"setKeyValuePromise\");\n" + - "\tJSBIND_PROPERTY(key);\n" + - "\tJSBIND_PROPERTY(val);\n" + - "};\n"; - assertEquals(expect, classContent); - } - } - - @Test - void getClassContent6() { - ClassObj co = new ClassObj(); - co.setName("kvProcessor"); - List tmpList = new CopyOnWriteArrayList<>(); - tmpList.add("T"); - tmpList.add("U"); - co.setTempList(tmpList); - List htList = new CopyOnWriteArrayList<>(); - htList.add("implements"); - co.setHeritageTypeList(htList); - List hnList = new CopyOnWriteArrayList<>(); - hnList.add("IKeyValueProcessor"); - co.setHeritageNameList(hnList); - List htempList = new CopyOnWriteArrayList<>(); - htempList.add("T"); - htempList.add("U"); - co.setHeritageTemplateList(htempList); - - List poList1 = new CopyOnWriteArrayList<>(); - FuncObj fo = new FuncObj(); - fo.setName("process"); - fo.setRetValue("void"); - fo.addParam("key", "T"); - fo.addParam("val", "U"); - co.addFunc(fo); - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = "\ntemplate class kvProcessor : " + - "public IKeyValueProcessor {\n" + - "\tvoid process(T key, U val);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(kvProcessor)\n" + - "{\n" + - "\tJSBIND_METHOD(process, \"process\");\n" + - "\tJSBIND_PMETHOD(process, \"processPromise\");\n" + - "};\n"; - assertEquals(expect, classContent); - } - } - - @Test - void getClassContent7() { - ClassObj co = new ClassObj(); - co.setName("Shape"); - - FuncObj fo = new FuncObj(); - fo.setName("process"); - fo.setRetValue("void"); - fo.addParam("key", ""); - fo.addParam("val", ""); - co.addFunc(fo); - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = "\nclass Shape {\n" + - "\tvoid process(auto key, auto val);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(Shape)\n" + - "{\n" + - "\tJSBIND_METHOD(process, \"process\");\n" + - "\tJSBIND_PMETHOD(process, \"processPromise\");\n" + - "};\n"; - assertEquals(expect, classContent); - } - } - - @Test - void getClassContent8() { - ClassObj co = new ClassObj(); - co.setName("myClass"); - - List poList1 = new CopyOnWriteArrayList<>(); - FuncObj fo = new FuncObj(); - fo.setName("foo"); - fo.setRetValue("Promise"); - fo.setAccessor("public"); - fo.setType("async"); - fo.setParamList(poList1); - co.addFunc(fo); - - ClassObj co1 = new ClassObj(); - co1.setName("myClass2"); - - List col = new CopyOnWriteArrayList<>(); - col.add(co); - col.add(co1); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = "\nclass myClass {\n" + - "\tauto foo();\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(myClass)\n" + - "{\n" + - "\tJSBIND_METHOD(foo, \"foo\");\n" + - "\tJSBIND_PMETHOD(foo, \"fooPromise\");\n" + - "};\n" + - "\n" + - "class myClass2 {\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(myClass2)\n" + - "{\n" + - "};\n"; - assertEquals(expect, classContent); - } - } - - @Test - void getFuncContent1() { - FuncObj fo = new FuncObj(); - fo.setName("TestFunc"); - fo.setRetValue("void"); - fo.addParam("name", "string"); - fo.addParam("age", "number"); - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nvoid TestFunc(char* name, int age);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + - "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent2() { - FuncObj fo = new FuncObj(); - fo.setName("ToCapital"); - fo.setRetValue("string"); - fo.addParam("str", "string"); - ParamObj pa = new ParamObj(); - pa.setName("length"); - pa.setType("number"); - pa.setStrValue("0"); - fo.addParam(pa); - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nchar* ToCapital(char* str, int length = 0);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(ToCapital, \"ToCapital\");\n" + - "\tJSBIND_PFUNCTION(ToCapital, \"ToCapitalPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent3() { - FuncObj fo = new FuncObj(); - fo.setName("Nemw"); - fo.setRetValue("string"); - ParamObj pa1 = new ParamObj(); - pa1.setName("str"); - pa1.setType("string"); - pa1.setStrValue("\"joke\""); - fo.addParam(pa1); - ParamObj pa2 = new ParamObj(); - pa2.setName("length"); - pa2.setType("number"); - pa2.setStrValue("0"); - fo.addParam(pa2); - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nchar* Nemw(char* str = \"joke\", int length = 0);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + - "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent4() { - FuncObj fo = new FuncObj(); - fo.setName("Nemw"); - fo.setRetValue("string"); - ParamObj pa1 = new ParamObj(); - pa1.setName("str"); - fo.addParam(pa1); - ParamObj pa2 = new ParamObj(); - pa2.setName("length"); - fo.addParam(pa2); - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nchar* Nemw(auto str, auto length);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + - "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent5() { - FuncObj fo = new FuncObj(); - fo.setName("Nemw"); - fo.setRetValue(""); - ParamObj pa1 = new ParamObj(); - pa1.setName("str"); - fo.addParam(pa1); - ParamObj pa2 = new ParamObj(); - pa2.setName("length"); - fo.addParam(pa2); - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nNemw(auto str, auto length);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + - "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent6() { - FuncObj fo = new FuncObj(); - fo.setName("getArray"); - fo.setRetValue("T[]"); - - List tempList = new CopyOnWriteArrayList<>(); - tempList.add("T"); - fo.setTempList(tempList); - ParamObj pa1 = new ParamObj(); - pa1.setName("items"); - pa1.setType("T[]"); - fo.addParam(pa1); - - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\ntemplate T* getArray(T* items);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(getArray, \"getArray\");\n" + - "\tJSBIND_PFUNCTION(getArray, \"getArrayPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent7() { - FuncObj fo = new FuncObj(); - fo.setName("displayType"); - fo.setRetValue("void"); - - List tempList = new CopyOnWriteArrayList<>(); - tempList.add("T"); - tempList.add("U"); - fo.setTempList(tempList); - ParamObj pa1 = new ParamObj(); - pa1.setName("id"); - pa1.setType("T"); - fo.addParam(pa1); - ParamObj pa2 = new ParamObj(); - pa2.setName("name"); - pa2.setType("U"); - fo.addParam(pa2); - - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\ntemplate void displayType(T id, U name);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(displayType, \"displayType\");\n" + - "\tJSBIND_PFUNCTION(displayType, \"displayTypePromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent8() { - FuncObj fo = new FuncObj(); - fo.setName("Nemw"); - fo.setRetValue("string"); - ParamObj pa1 = new ParamObj(); - pa1.setName("str"); - fo.addParam(pa1); - ParamObj pa2 = new ParamObj(); - pa2.setName("length"); - fo.addParam(pa2); - - FuncObj fo1 = new FuncObj(); - fo1.setName("getCnt"); - fo1.setRetValue("int"); - - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - fol.add(fo1); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nchar* Nemw(auto str, auto length);\n" + - "\n" + - "int getCnt();\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + - "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + - "\tJSBIND_FUNCTION(getCnt, \"getCnt\");\n" + - "\tJSBIND_PFUNCTION(getCnt, \"getCntPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getFuncContent9() { - FuncObj fo = new FuncObj(); - fo.setName("TestFunc"); - fo.setRetValue("void"); - fo.addParam("name", "string"); - - FuncObj foItem = new FuncObj(); - foItem.setRetValue("boolean"); - foItem.addParam("value", "boolean"); - - ParamObj paItem = new ParamObj(); - paItem.setName("func"); - paItem.setType("(value:boolean)=>boolean"); - paItem.addFunc(foItem); - - fo.addParam(paItem); - - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nvoid TestFunc(char* name, aki::SafetyCallback func);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + - "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void getStructContent1() { - StructObj so = new StructObj(); - so.setName("TestStruct"); - - so.addMember("name", "string"); - so.addMember("age", "boolean"); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType("boolean"); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType("boolean"); - poList.add(poItem2); - - so.addFunc("add", "number", poList); - - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); - ParseObj po = new ParseObj(); - po.setStructList(sol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genStructList(po.getStructList()); - - if (gb instanceof GenAkiCppFile gdf) { - String structContent = gdf.getStructContent(); - System.out.println("genStruct: " + structContent); - String expect = "\nstruct TestStruct {\n" + - "\tchar* name;\n" + - "\tbool age;\n" + - "\tint add(bool a, bool b);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestStruct)\n" + - "{\n" + - "\tJSBIND_METHOD(add, \"add\");\n" + - "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + - "\tJSBIND_PROPERTY(name);\n" + - "\tJSBIND_PROPERTY(age);\n" + - "};\n"; - assertEquals(expect, structContent); - } - } - - @Test - void getStructContent2() { - StructObj so = new StructObj(); - so.setName("TestStruct"); - so.addMember("name", "T"); - so.addMember("age", "U"); - so.addTemplate("T"); - so.addTemplate("U"); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType("T"); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType("U"); - poList.add(poItem2); - - so.addFunc("add", "number", poList); - - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); - ParseObj po = new ParseObj(); - po.setStructList(sol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genStructList(po.getStructList()); - - if (gb instanceof GenAkiCppFile gdf) { - String structContent = gdf.getStructContent(); - System.out.println("genStruct: " + structContent); - String expect = "\ntemplate struct TestStruct {\n" + - "\tT name;\n" + - "\tU age;\n" + - "\tint add(T a, U b);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestStruct)\n" + - "{\n" + - "\tJSBIND_METHOD(add, \"add\");\n" + - "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + - "\tJSBIND_PROPERTY(name);\n" + - "\tJSBIND_PROPERTY(age);\n" + - "};\n"; - assertEquals(expect, structContent); - } - } - - @Test - void getStructContent3() { - StructObj so = new StructObj(); - so.setName("TestStruct"); - - so.addMember("name", ""); - so.addMember("age", ""); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType(""); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType(""); - poList.add(poItem2); - - so.addFunc("add", "", poList); - - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); - ParseObj po = new ParseObj(); - po.setStructList(sol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genStructList(po.getStructList()); - - if (gb instanceof GenAkiCppFile gdf) { - String structContent = gdf.getStructContent(); - System.out.println("genStruct: " + structContent); - String expect = "\nstruct TestStruct {\n" + - "\tauto name;\n" + - "\tauto age;\n" + - "\tadd(auto a, auto b);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestStruct)\n" + - "{\n" + - "\tJSBIND_METHOD(add, \"add\");\n" + - "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + - "\tJSBIND_PROPERTY(name);\n" + - "\tJSBIND_PROPERTY(age);\n" + - "};\n"; - assertEquals(expect, structContent); - } - } - - @Test - void getStructContent4() { - StructObj so = new StructObj(); - so.setName("TestStruct"); - - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); - ParseObj po = new ParseObj(); - po.setStructList(sol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genStructList(po.getStructList()); - - if (gb instanceof GenAkiCppFile gdf) { - String structContent = gdf.getStructContent(); - System.out.println("genStruct: " + structContent); - String expect = "\nstruct TestStruct {\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestStruct)\n" + - "{\n" + - "};\n"; - assertEquals(expect, structContent); - } - } - - @Test - void getTypeContent() { - } - - @Test - void getUnionContent1() { - UnionObj uo = new UnionObj(); - uo.setName("TestUnion"); - - uo.addMember("name", "string"); - uo.addMember("age", "number"); - - List uol = new CopyOnWriteArrayList<>(); - uol.add(uo); - ParseObj po = new ParseObj(); - po.setUnionList(uol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genUnionList(po.getUnionList()); - - if (gb instanceof GenAkiCppFile gdf) { - String unionContent = gdf.getUnionContent(); - System.out.println("genUnion: " + unionContent); - String expect = "\nunion TestUnion{\n" + - "\tchar* name;\n" + - "\tint age;\n" + - "};\n"; - assertEquals(expect, unionContent); - } - } - - @Test - void getUnionContent2() { - UnionObj uo = new UnionObj(); - uo.setName("TestUnion"); - uo.addMember("name", "T"); - uo.addMember("age", "U"); - - uo.addTemplate("T"); - uo.addTemplate("U"); - - List uol = new CopyOnWriteArrayList<>(); - uol.add(uo); - ParseObj po = new ParseObj(); - po.setUnionList(uol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genUnionList(po.getUnionList()); - - if (gb instanceof GenAkiCppFile gdf) { - String unionContent = gdf.getUnionContent(); - System.out.println("genUnion: " + unionContent); - String expect = "\ntemplate union TestUnion{\n" + - "\tT name;\n" + - "\tU age;\n" + - "};\n"; - assertEquals(expect, unionContent); - } - } - - @Test - void getVarContent1() { - ParamObj paObj = new ParamObj(); - paObj.setName("employeeName"); - paObj.setStrValue("\"John\""); - - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); - ParseObj po = new ParseObj(); - po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); - - if (gb instanceof GenAkiCppFile gdf) { - String constContent = gdf.getConstContent(); - System.out.println("getVar: " + constContent); - String expect = "\nextends const auto employeeName = \"John\";\n"; - assertEquals(expect, constContent); - } - } - - @Test - void getVarContent2() { - ParamObj paObj = new ParamObj(); - paObj.setName("employeeName"); - paObj.setType("string"); - paObj.setStrValue("\"John\""); - - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); - ParseObj po = new ParseObj(); - po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); - - if (gb instanceof GenAkiCppFile gdf) { - String constContent = gdf.getConstContent(); - System.out.println("getVar: " + constContent); - String expect = "\nextends const char* employeeName = \"John\";\n"; - assertEquals(expect, constContent); - } - } - - @Test - void getVarContent3() { - ParamObj paObj = new ParamObj(); - paObj.setName("num1"); - paObj.setType("number"); - paObj.setStrValue("1"); - - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); - ParseObj po = new ParseObj(); - po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); - - if (gb instanceof GenAkiCppFile gdf) { - String constContent = gdf.getConstContent(); - System.out.println("getVar: " + constContent); - String expect = "\nextends const int num1 = 1;\n"; - assertEquals(expect, constContent); - } - } - - @Test - void getVarContent4() { - ParamObj paObj = new ParamObj(); - paObj.setName("playerCodes"); - - ParamObj paItem1 = new ParamObj(); - paItem1.setName("player1"); - paItem1.setStrValue("9"); - paObj.addParam(paItem1); - ParamObj paItem2 = new ParamObj(); - paItem2.setName("player2"); - paItem2.setStrValue("10"); - paObj.addParam(paItem2); - - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); - ParseObj po = new ParseObj(); - po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); - - if (gb instanceof GenAkiCppFile gdf) { - String constContent = gdf.getConstContent(); - System.out.println("getVar: " + constContent); - String expect = "\nextends const std::map pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); - ParseObj po = new ParseObj(); - po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); - - if (gb instanceof GenAkiCppFile gdf) { - String constContent = gdf.getConstContent(); - System.out.println("getVar: " + constContent); - String expect = "\nextends const auto playerCodes.player2 = 11;\n"; - assertEquals(expect, constContent); - } - } - - @Test - void getVarContent6() { - ParamObj paObj = new ParamObj(); - paObj.setName("ROUTES"); - paObj.setType("any[]"); - - ParamObj paListItem1 = new ParamObj(); - ParamObj paItem1 = new ParamObj(); - paItem1.setName("path"); - paItem1.setStrValue("'/dashboard'"); - paListItem1.addParam(paItem1); - - ParamObj paItem3 = new ParamObj(); - paItem3.setName("allowAnonymous"); - paItem3.setStrValue("false"); - paListItem1.addParam(paItem3); - paObj.addParam(paListItem1); - - ParamObj paListItem2 = new ParamObj(); - ParamObj paItem21 = new ParamObj(); - paItem21.setName("path"); - paItem21.setStrValue("'/deals'"); - paListItem2.addParam(paItem21); - - ParamObj paItem23 = new ParamObj(); - paItem23.setName("allowAnonymous"); - paItem23.setStrValue("true"); - paListItem2.addParam(paItem23); - paObj.addParam(paListItem2); - - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); - ParseObj po = new ParseObj(); - po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); - - if (gb instanceof GenAkiCppFile gdf) { - String constContent = gdf.getConstContent(); - System.out.println("getVar: " + constContent); - String expect = "\nstruct ROUTESST {\n" + - "\tstd::string path;\n" + - "\tboolean allowAnonymous;\n" + - "};\n" + - "\n" + - "const std::vector ROUTES = {\n" + - "\t{'/dashboard', false},\n" + - "\t{'/deals', true},\n" + - "};\n"; - assertEquals(expect, constContent); - } - } - - @Test - void getConstContent() { - ParseObj po = new ParseObj(); - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("int"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); - po.setVarList(pol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(pol); - - if (gb instanceof GenAkiCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); - } - } - - @Test - void genContent() { - ParseObj po = new ParseObj(); - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("int"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); - po.setVarList(pol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genContent(po); - - if (gb instanceof GenAkiCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); - } - } - - @Test - void genFile() { - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("int"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); - - ParseObj po = new ParseObj(); - po.setVarList(pol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genContent(po); - gb.genFile("./", "testGenFile.h"); - - File file = new File("./ag_akitestGenFile_h.cpp"); - assertEquals(true, file.exists()); - assertEquals(false, file.isDirectory()); - - List fcList = readText("./ag_akitestGenFile_h.cpp"); - - assertEquals("// Generated from ./\\testGenFile.h by KaiHong ohgen 1.0.0-PLUGIN", - fcList.get(0)); - - assertEquals("#include ", - fcList.get(1)); - assertEquals("#include ", - fcList.get(2)); - assertEquals("", - fcList.get(3)); - assertEquals("JSBIND_ADDON(testGenFileh)", - fcList.get(4)); - assertEquals("extends const int TestParam = 100;", - fcList.get(6)); - - if (gb instanceof GenAkiCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); - } - } - - @Test - void genInterfaceList() { - } - - @Test - void genEnumList() { - EnumObj eo = new EnumObj(); - eo.setName("TestEnum"); - List ml = new CopyOnWriteArrayList<>(); - ml.add("ONE"); - ml.add("TWO"); - eo.setMemberList(ml); - List vl = new CopyOnWriteArrayList<>(); - vl.add("1"); - vl.add("2"); - eo.setValueList(vl); - List eol = new CopyOnWriteArrayList<>(); - eol.add(eo); - ParseObj po = new ParseObj(); - po.setEnumList(eol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genEnumList(po.getEnumList()); - - if (gb instanceof GenAkiCppFile gdf) { - String enumContent = gdf.getEnumContent(); - System.out.println("genEnum: " + enumContent); - String expect = "\nenum TestEnum {\n" + - "\tONE = 1,\n" + - "\tTWO = 2,\n" + - "};\n" + - "\n" + - "JSBIND_ENUM(TestEnum) {\n" + - "\tJSBIND_ENUM_VALUE(ONE);\n" + - "\tJSBIND_ENUM_VALUE(TWO);\n" + - "};\n"; - assertEquals(expect, enumContent); - } - } - - @Test - void genClassList() { - ClassObj co = new ClassObj(); - co.setName("TestClass"); - - co.addParam("name", "string"); - co.addParam("age", "number"); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType("number"); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType("number"); - poList.add(poItem2); - - co.addFunc("add", "number", poList); - - poList = new CopyOnWriteArrayList<>(); - poItem = new ParamObj(); - poItem.setType("number"); - poList.add(poItem); - - co.addFunc("delete", "number", poList); - - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenAkiCppFile gdf) { - String classContent = gdf.getClassContent(); - System.out.println("genClass: " + classContent); - String expect = "\nclass TestClass {\n" + - "\tchar* name;\n" + - "\tint age;\n" + - "\tint add(int a, int b);\n" + - "\tint delete(int);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestClass)\n" + - "{\n" + - "\tJSBIND_METHOD(add, \"add\");\n" + - "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + - "\tJSBIND_METHOD(delete, \"delete\");\n" + - "\tJSBIND_PMETHOD(delete, \"deletePromise\");\n" + - "\tJSBIND_PROPERTY(name);\n" + - "\tJSBIND_PROPERTY(age);\n" + - "};\n"; - assertEquals(expect, classContent); - } - } - - @Test - void genFuncList() { - FuncObj fo = new FuncObj(); - fo.setName("TestFunc"); - fo.setRetValue("void"); - fo.addParam("name", "string"); - fo.addParam("age", "number"); - List fol = new CopyOnWriteArrayList<>(); - fol.add(fo); - ParseObj po = new ParseObj(); - po.setFuncList(fol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); - - if (gb instanceof GenAkiCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nvoid TestFunc(char* name, int age);\n" + - "\n" + - "JSBIND_GLOBAL()\n" + - "{\n" + - "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + - "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + - "};\n"; - assertEquals(expect, funcContent); - } - } - - @Test - void genStructList() { - StructObj so = new StructObj(); - so.setName("TestStruct"); - - so.addMember("name", "string"); - so.addMember("age", "number"); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType("int"); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType("int"); - poList.add(poItem2); - - so.addFunc("add", "int", poList); - - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); - ParseObj po = new ParseObj(); - po.setStructList(sol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genStructList(po.getStructList()); - - if (gb instanceof GenAkiCppFile gdf) { - String structContent = gdf.getStructContent(); - System.out.println("genStruct: " + structContent); - String expect = "\nstruct TestStruct {\n" + - "\tchar* name;\n" + - "\tint age;\n" + - "\tint add(int a, int b);\n" + - "};\n" + - "\n" + - "JSBIND_CLASS(TestStruct)\n" + - "{\n" + - "\tJSBIND_METHOD(add, \"add\");\n" + - "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + - "\tJSBIND_PROPERTY(name);\n" + - "\tJSBIND_PROPERTY(age);\n" + - "};\n"; - assertEquals(expect, structContent); - } - } - - @Test - void genTypeList() { - TypeObj to = new TypeObj(); - } - - @Test - void genUnionList() { - UnionObj uo = new UnionObj(); - uo.setName("TestUnion"); - - uo.addMember("name", "any"); - uo.addMember("age", "number"); - - List uol = new CopyOnWriteArrayList<>(); - uol.add(uo); - ParseObj po = new ParseObj(); - po.setUnionList(uol); - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genUnionList(po.getUnionList()); - - if (gb instanceof GenAkiCppFile gdf) { - String unionContent = gdf.getUnionContent(); - System.out.println("genUnion: " + unionContent); - String expect = "\nunion TestUnion{\n" + - "\tauto name;\n" + - "\tint age;\n" + - "};\n"; - assertEquals(expect, unionContent); - } - } - - @Test - void genVarList() { - ParseObj po = new ParseObj(); - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("number"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); - po.setVarList(pol); - - GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(pol); - - if (gb instanceof GenAkiCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); - } - } -} \ No newline at end of file -- Gitee From 9ad4cb8e19ae0d330a0a2133d1d0386853f3feb6 Mon Sep 17 00:00:00 2001 From: wangshi Date: Mon, 28 Apr 2025 16:55:17 +0800 Subject: [PATCH 2/6] add 20 types Signed-off-by: wangshi --- .../src/test/java/gen/GenAkiCppFileTest3.java | 720 ++++++++++++++++++ 1 file changed, 720 insertions(+) create mode 100644 src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java new file mode 100644 index 00000000..dfec825b --- /dev/null +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java @@ -0,0 +1,720 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital. + * 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. + */ + +package gen; + +import grammar.*; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static utils.FileUtils.readText; + +/** + *

类名:该类用于xxx

+ * description + * + * @author Administrator + * date 2025-02-28 + * @version 1.0 + * @since 2025-02-28 + */ +class GenAkiCppFileTest3 { + private String structListContent1 = "\nstruct TestStruct {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tlong p1;\n" + + "\tshort p2;\n" + + "\tlong long p3;\n" + + "\tfloat p4;\n" + + "\tdouble p5;\n" + + "\tuint8 p6;\n" + + "\tuint16 p7;\n" + + "\tuint32 p8;\n" + + "\tuint64 p9;\n" + + "\tint8 p10;\n" + + "\tint16 p11;\n" + + "\tint32 p12;\n" + + "\tint64 p13;\n" + + "\tsize_t p14;\n" + + "\tstd::string p15;\n" + + "\tstd::string p16;\n" + + "\tstd::array p17;\n" + + "\tstd::stack p18;\n" + + "\tstd::vector p19;\n" + + "\tstd::queue p20;\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "\tJSBIND_PROPERTY(p1);\n" + + "\tJSBIND_PROPERTY(p2);\n" + + "\tJSBIND_PROPERTY(p3);\n" + + "\tJSBIND_PROPERTY(p4);\n" + + "\tJSBIND_PROPERTY(p5);\n" + + "\tJSBIND_PROPERTY(p6);\n" + + "\tJSBIND_PROPERTY(p7);\n" + + "\tJSBIND_PROPERTY(p8);\n" + + "\tJSBIND_PROPERTY(p9);\n" + + "\tJSBIND_PROPERTY(p10);\n" + + "\tJSBIND_PROPERTY(p11);\n" + + "\tJSBIND_PROPERTY(p12);\n" + + "\tJSBIND_PROPERTY(p13);\n" + + "\tJSBIND_PROPERTY(p14);\n" + + "\tJSBIND_PROPERTY(p15);\n" + + "\tJSBIND_PROPERTY(p16);\n" + + "\tJSBIND_PROPERTY(p17);\n" + + "\tJSBIND_PROPERTY(p18);\n" + + "\tJSBIND_PROPERTY(p19);\n" + + "\tJSBIND_PROPERTY(p20);\n" + + "};\n"; + + private String structListContent2 = "\nstruct TestStruct {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tint add(int a, int b);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "\tJSBIND_METHOD(add, \"add\");\n" + + "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "};\n"; + + @Test + void genStructList1() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + + so.addMember("name", "string"); + so.addMember("age", "number"); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj poItem = new ParamObj(); + poItem.setName("a"); + poItem.setType("int"); + poList.add(poItem); + ParamObj poItem2 = new ParamObj(); + poItem2.setName("b"); + poItem2.setType("int"); + poList.add(poItem2); + + so.addFunc("add", "int", poList); + + List sol = new CopyOnWriteArrayList<>(); + sol.add(so); + ParseObj po = new ParseObj(); + po.setStructList(sol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenAkiCppFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = structListContent2; + assertEquals(expect, structContent); + } + } + + @Test + void genStructList2() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + + so.addMember("name", "string"); + so.addMember("age", "number"); + + so.addMember("p1", "long"); + so.addMember("p2", "short"); + so.addMember("p3", "long long"); + so.addMember("p4", "float"); + so.addMember("p5", "double"); + so.addMember("p6", "uint8"); + so.addMember("p7", "uint16"); + so.addMember("p8", "uint32"); + so.addMember("p9", "uint64"); + so.addMember("p10", "int8"); + so.addMember("p11", "int16"); + so.addMember("p12", "int32"); + so.addMember("p13", "int64"); + so.addMember("p14", "size_t"); + so.addMember("p15", "string"); + so.addMember("p16", "std::string"); + so.addMember("p17", "std::array"); + so.addMember("p18", "std::stack"); + so.addMember("p19", "std::vector"); + so.addMember("p20", "std::queue"); + + List sol = new CopyOnWriteArrayList<>(); + sol.add(so); + ParseObj po = new ParseObj(); + po.setStructList(sol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenAkiCppFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = structListContent1; + assertEquals(expect, structContent); + } + } + + @Test + void genTypeList() { + TypeObj to = new TypeObj(); + } + + @Test + void genUnionList() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "number"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tint age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genVarList1() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("number"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList2() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList3() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("long"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const long TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList4() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("short"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const short TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList5() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("long long"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const long long TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList6() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("float"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const float TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList7() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("double"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const double TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList8() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint8"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint8 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList9() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint16"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint16 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList10() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint32"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint32 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList11() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint64"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint64 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList12() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int8"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int8 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList13() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int16"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int16 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList14() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int32"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int32 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList15() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int64"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int64 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList16() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("size_t"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const size_t TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList17() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("string"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::string TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList18() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::string"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::string TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList19() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::array"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::array TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList20() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::stack"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::stack TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList21() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::vector"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::vector TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList22() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::queue"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::queue TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList23() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::map"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::map TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } +} \ No newline at end of file -- Gitee From af8e8f048573399b3008fed8deba523efc11a522 Mon Sep 17 00:00:00 2001 From: wangshi Date: Mon, 28 Apr 2025 16:55:22 +0800 Subject: [PATCH 3/6] add 20 types Signed-off-by: wangshi --- .../src/test/java/gen/GenAkiCppFileTest2.java | 1455 +++++++++++++++++ 1 file changed, 1455 insertions(+) create mode 100644 src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest2.java diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest2.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest2.java new file mode 100644 index 00000000..6901fcf5 --- /dev/null +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest2.java @@ -0,0 +1,1455 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital. + * 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. + */ + +package gen; + +import grammar.*; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static utils.FileUtils.readText; + +/** + *

类名:该类用于xxx

+ * description + * + * @author Administrator + * date 2025-02-28 + * @version 1.0 + * @since 2025-02-28 + */ +class GenAkiCppFileTest2 { + private String structListContent1 = "\nstruct TestStruct {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tlong p1;\n" + + "\tshort p2;\n" + + "\tlong long p3;\n" + + "\tfloat p4;\n" + + "\tdouble p5;\n" + + "\tuint8 p6;\n" + + "\tuint16 p7;\n" + + "\tuint32 p8;\n" + + "\tuint64 p9;\n" + + "\tint8 p10;\n" + + "\tint16 p11;\n" + + "\tint32 p12;\n" + + "\tint64 p13;\n" + + "\tsize_t p14;\n" + + "\tstd::string p15;\n" + + "\tstd::string p16;\n" + + "\tstd::array p17;\n" + + "\tstd::stack p18;\n" + + "\tstd::vector p19;\n" + + "\tstd::queue p20;\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "\tJSBIND_PROPERTY(p1);\n" + + "\tJSBIND_PROPERTY(p2);\n" + + "\tJSBIND_PROPERTY(p3);\n" + + "\tJSBIND_PROPERTY(p4);\n" + + "\tJSBIND_PROPERTY(p5);\n" + + "\tJSBIND_PROPERTY(p6);\n" + + "\tJSBIND_PROPERTY(p7);\n" + + "\tJSBIND_PROPERTY(p8);\n" + + "\tJSBIND_PROPERTY(p9);\n" + + "\tJSBIND_PROPERTY(p10);\n" + + "\tJSBIND_PROPERTY(p11);\n" + + "\tJSBIND_PROPERTY(p12);\n" + + "\tJSBIND_PROPERTY(p13);\n" + + "\tJSBIND_PROPERTY(p14);\n" + + "\tJSBIND_PROPERTY(p15);\n" + + "\tJSBIND_PROPERTY(p16);\n" + + "\tJSBIND_PROPERTY(p17);\n" + + "\tJSBIND_PROPERTY(p18);\n" + + "\tJSBIND_PROPERTY(p19);\n" + + "\tJSBIND_PROPERTY(p20);\n" + + "};\n"; + + private String structListContent2 = "\nstruct TestStruct {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tint add(int a, int b);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "\tJSBIND_METHOD(add, \"add\");\n" + + "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "};\n"; + + private String genClassContentExpect1 = "\nclass TestClass {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tlong p1;\n" + + "\tshort p2;\n" + + "\tlong long p3;\n" + + "\tfloat p4;\n" + + "\tdouble p5;\n" + + "\tuint8 p6;\n" + + "\tuint16 p7;\n" + + "\tuint32 p8;\n" + + "\tuint64 p9;\n" + + "\tint8 p10;\n" + + "\tint16 p11;\n" + + "\tint32 p12;\n" + + "\tint64 p13;\n" + + "\tsize_t p14;\n" + + "\tstd::string p15;\n" + + "\tstd::string p16;\n" + + "\tstd::array p17;\n" + + "\tstd::stack p18;\n" + + "\tstd::vector p19;\n" + + "\tstd::queue p20;\n" + + "\tint delete(int);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestClass)\n" + + "{\n" + + "\tJSBIND_METHOD(delete, \"delete\");\n" + + "\tJSBIND_PMETHOD(delete, \"deletePromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "\tJSBIND_PROPERTY(p1);\n" + + "\tJSBIND_PROPERTY(p2);\n" + + "\tJSBIND_PROPERTY(p3);\n" + + "\tJSBIND_PROPERTY(p4);\n" + + "\tJSBIND_PROPERTY(p5);\n" + + "\tJSBIND_PROPERTY(p6);\n" + + "\tJSBIND_PROPERTY(p7);\n" + + "\tJSBIND_PROPERTY(p8);\n" + + "\tJSBIND_PROPERTY(p9);\n" + + "\tJSBIND_PROPERTY(p10);\n" + + "\tJSBIND_PROPERTY(p11);\n" + + "\tJSBIND_PROPERTY(p12);\n" + + "\tJSBIND_PROPERTY(p13);\n" + + "\tJSBIND_PROPERTY(p14);\n" + + "\tJSBIND_PROPERTY(p15);\n" + + "\tJSBIND_PROPERTY(p16);\n" + + "\tJSBIND_PROPERTY(p17);\n" + + "\tJSBIND_PROPERTY(p18);\n" + + "\tJSBIND_PROPERTY(p19);\n" + + "\tJSBIND_PROPERTY(p20);\n" + + "};\n"; + + @Test + void getVarContent10() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("long long"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const long long num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent11() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("float"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const float num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent12() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("double"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const double num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent13() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("uint8"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const uint8 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent14() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("uint16"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const uint16 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent15() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("uint32"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const uint32 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent16() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("uint64"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const uint64 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent17() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int8"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int8 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent18() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int16"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int16 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent19() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int32"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int32 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent20() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int64"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int64 num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent21() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("size_t"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const size_t num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent22() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("string"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::string num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent23() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("std::string"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::string num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent24() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("std::array"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::array num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent25() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("std::stack"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::stack num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent26() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("std::vector"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::vector num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent27() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("std::queue"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::queue num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent28() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("std::map"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::map num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getConstContent() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(pol); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent() { + ParseObj po = new ParseObj(); + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genContent(po); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genFile() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + + ParseObj po = new ParseObj(); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genContent(po); + gb.genFile("./", "testGenFile.h"); + + File file = new File("./ag_akitestGenFile_h.cpp"); + assertEquals(true, file.exists()); + assertEquals(false, file.isDirectory()); + + List fcList = readText("./ag_akitestGenFile_h.cpp"); + + assertEquals("// Generated from ./\\testGenFile.h by KaiHong ohgen 1.0.0-PLUGIN", + fcList.get(0)); + + assertEquals("#include ", + fcList.get(1)); + assertEquals("#include ", + fcList.get(2)); + assertEquals("", + fcList.get(3)); + assertEquals("JSBIND_ADDON(testGenFileh)", + fcList.get(4)); + assertEquals("extends const int TestParam = 100;", + fcList.get(6)); + + if (gb instanceof GenAkiCppFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genInterfaceList() { + } + + @Test + void genEnumList() { + EnumObj eo = new EnumObj(); + eo.setName("TestEnum"); + List ml = new CopyOnWriteArrayList<>(); + ml.add("ONE"); + ml.add("TWO"); + eo.setMemberList(ml); + List vl = new CopyOnWriteArrayList<>(); + vl.add("1"); + vl.add("2"); + eo.setValueList(vl); + List eol = new CopyOnWriteArrayList<>(); + eol.add(eo); + ParseObj po = new ParseObj(); + po.setEnumList(eol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genEnumList(po.getEnumList()); + + if (gb instanceof GenAkiCppFile gdf) { + String enumContent = gdf.getEnumContent(); + System.out.println("genEnum: " + enumContent); + String expect = "\nenum TestEnum {\n" + + "\tONE = 1,\n" + + "\tTWO = 2,\n" + + "};\n" + + "\n" + + "JSBIND_ENUM(TestEnum) {\n" + + "\tJSBIND_ENUM_VALUE(ONE);\n" + + "\tJSBIND_ENUM_VALUE(TWO);\n" + + "};\n"; + assertEquals(expect, enumContent); + } + } + + @Test + void genClassList1() { + ClassObj co = new ClassObj(); + co.setName("TestClass"); + + co.addParam("name", "string"); + co.addParam("age", "number"); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj poItem = new ParamObj(); + poItem.setName("a"); + poItem.setType("number"); + poList.add(poItem); + ParamObj poItem2 = new ParamObj(); + poItem2.setName("b"); + poItem2.setType("number"); + poList.add(poItem2); + + co.addFunc("add", "number", poList); + + poList = new CopyOnWriteArrayList<>(); + poItem = new ParamObj(); + poItem.setType("number"); + poList.add(poItem); + + co.addFunc("delete", "number", poList); + + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = "\nclass TestClass {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tint add(int a, int b);\n" + + "\tint delete(int);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestClass)\n" + + "{\n" + + "\tJSBIND_METHOD(add, \"add\");\n" + + "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + + "\tJSBIND_METHOD(delete, \"delete\");\n" + + "\tJSBIND_PMETHOD(delete, \"deletePromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "};\n"; + assertEquals(expect, classContent); + } + } + + @Test + void genClassList2() { + ClassObj co = new ClassObj(); + co.setName("TestClass"); + + co.addParam("name", "string"); + co.addParam("age", "number"); + co.addParam("p1", "long"); + co.addParam("p2", "short"); + co.addParam("p3", "long long"); + co.addParam("p4", "float"); + co.addParam("p5", "double"); + co.addParam("p6", "uint8"); + co.addParam("p7", "uint16"); + co.addParam("p8", "uint32"); + co.addParam("p9", "uint64"); + co.addParam("p10", "int8"); + co.addParam("p11", "int16"); + co.addParam("p12", "int32"); + co.addParam("p13", "int64"); + co.addParam("p14", "size_t"); + co.addParam("p15", "string"); + co.addParam("p16", "std::string"); + co.addParam("p17", "std::array"); + co.addParam("p18", "std::stack"); + co.addParam("p19", "std::vector"); + co.addParam("p20", "std::queue"); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj poItem; + poItem = new ParamObj(); + poItem.setType("number"); + poList.add(poItem); + + co.addFunc("delete", "number", poList); + + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = genClassContentExpect1; + assertEquals(expect, classContent); + } + } + + @Test + void genFuncList1() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "number"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList2() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "int"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList3() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "long"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, long age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList4() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "short"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, short age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList5() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "long long"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, long long age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList6() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "float"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, float age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList7() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "double"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, double age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList8() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "uint8"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint8 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList9() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "uint16"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint16 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList10() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "uint32"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint32 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList11() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "uint64"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint64 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList12() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "int8"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int8 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList13() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "int16"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int16 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList14() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "int32"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int32 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList15() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "int64"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int64 age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList16() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "size_t"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, size_t age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList17() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "string"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::string age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList18() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "std::string"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::string age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList19() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "std::array"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::array age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList20() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "std::stack"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::stack age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList21() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "std::vector"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::vector age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList22() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "std::queue"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::queue age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList23() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "std::map"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::map age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } +} \ No newline at end of file -- Gitee From 17ec5b19514d47a786d2ec2b8cc328db91eca23f Mon Sep 17 00:00:00 2001 From: wangshi Date: Mon, 28 Apr 2025 18:11:12 +0800 Subject: [PATCH 4/6] add 20type tests Signed-off-by: wangshi --- .../src/test/java/gen/GenAkiCppFileTest1.java | 1804 +++++++++++++++++ 1 file changed, 1804 insertions(+) create mode 100644 src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest1.java diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest1.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest1.java new file mode 100644 index 00000000..84980f67 --- /dev/null +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest1.java @@ -0,0 +1,1804 @@ +/* + * Copyright (c) 2025 Shenzhen Kaihong Digital. + * 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. + */ + +package gen; + +import grammar.*; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + *

类名:该类用于xxx

+ * description + * + * @author Administrator + * date 2025-02-28 + * @version 1.0 + * @since 2025-02-28 + */ +class GenAkiCppFileTest1 { + private String classContentExpect2 = "\nclass TestClass : public IPerson {\n" + + "\tpublic std::string name;\n" + + "\tprivate int age;\n" + + "\tprotected std::string no;\n" + + "\treadonly std::string addr;\n" + + "\tconstructor();\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestClass)\n" + + "{\n" + + "\tJSBIND_CONSTRUCTOR<>();\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "\tJSBIND_PROPERTY(no);\n" + + "\tJSBIND_PROPERTY(addr);\n" + + "};\n"; + + private String classContentExpect3 = "\nclass Employee : public Person {\n" + + "\tint empCode;\n" + + "\tauto currentUser;\n" + + "\tstatic int pi = 3.14;\n" + + "\tconstructor();\n" + + "\tvoid displayName();\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(Employee)\n" + + "{\n" + + "\tJSBIND_CONSTRUCTOR<>();\n" + + "\tJSBIND_METHOD(displayName, \"displayName\");\n" + + "\tJSBIND_PMETHOD(displayName, \"displayNamePromise\");\n" + + "\tJSBIND_PROPERTY(empCode);\n" + + "\tJSBIND_PROPERTY(currentUser);\n" + + "\tJSBIND_PROPERTY(pi);\n" + + "};\n"; + + private String classContentExpect9 = "\nclass myClass2 {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tlong p1;\n" + + "\tshort p2;\n" + + "\tlong long p3;\n" + + "\tfloat p4;\n" + + "\tdouble p5;\n" + + "\tuint8 p6;\n" + + "\tuint16 p7;\n" + + "\tuint32 p8;\n" + + "\tuint64 p9;\n" + + "\tint8 p10;\n" + + "\tint16 p11;\n" + + "\tint32 p12;\n" + + "\tint64 p13;\n" + + "\tsize_t p14;\n" + + "\tstd::string p15;\n" + + "\tstd::string p16;\n" + + "\tstd::array p17;\n" + + "\tstd::stack p18;\n" + + "\tstd::vector p19;\n" + + "\tstd::queue p20;\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(myClass2)\n" + + "{\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "\tJSBIND_PROPERTY(p1);\n" + + "\tJSBIND_PROPERTY(p2);\n" + + "\tJSBIND_PROPERTY(p3);\n" + + "\tJSBIND_PROPERTY(p4);\n" + + "\tJSBIND_PROPERTY(p5);\n" + + "\tJSBIND_PROPERTY(p6);\n" + + "\tJSBIND_PROPERTY(p7);\n" + + "\tJSBIND_PROPERTY(p8);\n" + + "\tJSBIND_PROPERTY(p9);\n" + + "\tJSBIND_PROPERTY(p10);\n" + + "\tJSBIND_PROPERTY(p11);\n" + + "\tJSBIND_PROPERTY(p12);\n" + + "\tJSBIND_PROPERTY(p13);\n" + + "\tJSBIND_PROPERTY(p14);\n" + + "\tJSBIND_PROPERTY(p15);\n" + + "\tJSBIND_PROPERTY(p16);\n" + + "\tJSBIND_PROPERTY(p17);\n" + + "\tJSBIND_PROPERTY(p18);\n" + + "\tJSBIND_PROPERTY(p19);\n" + + "\tJSBIND_PROPERTY(p20);\n" + + "};\n"; + + @Test + void getInterfaceContent() { + } + + @Test + void getEnumContent1() { + EnumObj eo = new EnumObj(); + eo.setName("TestEnum"); + List ml = new CopyOnWriteArrayList<>(); + ml.add("ONE"); + ml.add("TWO"); + eo.setMemberList(ml); + List eol = new CopyOnWriteArrayList<>(); + eol.add(eo); + ParseObj po = new ParseObj(); + po.setEnumList(eol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genEnumList(po.getEnumList()); + + if (gb instanceof GenAkiCppFile gdf) { + String enumContent = gdf.getEnumContent(); + System.out.println("genEnum: " + enumContent); + String expect = "\nenum TestEnum {\n" + + "\tONE,\n" + + "\tTWO,\n" + + "};\n" + + "\n" + + "JSBIND_ENUM(TestEnum) {\n" + + "\tJSBIND_ENUM_VALUE(ONE);\n" + + "\tJSBIND_ENUM_VALUE(TWO);\n" + + "};\n"; + assertEquals(expect, enumContent); + } + } + + @Test + void getEnumContent2() { + EnumObj eo = new EnumObj(); + eo.setName("Colors"); + List ml = new CopyOnWriteArrayList<>(); + ml.add("Red"); + ml.add("Green"); + ml.add("Blue"); + eo.setMemberList(ml); + List vl = new CopyOnWriteArrayList<>(); + vl.add("RED"); + vl.add("GREEN"); + vl.add("BLUE"); + eo.setValueList(vl); + List eol = new CopyOnWriteArrayList<>(); + eol.add(eo); + ParseObj po = new ParseObj(); + po.setEnumList(eol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genEnumList(po.getEnumList()); + + if (gb instanceof GenAkiCppFile gdf) { + String enumContent = gdf.getEnumContent(); + System.out.println("genEnum: " + enumContent); + String expect = "\nenum Colors {\n" + + "\tRed = RED,\n" + + "\tGreen = GREEN,\n" + + "\tBlue = BLUE,\n" + + "};\n" + + "\n" + + "JSBIND_ENUM(Colors) {\n" + + "\tJSBIND_ENUM_VALUE(Red);\n" + + "\tJSBIND_ENUM_VALUE(Green);\n" + + "\tJSBIND_ENUM_VALUE(Blue);\n" + + "};\n"; + assertEquals(expect, enumContent); + } + } + + @Test + void getEnumContent3() { + EnumObj eo = new EnumObj(); + eo.setName("Colors"); + List ml = new CopyOnWriteArrayList<>(); + ml.add("Red"); + ml.add("Green"); + ml.add("Blue"); + eo.setMemberList(ml); + List vl = new CopyOnWriteArrayList<>(); + vl.add("\"RED\""); + vl.add("\"GREEN\""); + vl.add("\"BLUE\""); + eo.setValueList(vl); + List eol = new CopyOnWriteArrayList<>(); + eol.add(eo); + ParseObj po = new ParseObj(); + po.setEnumList(eol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genEnumList(po.getEnumList()); + + if (gb instanceof GenAkiCppFile gdf) { + String enumContent = gdf.getEnumContent(); + System.out.println("genEnum: " + enumContent); + String expect = "\nenum Colors {\n" + + "\tRed = RED,\n" + + "\tGreen = GREEN,\n" + + "\tBlue = BLUE,\n" + + "};\n" + + "\n" + + "std::string colors_STR[] = {\n" + + "\t[Red] = \"RED\",\n" + + "\t[Green] = \"GREEN\",\n" + + "\t[Blue] = \"BLUE\"\n" + + "};\n" + + "\n" + + "JSBIND_ENUM(Colors) {\n" + + "\tJSBIND_ENUM_VALUE(Red);\n" + + "\tJSBIND_ENUM_VALUE(Green);\n" + + "\tJSBIND_ENUM_VALUE(Blue);\n" + + "};\n"; + assertEquals(expect, enumContent); + } + } + + @Test + void getEnumContent4() { + EnumObj eo = new EnumObj(); + eo.setName("TestEnum"); + List ml = new CopyOnWriteArrayList<>(); + ml.add("ONE"); + ml.add("TWO"); + eo.setMemberList(ml); + + EnumObj eo1 = new EnumObj(); + eo1.setName("Colors"); + List ml1 = new CopyOnWriteArrayList<>(); + ml1.add("BLACK"); + ml1.add("WHITE"); + eo1.setMemberList(ml1); + + List eol = new CopyOnWriteArrayList<>(); + eol.add(eo); + eol.add(eo1); + + ParseObj po = new ParseObj(); + po.setEnumList(eol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genEnumList(po.getEnumList()); + + if (gb instanceof GenAkiCppFile gdf) { + String enumContent = gdf.getEnumContent(); + System.out.println("genEnum: " + enumContent); + String expect = "\nenum TestEnum {\n" + + "\tONE,\n" + + "\tTWO,\n" + + "};\n" + + "\n" + + "JSBIND_ENUM(TestEnum) {\n" + + "\tJSBIND_ENUM_VALUE(ONE);\n" + + "\tJSBIND_ENUM_VALUE(TWO);\n" + + "};\n" + + "\n" + + "enum Colors {\n" + + "\tBLACK,\n" + + "\tWHITE,\n" + + "};\n" + + "\n" + + "JSBIND_ENUM(Colors) {\n" + + "\tJSBIND_ENUM_VALUE(BLACK);\n" + + "\tJSBIND_ENUM_VALUE(WHITE);\n" + + "};\n"; + assertEquals(expect, enumContent); + } + } + + @Test + void getClassContent1() { + ClassObj co = new ClassObj(); + co.setName("TestClass"); + + co.addParam("name", "string"); + co.addParam("age", "number"); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj poItem = new ParamObj(); + poItem.setName("a"); + poItem.setType("number"); + poList.add(poItem); + ParamObj poItem2 = new ParamObj(); + poItem2.setName("b"); + poItem2.setType("number"); + poList.add(poItem2); + + co.addFunc("add", "number", poList); + + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = "\nclass TestClass {\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "\tint add(int a, int b);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestClass)\n" + + "{\n" + + "\tJSBIND_METHOD(add, \"add\");\n" + + "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "};\n"; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent2() { + ClassObj co = new ClassObj(); + co.setName("TestClass"); + List hList = new CopyOnWriteArrayList<>(); + hList.add("IPerson"); + co.setHeritageNameList(hList); + + ParamObj pa = new ParamObj(); + pa.setName("name"); + pa.setType("string"); + pa.setQualifier("public"); + co.addParam(pa); + ParamObj pa1 = new ParamObj(); + pa1.setName("age"); + pa1.setType("number"); + pa1.setQualifier("private"); + co.addParam(pa1); + ParamObj pa2 = new ParamObj(); + pa2.setName("no"); + pa2.setType("string"); + pa2.setQualifier("protected"); + co.addParam(pa2); + ParamObj pa3 = new ParamObj(); + pa3.setName("addr"); + pa3.setType("string"); + pa3.setQualifier("readonly"); + co.addParam(pa3); + + List poList = new CopyOnWriteArrayList<>(); + co.addFunc("constructor", "", poList); + + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = classContentExpect2; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent3() { + ClassObj co = new ClassObj(); + co.setName("Employee"); + List hList = new CopyOnWriteArrayList<>(); + hList.add("Person"); + co.setHeritageNameList(hList); + + ParamObj pa = new ParamObj(); + pa.setName("empCode"); + pa.setType("number"); + co.addParam(pa); + + ParamObj pa1 = new ParamObj(); + pa1.setName("currentUser"); + pa1.setType("any"); + co.addParam(pa1); + + ParamObj pa2 = new ParamObj(); + pa2.setName("pi"); + pa2.setType("number"); + pa2.setQualifier("static"); + pa2.setStrValue("3.14"); + co.addParam(pa2); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj p1 = new ParamObj(); + p1.setName("empcode"); + p1.setType("number"); + ParamObj p2 = new ParamObj(); + p2.setName("name"); + p2.setType("string"); + co.addFunc("constructor", "", poList); + List poList1 = new CopyOnWriteArrayList<>(); + co.addFunc("displayName", "void", poList1); + + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = classContentExpect3; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent4() { + ClassObj co = new ClassObj(); + co.setName("myClass"); + + List poList1 = new CopyOnWriteArrayList<>(); + FuncObj fo = new FuncObj(); + fo.setName("foo"); + fo.setRetValue("Promise"); + fo.setAccessor("public"); + fo.setType("async"); + fo.setParamList(poList1); + co.addFunc(fo); + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = "\nclass myClass {\n" + + "\tauto foo();\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(myClass)\n" + + "{\n" + + "\tJSBIND_METHOD(foo, \"foo\");\n" + + "\tJSBIND_PMETHOD(foo, \"fooPromise\");\n" + + "};\n"; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent5() { + ClassObj co = new ClassObj(); + co.setName("KeyValuePair"); + List pol = new CopyOnWriteArrayList<>(); + ParamObj pa = new ParamObj(); + pa.setName("key"); + pa.setType("T"); + pa.setQualifier("private"); + pol.add(pa); + ParamObj po1 = new ParamObj(); + po1.setName("val"); + po1.setType("U"); + po1.setQualifier("private"); + pol.add(po1); + co.setParamList(pol); + + List tmpList = new CopyOnWriteArrayList<>(); + tmpList.add("T"); + tmpList.add("U"); + co.setTempList(tmpList); + + List poList1 = new CopyOnWriteArrayList<>(); + FuncObj fo = new FuncObj(); + fo.setName("setKeyValue"); + fo.setRetValue("void"); + fo.addParam("key", "T"); + fo.addParam("val", "U"); + co.addFunc(fo); + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = "\ntemplate class KeyValuePair {\n" + + "\tprivate T key;\n" + + "\tprivate U val;\n" + + "\tvoid setKeyValue(T key, U val);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(KeyValuePair)\n" + + "{\n" + + "\tJSBIND_METHOD(setKeyValue, \"setKeyValue\");\n" + + "\tJSBIND_PMETHOD(setKeyValue, \"setKeyValuePromise\");\n" + + "\tJSBIND_PROPERTY(key);\n" + + "\tJSBIND_PROPERTY(val);\n" + + "};\n"; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent6() { + ClassObj co = new ClassObj(); + co.setName("kvProcessor"); + List tmpList = new CopyOnWriteArrayList<>(); + tmpList.add("T"); + tmpList.add("U"); + co.setTempList(tmpList); + List htList = new CopyOnWriteArrayList<>(); + htList.add("implements"); + co.setHeritageTypeList(htList); + List hnList = new CopyOnWriteArrayList<>(); + hnList.add("IKeyValueProcessor"); + co.setHeritageNameList(hnList); + List htempList = new CopyOnWriteArrayList<>(); + htempList.add("T"); + htempList.add("U"); + co.setHeritageTemplateList(htempList); + + List poList1 = new CopyOnWriteArrayList<>(); + FuncObj fo = new FuncObj(); + fo.setName("process"); + fo.setRetValue("void"); + fo.addParam("key", "T"); + fo.addParam("val", "U"); + co.addFunc(fo); + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = "\ntemplate class kvProcessor : " + + "public IKeyValueProcessor {\n" + + "\tvoid process(T key, U val);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(kvProcessor)\n" + + "{\n" + + "\tJSBIND_METHOD(process, \"process\");\n" + + "\tJSBIND_PMETHOD(process, \"processPromise\");\n" + + "};\n"; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent7() { + ClassObj co = new ClassObj(); + co.setName("Shape"); + + FuncObj fo = new FuncObj(); + fo.setName("process"); + fo.setRetValue("void"); + fo.addParam("key", ""); + fo.addParam("val", ""); + co.addFunc(fo); + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = "\nclass Shape {\n" + + "\tvoid process(auto key, auto val);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(Shape)\n" + + "{\n" + + "\tJSBIND_METHOD(process, \"process\");\n" + + "\tJSBIND_PMETHOD(process, \"processPromise\");\n" + + "};\n"; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent8() { + ClassObj co = new ClassObj(); + co.setName("myClass"); + + List poList1 = new CopyOnWriteArrayList<>(); + FuncObj fo = new FuncObj(); + fo.setName("foo"); + fo.setRetValue("Promise"); + fo.setAccessor("public"); + fo.setType("async"); + fo.setParamList(poList1); + co.addFunc(fo); + + ClassObj co1 = new ClassObj(); + co1.setName("myClass2"); + + List col = new CopyOnWriteArrayList<>(); + col.add(co); + col.add(co1); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = "\nclass myClass {\n" + + "\tauto foo();\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(myClass)\n" + + "{\n" + + "\tJSBIND_METHOD(foo, \"foo\");\n" + + "\tJSBIND_PMETHOD(foo, \"fooPromise\");\n" + + "};\n" + + "\n" + + "class myClass2 {\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(myClass2)\n" + + "{\n" + + "};\n"; + assertEquals(expect, classContent); + } + } + + @Test + void getClassContent9() { + ClassObj co = new ClassObj(); + co.setName("myClass2"); + + co.addParam("name", "string"); + co.addParam("age", "number"); + co.addParam("p1", "long"); + co.addParam("p2", "short"); + co.addParam("p3", "long long"); + co.addParam("p4", "float"); + co.addParam("p5", "double"); + co.addParam("p6", "uint8"); + co.addParam("p7", "uint16"); + co.addParam("p8", "uint32"); + co.addParam("p9", "uint64"); + co.addParam("p10", "int8"); + co.addParam("p11", "int16"); + co.addParam("p12", "int32"); + co.addParam("p13", "int64"); + co.addParam("p14", "size_t"); + co.addParam("p15", "string"); + co.addParam("p16", "std::string"); + co.addParam("p17", "std::array"); + co.addParam("p18", "std::stack"); + co.addParam("p19", "std::vector"); + co.addParam("p20", "std::queue"); + + List col = new CopyOnWriteArrayList<>(); + col.add(co); + + ParseObj po = new ParseObj(); + po.setClassList(col); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenAkiCppFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = classContentExpect9; + assertEquals(expect, classContent); + } + } + + @Test + void getFuncContent1() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + fo.addParam("age", "number"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int age);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent2() { + FuncObj fo = new FuncObj(); + fo.setName("ToCapital"); + fo.setRetValue("string"); + fo.addParam("str", "string"); + ParamObj pa = new ParamObj(); + pa.setName("length"); + pa.setType("number"); + pa.setStrValue("0"); + fo.addParam(pa); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nstd::string ToCapital(std::string str, int length = 0);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(ToCapital, \"ToCapital\");\n" + + "\tJSBIND_PFUNCTION(ToCapital, \"ToCapitalPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent3() { + FuncObj fo = new FuncObj(); + fo.setName("Nemw"); + fo.setRetValue("string"); + ParamObj pa1 = new ParamObj(); + pa1.setName("str"); + pa1.setType("string"); + pa1.setStrValue("\"joke\""); + fo.addParam(pa1); + ParamObj pa2 = new ParamObj(); + pa2.setName("length"); + pa2.setType("number"); + pa2.setStrValue("0"); + fo.addParam(pa2); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nstd::string Nemw(std::string str = \"joke\", int length = 0);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + + "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent4() { + FuncObj fo = new FuncObj(); + fo.setName("Nemw"); + fo.setRetValue("string"); + ParamObj pa1 = new ParamObj(); + pa1.setName("str"); + fo.addParam(pa1); + ParamObj pa2 = new ParamObj(); + pa2.setName("length"); + fo.addParam(pa2); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nstd::string Nemw(auto str, auto length);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + + "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent5() { + FuncObj fo = new FuncObj(); + fo.setName("Nemw"); + fo.setRetValue(""); + ParamObj pa1 = new ParamObj(); + pa1.setName("str"); + fo.addParam(pa1); + ParamObj pa2 = new ParamObj(); + pa2.setName("length"); + fo.addParam(pa2); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nNemw(auto str, auto length);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + + "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent6() { + FuncObj fo = new FuncObj(); + fo.setName("getArray"); + fo.setRetValue("T[]"); + + List tempList = new CopyOnWriteArrayList<>(); + tempList.add("T"); + fo.setTempList(tempList); + ParamObj pa1 = new ParamObj(); + pa1.setName("items"); + pa1.setType("T[]"); + fo.addParam(pa1); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\ntemplate T* getArray(T* items);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(getArray, \"getArray\");\n" + + "\tJSBIND_PFUNCTION(getArray, \"getArrayPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent7() { + FuncObj fo = new FuncObj(); + fo.setName("displayType"); + fo.setRetValue("void"); + + List tempList = new CopyOnWriteArrayList<>(); + tempList.add("T"); + tempList.add("U"); + fo.setTempList(tempList); + ParamObj pa1 = new ParamObj(); + pa1.setName("id"); + pa1.setType("T"); + fo.addParam(pa1); + ParamObj pa2 = new ParamObj(); + pa2.setName("name"); + pa2.setType("U"); + fo.addParam(pa2); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\ntemplate void displayType(T id, U name);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(displayType, \"displayType\");\n" + + "\tJSBIND_PFUNCTION(displayType, \"displayTypePromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent8() { + FuncObj fo = new FuncObj(); + fo.setName("Nemw"); + fo.setRetValue("string"); + ParamObj pa1 = new ParamObj(); + pa1.setName("str"); + fo.addParam(pa1); + ParamObj pa2 = new ParamObj(); + pa2.setName("length"); + fo.addParam(pa2); + + FuncObj fo1 = new FuncObj(); + fo1.setName("getCnt"); + fo1.setRetValue("int"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + fol.add(fo1); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nstd::string Nemw(auto str, auto length);\n" + + "\n" + + "int getCnt();\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(Nemw, \"Nemw\");\n" + + "\tJSBIND_PFUNCTION(Nemw, \"NemwPromise\");\n" + + "\tJSBIND_FUNCTION(getCnt, \"getCnt\");\n" + + "\tJSBIND_PFUNCTION(getCnt, \"getCntPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent9() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + fo.setRetValue("void"); + fo.addParam("name", "string"); + + FuncObj foItem = new FuncObj(); + foItem.setRetValue("boolean"); + foItem.addParam("value", "boolean"); + + ParamObj paItem = new ParamObj(); + paItem.setName("func"); + paItem.setType("(value:boolean)=>boolean"); + paItem.addFunc(foItem); + + fo.addParam(paItem); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenAkiCppFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, aki::SafetyCallback func);\n" + + "\n" + + "JSBIND_GLOBAL()\n" + + "{\n" + + "\tJSBIND_FUNCTION(TestFunc, \"TestFunc\");\n" + + "\tJSBIND_PFUNCTION(TestFunc, \"TestFuncPromise\");\n" + + "};\n"; + assertEquals(expect, funcContent); + } + } + + @Test + void getStructContent1() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + + so.addMember("name", "string"); + so.addMember("age", "boolean"); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj poItem = new ParamObj(); + poItem.setName("a"); + poItem.setType("boolean"); + poList.add(poItem); + ParamObj poItem2 = new ParamObj(); + poItem2.setName("b"); + poItem2.setType("boolean"); + poList.add(poItem2); + + so.addFunc("add", "number", poList); + + List sol = new CopyOnWriteArrayList<>(); + sol.add(so); + ParseObj po = new ParseObj(); + po.setStructList(sol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenAkiCppFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = "\nstruct TestStruct {\n" + + "\tstd::string name;\n" + + "\tbool age;\n" + + "\tint add(bool a, bool b);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "\tJSBIND_METHOD(add, \"add\");\n" + + "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "};\n"; + assertEquals(expect, structContent); + } + } + + @Test + void getStructContent2() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + so.addMember("name", "T"); + so.addMember("age", "U"); + so.addTemplate("T"); + so.addTemplate("U"); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj poItem = new ParamObj(); + poItem.setName("a"); + poItem.setType("T"); + poList.add(poItem); + ParamObj poItem2 = new ParamObj(); + poItem2.setName("b"); + poItem2.setType("U"); + poList.add(poItem2); + + so.addFunc("add", "number", poList); + + List sol = new CopyOnWriteArrayList<>(); + sol.add(so); + ParseObj po = new ParseObj(); + po.setStructList(sol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenAkiCppFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = "\ntemplate struct TestStruct {\n" + + "\tT name;\n" + + "\tU age;\n" + + "\tint add(T a, U b);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "\tJSBIND_METHOD(add, \"add\");\n" + + "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "};\n"; + assertEquals(expect, structContent); + } + } + + @Test + void getStructContent3() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + + so.addMember("name", ""); + so.addMember("age", ""); + + List poList = new CopyOnWriteArrayList<>(); + ParamObj poItem = new ParamObj(); + poItem.setName("a"); + poItem.setType(""); + poList.add(poItem); + ParamObj poItem2 = new ParamObj(); + poItem2.setName("b"); + poItem2.setType(""); + poList.add(poItem2); + + so.addFunc("add", "", poList); + + List sol = new CopyOnWriteArrayList<>(); + sol.add(so); + ParseObj po = new ParseObj(); + po.setStructList(sol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenAkiCppFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = "\nstruct TestStruct {\n" + + "\tauto name;\n" + + "\tauto age;\n" + + "\tadd(auto a, auto b);\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "\tJSBIND_METHOD(add, \"add\");\n" + + "\tJSBIND_PMETHOD(add, \"addPromise\");\n" + + "\tJSBIND_PROPERTY(name);\n" + + "\tJSBIND_PROPERTY(age);\n" + + "};\n"; + assertEquals(expect, structContent); + } + } + + @Test + void getStructContent4() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + + List sol = new CopyOnWriteArrayList<>(); + sol.add(so); + ParseObj po = new ParseObj(); + po.setStructList(sol); + + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenAkiCppFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = "\nstruct TestStruct {\n" + + "};\n" + + "\n" + + "JSBIND_CLASS(TestStruct)\n" + + "{\n" + + "};\n"; + assertEquals(expect, structContent); + } + } + + @Test + void getTypeContent() { + } + + @Test + void getUnionContent1() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "number"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent2() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + uo.addMember("name", "T"); + uo.addMember("age", "U"); + + uo.addTemplate("T"); + uo.addTemplate("U"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\ntemplate union TestUnion{\n" + + "\tT name;\n" + + "\tU age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent3() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "int"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent4() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tlong age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent5() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "short"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tshort age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent6() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "long long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tlong long age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent7() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "float"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tfloat age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent8() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "double"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tdouble age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent9() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "uint8"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tuint8 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent10() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "uint16"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tuint16 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent11() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "uint32"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tuint32 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent12() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "uint64"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tuint64 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent13() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "int8"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint8 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent14() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "int16"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint16 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent15() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "int32"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint32 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent16() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "int64"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint64 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent17() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "size_t"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tsize_t age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent18() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "string"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tstd::string age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent19() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "std::string"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tstd::string age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent20() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "std::array"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tstd::array age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent21() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "std::stack"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tstd::stack age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent22() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "std::vector"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tstd::vector age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void getUnionContent23() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "string"); + uo.addMember("age", "std::queue"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenAkiCppFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tstd::queue age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + +} \ No newline at end of file -- Gitee From 5afffcf791befa8665e4cd1966c5dca683c3ead0 Mon Sep 17 00:00:00 2001 From: wangshi Date: Mon, 28 Apr 2025 18:12:48 +0800 Subject: [PATCH 5/6] add 20type tests Signed-off-by: wangshi --- .../ohosgen/src/main/java/gen/GenAkiCppFile.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/intellij_plugin/ohosgen/src/main/java/gen/GenAkiCppFile.java b/src/intellij_plugin/ohosgen/src/main/java/gen/GenAkiCppFile.java index f68331d1..feee1a0c 100644 --- a/src/intellij_plugin/ohosgen/src/main/java/gen/GenAkiCppFile.java +++ b/src/intellij_plugin/ohosgen/src/main/java/gen/GenAkiCppFile.java @@ -42,6 +42,7 @@ public class GenAkiCppFile extends GeneratorBase { private static final String AKI_TYPE_NAME_TOKEN = "typename"; private static final String AKI_STAR_TOKEN = "*"; private static final String AKI_CHAR_START_TOKEN = "char*"; + private static final String AKI_STD_STRING_TOKEN = "std::string"; private static final String AKI_AUTO_TOKEN = "auto"; private static final String AKI_EXPORT_TOKEN = "export"; private static final String AKI_IMPLEMENAKI_TOKEN = "implements"; @@ -183,7 +184,7 @@ public class GenAkiCppFile extends GeneratorBase { private final Map ts2cppMap = Map.ofEntries( Map.entry("any", "auto"), Map.entry("boolean", "bool"), - Map.entry("string", "char*"), + Map.entry("string", "std::string"), Map.entry("number", "int"), Map.entry("void", "void"), Map.entry("[]", "*") @@ -404,7 +405,7 @@ public class GenAkiCppFile extends GeneratorBase { i = 0; if (vaList.size() > i && !vaList.get(i).isEmpty() && vaList.get(i).contains("\"")) { - resContent += AKI_NEW_LINE + AKI_CHAR_START_TOKEN + AKI_BLANK_SPACE + + resContent += AKI_NEW_LINE + AKI_STD_STRING_TOKEN + AKI_BLANK_SPACE + enumName.toLowerCase(Locale.ROOT) + AKI_UNDER_LINE + AKI_STR_SUFFIX + AKI_LEFT_SQUARE_BRACKET + AKI_RIGHT_SQUARE_BRACKET + AKI_EQUAL + AKI_LEFT_BRACE; for (String val : vaList) { -- Gitee From 866ca7f074d96566d8513075517b4d7710710df2 Mon Sep 17 00:00:00 2001 From: wangshi Date: Mon, 28 Apr 2025 18:13:23 +0800 Subject: [PATCH 6/6] add 20type tests Signed-off-by: wangshi --- .../src/test/java/gen/GenAkiCppFileTest3.java | 239 +++++++++++++++++- 1 file changed, 237 insertions(+), 2 deletions(-) diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java index dfec825b..1f1d0b74 100644 --- a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java @@ -18,12 +18,10 @@ package gen; import grammar.*; import org.junit.jupiter.api.Test; -import java.io.File; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import static org.junit.jupiter.api.Assertions.assertEquals; -import static utils.FileUtils.readText; /** *

类名:该类用于xxx

@@ -717,4 +715,241 @@ class GenAkiCppFileTest3 { assertEquals(expect, varContent); } } + + @Test + void getVarContent1() { + ParamObj paObj = new ParamObj(); + paObj.setName("employeeName"); + paObj.setStrValue("\"John\""); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const auto employeeName = \"John\";\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent2() { + ParamObj paObj = new ParamObj(); + paObj.setName("employeeName"); + paObj.setType("string"); + paObj.setStrValue("\"John\""); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::string employeeName = \"John\";\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent3() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("number"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent4() { + ParamObj paObj = new ParamObj(); + paObj.setName("playerCodes"); + + ParamObj paItem1 = new ParamObj(); + paItem1.setName("player1"); + paItem1.setStrValue("9"); + paObj.addParam(paItem1); + ParamObj paItem2 = new ParamObj(); + paItem2.setName("player2"); + paItem2.setStrValue("10"); + paObj.addParam(paItem2); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const std::map pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const auto playerCodes.player2 = 11;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent6() { + ParamObj paObj = new ParamObj(); + paObj.setName("ROUTES"); + paObj.setType("any[]"); + + ParamObj paListItem1 = new ParamObj(); + ParamObj paItem1 = new ParamObj(); + paItem1.setName("path"); + paItem1.setStrValue("'/dashboard'"); + paListItem1.addParam(paItem1); + + ParamObj paItem3 = new ParamObj(); + paItem3.setName("allowAnonymous"); + paItem3.setStrValue("false"); + paListItem1.addParam(paItem3); + paObj.addParam(paListItem1); + + ParamObj paListItem2 = new ParamObj(); + ParamObj paItem21 = new ParamObj(); + paItem21.setName("path"); + paItem21.setStrValue("'/deals'"); + paListItem2.addParam(paItem21); + + ParamObj paItem23 = new ParamObj(); + paItem23.setName("allowAnonymous"); + paItem23.setStrValue("true"); + paListItem2.addParam(paItem23); + paObj.addParam(paListItem2); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nstruct ROUTESST {\n" + + "\tstd::string path;\n" + + "\tboolean allowAnonymous;\n" + + "};\n" + + "\n" + + "const std::vector ROUTES = {\n" + + "\t{'/dashboard', false},\n" + + "\t{'/deals', true},\n" + + "};\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent7() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent8() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("long"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const long num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @Test + void getVarContent9() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("short"); + paObj.setStrValue("1"); + + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenAkiCppFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const short num1 = 1;\n"; + assertEquals(expect, constContent); + } + } } \ No newline at end of file -- Gitee