Source file misc/cgo/testplugin/testdata/iface/main.go

     1  // Copyright 2017 The Go 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 main
     6  
     7  import (
     8  	"log"
     9  	"plugin"
    10  
    11  	"testplugin/iface_i"
    12  )
    13  
    14  func main() {
    15  	a, err := plugin.Open("iface_a.so")
    16  	if err != nil {
    17  		log.Fatalf(`plugin.Open("iface_a.so"): %v`, err)
    18  	}
    19  	b, err := plugin.Open("iface_b.so")
    20  	if err != nil {
    21  		log.Fatalf(`plugin.Open("iface_b.so"): %v`, err)
    22  	}
    23  
    24  	af, err := a.Lookup("F")
    25  	if err != nil {
    26  		log.Fatalf(`a.Lookup("F") failed: %v`, err)
    27  	}
    28  	bf, err := b.Lookup("F")
    29  	if err != nil {
    30  		log.Fatalf(`b.Lookup("F") failed: %v`, err)
    31  	}
    32  	if af.(func() interface{})() != bf.(func() interface{})() {
    33  		panic("empty interfaces not equal")
    34  	}
    35  
    36  	ag, err := a.Lookup("G")
    37  	if err != nil {
    38  		log.Fatalf(`a.Lookup("G") failed: %v`, err)
    39  	}
    40  	bg, err := b.Lookup("G")
    41  	if err != nil {
    42  		log.Fatalf(`b.Lookup("G") failed: %v`, err)
    43  	}
    44  	if ag.(func() iface_i.I)() != bg.(func() iface_i.I)() {
    45  		panic("nonempty interfaces not equal")
    46  	}
    47  }
    48  

View as plain text