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

Unified Diff: base/scoped_bstr_win_unittest.cc

Issue 3781009: Move the windows-specific scoped_* stuff from base to base/win and in the bas... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 side-by-side diff with in-line comments
Download patch
Index: base/scoped_bstr_win_unittest.cc
===================================================================
--- base/scoped_bstr_win_unittest.cc (revision 62693)
+++ base/scoped_bstr_win_unittest.cc (working copy)
@@ -1,93 +0,0 @@
-// 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/scoped_bstr_win.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-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();
-}
-
-#define kSourceStr L"this is a string"
-#define kSourceStrEmpty L""
-
-TEST(StackBstrTest, StackBstr) {
- ScopedBstr system_bstr(kSourceStr);
- StackBstrVar(kSourceStr, stack_bstr);
- EXPECT_EQ(VARCMP_EQ,
- VarBstrCmp(system_bstr, stack_bstr, LOCALE_USER_DEFAULT, 0));
-
- StackBstrVar(kSourceStrEmpty, empty);
- UINT l1 = SysStringLen(stack_bstr);
- UINT l2 = SysStringLen(StackBstr(kSourceStr));
- UINT l3 = SysStringLen(system_bstr);
- EXPECT_EQ(l1, l2);
- EXPECT_EQ(l2, l3);
- EXPECT_EQ(0, SysStringLen(empty));
-
- const wchar_t one_more_test[] = L"this is my const string";
- EXPECT_EQ(SysStringLen(StackBstr(one_more_test)),
- lstrlen(one_more_test));
-}
« no previous file with comments | « base/scoped_bstr_win.cc ('k') | base/scoped_comptr_win.h » ('j') | base/win/scoped_comptr.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698