github.com/zhongdalu/gf@v1.0.0/third/golang.org/x/sys/windows/syscall_test.go (about)

     1  // Copyright 2013 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  // +build windows
     6  
     7  package windows_test
     8  
     9  import (
    10  	"syscall"
    11  	"testing"
    12  
    13  	"github.com/zhongdalu/gf/third/golang.org/x/sys/windows"
    14  )
    15  
    16  func testSetGetenv(t *testing.T, key, value string) {
    17  	err := windows.Setenv(key, value)
    18  	if err != nil {
    19  		t.Fatalf("Setenv failed to set %q: %v", value, err)
    20  	}
    21  	newvalue, found := windows.Getenv(key)
    22  	if !found {
    23  		t.Fatalf("Getenv failed to find %v variable (want value %q)", key, value)
    24  	}
    25  	if newvalue != value {
    26  		t.Fatalf("Getenv(%v) = %q; want %q", key, newvalue, value)
    27  	}
    28  }
    29  
    30  func TestEnv(t *testing.T) {
    31  	testSetGetenv(t, "TESTENV", "AVALUE")
    32  	// make sure TESTENV gets set to "", not deleted
    33  	testSetGetenv(t, "TESTENV", "")
    34  }
    35  
    36  func TestGetProcAddressByOrdinal(t *testing.T) {
    37  	// Attempt calling shlwapi.dll:IsOS, resolving it by ordinal, as
    38  	// suggested in
    39  	// https://msdn.microsoft.com/en-us/library/windows/desktop/bb773795.aspx
    40  	h, err := windows.LoadLibrary("shlwapi.dll")
    41  	if err != nil {
    42  		t.Fatalf("Failed to load shlwapi.dll: %s", err)
    43  	}
    44  	procIsOS, err := windows.GetProcAddressByOrdinal(h, 437)
    45  	if err != nil {
    46  		t.Fatalf("Could not find shlwapi.dll:IsOS by ordinal: %s", err)
    47  	}
    48  	const OS_NT = 1
    49  	r, _, _ := syscall.Syscall(procIsOS, 1, OS_NT, 0, 0)
    50  	if r == 0 {
    51  		t.Error("shlwapi.dll:IsOS(OS_NT) returned 0, expected non-zero value")
    52  	}
    53  }