OLD | NEW |
| (Empty) |
1 // Copyright 2007-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 // | |
17 // Unit test for RegistryStore. | |
18 | |
19 #include "omaha/base/registry_store.h" | |
20 #include "omaha/testing/unit_test.h" | |
21 | |
22 namespace omaha { | |
23 | |
24 static const TCHAR kRSTestKey[] = | |
25 _T("HKCU\\Software\\Google\\Common_Installer__TEST_STORE"); | |
26 static const TCHAR kRSTestName[] = _T("TestValueName"); | |
27 static const byte kRSTestValue[] = {0x01, 0x02, 0x03, 0x04, 0x05}; | |
28 static const int kRSTestValueSize = arraysize(kRSTestValue); | |
29 | |
30 TEST(RegistryStoreTest, RegistryStore) { | |
31 RegistryStore registry_store; | |
32 uint32 value_count = 42; // We want to make sure it's overwritten with 0. | |
33 CString value_name; | |
34 std::vector<byte> data; | |
35 | |
36 // Set up and get in a known state. | |
37 EXPECT_TRUE(registry_store.Open(kRSTestKey)); | |
38 EXPECT_TRUE(registry_store.Clear()); | |
39 | |
40 // Add and test a single value | |
41 EXPECT_FALSE(registry_store.Exists(kRSTestName)); | |
42 EXPECT_FALSE(registry_store.Read(kRSTestName, &data)); | |
43 data.clear(); | |
44 | |
45 EXPECT_TRUE(registry_store.Write(kRSTestName, | |
46 const_cast<byte*>(kRSTestValue), | |
47 kRSTestValueSize)); | |
48 | |
49 EXPECT_TRUE(registry_store.Exists(kRSTestName)); | |
50 EXPECT_TRUE(registry_store.Read(kRSTestName, &data)); | |
51 EXPECT_EQ(data.size(), kRSTestValueSize); | |
52 for (int i = 0; i < kRSTestValueSize; i++) | |
53 EXPECT_EQ(data[i], kRSTestValue[i]); | |
54 | |
55 // Remove and re-add value | |
56 EXPECT_TRUE(registry_store.Remove(kRSTestName)); | |
57 EXPECT_FALSE(registry_store.Exists(kRSTestName)); | |
58 EXPECT_TRUE(registry_store.GetValueCount(&value_count)); | |
59 EXPECT_EQ(value_count, 0); | |
60 EXPECT_TRUE(registry_store.Write(kRSTestName, | |
61 const_cast<byte*>(kRSTestValue), | |
62 kRSTestValueSize)); | |
63 EXPECT_TRUE(registry_store.GetValueCount(&value_count)); | |
64 EXPECT_EQ(value_count, 1); | |
65 EXPECT_TRUE(registry_store.GetValueNameAt(0, &value_name)); | |
66 EXPECT_TRUE(value_name == kRSTestName); | |
67 | |
68 // Clean up and finish. | |
69 EXPECT_TRUE(registry_store.Clear()); | |
70 EXPECT_FALSE(registry_store.Exists(kRSTestName)); | |
71 EXPECT_FALSE(registry_store.GetValueCount(&value_count)); | |
72 EXPECT_TRUE(registry_store.Close()); | |
73 } | |
74 | |
75 } // namespace omaha | |
OLD | NEW |