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

Side by Side Diff: sandbox/src/interception_unittest.cc

Issue 2081007: Enable warning 4389 as an error on windows builds. This will make... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « sandbox/src/file_policy_test.cc ('k') | sandbox/src/job_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains unit tests for InterceptionManager. 5 // This file contains unit tests for InterceptionManager.
6 // The tests require private information so the whole interception.cc file is 6 // The tests require private information so the whole interception.cc file is
7 // included from this file. 7 // included from this file.
8 8
9 #include <windows.h> 9 #include <windows.h>
10 10
11 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
30 ASSERT_TRUE(NULL != buffer); 30 ASSERT_TRUE(NULL != buffer);
31 ASSERT_TRUE(NULL != num_functions); 31 ASSERT_TRUE(NULL != num_functions);
32 ASSERT_TRUE(NULL != num_names); 32 ASSERT_TRUE(NULL != num_names);
33 *num_dlls = *num_functions = *num_names = 0; 33 *num_dlls = *num_functions = *num_names = 0;
34 SharedMemory *memory = reinterpret_cast<SharedMemory*>(buffer); 34 SharedMemory *memory = reinterpret_cast<SharedMemory*>(buffer);
35 35
36 ASSERT_GT(size, sizeof(SharedMemory)); 36 ASSERT_GT(size, sizeof(SharedMemory));
37 DllPatchInfo *dll = &memory->dll_list[0]; 37 DllPatchInfo *dll = &memory->dll_list[0];
38 38
39 for (int i = 0; i < memory->num_intercepted_dlls; i++) { 39 for (int i = 0; i < memory->num_intercepted_dlls; i++) {
40 ASSERT_NE(0, wcslen(dll->dll_name)); 40 ASSERT_NE(0u, wcslen(dll->dll_name));
41 ASSERT_EQ(0, dll->record_bytes % sizeof(size_t)); 41 ASSERT_EQ(0u, dll->record_bytes % sizeof(size_t));
42 ASSERT_EQ(0, dll->offset_to_functions % sizeof(size_t)); 42 ASSERT_EQ(0u, dll->offset_to_functions % sizeof(size_t));
43 ASSERT_NE(0, dll->num_functions); 43 ASSERT_NE(0, dll->num_functions);
44 44
45 FunctionInfo *function = reinterpret_cast<FunctionInfo*>( 45 FunctionInfo *function = reinterpret_cast<FunctionInfo*>(
46 reinterpret_cast<char*>(dll) + dll->offset_to_functions); 46 reinterpret_cast<char*>(dll) + dll->offset_to_functions);
47 47
48 for (int j = 0; j < dll->num_functions; j++) { 48 for (int j = 0; j < dll->num_functions; j++) {
49 ASSERT_EQ(0, function->record_bytes % sizeof(size_t)); 49 ASSERT_EQ(0u, function->record_bytes % sizeof(size_t));
50 50
51 char* name = function->function; 51 char* name = function->function;
52 size_t length = strlen(name); 52 size_t length = strlen(name);
53 ASSERT_NE(0, length); 53 ASSERT_NE(0u, length);
54 name += length + 1; 54 name += length + 1;
55 55
56 // look for overflows 56 // look for overflows
57 ASSERT_GT(reinterpret_cast<char*>(buffer) + size, name + strlen(name)); 57 ASSERT_GT(reinterpret_cast<char*>(buffer) + size, name + strlen(name));
58 58
59 // look for a named interceptor 59 // look for a named interceptor
60 if (strlen(name)) { 60 if (strlen(name)) {
61 (*num_names)++; 61 (*num_names)++;
62 EXPECT_TRUE(NULL == function->interceptor_address); 62 EXPECT_TRUE(NULL == function->interceptor_address);
63 } else { 63 } else {
64 EXPECT_TRUE(NULL != function->interceptor_address); 64 EXPECT_TRUE(NULL != function->interceptor_address);
65 } 65 }
66 66
67 (*num_functions)++; 67 (*num_functions)++;
68 function = reinterpret_cast<FunctionInfo*>( 68 function = reinterpret_cast<FunctionInfo*>(
69 reinterpret_cast<char*>(function) + function->record_bytes); 69 reinterpret_cast<char*>(function) + function->record_bytes);
70 } 70 }
71 71
72 (*num_dlls)++; 72 (*num_dlls)++;
73 dll = reinterpret_cast<DllPatchInfo*>(reinterpret_cast<char*>(dll) + 73 dll = reinterpret_cast<DllPatchInfo*>(reinterpret_cast<char*>(dll) +
74 dll->record_bytes); 74 dll->record_bytes);
75 } 75 }
76 } 76 }
77 77
78 TEST(InterceptionManagerTest, BufferLayout1) { 78 TEST(InterceptionManagerTest, BufferLayout1) {
79 wchar_t exe_name[MAX_PATH]; 79 wchar_t exe_name[MAX_PATH];
80 ASSERT_NE(0, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); 80 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1));
81 81
82 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(), 82 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(),
83 ::GetModuleHandle(exe_name)); 83 ::GetModuleHandle(exe_name));
84 84
85 InterceptionManager interceptions(target, true); 85 InterceptionManager interceptions(target, true);
86 86
87 // Any pointer will do for a function pointer. 87 // Any pointer will do for a function pointer.
88 void* function = &interceptions; 88 void* function = &interceptions;
89 89
90 // We don't care about the interceptor id. 90 // We don't care about the interceptor id.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // The 15 interceptions on the buffer (to the child) should be grouped on 6 157 // The 15 interceptions on the buffer (to the child) should be grouped on 6
158 // dlls. Only four interceptions are using an explicit name for the 158 // dlls. Only four interceptions are using an explicit name for the
159 // interceptor function. 159 // interceptor function.
160 EXPECT_EQ(6, num_dlls); 160 EXPECT_EQ(6, num_dlls);
161 EXPECT_EQ(15, num_functions); 161 EXPECT_EQ(15, num_functions);
162 EXPECT_EQ(4, num_names); 162 EXPECT_EQ(4, num_names);
163 } 163 }
164 164
165 TEST(InterceptionManagerTest, BufferLayout2) { 165 TEST(InterceptionManagerTest, BufferLayout2) {
166 wchar_t exe_name[MAX_PATH]; 166 wchar_t exe_name[MAX_PATH];
167 ASSERT_NE(0, GetModuleFileName(NULL, exe_name, MAX_PATH - 1)); 167 ASSERT_NE(0u, GetModuleFileName(NULL, exe_name, MAX_PATH - 1));
168 168
169 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(), 169 TargetProcess *target = MakeTestTargetProcess(::GetCurrentProcess(),
170 ::GetModuleHandle(exe_name)); 170 ::GetModuleHandle(exe_name));
171 171
172 InterceptionManager interceptions(target, true); 172 InterceptionManager interceptions(target, true);
173 173
174 // Any pointer will do for a function pointer. 174 // Any pointer will do for a function pointer.
175 void* function = &interceptions; 175 void* function = &interceptions;
176 interceptions.AddToUnloadModules(L"some01.dll"); 176 interceptions.AddToUnloadModules(L"some01.dll");
177 // We don't care about the interceptor id. 177 // We don't care about the interceptor id.
(...skipping 25 matching lines...) Expand all
203 int num_dlls, num_functions, num_names; 203 int num_dlls, num_functions, num_names;
204 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions, 204 WalkBuffer(local_buffer.get(), buffer_size, &num_dlls, &num_functions,
205 &num_names); 205 &num_names);
206 206
207 EXPECT_EQ(3, num_dlls); 207 EXPECT_EQ(3, num_dlls);
208 EXPECT_EQ(4, num_functions); 208 EXPECT_EQ(4, num_functions);
209 EXPECT_EQ(0, num_names); 209 EXPECT_EQ(0, num_names);
210 } 210 }
211 211
212 } // namespace sandbox 212 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/src/file_policy_test.cc ('k') | sandbox/src/job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698