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 f68331d122ae5c7204649e51b71fa2399e3d0832..feee1a0cf5cdaf251fdce61409556717624c8d39 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) { diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest1.java similarity index 70% rename from src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest.java rename to src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest1.java index 53d645bf89dcf56c9eeacb986c844762d6e40cc7..84980f67c8f23255715094f9d8f32e32a507be62 100644 --- a/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest.java +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest1.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

@@ -34,12 +32,12 @@ import static utils.FileUtils.readText; * @version 1.0 * @since 2025-02-28 */ -class GenAkiCppFileTest { +class GenAkiCppFileTest1 { private String classContentExpect2 = "\nclass TestClass : public IPerson {\n" + - "\tpublic char* name;\n" + + "\tpublic std::string name;\n" + "\tprivate int age;\n" + - "\tprotected char* no;\n" + - "\treadonly char* addr;\n" + + "\tprotected std::string no;\n" + + "\treadonly std::string addr;\n" + "\tconstructor();\n" + "};\n" + "\n" + @@ -70,6 +68,57 @@ class GenAkiCppFileTest { "\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() { } @@ -174,7 +223,7 @@ class GenAkiCppFileTest { "\tBlue = BLUE,\n" + "};\n" + "\n" + - "char* colors_STR[] = {\n" + + "std::string colors_STR[] = {\n" + "\t[Red] = \"RED\",\n" + "\t[Green] = \"GREEN\",\n" + "\t[Blue] = \"BLUE\"\n" + @@ -272,7 +321,7 @@ class GenAkiCppFileTest { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\nclass TestClass {\n" + - "\tchar* name;\n" + + "\tstd::string name;\n" + "\tint age;\n" + "\tint add(int a, int b);\n" + "};\n" + @@ -617,6 +666,50 @@ class GenAkiCppFileTest { } } + @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(); @@ -634,7 +727,7 @@ class GenAkiCppFileTest { if (gb instanceof GenAkiCppFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); - String expect = "\nvoid TestFunc(char* name, int age);\n" + + String expect = "\nvoid TestFunc(std::string name, int age);\n" + "\n" + "JSBIND_GLOBAL()\n" + "{\n" + @@ -666,7 +759,7 @@ class GenAkiCppFileTest { if (gb instanceof GenAkiCppFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); - String expect = "\nchar* ToCapital(char* str, int length = 0);\n" + + String expect = "\nstd::string ToCapital(std::string str, int length = 0);\n" + "\n" + "JSBIND_GLOBAL()\n" + "{\n" + @@ -702,7 +795,7 @@ class GenAkiCppFileTest { 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" + + String expect = "\nstd::string Nemw(std::string str = \"joke\", int length = 0);\n" + "\n" + "JSBIND_GLOBAL()\n" + "{\n" + @@ -734,7 +827,7 @@ class GenAkiCppFileTest { if (gb instanceof GenAkiCppFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); - String expect = "\nchar* Nemw(auto str, auto length);\n" + + String expect = "\nstd::string Nemw(auto str, auto length);\n" + "\n" + "JSBIND_GLOBAL()\n" + "{\n" + @@ -879,7 +972,7 @@ class GenAkiCppFileTest { if (gb instanceof GenAkiCppFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); - String expect = "\nchar* Nemw(auto str, auto length);\n" + + String expect = "\nstd::string Nemw(auto str, auto length);\n" + "\n" + "int getCnt();\n" + "\n" + @@ -922,7 +1015,7 @@ class GenAkiCppFileTest { if (gb instanceof GenAkiCppFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); - String expect = "\nvoid TestFunc(char* name, aki::SafetyCallback func);\n" + + String expect = "\nvoid TestFunc(std::string name, aki::SafetyCallback func);\n" + "\n" + "JSBIND_GLOBAL()\n" + "{\n" + @@ -965,7 +1058,7 @@ class GenAkiCppFileTest { String structContent = gdf.getStructContent(); System.out.println("genStruct: " + structContent); String expect = "\nstruct TestStruct {\n" + - "\tchar* name;\n" + + "\tstd::string name;\n" + "\tbool age;\n" + "\tint add(bool a, bool b);\n" + "};\n" + @@ -1127,7 +1220,7 @@ class GenAkiCppFileTest { String unionContent = gdf.getUnionContent(); System.out.println("genUnion: " + unionContent); String expect = "\nunion TestUnion{\n" + - "\tchar* name;\n" + + "\tstd::string name;\n" + "\tint age;\n" + "};\n"; assertEquals(expect, unionContent); @@ -1163,449 +1256,480 @@ class GenAkiCppFileTest { } @Test - void getVarContent1() { - ParamObj paObj = new ParamObj(); - paObj.setName("employeeName"); - paObj.setStrValue("\"John\""); + void getUnionContent3() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); + uo.addMember("name", "string"); + uo.addMember("age", "int"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); ParseObj po = new ParseObj(); - po.setVarList(pol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); + gb.genUnionList(po.getUnionList()); 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); + 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 getVarContent2() { - ParamObj paObj = new ParamObj(); - paObj.setName("employeeName"); - paObj.setType("string"); - paObj.setStrValue("\"John\""); + void getUnionContent4() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); + uo.addMember("name", "string"); + uo.addMember("age", "long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); ParseObj po = new ParseObj(); - po.setVarList(pol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); + gb.genUnionList(po.getUnionList()); 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); + 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 getVarContent3() { - ParamObj paObj = new ParamObj(); - paObj.setName("num1"); - paObj.setType("number"); - paObj.setStrValue("1"); + void getUnionContent5() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); + uo.addMember("name", "string"); + uo.addMember("age", "short"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); ParseObj po = new ParseObj(); - po.setVarList(pol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); + gb.genUnionList(po.getUnionList()); 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); + 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 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); + void getUnionContent6() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); + uo.addMember("name", "string"); + uo.addMember("age", "long long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); ParseObj po = new ParseObj(); - po.setVarList(pol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); + gb.genUnionList(po.getUnionList()); 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); + uo.addMember("name", "string"); + uo.addMember("age", "float"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); ParseObj po = new ParseObj(); - po.setVarList(pol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); + gb.genUnionList(po.getUnionList()); 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); + 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 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); + void getUnionContent8() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(paObj); + uo.addMember("name", "string"); + uo.addMember("age", "double"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); ParseObj po = new ParseObj(); - po.setVarList(pol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genVarList(po.getVarList()); + gb.genUnionList(po.getUnionList()); 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" + + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tdouble age;\n" + "};\n"; - assertEquals(expect, constContent); + assertEquals(expect, unionContent); } } @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); + 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.genVarList(pol); + gb.genUnionList(po.getUnionList()); 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); + 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 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); + 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.genContent(po); + gb.genUnionList(po.getUnionList()); 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); + 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 genFile() { - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("int"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); + void getUnionContent11() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - ParseObj po = new ParseObj(); - po.setVarList(pol); + 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.genContent(po); - gb.genFile("./", "testGenFile.h"); + gb.genUnionList(po.getUnionList()); - File file = new File("./ag_akitestGenFile_h.cpp"); - assertEquals(true, file.exists()); - assertEquals(false, file.isDirectory()); + 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); + } + } - List fcList = readText("./ag_akitestGenFile_h.cpp"); + @Test + void getUnionContent12() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - assertEquals("// Generated from ./\\testGenFile.h by KaiHong ohgen 1.0.0-PLUGIN", - fcList.get(0)); + uo.addMember("name", "string"); + uo.addMember("age", "uint64"); - 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)); + 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 varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); + 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 genInterfaceList() { + 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 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); + 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.setEnumList(eol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genEnumList(po.getEnumList()); + gb.genUnionList(po.getUnionList()); 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" + + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint16 age;\n" + "};\n"; - assertEquals(expect, enumContent); + assertEquals(expect, unionContent); } } @Test - void genClassList() { - ClassObj co = new ClassObj(); - co.setName("TestClass"); - - co.addParam("name", "string"); - co.addParam("age", "number"); + void getUnionContent15() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - 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); + uo.addMember("name", "string"); + uo.addMember("age", "int32"); - co.addFunc("add", "number", poList); + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); - poList = new CopyOnWriteArrayList<>(); - poItem = new ParamObj(); - poItem.setType("number"); - poList.add(poItem); + 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); + } + } - co.addFunc("delete", "number", poList); + @Test + void getUnionContent16() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - List col = new CopyOnWriteArrayList<>(); - col.add(co); + uo.addMember("name", "string"); + uo.addMember("age", "int64"); + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); ParseObj po = new ParseObj(); - po.setClassList(col); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genClassList(po.getClassList()); + gb.genUnionList(po.getUnionList()); 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" + + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tstd::string name;\n" + + "\tint64 age;\n" + "};\n"; - assertEquals(expect, classContent); + assertEquals(expect, unionContent); } } @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); + 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.setFuncList(fol); + po.setUnionList(uol); GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); - gb.genFuncList(po.getFuncList()); + gb.genUnionList(po.getUnionList()); 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" + + 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, funcContent); + assertEquals(expect, unionContent); } } @Test - void genStructList() { - StructObj so = new StructObj(); - so.setName("TestStruct"); + void getUnionContent18() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); - so.addMember("name", "string"); - so.addMember("age", "number"); + uo.addMember("name", "string"); + uo.addMember("age", "string"); - 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); + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("AKICPP"); + gb.genUnionList(po.getUnionList()); - so.addFunc("add", "int", poList); + 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); + } + } - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); - ParseObj po = new ParseObj(); - po.setStructList(sol); + @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.genStructList(po.getStructList()); + gb.genUnionList(po.getUnionList()); 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); + 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 genTypeList() { - TypeObj to = new TypeObj(); + 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 genUnionList() { + void getUnionContent21() { UnionObj uo = new UnionObj(); uo.setName("TestUnion"); - uo.addMember("name", "any"); - uo.addMember("age", "number"); + uo.addMember("name", "string"); + uo.addMember("age", "std::stack"); List uol = new CopyOnWriteArrayList<>(); uol.add(uo); @@ -1618,32 +1742,63 @@ class GenAkiCppFileTest { String unionContent = gdf.getUnionContent(); System.out.println("genUnion: " + unionContent); String expect = "\nunion TestUnion{\n" + - "\tauto name;\n" + - "\tint age;\n" + + "\tstd::string name;\n" + + "\tstd::stack age;\n" + "};\n"; assertEquals(expect, unionContent); } } @Test - void genVarList() { + 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(); - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("number"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); - po.setVarList(pol); + 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.genVarList(pol); + gb.genUnionList(po.getUnionList()); 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); + 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 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 0000000000000000000000000000000000000000..6901fcf59ccdb361e8284d010a8dde546f841876 --- /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 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 0000000000000000000000000000000000000000..1f1d0b74500f1633ba3a8b3f3d29876404f9649a --- /dev/null +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenAkiCppFileTest3.java @@ -0,0 +1,955 @@ +/* + * 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 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); + } + } + + @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