| OLD | NEW |
| 1 // Copyright (c) 2010 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 "base/scoped_bstr_win.h" | 5 #include "base/scoped_bstr_win.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace { | 8 namespace { |
| 9 | 9 |
| 10 static const wchar_t kTestString1[] = L"123"; | 10 static const wchar_t kTestString1[] = L"123"; |
| 11 static const wchar_t kTestString2[] = L"456789"; | 11 static const wchar_t kTestString2[] = L"456789"; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 EXPECT_TRUE(b2 == NULL); | 45 EXPECT_TRUE(b2 == NULL); |
| 46 SysFreeString(tmp); | 46 SysFreeString(tmp); |
| 47 | 47 |
| 48 GiveMeABstr(b2.Receive()); | 48 GiveMeABstr(b2.Receive()); |
| 49 EXPECT_TRUE(b2 != NULL); | 49 EXPECT_TRUE(b2 != NULL); |
| 50 b2.Reset(); | 50 b2.Reset(); |
| 51 EXPECT_TRUE(b2.AllocateBytes(100) != NULL); | 51 EXPECT_TRUE(b2.AllocateBytes(100) != NULL); |
| 52 EXPECT_TRUE(b2.ByteLength() == 100); | 52 EXPECT_TRUE(b2.ByteLength() == 100); |
| 53 EXPECT_TRUE(b2.Length() == 100 / sizeof(kTestString1[0])); | 53 EXPECT_TRUE(b2.Length() == 100 / sizeof(kTestString1[0])); |
| 54 lstrcpyW(static_cast<BSTR>(b2), kTestString1); | 54 lstrcpyW(static_cast<BSTR>(b2), kTestString1); |
| 55 EXPECT_TRUE(lstrlen(b2) == static_cast<int>(test1_len)); | 55 EXPECT_TRUE(lstrlen(b2) == test1_len); |
| 56 EXPECT_TRUE(b2.Length() == 100 / sizeof(kTestString1[0])); | 56 EXPECT_TRUE(b2.Length() == 100 / sizeof(kTestString1[0])); |
| 57 b2.SetByteLen(lstrlen(b2) * sizeof(kTestString2[0])); | 57 b2.SetByteLen(lstrlen(b2) * sizeof(kTestString2[0])); |
| 58 EXPECT_TRUE(lstrlen(b2) == static_cast<int>(b2.Length())); | 58 EXPECT_TRUE(lstrlen(b2) == b2.Length()); |
| 59 | 59 |
| 60 EXPECT_TRUE(b1.Allocate(kTestString2) != NULL); | 60 EXPECT_TRUE(b1.Allocate(kTestString2) != NULL); |
| 61 EXPECT_TRUE(b1.Length() == test2_len); | 61 EXPECT_TRUE(b1.Length() == test2_len); |
| 62 b1.SetByteLen((test2_len - 1) * sizeof(kTestString2[0])); | 62 b1.SetByteLen((test2_len - 1) * sizeof(kTestString2[0])); |
| 63 EXPECT_TRUE(b1.Length() == test2_len - 1); | 63 EXPECT_TRUE(b1.Length() == test2_len - 1); |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace | 66 } // namespace |
| 67 | 67 |
| 68 TEST(ScopedBstrTest, ScopedBstr) { | 68 TEST(ScopedBstrTest, ScopedBstr) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 84 uint32 l2 = SysStringLen(StackBstr(kSourceStr)); | 84 uint32 l2 = SysStringLen(StackBstr(kSourceStr)); |
| 85 uint32 l3 = SysStringLen(system_bstr); | 85 uint32 l3 = SysStringLen(system_bstr); |
| 86 EXPECT_TRUE(l1 == l2); | 86 EXPECT_TRUE(l1 == l2); |
| 87 EXPECT_TRUE(l2 == l3); | 87 EXPECT_TRUE(l2 == l3); |
| 88 EXPECT_TRUE(SysStringLen(empty) == 0); | 88 EXPECT_TRUE(SysStringLen(empty) == 0); |
| 89 | 89 |
| 90 const wchar_t one_more_test[] = L"this is my const string"; | 90 const wchar_t one_more_test[] = L"this is my const string"; |
| 91 EXPECT_EQ(SysStringLen(StackBstr(one_more_test)), | 91 EXPECT_EQ(SysStringLen(StackBstr(one_more_test)), |
| 92 lstrlenW(one_more_test)); | 92 lstrlenW(one_more_test)); |
| 93 } | 93 } |
| OLD | NEW |