OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 // Main entry point for all unit tests. | |
6 | |
7 #include "rlz_test_helpers.h" | |
8 | |
9 #include "rlz/lib/rlz_lib.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 #if defined(OS_WIN) | |
13 #include <shlwapi.h> | |
14 #include "base/win/registry.h" | |
15 #include "rlz/win/lib/rlz_lib.h" | |
16 #elif defined(OS_MACOSX) | |
17 #include "base/file_path.h" | |
18 #include "rlz/lib/rlz_value_store.h" | |
19 #endif | |
20 | |
21 #if defined(OS_WIN) | |
22 namespace { | |
23 | |
24 const wchar_t* kHKCUReplacement = L"Software\\Google\\RlzUtilUnittest\\HKCU"; | |
25 const wchar_t* kHKLMReplacement = L"Software\\Google\\RlzUtilUnittest\\HKLM"; | |
26 | |
27 void OverrideRegistryHives() { | |
28 // Wipe the keys we redirect to. | |
29 // This gives us a stable run, even in the presence of previous | |
30 // crashes or failures. | |
31 LSTATUS err = SHDeleteKey(HKEY_CURRENT_USER, kHKCUReplacement); | |
32 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); | |
33 err = SHDeleteKey(HKEY_CURRENT_USER, kHKLMReplacement); | |
34 EXPECT_TRUE(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND); | |
35 | |
36 // Create the keys we're redirecting HKCU and HKLM to. | |
37 base::win::RegKey hkcu; | |
38 base::win::RegKey hklm; | |
39 ASSERT_EQ(ERROR_SUCCESS, | |
40 hkcu.Create(HKEY_CURRENT_USER, kHKCUReplacement, KEY_READ)); | |
41 ASSERT_EQ(ERROR_SUCCESS, | |
42 hklm.Create(HKEY_CURRENT_USER, kHKLMReplacement, KEY_READ)); | |
43 | |
44 rlz_lib::InitializeTempHivesForTesting(hklm, hkcu); | |
45 | |
46 // And do the switcharoo. | |
47 ASSERT_EQ(ERROR_SUCCESS, | |
48 ::RegOverridePredefKey(HKEY_CURRENT_USER, hkcu.Handle())); | |
49 ASSERT_EQ(ERROR_SUCCESS, | |
50 ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, hklm.Handle())); | |
51 } | |
52 | |
53 void UndoOverrideRegistryHives() { | |
54 // Undo the redirection. | |
55 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_CURRENT_USER, NULL)); | |
56 EXPECT_EQ(ERROR_SUCCESS, ::RegOverridePredefKey(HKEY_LOCAL_MACHINE, NULL)); | |
57 } | |
58 | |
59 } // namespace | |
60 #endif // defined(OS_WIN) | |
61 | |
62 | |
63 void RlzLibTestNoMachineState::SetUp() { | |
64 #if defined(OS_WIN) | |
65 OverrideRegistryHives(); | |
66 #elif defined(OS_MACOSX) | |
67 base::mac::ScopedNSAutoreleasePool pool; | |
68 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
69 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); | |
70 #endif // defined(OS_WIN) | |
71 } | |
72 | |
73 void RlzLibTestNoMachineState::TearDown() { | |
74 #if defined(OS_WIN) | |
75 UndoOverrideRegistryHives(); | |
76 #elif defined(OS_MACOSX) | |
77 rlz_lib::testing::SetRlzStoreDirectory(FilePath()); | |
78 #endif // defined(OS_WIN) | |
79 } | |
80 | |
81 void RlzLibTestBase::SetUp() { | |
82 RlzLibTestNoMachineState::SetUp(); | |
83 #if defined(OS_WIN) | |
84 rlz_lib::CreateMachineState(); | |
85 #endif // defined(OS_WIN) | |
86 } | |
OLD | NEW |