go-hep.org/x/hep@v0.38.1/groot/rbase/processid_test.go (about)

     1  // Copyright ©2020 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package rbase_test
     6  
     7  import (
     8  	"testing"
     9  
    10  	"go-hep.org/x/hep/groot"
    11  	"go-hep.org/x/hep/groot/rbase"
    12  )
    13  
    14  func TestProcessID(t *testing.T) {
    15  	var pid rbase.ProcessID
    16  
    17  	if got, want := pid.Name(), ""; got != want {
    18  		t.Fatalf("invalid name. got=%q, want=%q", got, want)
    19  	}
    20  	if got, want := pid.Title(), ""; got != want {
    21  		t.Fatalf("invalid title. got=%q, want=%q", got, want)
    22  	}
    23  
    24  	pid.SetName("my-name")
    25  	pid.SetTitle("my-title")
    26  
    27  	if got, want := pid.Name(), "my-name"; got != want {
    28  		t.Fatalf("invalid name. got=%q, want=%q", got, want)
    29  	}
    30  	if got, want := pid.Title(), "my-title"; got != want {
    31  		t.Fatalf("invalid title. got=%q, want=%q", got, want)
    32  	}
    33  	if got, want := pid.String(), `TProcessID{Name: my-name, Title: my-title}`; got != want {
    34  		t.Fatalf("invalid string representation. got=%s, want=%s", got, want)
    35  	}
    36  
    37  	t.Run("read-from-root", func(t *testing.T) {
    38  		f, err := groot.Open("../testdata/pid.root")
    39  		if err != nil {
    40  			t.Fatalf("%+v", err)
    41  		}
    42  		defer f.Close()
    43  
    44  		o, err := f.Get("type-TProcessID")
    45  		if err != nil {
    46  			t.Fatalf("%+v", err)
    47  		}
    48  
    49  		pid := o.(*rbase.ProcessID)
    50  
    51  		if got, want := pid.Name(), "my-pid"; got != want {
    52  			t.Fatalf("invalid name. got=%q, want=%q", got, want)
    53  		}
    54  		if got, want := pid.Title(), "my-title"; got != want {
    55  			t.Fatalf("invalid title. got=%q, want=%q", got, want)
    56  		}
    57  	})
    58  }