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

Side by Side Diff: sandbox/win/src/policy_opcodes_unittest.cc

Issue 1538283002: Switch to standard integer types in sandbox/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: macros 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 | « sandbox/win/src/policy_low_level_unittest.cc ('k') | sandbox/win/src/policy_target.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-2008 The Chromium Authors. All rights reserved. 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 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 #include <stddef.h>
6 #include <stdint.h>
7
8 #include "sandbox/win/src/policy_engine_opcodes.h"
9 #include "sandbox/win/src/policy_engine_params.h"
10 #include "sandbox/win/src/sandbox_nt_types.h"
5 #include "sandbox/win/src/sandbox_types.h" 11 #include "sandbox/win/src/sandbox_types.h"
6 #include "sandbox/win/src/sandbox_nt_types.h"
7 #include "sandbox/win/src/policy_engine_params.h"
8 #include "sandbox/win/src/policy_engine_opcodes.h"
9 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
10 13
11 14
12 #define INIT_GLOBAL_RTL(member) \ 15 #define INIT_GLOBAL_RTL(member) \
13 g_nt.member = reinterpret_cast<member##Function>( \ 16 g_nt.member = reinterpret_cast<member##Function>( \
14 ::GetProcAddress(ntdll, #member)); \ 17 ::GetProcAddress(ntdll, #member)); \
15 if (NULL == g_nt.member) \ 18 if (NULL == g_nt.member) \
16 return false 19 return false
17 20
18 namespace sandbox { 21 namespace sandbox {
(...skipping 19 matching lines...) Expand all
38 } 41 }
39 42
40 TEST(PolicyEngineTest, ParameterSetTest) { 43 TEST(PolicyEngineTest, ParameterSetTest) {
41 void* pv1 = reinterpret_cast<void*>(0x477EAA5); 44 void* pv1 = reinterpret_cast<void*>(0x477EAA5);
42 const void* pv2 = reinterpret_cast<void*>(0x987654); 45 const void* pv2 = reinterpret_cast<void*>(0x987654);
43 ParameterSet pset1 = ParamPickerMake(pv1); 46 ParameterSet pset1 = ParamPickerMake(pv1);
44 ParameterSet pset2 = ParamPickerMake(pv2); 47 ParameterSet pset2 = ParamPickerMake(pv2);
45 48
46 // Test that we can store and retrieve a void pointer: 49 // Test that we can store and retrieve a void pointer:
47 const void* result1 =0; 50 const void* result1 =0;
48 uint32 result2 = 0; 51 uint32_t result2 = 0;
49 EXPECT_TRUE(pset1.Get(&result1)); 52 EXPECT_TRUE(pset1.Get(&result1));
50 EXPECT_TRUE(pv1 == result1); 53 EXPECT_TRUE(pv1 == result1);
51 EXPECT_FALSE(pset1.Get(&result2)); 54 EXPECT_FALSE(pset1.Get(&result2));
52 EXPECT_TRUE(pset2.Get(&result1)); 55 EXPECT_TRUE(pset2.Get(&result1));
53 EXPECT_TRUE(pv2 == result1); 56 EXPECT_TRUE(pv2 == result1);
54 EXPECT_FALSE(pset2.Get(&result2)); 57 EXPECT_FALSE(pset2.Get(&result2));
55 58
56 // Test that we can store and retrieve a uint32: 59 // Test that we can store and retrieve a uint32_t:
57 uint32 number = 12747; 60 uint32_t number = 12747;
58 ParameterSet pset3 = ParamPickerMake(number); 61 ParameterSet pset3 = ParamPickerMake(number);
59 EXPECT_FALSE(pset3.Get(&result1)); 62 EXPECT_FALSE(pset3.Get(&result1));
60 EXPECT_TRUE(pset3.Get(&result2)); 63 EXPECT_TRUE(pset3.Get(&result2));
61 EXPECT_EQ(number, result2); 64 EXPECT_EQ(number, result2);
62 65
63 // Test that we can store and retrieve a string: 66 // Test that we can store and retrieve a string:
64 const wchar_t* txt = L"S231L"; 67 const wchar_t* txt = L"S231L";
65 ParameterSet pset4 = ParamPickerMake(txt); 68 ParameterSet pset4 = ParamPickerMake(txt);
66 const wchar_t* result3 = NULL; 69 const wchar_t* result3 = NULL;
67 EXPECT_TRUE(pset4.Get(&result3)); 70 EXPECT_TRUE(pset4.Get(&result3));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 177
175 // There should be no room more another opcode: 178 // There should be no room more another opcode:
176 PolicyOpcode* op1 = opcode_maker.MakeOpWStringMatch(0, txt2, 0, 179 PolicyOpcode* op1 = opcode_maker.MakeOpWStringMatch(0, txt2, 0,
177 CASE_SENSITIVE, 180 CASE_SENSITIVE,
178 kPolNone); 181 kPolNone);
179 ASSERT_EQ(nullptr, op1); 182 ASSERT_EQ(nullptr, op1);
180 } 183 }
181 184
182 TEST(PolicyEngineTest, IntegerOpcodes) { 185 TEST(PolicyEngineTest, IntegerOpcodes) {
183 const wchar_t* txt = L"abcdef"; 186 const wchar_t* txt = L"abcdef";
184 uint32 num1 = 42; 187 uint32_t num1 = 42;
185 uint32 num2 = 113377; 188 uint32_t num2 = 113377;
186 189
187 ParameterSet pp_wrong1 = ParamPickerMake(txt); 190 ParameterSet pp_wrong1 = ParamPickerMake(txt);
188 ParameterSet pp_num1 = ParamPickerMake(num1); 191 ParameterSet pp_num1 = ParamPickerMake(num1);
189 ParameterSet pp_num2 = ParamPickerMake(num2); 192 ParameterSet pp_num2 = ParamPickerMake(num2);
190 193
191 char memory[kOpcodeMemory]; 194 char memory[kOpcodeMemory];
192 OpcodeFactory opcode_maker(memory, sizeof(memory)); 195 OpcodeFactory opcode_maker(memory, sizeof(memory));
193 196
194 // Test basic match for uint32s 42 == 42 and 42 != 113377. 197 // Test basic match for uint32s 42 == 42 and 42 != 113377.
195 PolicyOpcode* op_m42 = opcode_maker.MakeOpNumberMatch(0, 42UL, kPolNone); 198 PolicyOpcode* op_m42 = opcode_maker.MakeOpNumberMatch(0, 42UL, kPolNone);
(...skipping 18 matching lines...) Expand all
214 ASSERT_NE(nullptr, op_range1); 217 ASSERT_NE(nullptr, op_range1);
215 EXPECT_EQ(EVAL_TRUE, op_range1->Evaluate(&pp_num1, 1, NULL)); 218 EXPECT_EQ(EVAL_TRUE, op_range1->Evaluate(&pp_num1, 1, NULL));
216 EXPECT_EQ(EVAL_FALSE, op_range1->Evaluate(&pp_num2, 1, NULL)); 219 EXPECT_EQ(EVAL_FALSE, op_range1->Evaluate(&pp_num2, 1, NULL));
217 EXPECT_EQ(EVAL_ERROR, op_range1->Evaluate(&pp_wrong1, 1, NULL)); 220 EXPECT_EQ(EVAL_ERROR, op_range1->Evaluate(&pp_wrong1, 1, NULL));
218 } 221 }
219 222
220 TEST(PolicyEngineTest, LogicalOpcodes) { 223 TEST(PolicyEngineTest, LogicalOpcodes) {
221 char memory[kOpcodeMemory]; 224 char memory[kOpcodeMemory];
222 OpcodeFactory opcode_maker(memory, sizeof(memory)); 225 OpcodeFactory opcode_maker(memory, sizeof(memory));
223 226
224 uint32 num1 = 0x10100702; 227 uint32_t num1 = 0x10100702;
225 ParameterSet pp_num1 = ParamPickerMake(num1); 228 ParameterSet pp_num1 = ParamPickerMake(num1);
226 229
227 PolicyOpcode* op_and1 = 230 PolicyOpcode* op_and1 =
228 opcode_maker.MakeOpNumberAndMatch(0, 0x00100000, kPolNone); 231 opcode_maker.MakeOpNumberAndMatch(0, 0x00100000, kPolNone);
229 ASSERT_NE(nullptr, op_and1); 232 ASSERT_NE(nullptr, op_and1);
230 EXPECT_EQ(EVAL_TRUE, op_and1->Evaluate(&pp_num1, 1, NULL)); 233 EXPECT_EQ(EVAL_TRUE, op_and1->Evaluate(&pp_num1, 1, NULL));
231 PolicyOpcode* op_and2 = 234 PolicyOpcode* op_and2 =
232 opcode_maker.MakeOpNumberAndMatch(0, 0x00000001, kPolNone); 235 opcode_maker.MakeOpNumberAndMatch(0, 0x00000001, kPolNone);
233 ASSERT_NE(nullptr, op_and2); 236 ASSERT_NE(nullptr, op_and2);
234 EXPECT_EQ(EVAL_FALSE, op_and2->Evaluate(&pp_num1, 1, NULL)); 237 EXPECT_EQ(EVAL_FALSE, op_and2->Evaluate(&pp_num1, 1, NULL));
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 void* dummy = NULL; 363 void* dummy = NULL;
361 ParameterSet ppb1 = ParamPickerMake(dummy); 364 ParameterSet ppb1 = ParamPickerMake(dummy);
362 365
363 PolicyOpcode* op1 = opcode_maker.MakeOpAction(ASK_BROKER, kPolNone); 366 PolicyOpcode* op1 = opcode_maker.MakeOpAction(ASK_BROKER, kPolNone);
364 ASSERT_NE(nullptr, op1); 367 ASSERT_NE(nullptr, op1);
365 EXPECT_TRUE(op1->IsAction()); 368 EXPECT_TRUE(op1->IsAction());
366 EXPECT_EQ(ASK_BROKER, op1->Evaluate(&ppb1, 1, &mc1)); 369 EXPECT_EQ(ASK_BROKER, op1->Evaluate(&ppb1, 1, &mc1));
367 } 370 }
368 371
369 } // namespace sandbox 372 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/policy_low_level_unittest.cc ('k') | sandbox/win/src/policy_target.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698