diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 04:34:12 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 04:34:12 +0000 |
commit | 0a02d61d7c499e3fd05c428bbb1ce88ffd950714 (patch) | |
tree | 2649bcdc82d8244c17d7e2c431b9470894593d15 /app/gfx | |
parent | d55e76095697233ab43bb8ddce9cc65bb82d0b7f (diff) | |
download | chromium_src-0a02d61d7c499e3fd05c428bbb1ce88ffd950714.zip chromium_src-0a02d61d7c499e3fd05c428bbb1ce88ffd950714.tar.gz chromium_src-0a02d61d7c499e3fd05c428bbb1ce88ffd950714.tar.bz2 |
Add gfx::Insets::ToString().
This will be useful for debugging views and views applications
(I needed this when I was debugging my views application).
Along the way, added tests for Insets.
TEST=added tests; app_unittests; try
BUG=none
Review URL: http://codereview.chromium.org/497004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gfx')
-rw-r--r-- | app/gfx/insets.cc | 16 | ||||
-rw-r--r-- | app/gfx/insets.h | 7 | ||||
-rw-r--r-- | app/gfx/insets_unittest.cc | 68 |
3 files changed, 90 insertions, 1 deletions
diff --git a/app/gfx/insets.cc b/app/gfx/insets.cc new file mode 100644 index 0000000..7e3da0c --- /dev/null +++ b/app/gfx/insets.cc @@ -0,0 +1,16 @@ +// Copyright (c) 2009 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 "app/gfx/insets.h" + +#include "base/string_util.h" + +namespace gfx { + +std::string Insets::ToString() const { + // Print members in the same order of the constructor parameters. + return StringPrintf("%d,%d,%d,%d", top_, left_, bottom_, right_); +} + +} // namespace gfx diff --git a/app/gfx/insets.h b/app/gfx/insets.h index f5806ac..70b3683 100644 --- a/app/gfx/insets.h +++ b/app/gfx/insets.h @@ -11,6 +11,8 @@ #include <gtk/gtkstyle.h> #endif +#include <string> + namespace gfx { // @@ -76,6 +78,9 @@ class Insets { return *this; } + // Returns a string representation of the insets. + std::string ToString() const; + private: int top_; int left_; @@ -83,6 +88,6 @@ class Insets { int right_; }; -} // namespace +} // namespace gfx #endif // APP_GFX_INSETS_H_ diff --git a/app/gfx/insets_unittest.cc b/app/gfx/insets_unittest.cc new file mode 100644 index 0000000..9430a09 --- /dev/null +++ b/app/gfx/insets_unittest.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2009 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 "app/gfx/insets.h" + +#include <iostream> + +#include "testing/gtest/include/gtest/gtest.h" + +TEST(InsetsTest, InsetsDefault) { + gfx::Insets insets; + EXPECT_EQ(0, insets.top()); + EXPECT_EQ(0, insets.left()); + EXPECT_EQ(0, insets.bottom()); + EXPECT_EQ(0, insets.right()); + EXPECT_EQ(0, insets.width()); + EXPECT_EQ(0, insets.height()); + EXPECT_TRUE(insets.empty()); +} + +TEST(InsetsTest, Insets) { + gfx::Insets insets(1, 2, 3, 4); + EXPECT_EQ(1, insets.top()); + EXPECT_EQ(2, insets.left()); + EXPECT_EQ(3, insets.bottom()); + EXPECT_EQ(4, insets.right()); + EXPECT_EQ(6, insets.width()); // Left + right. + EXPECT_EQ(4, insets.height()); // Top + bottom. + EXPECT_FALSE(insets.empty()); +} + +TEST(InsetsTest, Set) { + gfx::Insets insets; + insets.Set(1, 2, 3, 4); + EXPECT_EQ(1, insets.top()); + EXPECT_EQ(2, insets.left()); + EXPECT_EQ(3, insets.bottom()); + EXPECT_EQ(4, insets.right()); +} + +TEST(InsetsTest, Add) { + gfx::Insets insets; + insets.Set(1, 2, 3, 4); + insets += gfx::Insets(5, 6, 7, 8); + EXPECT_EQ(6, insets.top()); + EXPECT_EQ(8, insets.left()); + EXPECT_EQ(10, insets.bottom()); + EXPECT_EQ(12, insets.right()); +} + +TEST(InsetsTest, Equality) { + gfx::Insets insets1; + insets1.Set(1, 2, 3, 4); + gfx::Insets insets2; + // Test operator== and operator!=. + EXPECT_FALSE(insets1 == insets2); + EXPECT_TRUE(insets1 != insets2); + + insets2.Set(1, 2, 3, 4); + EXPECT_TRUE(insets1 == insets2); + EXPECT_FALSE(insets1 != insets2); +} + +TEST(InsetsTest, ToString) { + gfx::Insets insets(1, 2, 3, 4); + EXPECT_EQ("1,2,3,4", insets.ToString()); +} |