| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <stdlib.h> |
| 6 | 7 |
| 7 #include <string> | 8 #include <string> |
| 8 | 9 |
| 9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 10 #include "chrome/installer/mini_installer/mini_string.h" | 11 #include "chrome/installer/mini_installer/mini_string.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 using mini_installer::StackString; | 14 using mini_installer::StackString; |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 27 StackString<MAX_PATH> str; | 28 StackString<MAX_PATH> str; |
| 28 EXPECT_EQ(MAX_PATH, str.capacity()); | 29 EXPECT_EQ(MAX_PATH, str.capacity()); |
| 29 | 30 |
| 30 std::wstring compare_str; | 31 std::wstring compare_str; |
| 31 | 32 |
| 32 EXPECT_EQ(str.length(), compare_str.length()); | 33 EXPECT_EQ(str.length(), compare_str.length()); |
| 33 EXPECT_EQ(0, compare_str.compare(str.get())); | 34 EXPECT_EQ(0, compare_str.compare(str.get())); |
| 34 | 35 |
| 35 size_t max_chars = str.capacity() - 1; | 36 size_t max_chars = str.capacity() - 1; |
| 36 | 37 |
| 37 while ((str.length() + (arraysize(kTestString) - 1)) <= max_chars) { | 38 while ((str.length() + (_countof(kTestString) - 1)) <= max_chars) { |
| 38 EXPECT_TRUE(str.append(kTestString)); | 39 EXPECT_TRUE(str.append(kTestString)); |
| 39 compare_str.append(kTestString); | 40 compare_str.append(kTestString); |
| 40 EXPECT_EQ(str.length(), compare_str.length()); | 41 EXPECT_EQ(str.length(), compare_str.length()); |
| 41 EXPECT_EQ(0, compare_str.compare(str.get())); | 42 EXPECT_EQ(0, compare_str.compare(str.get())); |
| 42 } | 43 } |
| 43 | 44 |
| 44 EXPECT_GT(static_cast<size_t>(MAX_PATH), str.length()); | 45 EXPECT_GT(static_cast<size_t>(MAX_PATH), str.length()); |
| 45 | 46 |
| 46 // Now we've exhausted the space we allocated for the string, | 47 // Now we've exhausted the space we allocated for the string, |
| 47 // so append should fail. | 48 // so append should fail. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 63 static const wchar_t kTestStringSource[] = L"1234ABcD567890"; | 64 static const wchar_t kTestStringSource[] = L"1234ABcD567890"; |
| 64 static const wchar_t kTestStringFind[] = L"abcd"; | 65 static const wchar_t kTestStringFind[] = L"abcd"; |
| 65 static const wchar_t kTestStringNotFound[] = L"80"; | 66 static const wchar_t kTestStringNotFound[] = L"80"; |
| 66 | 67 |
| 67 StackString<MAX_PATH> str; | 68 StackString<MAX_PATH> str; |
| 68 EXPECT_TRUE(str.assign(kTestStringSource)); | 69 EXPECT_TRUE(str.assign(kTestStringSource)); |
| 69 EXPECT_EQ(str.get(), str.findi(kTestStringSource)); | 70 EXPECT_EQ(str.get(), str.findi(kTestStringSource)); |
| 70 EXPECT_EQ(static_cast<const wchar_t*>(NULL), str.findi(kTestStringNotFound)); | 71 EXPECT_EQ(static_cast<const wchar_t*>(NULL), str.findi(kTestStringNotFound)); |
| 71 const wchar_t* found = str.findi(kTestStringFind); | 72 const wchar_t* found = str.findi(kTestStringFind); |
| 72 EXPECT_NE(static_cast<const wchar_t*>(NULL), found); | 73 EXPECT_NE(static_cast<const wchar_t*>(NULL), found); |
| 73 std::wstring check(found, arraysize(kTestStringFind) - 1); | 74 std::wstring check(found, _countof(kTestStringFind) - 1); |
| 74 EXPECT_EQ(0, lstrcmpi(check.c_str(), kTestStringFind)); | 75 EXPECT_EQ(0, lstrcmpi(check.c_str(), kTestStringFind)); |
| 75 } | 76 } |
| OLD | NEW |