// Code generated by cmd/cgo; DO NOT EDIT.

//line /home/xzl/work/golang-1.22/golang-1.22/src/cmd/cgo/internal/test/issue4029.go:1:1
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !windows && !static && !(darwin && internal)

// Excluded in darwin internal linking PIE (which is the default) mode,
// as dynamic export is not supported.

package cgotest

/*
#include <stdint.h>
#include <dlfcn.h>
#cgo linux LDFLAGS: -ldl

extern uintptr_t dlopen4029(char*, int);
extern uintptr_t dlsym4029(uintptr_t, char*);
extern int dlclose4029(uintptr_t);

extern void call4029(uintptr_t arg);
*/
import _ "unsafe"

import (
	"testing"
)

var callbacks int

//export IMPIsOpaque
func IMPIsOpaque() {
	callbacks++
}

//export IMPInitWithFrame
func IMPInitWithFrame() {
	callbacks++
}

//export IMPDrawRect
func IMPDrawRect() {
	callbacks++
}

//export IMPWindowResize
func IMPWindowResize() {
	callbacks++
}

func test4029(t *testing.T) {
	loadThySelf(t, "IMPWindowResize")
	loadThySelf(t, "IMPDrawRect")
	loadThySelf(t, "IMPInitWithFrame")
	loadThySelf(t, "IMPIsOpaque")
	if callbacks != 4 {
		t.Errorf("got %d callbacks, expected 4", callbacks)
	}
}

func loadThySelf(t *testing.T, symbol string) {
	this_process := ( /*line :62:18*/_Cfunc_dlopen4029 /*line :62:29*/)(nil, ( /*line :62:36*/_Ciconst_RTLD_NOW /*line :62:45*/))
	if this_process == 0 {
		t.Error("dlopen:", ( /*line :64:22*/_Cfunc_GoString /*line :64:31*/)(( /*line :64:33*/_Cfunc_dlerror /*line :64:41*/)()))
		return
	}
	defer ( /*line :67:8*/_Cfunc_dlclose4029 /*line :67:20*/)(this_process)

	symbol_address := ( /*line :69:20*/_Cfunc_dlsym4029 /*line :69:30*/)(this_process, ( /*line :69:46*/_Cfunc_CString /*line :69:54*/)(symbol))
	if symbol_address == 0 {
		t.Error("dlsym:", ( /*line :71:21*/_Cfunc_GoString /*line :71:30*/)(( /*line :71:32*/_Cfunc_dlerror /*line :71:40*/)()))
		return
	}
	t.Log(symbol, symbol_address)
	( /*line :75:2*/_Cfunc_call4029 /*line :75:11*/)(symbol_address)
}
