Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: syzygy/refinery/types/type_repository_unittest.cc

Issue 1475083002: [Refinery] Introduce TypePropagatorAnalyzer - pointer types. (Closed) Base URL: https://github.com/google/syzygy.git@master
Patch Set: Final nit Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « syzygy/refinery/types/type_repository.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 Google Inc. All Rights Reserved. 1 // Copyright 2015 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with 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 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "syzygy/refinery/types/type_repository.h" 15 #include "syzygy/refinery/types/type_repository.h"
16 16
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "gtest/gtest.h" 18 #include "gtest/gtest.h"
19 #include "syzygy/pe/pe_file.h"
19 #include "syzygy/refinery/types/type.h" 20 #include "syzygy/refinery/types/type.h"
20 21
21 namespace refinery { 22 namespace refinery {
22 23
23 TEST(TypeRepositoryTest, AddType) { 24 TEST(TypeRepositoryTest, AddType) {
24 scoped_refptr<TypeRepository> repo = new TypeRepository(); 25 scoped_refptr<TypeRepository> repo = new TypeRepository();
25 EXPECT_EQ(0U, repo->size()); 26 EXPECT_EQ(0U, repo->size());
26 27
27 // Returns a NULL type for unknown TypeId. 28 // Returns a NULL type for unknown TypeId.
28 EXPECT_FALSE(repo->GetType(1)); 29 EXPECT_FALSE(repo->GetType(1));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // There is still no object with id 1. 78 // There is still no object with id 1.
78 EXPECT_FALSE(repo->GetType(1)); 79 EXPECT_FALSE(repo->GetType(1));
79 80
80 // This index is already taken. 81 // This index is already taken.
81 EXPECT_FALSE(repo->AddTypeWithId(t3, kId1)); 82 EXPECT_FALSE(repo->AddTypeWithId(t3, kId1));
82 83
83 EXPECT_EQ(t1, repo->GetType(kId1)); 84 EXPECT_EQ(t1, repo->GetType(kId1));
84 EXPECT_EQ(t2, repo->GetType(kId2)); 85 EXPECT_EQ(t2, repo->GetType(kId2));
85 } 86 }
86 87
88 TEST(TypeRepositoryTest, GetSignature) {
89 pe::PEFile::Signature retrieved_sig;
90
91 scoped_refptr<TypeRepository> repo = new TypeRepository();
92 ASSERT_FALSE(repo->GetModuleSignature(&retrieved_sig));
93
94 pe::PEFile::Signature sig(L"Path", core::AbsoluteAddress(1U), 2, 3, 4);
95 repo = new TypeRepository(sig);
96 ASSERT_TRUE(repo->GetModuleSignature(&retrieved_sig));
97 ASSERT_EQ(sig, retrieved_sig);
98 }
99
87 TEST(TypeRepositoryTest, Iteration) { 100 TEST(TypeRepositoryTest, Iteration) {
88 scoped_refptr<TypeRepository> repo = new TypeRepository(); 101 scoped_refptr<TypeRepository> repo = new TypeRepository();
89 102
90 repo->AddType(new BasicType(L"one", 4)); 103 repo->AddType(new BasicType(L"one", 4));
91 repo->AddType(new BasicType(L"two", 4)); 104 repo->AddType(new BasicType(L"two", 4));
92 repo->AddType(new BasicType(L"three", 4)); 105 repo->AddType(new BasicType(L"three", 4));
93 EXPECT_EQ(3U, repo->size()); 106 EXPECT_EQ(3U, repo->size());
94 107
95 size_t iterated = 0; 108 size_t iterated = 0;
96 for (auto type : *repo) { 109 for (auto type : *repo) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 ASSERT_EQ(2, matching_types.size()); 145 ASSERT_EQ(2, matching_types.size());
133 146
134 // Match with single hit. 147 // Match with single hit.
135 matching_types.clear(); 148 matching_types.clear();
136 index->GetTypes(kTypeNameTwo, &matching_types); 149 index->GetTypes(kTypeNameTwo, &matching_types);
137 ASSERT_EQ(1, matching_types.size()); 150 ASSERT_EQ(1, matching_types.size());
138 ASSERT_EQ(two.get(), matching_types[0].get()); 151 ASSERT_EQ(two.get(), matching_types[0].get());
139 } 152 }
140 153
141 } // namespace refinery 154 } // namespace refinery
OLDNEW
« no previous file with comments | « syzygy/refinery/types/type_repository.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698