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

Side by Side Diff: testing/unit_test_unittest.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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 | « testing/unit_test.cc ('k') | testing/unittest_debug_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009-2010 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/base/utils.h"
17 #include "omaha/base/user_info.h"
18 #include "omaha/base/vistautil.h"
19 #include "testing/unit_test.h"
20
21 namespace omaha {
22
23 TEST(UnitTestHelpersTest, GetLocalAppDataPath) {
24 if (IsTestRunByLocalSystem()) {
25 return;
26 }
27
28 const TCHAR kUserXpLocalAppDataPathFormat[] =
29 _T("C:\\Documents and Settings\\%s\\Local Settings\\Application Data\\");
30 const TCHAR kUserVistaLocalAppDataPathFormat[] =
31 _T("C:\\Users\\%s\\AppData\\Local\\");
32
33 TCHAR username[MAX_PATH] = {0};
34 EXPECT_TRUE(::GetEnvironmentVariable(_T("USERNAME"),
35 username,
36 arraysize(username)));
37 CString expected_path;
38 expected_path.Format(vista_util::IsVistaOrLater() ?
39 kUserVistaLocalAppDataPathFormat :
40 kUserXpLocalAppDataPathFormat,
41 username);
42 EXPECT_STREQ(expected_path, GetLocalAppDataPath());
43 }
44
45 // GUIDs cannot be compared in GTest because there is no << operator. Therefore,
46 // we must treat them as strings. All these tests rely on GuidToString working.
47 #define EXPECT_GUID_EQ(expected, actual) \
48 EXPECT_STREQ(GuidToString(expected), GuidToString(actual))
49
50 TEST(UnitTestHelpersTest, StringToGuid_InvalidString) {
51 ExpectAsserts expect_asserts; // Invalid strings cause an assert.
52
53 EXPECT_GUID_EQ(GUID_NULL, StringToGuid(_T("")));
54 EXPECT_GUID_EQ(GUID_NULL, StringToGuid(_T("{}")));
55 EXPECT_GUID_EQ(GUID_NULL, StringToGuid(_T("a")));
56 EXPECT_GUID_EQ(GUID_NULL,
57 StringToGuid(_T("CA3045BFA6B14fb8A0EFA615CEFE452C")));
58
59 // Missing {}
60 EXPECT_GUID_EQ(GUID_NULL,
61 StringToGuid(_T("CA3045BF-A6B1-4fb8-A0EF-A615CEFE452C")));
62
63 // Invalid char X
64 EXPECT_GUID_EQ(GUID_NULL,
65 StringToGuid(_T("{XA3045BF-A6B1-4fb8-A0EF-A615CEFE452C}")));
66
67 // Invalid binary char 0x200
68 EXPECT_GUID_EQ(
69 GUID_NULL,
70 StringToGuid(_T("{\0x200a3045bf-a6b1-4fb8-a0ef-a615cefe452c}")));
71
72 // Missing -
73 EXPECT_GUID_EQ(GUID_NULL,
74 StringToGuid(_T("{CA3045BFA6B14fb8A0EFA615CEFE452C}")));
75
76 // Double quotes
77 EXPECT_GUID_EQ(
78 GUID_NULL,
79 StringToGuid(_T("\"{ca3045bf-a6b1-4fb8-a0ef-a615cefe452c}\"")));
80 }
81
82 TEST(UnitTestHelpersTest, StringToGuid_ValidString) {
83 const GUID kExpectedGuid = {0xCA3045BF, 0xA6B1, 0x4FB8,
84 {0xA0, 0xEF, 0xA6, 0x15, 0xCE, 0xFE, 0x45, 0x2C}};
85
86 // Converted successfully, but indistinguishable from failures.
87 EXPECT_GUID_EQ(GUID_NULL,
88 StringToGuid(_T("{00000000-0000-0000-0000-000000000000}")));
89
90 EXPECT_GUID_EQ(kExpectedGuid,
91 StringToGuid(_T("{CA3045BF-A6B1-4fb8-A0EF-A615CEFE452C}")));
92
93 EXPECT_GUID_EQ(kExpectedGuid,
94 StringToGuid(_T("{ca3045bf-a6b1-4fb8-a0ef-a615cefe452c}")));
95 }
96
97 } // namespace omaha
OLDNEW
« no previous file with comments | « testing/unit_test.cc ('k') | testing/unittest_debug_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698