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

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

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