license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | #include <windows.h> |
| 6 | |
| 7 | #include "testing/gtest/include/gtest/gtest.h" |
| 8 | #include "base/wmi_util.h" |
| 9 | |
| 10 | TEST(WMIUtilTest, TestLocalConnectionSecurityBlanket) { |
| 11 | ::CoInitialize(NULL); |
| 12 | IWbemServices* services = NULL; |
| 13 | EXPECT_TRUE(WMIUtil::CreateLocalConnection(true, &services)); |
| 14 | ASSERT_TRUE(NULL != services); |
| 15 | ULONG refs = services->Release(); |
| 16 | EXPECT_EQ(refs, 0); |
| 17 | ::CoUninitialize(); |
| 18 | } |
| 19 | |
| 20 | TEST(WMIUtilTest, TestLocalConnectionNoSecurityBlanket) { |
| 21 | ::CoInitialize(NULL); |
| 22 | IWbemServices* services = NULL; |
| 23 | EXPECT_TRUE(WMIUtil::CreateLocalConnection(false, &services)); |
| 24 | ASSERT_TRUE(NULL != services); |
| 25 | ULONG refs = services->Release(); |
| 26 | EXPECT_EQ(refs, 0); |
| 27 | ::CoUninitialize(); |
| 28 | } |
| 29 | |
| 30 | TEST(WMIUtilTest, TestCreateClassMethod) { |
| 31 | ::CoInitialize(NULL); |
| 32 | IWbemServices* wmi_services = NULL; |
| 33 | EXPECT_TRUE(WMIUtil::CreateLocalConnection(true, &wmi_services)); |
| 34 | ASSERT_TRUE(NULL != wmi_services); |
| 35 | IWbemClassObject* class_method = NULL; |
| 36 | EXPECT_TRUE(WMIUtil::CreateClassMethodObject(wmi_services, |
| 37 | L"Win32_ShortcutFile", |
| 38 | L"Rename", &class_method)); |
| 39 | ASSERT_TRUE(NULL != class_method); |
| 40 | ULONG refs = class_method->Release(); |
| 41 | EXPECT_EQ(refs, 0); |
| 42 | refs = wmi_services->Release(); |
| 43 | EXPECT_EQ(refs, 0); |
| 44 | ::CoUninitialize(); |
| 45 | } |
| 46 | |
| 47 | // Creates an instance of cmd which executes 'echo' and exits immediately. |
| 48 | TEST(WMIUtilTest, TestLaunchProcess) { |
| 49 | ::CoInitialize(NULL); |
| 50 | int pid = 0; |
| 51 | bool result = WMIProcessUtil::Launch(L"cmd.exe /c echo excelent!", &pid); |
| 52 | EXPECT_TRUE(result); |
| 53 | EXPECT_GT(pid, 0); |
| 54 | ::CoUninitialize(); |
| 55 | } |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 56 | |