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

Side by Side Diff: util/misc/uuid_test.cc

Issue 1004913004: win: Add UUID::InitializeFromSystemUUID() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « util/misc/uuid.cc ('k') | util/util.gyp » ('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 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. 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 "util/misc/uuid.h" 15 #include "util/misc/uuid.h"
16 16
17 #include <stdint.h> 17 #include <stdint.h>
18 18
19 #include <string> 19 #include <string>
20 20
21 #include "base/basictypes.h" 21 #include "base/basictypes.h"
22 #include "base/format_macros.h" 22 #include "base/format_macros.h"
23 #include "base/scoped_generic.h"
23 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h"
24 #include "gtest/gtest.h" 26 #include "gtest/gtest.h"
25 27
26 namespace crashpad { 28 namespace crashpad {
27 namespace test { 29 namespace test {
28 namespace { 30 namespace {
29 31
30 TEST(UUID, UUID) { 32 TEST(UUID, UUID) {
31 UUID uuid_zero; 33 UUID uuid_zero;
32 EXPECT_EQ(0u, uuid_zero.data_1); 34 EXPECT_EQ(0u, uuid_zero.data_1);
33 EXPECT_EQ(0u, uuid_zero.data_2); 35 EXPECT_EQ(0u, uuid_zero.data_2);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // Test for case insensitivty. 199 // Test for case insensitivty.
198 UUID uuid; 200 UUID uuid;
199 uuid.InitializeFromString("F32E5BDC-2681-4C73-A4E6-911FFD89B846"); 201 uuid.InitializeFromString("F32E5BDC-2681-4C73-A4E6-911FFD89B846");
200 EXPECT_EQ("f32e5bdc-2681-4c73-a4e6-911ffd89b846", uuid.ToString()); 202 EXPECT_EQ("f32e5bdc-2681-4c73-a4e6-911ffd89b846", uuid.ToString());
201 203
202 // Mixed case. 204 // Mixed case.
203 uuid.InitializeFromString("5762C15D-50b5-4171-a2e9-7429C9EC6CAB"); 205 uuid.InitializeFromString("5762C15D-50b5-4171-a2e9-7429C9EC6CAB");
204 EXPECT_EQ("5762c15d-50b5-4171-a2e9-7429c9ec6cab", uuid.ToString()); 206 EXPECT_EQ("5762c15d-50b5-4171-a2e9-7429c9ec6cab", uuid.ToString());
205 } 207 }
206 208
209 #if defined(OS_WIN)
210
211 TEST(UUID, FromSystem) {
212 ::GUID system_uuid;
213 ASSERT_EQ(RPC_S_OK, UuidCreate(&system_uuid));
214
215 UUID uuid;
216 uuid.InitializeFromSystemUUID(&system_uuid);
217
218 RPC_WSTR system_string;
219 ASSERT_EQ(RPC_S_OK, UuidToString(&system_uuid, &system_string));
220
221 struct ScopedRpcStringFreeTraits {
222 static RPC_WSTR* InvalidValue() { return nullptr; }
223 static void Free(RPC_WSTR* rpc_string) {
224 EXPECT_EQ(RPC_S_OK, RpcStringFree(rpc_string));
225 }
226 };
227 using ScopedRpcString =
228 base::ScopedGeneric<RPC_WSTR*, ScopedRpcStringFreeTraits>;
229 ScopedRpcString scoped_system_string(&system_string);
230
231 std::string system_string_utf8 =
232 base::UTF16ToUTF8(reinterpret_cast<wchar_t*>(system_string));
233
234 EXPECT_EQ(system_string_utf8, uuid.ToString());
scottmg 2015/03/13 16:52:32 maybe just system_string == uuid.ToString16()? Or
235 }
236
237 #endif // OS_WIN
238
207 } // namespace 239 } // namespace
208 } // namespace test 240 } // namespace test
209 } // namespace crashpad 241 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/misc/uuid.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698