Home | History | Annotate | Download | only in util
      1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include <windows.h>
      6 
      7 #include "chrome/installer/util/wmi.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 
     10 namespace installer {
     11 
     12 TEST(WMITest, TestLocalConnectionSecurityBlanket) {
     13   IWbemServices* services = NULL;
     14   EXPECT_TRUE(WMI::CreateLocalConnection(true, &services));
     15   ASSERT_TRUE(NULL != services);
     16   ULONG refs = services->Release();
     17   EXPECT_EQ(refs, 0);
     18 }
     19 
     20 TEST(WMITest, TestLocalConnectionNoSecurityBlanket) {
     21   IWbemServices* services = NULL;
     22   EXPECT_TRUE(WMI::CreateLocalConnection(false, &services));
     23   ASSERT_TRUE(NULL != services);
     24   ULONG refs = services->Release();
     25   EXPECT_EQ(refs, 0);
     26 }
     27 
     28 TEST(WMITest, TestCreateClassMethod) {
     29   IWbemServices* wmi_services = NULL;
     30   EXPECT_TRUE(WMI::CreateLocalConnection(true, &wmi_services));
     31   ASSERT_TRUE(NULL != wmi_services);
     32   IWbemClassObject* class_method = NULL;
     33   EXPECT_TRUE(WMI::CreateClassMethodObject(wmi_services,
     34                                                L"Win32_ShortcutFile",
     35                                                L"Rename", &class_method));
     36   ASSERT_TRUE(NULL != class_method);
     37   ULONG refs = class_method->Release();
     38   EXPECT_EQ(refs, 0);
     39   refs = wmi_services->Release();
     40   EXPECT_EQ(refs, 0);
     41 }
     42 
     43 // Creates an instance of cmd which executes 'echo' and exits immediately.
     44 TEST(WMITest, TestLaunchProcess) {
     45   int pid = 0;
     46   bool result = WMIProcess::Launch(L"cmd.exe /c echo excelent!", &pid);
     47   EXPECT_TRUE(result);
     48   EXPECT_GT(pid, 0);
     49 }
     50 
     51 }  // namespace installer
     52