diff --git a/src/intellij_plugin/ohosgen/src/main/java/gen/GenCHFile.java b/src/intellij_plugin/ohosgen/src/main/java/gen/GenCHFile.java index d3c893ec42b19c8ffbff5229d6bdd1340173d876..986e345a3a9048fab43364e3fce6b1811dfbbef4 100644 --- a/src/intellij_plugin/ohosgen/src/main/java/gen/GenCHFile.java +++ b/src/intellij_plugin/ohosgen/src/main/java/gen/GenCHFile.java @@ -132,9 +132,14 @@ public class GenCHFile extends GeneratorBase { private final Map ts2cppMap = Map.ofEntries( Map.entry("any", "auto"), Map.entry("boolean", "bool"), + Map.entry("std::string", "char*"), Map.entry("string", "char*"), Map.entry("number", "int"), - Map.entry("void", "void"), + Map.entry("std::array", "int*"), + Map.entry("std::stack", "int*"), + Map.entry("std::vector", "int*"), + Map.entry("std::queue", "int*"), + Map.entry("std::list", "int*"), Map.entry("[]", "*") ); @@ -168,7 +173,7 @@ public class GenCHFile extends GeneratorBase { String key = entry.getKey(); String value = entry.getValue(); int ret = cppKey.indexOf(key); - if (ret >= 0 && value.contains(C_STAR_TOKEN)) { + if (ret >= 0 && value.contains(C_STAR_TOKEN) && !(cppKey.substring(0, ret).contains("std"))) { return cppKey.substring(0, ret) + value; } else if (ret >= 0) { return value; diff --git a/src/intellij_plugin/ohosgen/src/main/java/gen/GenDtsFile.java b/src/intellij_plugin/ohosgen/src/main/java/gen/GenDtsFile.java index 141d33358811f895362b1ab86650e51d3932df3e..88a9575e262efc2d19b69182a6e89f6eabae466a 100644 --- a/src/intellij_plugin/ohosgen/src/main/java/gen/GenDtsFile.java +++ b/src/intellij_plugin/ohosgen/src/main/java/gen/GenDtsFile.java @@ -124,10 +124,17 @@ public class GenDtsFile extends GeneratorBase { Map.entry("char", "string"), Map.entry("char16_t", "string"), Map.entry("char32_t", "string"), + Map.entry("string", "string"), + Map.entry("std::string", "string"), Map.entry("double", "number"), Map.entry("float", "number"), Map.entry("int", "number"), Map.entry("long", "number"), + Map.entry("short", "number"), + Map.entry("uint8", "number"), + Map.entry("uint16", "number"), + Map.entry("uint32", "number"), + Map.entry("uint64", "number"), Map.entry("wchar_t", "number"), Map.entry("size_t", "number"), Map.entry("void", "void"), diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCHFileTest.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCHFileTest.java index df80f1d76de7638459eb39155ab583a75eabdb96..4187f3d63df7988a6b4ef606d306edd464b575c0 100644 --- a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCHFileTest.java +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCHFileTest.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

@@ -35,6 +33,83 @@ import static utils.FileUtils.readText; * @since 2025-02-28 */ class GenCHFileTest { + private String genUnionContentTest = "\nstruct TestStruct {\n" + + "\tchar* 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" + + "\tchar* p15;\n" + + "\tchar* p16;\n" + + "\tint* p17;\n" + + "\tint* p18;\n" + + "\tint* p19;\n" + + "\tint* p20;\n" + + "\tint add(int a, int b);\n" + + "};\n"; + + private String genStructCOntentTest = "\nstruct TestStruct {\n" + + "\tchar* 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" + + "\tchar* p15;\n" + + "\tchar* p16;\n" + + "\tint* p17;\n" + + "\tint* p18;\n" + + "\tint* p19;\n" + + "\tint* p20;\n" + + "};\n"; + + private String genClassContentTest = "\nclass TestClass {\n" + + "\tchar* 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" + + "\tchar* p15;\n" + + "\tchar* p16;\n" + + "\tint* p17;\n" + + "\tint* p18;\n" + + "\tint* p19;\n" + + "\tint* p20;\n" + + "\tint add(int a, int b);\n" + + "\tint delete(int);\n" + + "};\n"; @Test void getInterfaceContent() { @@ -55,7 +130,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genEnumList(po.getEnumList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String enumContent = gdf.getEnumContent(); System.out.println("genEnum: " + enumContent); String expect = "\nenum TestEnum {\n" + @@ -87,7 +162,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genEnumList(po.getEnumList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String enumContent = gdf.getEnumContent(); System.out.println("genEnum: " + enumContent); String expect = "\nenum Colors {\n" + @@ -120,7 +195,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genEnumList(po.getEnumList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String enumContent = gdf.getEnumContent(); System.out.println("genEnum: " + enumContent); String expect = "\nenum Colors {\n" + @@ -166,7 +241,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genClassList(po.getClassList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\nclass TestClass {\n" + @@ -218,7 +293,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genClassList(po.getClassList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\nclass TestClass : public IPerson {\n" + @@ -276,7 +351,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genClassList(po.getClassList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\nclass Employee : public Person {\n" + @@ -311,7 +386,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genClassList(po.getClassList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\nclass myClass {\n" + @@ -358,7 +433,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genClassList(po.getClassList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\ntemplate class KeyValuePair {\n" + @@ -404,7 +479,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genClassList(po.getClassList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\ntemplate class kvProcessor : " + @@ -434,7 +509,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genClassList(po.getClassList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); String expect = "\nclass Shape {\n" + @@ -458,7 +533,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genFuncList(po.getFuncList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); String expect = "\nvoid TestFunc(char* name, int age);"; @@ -484,7 +559,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genFuncList(po.getFuncList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); String expect = "\nchar* ToCapital(char* str, int length = 0);"; @@ -514,7 +589,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genFuncList(po.getFuncList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); String expect = "\nchar* Nemw(char* str = \"joke\", int length = 0);"; @@ -540,7 +615,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genFuncList(po.getFuncList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); String expect = "\nchar* Nemw(auto str, auto length);"; @@ -566,7 +641,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genFuncList(po.getFuncList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); String expect = "\nNemw(auto str, auto length);"; @@ -595,7 +670,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genFuncList(po.getFuncList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); String expect = "\ntemplate T* getArray(T* items);"; @@ -629,7 +704,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genFuncList(po.getFuncList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); String expect = "\ntemplate void displayType(T id, U name);"; @@ -637,6 +712,468 @@ class GenCHFileTest { } } + @Test + void getFuncContent8() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent9() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, long age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent10() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, short age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent11() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, long long age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent12() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, float age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent13() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, double age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent14() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, uint8 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent15() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, uint16 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent16() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, uint32 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent17() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, uint64 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent18() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int8 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent19() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int16 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent20() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int32 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent21() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int64 age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent22() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, size_t age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent23() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, char* age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent24() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, char* age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent25() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent26() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent27() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void getFuncContent28() { + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* age);"; + assertEquals(expect, funcContent); + } + } + @Test void getStructContent1() { StructObj so = new StructObj(); @@ -665,7 +1202,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genStructList(po.getStructList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String structContent = gdf.getStructContent(); System.out.println("genStruct: " + structContent); String expect = "\nstruct TestStruct {\n" + @@ -706,7 +1243,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genStructList(po.getStructList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String structContent = gdf.getStructContent(); System.out.println("genStruct: " + structContent); String expect = "\ntemplate struct TestStruct {\n" + @@ -746,7 +1283,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genStructList(po.getStructList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String structContent = gdf.getStructContent(); System.out.println("genStruct: " + structContent); String expect = "\nstruct TestStruct {\n" + @@ -771,7 +1308,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genStructList(po.getStructList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String structContent = gdf.getStructContent(); System.out.println("genStruct: " + structContent); String expect = "\nstruct TestStruct {\n" + @@ -780,6 +1317,49 @@ class GenCHFileTest { } } + @Test + void getStructContent5() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + so.addMember("name", "char*"); + so.addMember("age", "int"); + 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("CH"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenCHFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = genStructCOntentTest; + assertEquals(expect, structContent); + } + } + @Test void getTypeContent() { } @@ -799,7 +1379,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genUnionList(po.getUnionList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String unionContent = gdf.getUnionContent(); System.out.println("genUnion: " + unionContent); String expect = "\nunion TestUnion{\n" + @@ -827,7 +1407,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genUnionList(po.getUnionList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String unionContent = gdf.getUnionContent(); System.out.println("genUnion: " + unionContent); String expect = "\ntemplate union TestUnion{\n" + @@ -851,7 +1431,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String constContent = gdf.getConstContent(); System.out.println("getVar: " + constContent); String expect = "\nextends const auto employeeName = \"John\";\n"; @@ -873,7 +1453,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String constContent = gdf.getConstContent(); System.out.println("getVar: " + constContent); String expect = "\nextends const char* employeeName = \"John\";\n"; @@ -895,7 +1475,7 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String constContent = gdf.getConstContent(); System.out.println("getVar: " + constContent); String expect = "\nextends const int num1 = 1;\n"; @@ -924,22 +1504,273 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const short num1 = 1;\n"; + assertEquals(expect, constContent); + } + } + + @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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile gdf) { String constContent = gdf.getConstContent(); System.out.println("getVar: " + constContent); - String expect = "\nextends const std::map pol = new CopyOnWriteArrayList<>(); pol.add(paObj); @@ -948,43 +1779,20 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile gdf) { String constContent = gdf.getConstContent(); System.out.println("getVar: " + constContent); - String expect = "\nextends const auto playerCodes.player2 = 11;\n"; + String expect = "\nextends const uint32 num1 = 1;\n"; assertEquals(expect, constContent); } } @Test - void getVarContent6() { + void getVarContent16() { 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); + paObj.setName("num1"); + paObj.setType("uint64"); + paObj.setStrValue("1"); List pol = new CopyOnWriteArrayList<>(); pol.add(paObj); @@ -993,295 +1801,166 @@ class GenCHFileTest { GeneratorBase gb = GenerateFactory.getGenerator("CH"); gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { + if (gb instanceof GenCHFile 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"; + String expect = "\nextends const uint64 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("CH"); - gb.genVarList(pol); - - if (gb instanceof GenCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); - } - } + void getVarContent17() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int8"); + paObj.setStrValue("1"); - @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); + pol.add(paObj); + ParseObj po = new ParseObj(); po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("CH"); - gb.genContent(po); + gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int8 num1 = 1;\n"; + assertEquals(expect, constContent); } } @Test - void genFile() { - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("int"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); + 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("CH"); - 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)); + gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int16 num1 = 1;\n"; + assertEquals(expect, constContent); } } @Test - void genInterfaceList() { - } + void getVarContent19() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int32"); + paObj.setStrValue("1"); - @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); + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); ParseObj po = new ParseObj(); - po.setEnumList(eol); + po.setVarList(pol); GeneratorBase gb = GenerateFactory.getGenerator("CH"); - gb.genEnumList(po.getEnumList()); + gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile 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); + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int32 num1 = 1;\n"; + assertEquals(expect, constContent); } } @Test - void genClassList() { - ClassObj co = new ClassObj(); - co.setName("TestClass"); - - co.addParam("name", "string"); - co.addParam("age", "number"); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType("number"); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType("number"); - poList.add(poItem2); - - co.addFunc("add", "number", poList); - - poList = new CopyOnWriteArrayList<>(); - poItem = new ParamObj(); - poItem.setType("number"); - poList.add(poItem); - - co.addFunc("delete", "number", poList); - - List col = new CopyOnWriteArrayList<>(); - col.add(co); - - ParseObj po = new ParseObj(); - po.setClassList(col); - GeneratorBase gb = GenerateFactory.getGenerator("CH"); - gb.genClassList(po.getClassList()); - - if (gb instanceof GenCppFile 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"; - assertEquals(expect, classContent); - } - } + void getVarContent20() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("int64"); + paObj.setStrValue("1"); - @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); + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); ParseObj po = new ParseObj(); - po.setFuncList(fol); + po.setVarList(pol); GeneratorBase gb = GenerateFactory.getGenerator("CH"); - gb.genFuncList(po.getFuncList()); + gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { - String funcContent = gdf.getFuncContent(); - System.out.println("genFunc: " + funcContent); - String expect = "\nvoid TestFunc(char* name, int age);"; - assertEquals(expect, funcContent); + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int64 num1 = 1;\n"; + assertEquals(expect, constContent); } } @Test - void genStructList() { - StructObj so = new StructObj(); - so.setName("TestStruct"); - - so.addMember("name", "string"); - so.addMember("age", "number"); - - List poList = new CopyOnWriteArrayList<>(); - ParamObj poItem = new ParamObj(); - poItem.setName("a"); - poItem.setType("int"); - poList.add(poItem); - ParamObj poItem2 = new ParamObj(); - poItem2.setName("b"); - poItem2.setType("int"); - poList.add(poItem2); - - so.addFunc("add", "int", poList); + void getVarContent21() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("size_t"); + paObj.setStrValue("1"); - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); ParseObj po = new ParseObj(); - po.setStructList(sol); - + po.setVarList(pol); GeneratorBase gb = GenerateFactory.getGenerator("CH"); - gb.genStructList(po.getStructList()); + gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile 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"; - assertEquals(expect, structContent); + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const size_t num1 = 1;\n"; + assertEquals(expect, constContent); } } @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"); + void getVarContent22() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("string"); + paObj.setStrValue("1"); - List uol = new CopyOnWriteArrayList<>(); - uol.add(uo); + List pol = new CopyOnWriteArrayList<>(); + pol.add(paObj); ParseObj po = new ParseObj(); - po.setUnionList(uol); + po.setVarList(pol); GeneratorBase gb = GenerateFactory.getGenerator("CH"); - gb.genUnionList(po.getUnionList()); + gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile 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); + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const char* num1 = 1;\n"; + assertEquals(expect, constContent); } } @Test - void genVarList() { - ParseObj po = new ParseObj(); - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("number"); - pao.setStrValue("100"); + void getVarContent23() { + ParamObj paObj = new ParamObj(); + paObj.setName("num1"); + paObj.setType("std::string"); + paObj.setStrValue("1"); + List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); + pol.add(paObj); + ParseObj po = new ParseObj(); po.setVarList(pol); - GeneratorBase gb = GenerateFactory.getGenerator("CH"); - gb.genVarList(pol); + gb.genVarList(po.getVarList()); - if (gb instanceof GenCppFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nextends const int TestParam = 100;\n"; - assertEquals(expect, varContent); + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const char* num1 = 1;\n"; + assertEquals(expect, constContent); } } + } \ No newline at end of file diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenCHFileTest2.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCHFileTest2.java new file mode 100644 index 0000000000000000000000000000000000000000..523c98c968fa51b391067ca26025ac6450fb6bd5 --- /dev/null +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenCHFileTest2.java @@ -0,0 +1,1924 @@ +/* + * 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 GenCHFileTest2 { + private String genUnionContentTest = "\nstruct TestStruct {\n" + + "\tchar* 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" + + "\tchar* p15;\n" + + "\tchar* p16;\n" + + "\tint* p17;\n" + + "\tint* p18;\n" + + "\tint* p19;\n" + + "\tint* p20;\n" + + "\tint add(int a, int b);\n" + + "};\n"; + + private String genClassContentTest = "\nclass TestClass {\n" + + "\tchar* 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" + + "\tchar* p15;\n" + + "\tchar* p16;\n" + + "\tint* p17;\n" + + "\tint* p18;\n" + + "\tint* p19;\n" + + "\tint* p20;\n" + + "\tint delete(int);\n" + + "};\n"; + + @Test + void getInterfaceContent() { + } + + @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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int* 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int* 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int* 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("CH"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenCHFile gdf) { + String constContent = gdf.getConstContent(); + System.out.println("getVar: " + constContent); + String expect = "\nextends const int* 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile 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("CH"); + gb.genContent(po); + + if (gb instanceof GenCHFile 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("CH"); + 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 GenCHFile 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("CH"); + gb.genEnumList(po.getEnumList()); + + if (gb instanceof GenCHFile 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 genClassList() { + 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("CH"); + gb.genClassList(po.getClassList()); + + if (gb instanceof GenCHFile gdf) { + String classContent = gdf.getClassContent(); + System.out.println("genClass: " + classContent); + String expect = genClassContentTest; + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int16 age);"; + 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, char* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* 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("CH"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenCHFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nvoid TestFunc(char* name, int* age);"; + assertEquals(expect, funcContent); + } + } + + @Test + void genStructList() { + 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 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("CH"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenCHFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = genUnionContentTest; + 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tchar* 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nunion TestUnion{\n" + + "\tauto name;\n" + + "\tchar* 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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 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("CH"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenCHFile 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile 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("long"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + po.setVarList(pol); + + GeneratorBase gb = GenerateFactory.getGenerator("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const long TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList3() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const short TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList4() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const long long TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList5() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const float TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList6() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const double TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList7() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint8 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList8() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint16 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList9() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint32 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList10() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const uint64 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList11() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int8 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList12() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int16 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList13() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int32 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList14() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int64 TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList15() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const size_t TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList16() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const char* TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList17() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const char* TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList18() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int* TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList19() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int* TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList20() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int* TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } + + + @Test + void genVarList21() { + 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("CH"); + gb.genVarList(pol); + + if (gb instanceof GenCHFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nextends const int* TestParam = 100;\n"; + assertEquals(expect, varContent); + } + } +} \ No newline at end of file diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenDtsFileTest.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenDtsFileTest.java index 795603d92514ac92e35da7ec2fa3ce932a3c3248..0bcda6c471ad5608bc532d73d0c9c3132da05527 100644 --- a/src/intellij_plugin/ohosgen/src/test/java/gen/GenDtsFileTest.java +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenDtsFileTest.java @@ -38,6 +38,61 @@ import static utils.FileUtils.readText; * @since 2025-02-28 */ class GenDtsFileTest { + private final String genClassTestConent = "\nexport class TestClass {\n" + + "\tname: string;\n" + + "\tage: number;\n" + + "\tp1: number;\n" + + "\tp2: number;\n" + + "\tp3: number;\n" + + "\tp4: number;\n" + + "\tp5: number;\n" + + "\tp6: number;\n" + + "\tp7: number;\n" + + "\tp8: number;\n" + + "\tp9: number;\n" + + "\tp10: number;\n" + + "\tp11: number;\n" + + "\tp12: number;\n" + + "\tp13: number;\n" + + "\tp14: number;\n" + + "\tp15: string;\n" + + "\tp16: string;\n" + + "\tp17: number;\n" + + "\tp18: number;\n" + + "\tp19: number;\n" + + "\tp20: number;\n" + + "\tadd(a: number, b: number) : number;\n" + + "\taddAsync(a: number, b: number, cb: (err: string, res: number) => void) : void;\n" + + "\taddPromise(a: number, b: number) : Promise;\n" + + "};\n"; + + private final String genStructTestContent = "\nexport class TestStruct {\n" + + "\tname: string;\n" + + "\tage: number;\n" + + "\tp1: number;\n" + + "\tp2: number;\n" + + "\tp3: number;\n" + + "\tp4: number;\n" + + "\tp5: number;\n" + + "\tp6: number;\n" + + "\tp7: number;\n" + + "\tp8: number;\n" + + "\tp9: number;\n" + + "\tp10: number;\n" + + "\tp11: number;\n" + + "\tp12: number;\n" + + "\tp13: number;\n" + + "\tp14: number;\n" + + "\tp15: string;\n" + + "\tp16: string;\n" + + "\tp17: number;\n" + + "\tp18: number;\n" + + "\tp19: number;\n" + + "\tp20: number;\n" + + "\tadd(a: number, b: number) : number;\n" + + "\taddAsync(a: number, b: number, cb: (err: string, res: number) => void) : void;\n" + + "\taddPromise(a: number, b: number) : Promise;\n" + + "};\n"; @BeforeEach void setUp() { @@ -174,6 +229,26 @@ class GenDtsFileTest { co.addParam("name", "char*"); co.addParam("age", "int"); + 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(); @@ -198,19 +273,13 @@ class GenDtsFileTest { if (gb instanceof GenDtsFile gdf) { String classContent = gdf.getClassContent(); System.out.println("genClass: " + classContent); - String expect = "\nexport class TestClass {\n" + - "\tname: string;\n" + - "\tage: number;\n" + - "\tadd(a: number, b: number) : number;\n" + - "\taddAsync(a: number, b: number, cb: (err: string, res: number) => void) : void;\n" + - "\taddPromise(a: number, b: number) : Promise;\n" + - "};\n"; + String expect = genClassTestConent; assertEquals(expect, classContent); } } @Test - void genFuncList() { + void genFuncList1() { FuncObj fo = new FuncObj(); fo.setName("TestFunc"); @@ -240,118 +309,1187 @@ class GenDtsFileTest { fo.setName("TestFunc"); fo.addParam("name", "char*"); - fo.addParam("age", "int"); + fo.addParam("age", "long"); List fol = new CopyOnWriteArrayList<>(); fol.add(fo); ParseObj po = new ParseObj(); po.setFuncList(fol); GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); - if (gb instanceof GenDtsFile gdts) { - gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); } + } + + @Test + void genFuncList3() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "short"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); gb.genFuncList(po.getFuncList()); if (gb instanceof GenDtsFile gdf) { String funcContent = gdf.getFuncContent(); System.out.println("genFunc: " + funcContent); - String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + - "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + - "export const TestFuncPromise: (name: string, age: number) => Promise;"; + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; assertEquals(expect, funcContent); } } + @Test + void genFuncList4() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "long long"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } @Test - void genStructList() { - StructObj so = new StructObj(); - so.setName("TestStruct"); + void genFuncList5() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); - so.addMember("name", "char*"); - so.addMember("age", "int"); + fo.addParam("name", "char*"); + fo.addParam("age", "float"); - 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 fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); - so.addFunc("add", "int", poList); + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } - List sol = new CopyOnWriteArrayList<>(); - sol.add(so); + @Test + void genFuncList6() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "double"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); ParseObj po = new ParseObj(); - po.setStructList(sol); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList7() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "uint8"); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); GeneratorBase gb = GenerateFactory.getGenerator("DTS"); - gb.genStructList(po.getStructList()); + gb.genFuncList(po.getFuncList()); if (gb instanceof GenDtsFile gdf) { - String structContent = gdf.getStructContent(); - System.out.println("genStruct: " + structContent); - String expect = "\nexport class TestStruct {\n" + - "\tname: string;\n" + - "\tage: number;\n" + - "\tadd(a: number, b: number) : number;\n" + - "\taddAsync(a: number, b: number, cb: (err: string, res: number) => void) : void;\n" + - "\taddPromise(a: number, b: number) : Promise;\n" + - "};\n"; - assertEquals(expect, structContent); + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); } } @Test - void genTypeList() { + void genFuncList8() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "uint16"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } } @Test - void genUnionList() { - UnionObj uo = new UnionObj(); - uo.setName("TestUnion"); + void genFuncList9() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); - uo.addMember("name", "char*"); - uo.addMember("age", "int"); + fo.addParam("name", "char*"); + fo.addParam("age", "uint32"); - List uol = new CopyOnWriteArrayList<>(); - uol.add(uo); + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); ParseObj po = new ParseObj(); - po.setUnionList(uol); + po.setFuncList(fol); GeneratorBase gb = GenerateFactory.getGenerator("DTS"); - gb.genUnionList(po.getUnionList()); + gb.genFuncList(po.getFuncList()); if (gb instanceof GenDtsFile gdf) { - String unionContent = gdf.getUnionContent(); - System.out.println("genUnion: " + unionContent); - String expect = "\nexport type TestUnion = string | number;\n"; - assertEquals(expect, unionContent); + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); } } @Test - void genVarList() { - ParamObj pao = new ParamObj(); - pao.setName("TestParam"); - pao.setType("int"); - pao.setStrValue("100"); - List pol = new CopyOnWriteArrayList<>(); - pol.add(pao); + void genFuncList10() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "uint64"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); ParseObj po = new ParseObj(); - po.setVarList(pol); + po.setFuncList(fol); GeneratorBase gb = GenerateFactory.getGenerator("DTS"); - gb.genVarList(po.getVarList()); + gb.genFuncList(po.getFuncList()); if (gb instanceof GenDtsFile gdf) { - String varContent = gdf.getConstContent(); - System.out.println("genVar: " + varContent); - String expect = "\nexport const TestParam : number = 100;\n"; - assertEquals(expect, varContent); + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList11() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int8"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + @Test + void genFuncList12() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int16"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); } } + + @Test + void genFuncList13() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int32"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList14() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int64"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList15() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "size_t"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList16() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "string"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: string) : void;\n" + + "export function TestFuncAsync(name: string, age: string, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: string) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList17() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::string"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: string) : void;\n" + + "export function TestFuncAsync(name: string, age: string, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: string) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList18() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::array"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList19() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::stack"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList20() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::vector"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncList21() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::queue"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport function TestFunc(name: string, age: number) : void;\n" + + "export function TestFuncAsync(name: string, age: number, cb: (err: string) => void) : void;\n" + + "export function TestFuncPromise(name: string, age: number) : Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList1() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList2() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "long"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList3() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "short"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList4() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "long long"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList5() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "float"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList6() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "double"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList7() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "uint8"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList8() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "uint16"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList9() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "uint32"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList10() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "uint64"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList11() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int8"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList12() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int16"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList13() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int32"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList14() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "int64"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList15() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "size_t"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList16() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "string"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: string) => void;\n" + + "export const TestFuncAsync: (name: string, age: string, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: string) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList17() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::string"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: string) => void;\n" + + "export const TestFuncAsync: (name: string, age: string, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: string) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList18() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::array"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList19() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::stack"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList20() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::vector"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genFuncConstStyleList21() { + FuncObj fo = new FuncObj(); + fo.setName("TestFunc"); + + fo.addParam("name", "char*"); + fo.addParam("age", "std::queue"); + + List fol = new CopyOnWriteArrayList<>(); + fol.add(fo); + ParseObj po = new ParseObj(); + po.setFuncList(fol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + + if (gb instanceof GenDtsFile gdts) { + gdts.setStyleType(GenDtsFile.CONV_CONST_STYLE); + } + + gb.genFuncList(po.getFuncList()); + + if (gb instanceof GenDtsFile gdf) { + String funcContent = gdf.getFuncContent(); + System.out.println("genFunc: " + funcContent); + String expect = "\nexport const TestFunc: (name: string, age: number) => void;\n" + + "export const TestFuncAsync: (name: string, age: number, cb: (err: string) => void) => void;\n" + + "export const TestFuncPromise: (name: string, age: number) => Promise;"; + assertEquals(expect, funcContent); + } + } + + @Test + void genStructList() { + StructObj so = new StructObj(); + so.setName("TestStruct"); + + so.addMember("name", "char*"); + so.addMember("age", "int"); + 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("DTS"); + gb.genStructList(po.getStructList()); + + if (gb instanceof GenDtsFile gdf) { + String structContent = gdf.getStructContent(); + System.out.println("genStruct: " + structContent); + String expect = genStructTestContent; + assertEquals(expect, structContent); + } + } + + @Test + void genTypeList() { + } + } \ No newline at end of file diff --git a/src/intellij_plugin/ohosgen/src/test/java/gen/GenDtsFileTest2.java b/src/intellij_plugin/ohosgen/src/test/java/gen/GenDtsFileTest2.java new file mode 100644 index 0000000000000000000000000000000000000000..76e8fdeb3f1a6a54056a0a159d9ef32c71223c0c --- /dev/null +++ b/src/intellij_plugin/ohosgen/src/test/java/gen/GenDtsFileTest2.java @@ -0,0 +1,948 @@ +/* + * 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.AfterEach; +import org.junit.jupiter.api.BeforeEach; +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 GenDtsFileTest2 { + @BeforeEach + void setUp() { + } + + @AfterEach + void tearDown() { + } + + @Test + void genUnionList1() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "int"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList2() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList3() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "short"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList4() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "long long"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList5() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "float"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList6() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "double"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList7() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "uint8"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList8() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "uint16"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList9() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "uint32"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList10() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "uint64"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList11() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "int8"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList12() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "int16"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList13() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "int32"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList14() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "int64"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList15() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "size_t"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList16() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "string"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | string;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList17() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "std::string"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | string;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList18() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "std::array"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList19() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "std::stack"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList20() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "int"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genUnionList21() { + UnionObj uo = new UnionObj(); + uo.setName("TestUnion"); + + uo.addMember("name", "char*"); + uo.addMember("age", "std::queue"); + + List uol = new CopyOnWriteArrayList<>(); + uol.add(uo); + ParseObj po = new ParseObj(); + po.setUnionList(uol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genUnionList(po.getUnionList()); + + if (gb instanceof GenDtsFile gdf) { + String unionContent = gdf.getUnionContent(); + System.out.println("genUnion: " + unionContent); + String expect = "\nexport type TestUnion = string | number;\n"; + assertEquals(expect, unionContent); + } + } + + @Test + void genVarList1() { + 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("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList2() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("long"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList3() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("short"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList4() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("long long"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList5() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("float"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList6() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("double"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList7() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint8"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList8() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint16"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList9() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint32"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList10() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("uint64"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList11() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int8"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList12() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int32"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList13() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("int64"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList14() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("size_t"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList15() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("string"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : string = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList16() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::string"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : string = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList17() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::array"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList18() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::stack"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList19() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::vector"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } + + @Test + void genVarList20() { + ParamObj pao = new ParamObj(); + pao.setName("TestParam"); + pao.setType("std::queue"); + pao.setStrValue("100"); + List pol = new CopyOnWriteArrayList<>(); + pol.add(pao); + ParseObj po = new ParseObj(); + po.setVarList(pol); + GeneratorBase gb = GenerateFactory.getGenerator("DTS"); + gb.genVarList(po.getVarList()); + + if (gb instanceof GenDtsFile gdf) { + String varContent = gdf.getConstContent(); + System.out.println("genVar: " + varContent); + String expect = "\nexport const TestParam : number = 100;\n"; + assertEquals(expect, varContent); + } + } +} \ No newline at end of file