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

Side by Side Diff: components/policy/core/common/policy_loader_win_unittest.cc

Issue 1441543002: Make vector_as_array use std::vector::data and switch a few directories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark comment Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/policy/core/common/policy_loader_win.h" 5 #include "components/policy/core/common/policy_loader_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <userenv.h> 8 #include <userenv.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 uint8* type_data = reinterpret_cast<uint8*>(&type); 582 uint8* type_data = reinterpret_cast<uint8*>(&type);
583 buffer.insert(buffer.end(), type_data, type_data + sizeof(DWORD)); 583 buffer.insert(buffer.end(), type_data, type_data + sizeof(DWORD));
584 AppendChars(&buffer, L";"); 584 AppendChars(&buffer, L";");
585 size = base::ByteSwapToLE32(size); 585 size = base::ByteSwapToLE32(size);
586 uint8* size_data = reinterpret_cast<uint8*>(&size); 586 uint8* size_data = reinterpret_cast<uint8*>(&size);
587 buffer.insert(buffer.end(), size_data, size_data + sizeof(DWORD)); 587 buffer.insert(buffer.end(), size_data, size_data + sizeof(DWORD));
588 AppendChars(&buffer, L";"); 588 AppendChars(&buffer, L";");
589 buffer.insert(buffer.end(), data, data + size); 589 buffer.insert(buffer.end(), data, data + size);
590 AppendChars(&buffer, L"]"); 590 AppendChars(&buffer, L"]");
591 591
592 ASSERT_TRUE(base::AppendToFile( 592 ASSERT_TRUE(base::AppendToFile(preg_file_path_,
593 preg_file_path_, 593 reinterpret_cast<const char*>(buffer.data()),
594 reinterpret_cast<const char*>(vector_as_array(&buffer)), 594 buffer.size()));
595 buffer.size()));
596 } 595 }
597 596
598 void PRegTestHarness::AppendDWORDToPRegFile(const base::string16& path, 597 void PRegTestHarness::AppendDWORDToPRegFile(const base::string16& path,
599 const std::string& key, 598 const std::string& key,
600 DWORD value) { 599 DWORD value) {
601 value = base::ByteSwapToLE32(value); 600 value = base::ByteSwapToLE32(value);
602 AppendRecordToPRegFile(path, key, REG_DWORD, sizeof(DWORD), 601 AppendRecordToPRegFile(path, key, REG_DWORD, sizeof(DWORD),
603 reinterpret_cast<uint8*>(&value)); 602 reinterpret_cast<uint8*>(&value));
604 } 603 }
605 604
606 void PRegTestHarness::AppendStringToPRegFile(const base::string16& path, 605 void PRegTestHarness::AppendStringToPRegFile(const base::string16& path,
607 const std::string& key, 606 const std::string& key,
608 const std::string& value) { 607 const std::string& value) {
609 base::string16 string16_value(UTF8ToUTF16(value)); 608 base::string16 string16_value(UTF8ToUTF16(value));
610 std::vector<base::char16> data; 609 std::vector<base::char16> data;
611 std::transform(string16_value.begin(), string16_value.end(), 610 std::transform(string16_value.begin(), string16_value.end(),
612 std::back_inserter(data), std::ptr_fun(base::ByteSwapToLE16)); 611 std::back_inserter(data), std::ptr_fun(base::ByteSwapToLE16));
613 data.push_back(base::ByteSwapToLE16(L'\0')); 612 data.push_back(base::ByteSwapToLE16(L'\0'));
614 613
615 AppendRecordToPRegFile(path, key, REG_SZ, data.size() * sizeof(base::char16), 614 AppendRecordToPRegFile(path, key, REG_SZ, data.size() * sizeof(base::char16),
616 reinterpret_cast<uint8*>(vector_as_array(&data))); 615 reinterpret_cast<uint8*>(data.data()));
617 } 616 }
618 617
619 void PRegTestHarness::AppendPolicyToPRegFile(const base::string16& path, 618 void PRegTestHarness::AppendPolicyToPRegFile(const base::string16& path,
620 const std::string& key, 619 const std::string& key,
621 const base::Value* value) { 620 const base::Value* value) {
622 switch (value->GetType()) { 621 switch (value->GetType()) {
623 case base::Value::TYPE_BOOLEAN: { 622 case base::Value::TYPE_BOOLEAN: {
624 bool boolean_value = false; 623 bool boolean_value = false;
625 ASSERT_TRUE(value->GetAsBoolean(&boolean_value)); 624 ASSERT_TRUE(value->GetAsBoolean(&boolean_value));
626 AppendDWORDToPRegFile(path, key, boolean_value); 625 AppendDWORDToPRegFile(path, key, boolean_value);
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 expected_policy.Set("alternative_browser_path", 1233 expected_policy.Set("alternative_browser_path",
1235 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 1234 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
1236 POLICY_SOURCE_PLATFORM, 1235 POLICY_SOURCE_PLATFORM,
1237 new base::StringValue("c:\\legacy\\browser.exe"), NULL); 1236 new base::StringValue("c:\\legacy\\browser.exe"), NULL);
1238 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 1237 expected_policy.Set("url_list", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
1239 POLICY_SOURCE_PLATFORM, list.DeepCopy(), nullptr); 1238 POLICY_SOURCE_PLATFORM, list.DeepCopy(), nullptr);
1240 EXPECT_TRUE(Matches(expected)); 1239 EXPECT_TRUE(Matches(expected));
1241 } 1240 }
1242 1241
1243 } // namespace policy 1242 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/cloud/policy_builder.cc ('k') | components/policy/core/common/preg_parser_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698