Skip to content

Commit

Permalink
JACOBIN-418 Added test instantiation of java/lang/Object. If this wor…
Browse files Browse the repository at this point in the history
…ks on GitHub, will expand with other classes.
  • Loading branch information
platypusguy committed Dec 29, 2023
1 parent 0350153 commit 59d13e3
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/jvm/instantiate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,48 @@ func TestLoadClassWithEmptyStringAsName(t *testing.T) {
os.Stderr = normalStderr

if err == nil {
t.Errorf("Expected error message for class with no nsmr, but got none")
t.Errorf("Expected error message for class with no name string, but got none")
}

if !strings.Contains(err.Error(), "Failed to load class") {
t.Errorf("Got the wrong error message: %s", err.Error())
}
}

// This should always work. java/lang/Object contains no instance or static fields,
// so this is about as simple a class instantiation as possible
func TestLoadClassJavaLangObject(t *testing.T) {
globals.InitGlobals("test")
log.Init()
_ = log.SetLogLevel(log.WARNING)

// redirect stderr, to avoid all the error msgs for a non-existent class
normalStderr := os.Stderr
_, werr, err := os.Pipe()
os.Stderr = werr

classloader.InitMethodArea()

// initialize the MTable and other class entries
classloader.MTable = make(map[string]classloader.MTentry)

// Init classloader and load base classes
err = classloader.Init() // must precede classloader.LoadBaseClasses
if err != nil {
t.Errorf("Got unexpected error from classloader.Init: %s", err.Error())
}
classloader.LoadBaseClasses()

err = loadThisClass("java/lang/Object")

// this should always work. java/lang/Object contains no instance or static fields,
// so this is about as simple a class instantiation as possible

// restore stderr
_ = werr.Close()
os.Stderr = normalStderr

if err != nil {
t.Errorf("Got unexpected error from loadThisClass: %s", err.Error())
}
}

0 comments on commit 59d13e3

Please sign in to comment.