(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestImport(t *testing.T) { |
| 15 | if !IsAvailable() { |
| 16 | t.Skipf("javap not available") |
| 17 | } |
| 18 | tests := []struct { |
| 19 | ref importers.PkgRef |
| 20 | name string |
| 21 | methods []*FuncSet |
| 22 | }{ |
| 23 | { |
| 24 | ref: importers.PkgRef{Pkg: "java/lang/Object", Name: "equals"}, |
| 25 | name: "java.lang.Object", |
| 26 | methods: []*FuncSet{ |
| 27 | &FuncSet{ |
| 28 | Name: "equals", |
| 29 | GoName: "Equals", |
| 30 | CommonSig: CommonSig{ |
| 31 | Params: []*Type{&Type{Kind: Object, Class: "java.lang.Object"}}, Ret: &Type{Kind: Boolean}, HasRet: true, |
| 32 | }, |
| 33 | Funcs: []*Func{&Func{FuncSig: FuncSig{Name: "equals", Desc: "(Ljava/lang/Object;)Z"}, ArgDesc: "Ljava/lang/Object;", JNIName: "equals", Public: true, Params: []*Type{&Type{Kind: Object, Class: "java.lang.Object"}}, Ret: &Type{Kind: Boolean}}}, |
| 34 | }, |
| 35 | }, |
| 36 | }, |
| 37 | { |
| 38 | ref: importers.PkgRef{Pkg: "java/lang/Runnable", Name: "run"}, |
| 39 | name: "java.lang.Runnable", |
| 40 | methods: []*FuncSet{ |
| 41 | &FuncSet{ |
| 42 | Name: "run", |
| 43 | GoName: "Run", |
| 44 | CommonSig: CommonSig{}, |
| 45 | Funcs: []*Func{&Func{FuncSig: FuncSig{Name: "run", Desc: "()V"}, ArgDesc: "", JNIName: "run", Public: true, Abstract: true}}, |
| 46 | }, |
| 47 | }, |
| 48 | }, |
| 49 | } |
| 50 | toString := &FuncSet{ |
| 51 | Name: "toString", |
| 52 | GoName: "ToString", |
| 53 | CommonSig: CommonSig{ |
| 54 | Ret: &Type{Kind: String}, HasRet: true, |
| 55 | }, |
| 56 | Funcs: []*Func{&Func{FuncSig: FuncSig{Name: "toString", Desc: "()Ljava/lang/String;"}, ArgDesc: "", JNIName: "toString", Public: true, Ret: &Type{Kind: String}}}, |
| 57 | } |
| 58 | for _, test := range tests { |
| 59 | refs := &importers.References{ |
| 60 | Refs: []importers.PkgRef{test.ref}, |
| 61 | Names: make(map[string]struct{}), |
| 62 | } |
| 63 | for _, m := range test.methods { |
| 64 | refs.Names[m.GoName] = struct{}{} |
| 65 | } |
| 66 | classes, err := (&Importer{}).Import(refs) |
| 67 | if err != nil { |
| 68 | t.Fatal(err) |
| 69 | } |
| 70 | if len(classes) != 1 { |
| 71 | t.Fatalf("got %d classes, expected 1", len(classes)) |
nothing calls this directly
no test coverage detected