You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB

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