From e98eb695aa74e8425bf327b18cf70607702c0549 Mon Sep 17 00:00:00 2001 From: shitijun Date: Sun, 27 Apr 2025 15:54:48 +0800 Subject: [PATCH 1/3] add 20 types Signed-off-by: shitijun --- .../src/test/java/gen/GenCppHFileTest.java | 974 +++++++++++++++--- 1 file changed, 830 insertions(+), 144 deletions(-) diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest.java index 26c6968c..5acd1b77 100644 --- a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest.java +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest.java @@ -35,6 +35,31 @@ import static utils.FileUtils.readText; * @since 2025-02-28 */ class GenCppHFileTest { + private String genClassContentTest2 = "\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"; @Test void getInterfaceContent() { @@ -1032,7 +1057,7 @@ class GenCppHFileTest { } @Test - void genContent() { + void genContent1() { ParseObj po = new ParseObj(); ParamObj pao = new ParamObj(); pao.setName("TestParam"); @@ -1054,234 +1079,895 @@ class GenCppHFileTest { } @Test - void genFile() { + void genContent2() { + ParseObj po = new ParseObj(); ParamObj pao = new ParamObj(); pao.setName("TestParam"); - pao.setType("int"); + pao.setType("long"); pao.setStrValue("100"); List pol = new CopyOnWriteArrayList<>(); pol.add(pao); - - ParseObj po = new ParseObj(); po.setVarList(pol); GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); gb.genContent(po); - gb.genFile("./", "testGenFile.d.ts"); - - File file = new File("./ag_testGenFile_d_ts.h"); - assertEquals(true, file.exists()); - assertEquals(false, file.isDirectory()); - - List fcList = readText("./ag_testGenFile_d_ts.h"); - - assertEquals("// Generated from ./\\testGenFile.d.ts by KaiHong ohgen 1.0.0-PLUGIN", - fcList.get(0)); - assertEquals("extends const int TestParam = 100;", - fcList.get(1)); if (gb instanceof GenCppHFile gdf) { String varContent = gdf.getConstContent(); System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; + String expect = "\nextends const long 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); + void genContent3() { ParseObj po = new ParseObj(); - po.setEnumList(eol); + 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("CPPH"); - gb.genEnumList(po.getEnumList()); + gb.genContent(po); if (gb instanceof GenCppHFile gdf) { - String enumContent = gdf.getEnumContent(); - System.out.println("genEnum: " + enumContent); - String expect = "\nenum TestEnum {\n" + - "\tONE = 1,\n" + - "\tTWO = 2,\n" + - "};\n"; - assertEquals(expect, enumContent); + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const short TestParam = 100;\n"; + assertEquals(expect, varContent); } } @Test - void genClassList() { - ClassObj co = new ClassObj(); - co.setName("TestClass"); - - co.addParam("name", "string"); - co.addParam("age", "number"); + void genContent4() { + 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); - 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); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genContent(po); - co.addFunc("add", "number", poList); + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const long long TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } - poList = new CopyOnWriteArrayList<>(); - poItem = new ParamObj(); - poItem.setType("number"); - poList.add(poItem); + @Test + void genContent5() { + 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); - co.addFunc("delete", "number", poList); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genContent(po); - List col = new CopyOnWriteArrayList<>(); - col.add(co); + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const float TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + @Test + void genContent6() { ParseObj po = new ParseObj(); - po.setClassList(col); + 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("CPPH"); - gb.genClassList(po.getClassList()); + gb.genContent(po); if (gb instanceof GenCppHFile 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"; - assertEquals(expect, classContent); + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const double TestParam = 100;\n"; + assertEquals(expect, varContent); } } @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 genContent7() { ParseObj po = new ParseObj(); - po.setFuncList(fol); + 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("CPPH"); - gb.genFuncList(po.getFuncList()); + gb.genContent(po); if (gb instanceof GenCppHFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nvoid TestFunc(std::string name, int age);"; - assertEquals(expect, funcContent); + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint8 TestParam = 100;\n"; + assertEquals(expect, varContent); } } @Test - void genStructList() { - StructObj so = new StructObj(); - so.setName("TestStruct"); - - so.addMember("name", "string"); - so.addMember("age", "number"); + void genContent8() { + 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); - 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); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genContent(po); - so.addFunc("add", "int", poList); + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint16 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); + @Test + void genContent9() { ParseObj po = new ParseObj(); - po.setStructList(sol); + 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("CPPH"); - gb.genStructList(po.getStructList()); + gb.genContent(po); if (gb instanceof GenCppHFile gdf) { - String structContent = gdf.getStructContent(); - System.out.println("genStruct: " + structContent); - String expect = "\nstruct TestStruct {\n" + - "\tstd::string name;\n" + - "\tint age;\n" + - "\tint add(int a, int b);\n" + - "};\n"; - assertEquals(expect, structContent); + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint32 TestParam = 100;\n"; + assertEquals(expect, varContent); } } @Test - void genTypeList() { - TypeObj to = new TypeObj(); - } + void genContent10() { + 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); - @Test - void genUnionList() { - UnionObj uo = new UnionObj(); - uo.setName("TestUnion"); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genContent(po); - uo.addMember("name", "any"); - uo.addMember("age", "number"); + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint64 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } - List uol = new CopyOnWriteArrayList<>(); - uol.add(uo); + @Test + void genContent11() { ParseObj po = new ParseObj(); - po.setUnionList(uol); + 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("CPPH"); - gb.genUnionList(po.getUnionList()); + gb.genContent(po); if (gb instanceof GenCppHFile 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); + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int8 TestParam = 100;\n"; + assertEquals(expect, varContent); } } @Test - void genVarList() { + void genContent12() { ParseObj po = new ParseObj(); ParamObj pao = new ParamObj(); pao.setName("TestParam"); - pao.setType("number"); + pao.setType("int16"); pao.setStrValue("100"); List pol = new CopyOnWriteArrayList<>(); pol.add(pao); po.setVarList(pol); GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); - gb.genVarList(pol); + gb.genContent(po); if (gb instanceof GenCppHFile gdf) { String varContent = gdf.getConstContent(); System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; + String expect = "\nextends const int16 TestParam = 100;\n"; assertEquals(expect, varContent); } } + + @Test + void genContent13() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int32 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent14() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int64 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent15() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const size_t TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + @Test + void genContent16() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::string TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent17() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::string TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent18() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::array TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent19() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::stack TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent20() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::vector TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genContent21() { + 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("CPPH"); + gb.genContent(po); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::queue 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("CPPH"); + gb.genContent(po); + gb.genFile("./", "testGenFile.d.ts"); + + File file = new File("./ag_testGenFile_d_ts.h"); + assertEquals(true, file.exists()); + assertEquals(false, file.isDirectory()); + + List fcList = readText("./ag_testGenFile_d_ts.h"); + + assertEquals("// Generated from ./\\testGenFile.d.ts by KaiHong ohgen 1.0.0-PLUGIN", + fcList.get(0)); + assertEquals("extends const int TestParam = 100;", + fcList.get(1)); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genEnumList(po.getEnumList()); + + if (gb instanceof GenCppHFile gdf) { + String enumContent = gdf.getEnumContent(); + System.out.println("genEnum: " + enumContent); + String expect = "\nenum TestEnum {\n" + + "\tONE = 1,\n" + + "\tTWO = 2,\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("CPPH"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenCppHFile 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"; + 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 = 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("CPPH"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenCppHFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = genClassContentTest2; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, long age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, short age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, long long age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, float age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, double age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint8 age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint16 age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint32 age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, uint64 age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int8 age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int16 age);"; + assertEquals(expect, funcContent); + } + } } \ No newline at end of file -- Gitee From 410ed1de0b874a3ff6570c5560f2400c065dad13 Mon Sep 17 00:00:00 2001 From: shitijun Date: Sun, 27 Apr 2025 15:54:56 +0800 Subject: [PATCH 2/3] add 20 types Signed-off-by: shitijun --- .../src/test/java/gen/GenCppHFileTest2.java | 1410 +++++++++++++++++ 1 file changed, 1410 insertions(+) create mode 100644 src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.java diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.java new file mode 100644 index 00000000..ac95c4b9 --- /dev/null +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.java @@ -0,0 +1,1410 @@ +/* + * 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 GenCppHFileTest2 { + + private String genStructContentTest = "\nstruct TestStruct {\n" + + "\tstd::string name;\n" + + "\tint age;\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 add(int a, int b);\n" + + "};\n"; + + @Test + void getInterfaceContent() { + } + + @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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int32 age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, int64 age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, size_t age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::string age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::string age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::array age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::stack age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::vector age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::queue age);"; + 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("CPPH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCppHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(std::string name, std::map age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void genStructList() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + + so.addMember("name", "string"); + so.addMember("age", "number"); + + 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 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("CPPH"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenCppHFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = genStructContentTest; + assertEquals(expect, structContent); + } + } + + @Test + void genTypeList() { + TypeObj to = new TypeObj(); + } + + @Test + void genUnionList1() { + 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("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile 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 genUnionList2() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "int"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile 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 genUnionList3() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tlong age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList4() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "short"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tshort age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList5() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "long long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tlong long age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList6() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "float"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tfloat age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList7() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "double"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tdouble age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList8() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "uint8"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tuint8 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList9() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "uint16"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tuint16 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList10() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "uint32"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tuint32 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList11() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "uint64"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tuint64 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList12() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "int8"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tint8 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList13() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "int16"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tint16 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList14() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "int32"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tint32 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList15() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "int64"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tint64 age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList16() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "size_t"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tsize_t age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList17() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "string"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tstd::string age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList18() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "std::string"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tstd::string age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList19() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "std::array"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tstd::array age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList20() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "std::stack"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tstd::stack age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList21() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "std::vector"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tstd::vector age;\n" + + "};\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList22() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "any"); + uo.addMember("age", "std::queue"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("CPPH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCppHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tstd::queue 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile 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("CPPH"); + gb.genVarList(pol); + + if (gb instanceof GenCppHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const std::queue TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } +} \ No newline at end of file -- Gitee From 56597ae34de5d2d8c8befac1ea3101ab82588f3c Mon Sep 17 00:00:00 2001 From: shitijun Date: Sun, 27 Apr 2025 16:14:22 +0800 Subject: [PATCH 3/3] fix code check Signed-off-by: shitijun --- .../ohosgen/src/test/java/gen/GenCppHFileTest2.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.java index ac95c4b9..ef460071 100644 --- a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.java +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCppHFileTest2.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

-- Gitee