summaryrefslogtreecommitdiffstats
path: root/base/win/scoped_bstr_unittest.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-16 03:46:05 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-16 03:46:05 +0000
commitce0e7246e92f2da8e6b865dd51ae626f9867ca4f (patch)
tree8181f26fbe349c35ff37a9ae837603c3f11be7f8 /base/win/scoped_bstr_unittest.cc
parent21e74460f5b7cfe6f622557b20d40eecf3b8e98b (diff)
downloadchromium_src-ce0e7246e92f2da8e6b865dd51ae626f9867ca4f.zip
chromium_src-ce0e7246e92f2da8e6b865dd51ae626f9867ca4f.tar.gz
chromium_src-ce0e7246e92f2da8e6b865dd51ae626f9867ca4f.tar.bz2
Move the windows-specific scoped_* stuff from base to base/win and in the base::win namespace.
This keeps old headers that forward to the new versions and have using declarations that allow the existing code to compile. I fixed all the callers in base to use the new ones, and also the other files I happened to touch. This splits out the stuff from scoped_handle into a few separate files. I just deleted ScopedFindFile since it was only used in one place and it wasn't even really helping there. I removed StackBstr which was a #define and used the "regular" ScopedBstr in the 7 places that used it. This is an optimization to avoid an extra allocation, but none of the callers are remotely performance critical. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/3781009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62843 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/win/scoped_bstr_unittest.cc')
-rw-r--r--base/win/scoped_bstr_unittest.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/base/win/scoped_bstr_unittest.cc b/base/win/scoped_bstr_unittest.cc
new file mode 100644
index 0000000..5f6f7df
--- /dev/null
+++ b/base/win/scoped_bstr_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/win/scoped_bstr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+namespace win {
+
+namespace {
+
+static const wchar_t kTestString1[] = L"123";
+static const wchar_t kTestString2[] = L"456789";
+size_t test1_len = arraysize(kTestString1) - 1;
+size_t test2_len = arraysize(kTestString2) - 1;
+
+void DumbBstrTests() {
+ ScopedBstr b;
+ EXPECT_TRUE(b == NULL);
+ EXPECT_EQ(0, b.Length());
+ EXPECT_EQ(0, b.ByteLength());
+ b.Reset(NULL);
+ EXPECT_TRUE(b == NULL);
+ EXPECT_TRUE(b.Release() == NULL);
+ ScopedBstr b2;
+ b.Swap(b2);
+ EXPECT_TRUE(b2 == NULL);
+}
+
+void GiveMeABstr(BSTR* ret) {
+ *ret = SysAllocString(kTestString1);
+}
+
+void BasicBstrTests() {
+ ScopedBstr b1(kTestString1);
+ EXPECT_EQ(test1_len, b1.Length());
+ EXPECT_EQ(test1_len * sizeof(kTestString1[0]), b1.ByteLength());
+
+ ScopedBstr b2;
+ b1.Swap(b2);
+ EXPECT_EQ(test1_len, b2.Length());
+ EXPECT_EQ(0, b1.Length());
+ EXPECT_EQ(0, lstrcmp(b2, kTestString1));
+ BSTR tmp = b2.Release();
+ EXPECT_TRUE(tmp != NULL);
+ EXPECT_EQ(0, lstrcmp(tmp, kTestString1));
+ EXPECT_TRUE(b2 == NULL);
+ SysFreeString(tmp);
+
+ GiveMeABstr(b2.Receive());
+ EXPECT_TRUE(b2 != NULL);
+ b2.Reset();
+ EXPECT_TRUE(b2.AllocateBytes(100) != NULL);
+ EXPECT_EQ(100, b2.ByteLength());
+ EXPECT_EQ(100 / sizeof(kTestString1[0]), b2.Length());
+ lstrcpy(static_cast<BSTR>(b2), kTestString1);
+ EXPECT_EQ(test1_len, lstrlen(b2));
+ EXPECT_EQ(100 / sizeof(kTestString1[0]), b2.Length());
+ b2.SetByteLen(lstrlen(b2) * sizeof(kTestString2[0]));
+ EXPECT_EQ(b2.Length(), lstrlen(b2));
+
+ EXPECT_TRUE(b1.Allocate(kTestString2) != NULL);
+ EXPECT_EQ(test2_len, b1.Length());
+ b1.SetByteLen((test2_len - 1) * sizeof(kTestString2[0]));
+ EXPECT_EQ(test2_len - 1, b1.Length());
+}
+
+} // namespace
+
+TEST(ScopedBstrTest, ScopedBstr) {
+ DumbBstrTests();
+ BasicBstrTests();
+}
+
+} // namespace win
+} // namespace base