github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/jvm/gojvm_test.go (about)

     1  package jvm
     2  
     3  import "testing"
     4  
     5  func TestStaticInvoke(t *testing.T) {
     6  	jvm := NewJVM(".", "128m", "512m", "384m", "512k")
     7  	env := jvm.Attach()
     8  	c1 := env.FindClass("Hello")
     9  	s0, _ := c1.InvokeString("hello", "rarnu", 8)
    10  	t.Logf("%v\n", s0)
    11  	env.Detach()
    12  	jvm.Free()
    13  }
    14  
    15  func TestStaticGetClass(t *testing.T) {
    16  	jvm := NewJVM(".", "128m", "512m", "384m", "512k")
    17  	env := jvm.Attach()
    18  
    19  	c1 := env.FindClass("Hello")
    20  	jo := c1.GetObject("h", "H1")
    21  	t.Logf("%v\n", jo)
    22  	jo.Free()
    23  	c1.Free()
    24  
    25  	env.Detach()
    26  	jvm.Free()
    27  }
    28  
    29  func TestNewClass(t *testing.T) {
    30  	jvm := NewJVM(".", "128m", "512m", "384m", "512k")
    31  	env := jvm.Attach()
    32  
    33  	c1 := env.NewObject("Hello")
    34  	t.Logf("%v\n", c1)
    35  	c1.Free()
    36  
    37  	env.Detach()
    38  	jvm.Free()
    39  }
    40  
    41  func TestClassFields(t *testing.T) {
    42  
    43  	jvm := NewJVM(".", "128m", "512m", "384m", "512k")
    44  	env := jvm.Attach()
    45  
    46  	c1 := env.NewObject("H1")
    47  	t.Logf("%v\n", c1)
    48  
    49  	s1 := c1.GetString("v")
    50  	t.Logf("%v\n", s1)
    51  
    52  	c1.SetString("v", "rarnu")
    53  	s2 := c1.GetString("v")
    54  	t.Logf("%v\n", s2)
    55  
    56  	c1.Free()
    57  
    58  	env.Detach()
    59  	jvm.Free()
    60  
    61  }
    62  
    63  func TestJar(t *testing.T) {
    64  	jvm := NewJVM("./jarsample.jar:.", "128m", "512m", "384m", "512k")
    65  	env := jvm.Attach()
    66  
    67  	c1 := env.FindClass("SampleClass")
    68  	s0, _ := c1.InvokeString("helloStatic", "rarnu")
    69  	t.Logf("%v\n", s0)
    70  
    71  	o1 := env.NewObject("SampleClass")
    72  	v1 := o1.GetInt("v1")
    73  	t.Logf("%v\n", v1)
    74  
    75  	o1.Free()
    76  
    77  	c1.Free()
    78  	env.Detach()
    79  	jvm.Free()
    80  }