github.com/remoteit/go-ole@v1.2.7/com_func_test.go (about)

     1  // +build !windows
     2  
     3  package ole
     4  
     5  import "testing"
     6  
     7  // TestComSetupAndShutDown tests that API fails on Linux.
     8  func TestComSetupAndShutDown(t *testing.T) {
     9  	defer func() {
    10  		if r := recover(); r != nil {
    11  			t.Log(r)
    12  			t.Fail()
    13  		}
    14  	}()
    15  
    16  	err := coInitialize()
    17  	if err == nil {
    18  		t.Error("should be error, because only Windows is supported.")
    19  		t.FailNow()
    20  	}
    21  
    22  	CoUninitialize()
    23  }
    24  
    25  // TestComPublicSetupAndShutDown tests that API fails on Linux.
    26  func TestComPublicSetupAndShutDown(t *testing.T) {
    27  	defer func() {
    28  		if r := recover(); r != nil {
    29  			t.Log(r)
    30  			t.Fail()
    31  		}
    32  	}()
    33  
    34  	err := CoInitialize(0)
    35  	if err == nil {
    36  		t.Error("should be error, because only Windows is supported.")
    37  		t.FailNow()
    38  	}
    39  
    40  	CoUninitialize()
    41  }
    42  
    43  // TestComPublicSetupAndShutDown_WithValue tests that API fails on Linux.
    44  func TestComPublicSetupAndShutDown_WithValue(t *testing.T) {
    45  	defer func() {
    46  		if r := recover(); r != nil {
    47  			t.Log(r)
    48  			t.Fail()
    49  		}
    50  	}()
    51  
    52  	err := CoInitialize(5)
    53  	if err == nil {
    54  		t.Error("should be error, because only Windows is supported.")
    55  		t.FailNow()
    56  	}
    57  
    58  	CoUninitialize()
    59  }
    60  
    61  // TestComExSetupAndShutDown tests that API fails on Linux.
    62  func TestComExSetupAndShutDown(t *testing.T) {
    63  	defer func() {
    64  		if r := recover(); r != nil {
    65  			t.Log(r)
    66  			t.Fail()
    67  		}
    68  	}()
    69  
    70  	err := coInitializeEx(COINIT_MULTITHREADED)
    71  	if err == nil {
    72  		t.Error("should be error, because only Windows is supported.")
    73  		t.FailNow()
    74  	}
    75  
    76  	CoUninitialize()
    77  }
    78  
    79  // TestComPublicExSetupAndShutDown tests that API fails on Linux.
    80  func TestComPublicExSetupAndShutDown(t *testing.T) {
    81  	defer func() {
    82  		if r := recover(); r != nil {
    83  			t.Log(r)
    84  			t.Fail()
    85  		}
    86  	}()
    87  
    88  	err := CoInitializeEx(0, COINIT_MULTITHREADED)
    89  	if err == nil {
    90  		t.Error("should be error, because only Windows is supported.")
    91  		t.FailNow()
    92  	}
    93  
    94  	CoUninitialize()
    95  }
    96  
    97  // TestComPublicExSetupAndShutDown_WithValue tests that API fails on Linux.
    98  func TestComPublicExSetupAndShutDown_WithValue(t *testing.T) {
    99  	defer func() {
   100  		if r := recover(); r != nil {
   101  			t.Log(r)
   102  			t.Fail()
   103  		}
   104  	}()
   105  
   106  	err := CoInitializeEx(5, COINIT_MULTITHREADED)
   107  	if err == nil {
   108  		t.Error("should be error, because only Windows is supported.")
   109  		t.FailNow()
   110  	}
   111  
   112  	CoUninitialize()
   113  }
   114  
   115  // TestClsidFromProgID_WindowsMediaNSSManager tests that API fails on Linux.
   116  func TestClsidFromProgID_WindowsMediaNSSManager(t *testing.T) {
   117  	defer func() {
   118  		if r := recover(); r != nil {
   119  			t.Log(r)
   120  			t.Fail()
   121  		}
   122  	}()
   123  
   124  	coInitialize()
   125  	defer CoUninitialize()
   126  	_, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
   127  	if err == nil {
   128  		t.Error("should be error, because only Windows is supported.")
   129  		t.FailNow()
   130  	}
   131  }
   132  
   133  // TestClsidFromString_WindowsMediaNSSManager tests that API fails on Linux.
   134  func TestClsidFromString_WindowsMediaNSSManager(t *testing.T) {
   135  	defer func() {
   136  		if r := recover(); r != nil {
   137  			t.Log(r)
   138  			t.Fail()
   139  		}
   140  	}()
   141  
   142  	coInitialize()
   143  	defer CoUninitialize()
   144  	_, err := CLSIDFromString("{92498132-4D1A-4297-9B78-9E2E4BA99C07}")
   145  
   146  	if err == nil {
   147  		t.Error("should be error, because only Windows is supported.")
   148  		t.FailNow()
   149  	}
   150  }
   151  
   152  // TestCreateInstance_WindowsMediaNSSManager tests that API fails on Linux.
   153  func TestCreateInstance_WindowsMediaNSSManager(t *testing.T) {
   154  	defer func() {
   155  		if r := recover(); r != nil {
   156  			t.Log(r)
   157  			t.Fail()
   158  		}
   159  	}()
   160  
   161  	coInitialize()
   162  	defer CoUninitialize()
   163  	_, err := CLSIDFromProgID("WMPNSSCI.NSSManager")
   164  
   165  	if err == nil {
   166  		t.Error("should be error, because only Windows is supported.")
   167  		t.FailNow()
   168  	}
   169  }
   170  
   171  // TestError tests that API fails on Linux.
   172  func TestError(t *testing.T) {
   173  	defer func() {
   174  		if r := recover(); r != nil {
   175  			t.Log(r)
   176  			t.Fail()
   177  		}
   178  	}()
   179  
   180  	coInitialize()
   181  	defer CoUninitialize()
   182  	_, err := CLSIDFromProgID("INTERFACE-NOT-FOUND")
   183  	if err == nil {
   184  		t.Error("should be error, because only Windows is supported.")
   185  		t.FailNow()
   186  	}
   187  
   188  	switch vt := err.(type) {
   189  	case *OleError:
   190  	default:
   191  		t.Fatalf("should be *ole.OleError %t", vt)
   192  	}
   193  }