Rename range.mm to range_mac.mm.
For consistency, move the windows-specific code from range.cc into range_win.cc. Do the same for unit tests. In addition to this being nicer in general, the make build also gets confused if two files have the same path and basename, but different extensions (range.cc, range.mm), which is fixed by this CL. BUG=none TEST=none Review URL: http://codereview.chromium.org/7248068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91480 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -75,40 +75,6 @@ Range Range::Intersect(const Range& range) const {
|
||||
return Range(min, max);
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
Range::Range(const CHARRANGE& range, LONG total_length) {
|
||||
// Check if this is an invalid range.
|
||||
if (range.cpMin == -1 && range.cpMax == -1) {
|
||||
*this = InvalidRange();
|
||||
} else {
|
||||
DCHECK_GE(range.cpMin, 0);
|
||||
set_start(range.cpMin);
|
||||
// {0,-1} is the "whole range" but that doesn't mean much out of context,
|
||||
// so use the |total_length| parameter.
|
||||
if (range.cpMax == -1) {
|
||||
DCHECK_EQ(0, range.cpMin);
|
||||
DCHECK_NE(-1, total_length);
|
||||
set_end(total_length);
|
||||
} else {
|
||||
set_end(range.cpMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CHARRANGE Range::ToCHARRANGE() const {
|
||||
CHARRANGE r = { -1, -1 };
|
||||
if (!IsValid())
|
||||
return r;
|
||||
|
||||
const LONG kLONGMax = std::numeric_limits<LONG>::max();
|
||||
DCHECK_LE(static_cast<LONG>(start()), kLONGMax);
|
||||
DCHECK_LE(static_cast<LONG>(end()), kLONGMax);
|
||||
r.cpMin = start();
|
||||
r.cpMax = end();
|
||||
return r;
|
||||
}
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const ui::Range& range) {
|
||||
return out << "{" << range.start() << "," << range.end() << "}";
|
||||
}
|
||||
|
@ -206,62 +206,3 @@ TEST(RangeTest, ContainAndIntersect) {
|
||||
EXPECT_FALSE(r1.Contains(invalid));
|
||||
EXPECT_FALSE(r1.Intersects(invalid));
|
||||
}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
TEST(RangeTest, FromCHARRANGE) {
|
||||
CHARRANGE cr = { 10, 32 };
|
||||
ui::Range r(cr, 50);
|
||||
EXPECT_EQ(10U, r.start());
|
||||
EXPECT_EQ(32U, r.end());
|
||||
EXPECT_EQ(22U, r.length());
|
||||
EXPECT_FALSE(r.is_reversed());
|
||||
EXPECT_TRUE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, FromReversedCHARRANGE) {
|
||||
CHARRANGE cr = { 20, 10 };
|
||||
ui::Range r(cr, 40);
|
||||
EXPECT_EQ(20U, r.start());
|
||||
EXPECT_EQ(10U, r.end());
|
||||
EXPECT_EQ(10U, r.length());
|
||||
EXPECT_TRUE(r.is_reversed());
|
||||
EXPECT_TRUE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, FromCHARRANGETotal) {
|
||||
CHARRANGE cr = { 0, -1 };
|
||||
ui::Range r(cr, 20);
|
||||
EXPECT_EQ(0U, r.start());
|
||||
EXPECT_EQ(20U, r.end());
|
||||
EXPECT_EQ(20U, r.length());
|
||||
EXPECT_FALSE(r.is_reversed());
|
||||
EXPECT_TRUE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, ToCHARRANGE) {
|
||||
ui::Range r(10, 30);
|
||||
CHARRANGE cr = r.ToCHARRANGE();
|
||||
EXPECT_EQ(10, cr.cpMin);
|
||||
EXPECT_EQ(30, cr.cpMax);
|
||||
}
|
||||
|
||||
TEST(RangeTest, ReversedToCHARRANGE) {
|
||||
ui::Range r(20, 10);
|
||||
CHARRANGE cr = r.ToCHARRANGE();
|
||||
EXPECT_EQ(20U, cr.cpMin);
|
||||
EXPECT_EQ(10U, cr.cpMax);
|
||||
}
|
||||
|
||||
TEST(RangeTest, FromCHARRANGEInvalid) {
|
||||
CHARRANGE cr = { -1, -1 };
|
||||
ui::Range r(cr, 30);
|
||||
EXPECT_FALSE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, ToCHARRANGEInvalid) {
|
||||
ui::Range r(ui::Range::InvalidRange());
|
||||
CHARRANGE cr = r.ToCHARRANGE();
|
||||
EXPECT_EQ(-1, cr.cpMin);
|
||||
EXPECT_EQ(-1, cr.cpMax);
|
||||
}
|
||||
#endif // defined(OS_WIN)
|
||||
|
45
ui/base/range/range_win.cc
Normal file
45
ui/base/range/range_win.cc
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2011 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 "ui/base/range/range.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "base/logging.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
Range::Range(const CHARRANGE& range, LONG total_length) {
|
||||
// Check if this is an invalid range.
|
||||
if (range.cpMin == -1 && range.cpMax == -1) {
|
||||
*this = InvalidRange();
|
||||
} else {
|
||||
DCHECK_GE(range.cpMin, 0);
|
||||
set_start(range.cpMin);
|
||||
// {0,-1} is the "whole range" but that doesn't mean much out of context,
|
||||
// so use the |total_length| parameter.
|
||||
if (range.cpMax == -1) {
|
||||
DCHECK_EQ(0, range.cpMin);
|
||||
DCHECK_NE(-1, total_length);
|
||||
set_end(total_length);
|
||||
} else {
|
||||
set_end(range.cpMax);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CHARRANGE Range::ToCHARRANGE() const {
|
||||
CHARRANGE r = { -1, -1 };
|
||||
if (!IsValid())
|
||||
return r;
|
||||
|
||||
const LONG kLONGMax = std::numeric_limits<LONG>::max();
|
||||
DCHECK_LE(static_cast<LONG>(start()), kLONGMax);
|
||||
DCHECK_LE(static_cast<LONG>(end()), kLONGMax);
|
||||
r.cpMin = start();
|
||||
r.cpMax = end();
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace gfx
|
63
ui/base/range/range_win_unittest.cc
Normal file
63
ui/base/range/range_win_unittest.cc
Normal file
@ -0,0 +1,63 @@
|
||||
// Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/base/range/range.h"
|
||||
|
||||
TEST(RangeTest, FromCHARRANGE) {
|
||||
CHARRANGE cr = { 10, 32 };
|
||||
ui::Range r(cr, 50);
|
||||
EXPECT_EQ(10U, r.start());
|
||||
EXPECT_EQ(32U, r.end());
|
||||
EXPECT_EQ(22U, r.length());
|
||||
EXPECT_FALSE(r.is_reversed());
|
||||
EXPECT_TRUE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, FromReversedCHARRANGE) {
|
||||
CHARRANGE cr = { 20, 10 };
|
||||
ui::Range r(cr, 40);
|
||||
EXPECT_EQ(20U, r.start());
|
||||
EXPECT_EQ(10U, r.end());
|
||||
EXPECT_EQ(10U, r.length());
|
||||
EXPECT_TRUE(r.is_reversed());
|
||||
EXPECT_TRUE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, FromCHARRANGETotal) {
|
||||
CHARRANGE cr = { 0, -1 };
|
||||
ui::Range r(cr, 20);
|
||||
EXPECT_EQ(0U, r.start());
|
||||
EXPECT_EQ(20U, r.end());
|
||||
EXPECT_EQ(20U, r.length());
|
||||
EXPECT_FALSE(r.is_reversed());
|
||||
EXPECT_TRUE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, ToCHARRANGE) {
|
||||
ui::Range r(10, 30);
|
||||
CHARRANGE cr = r.ToCHARRANGE();
|
||||
EXPECT_EQ(10, cr.cpMin);
|
||||
EXPECT_EQ(30, cr.cpMax);
|
||||
}
|
||||
|
||||
TEST(RangeTest, ReversedToCHARRANGE) {
|
||||
ui::Range r(20, 10);
|
||||
CHARRANGE cr = r.ToCHARRANGE();
|
||||
EXPECT_EQ(20U, cr.cpMin);
|
||||
EXPECT_EQ(10U, cr.cpMax);
|
||||
}
|
||||
|
||||
TEST(RangeTest, FromCHARRANGEInvalid) {
|
||||
CHARRANGE cr = { -1, -1 };
|
||||
ui::Range r(cr, 30);
|
||||
EXPECT_FALSE(r.IsValid());
|
||||
}
|
||||
|
||||
TEST(RangeTest, ToCHARRANGEInvalid) {
|
||||
ui::Range r(ui::Range::InvalidRange());
|
||||
CHARRANGE cr = r.ToCHARRANGE();
|
||||
EXPECT_EQ(-1, cr.cpMin);
|
||||
EXPECT_EQ(-1, cr.cpMax);
|
||||
}
|
@ -128,7 +128,8 @@
|
||||
'base/models/tree_node_model.h',
|
||||
'base/range/range.cc',
|
||||
'base/range/range.h',
|
||||
'base/range/range.mm',
|
||||
'base/range/range_mac.mm',
|
||||
'base/range/range_win.cc',
|
||||
'base/resource/data_pack.cc',
|
||||
'base/resource/data_pack.h',
|
||||
'base/resource/resource_bundle.cc',
|
||||
|
@ -29,7 +29,8 @@
|
||||
'base/models/tree_node_iterator_unittest.cc',
|
||||
'base/models/tree_node_model_unittest.cc',
|
||||
'base/range/range_unittest.cc',
|
||||
'base/range/range_unittest.mm',
|
||||
'base/range/range_mac_unittest.mm',
|
||||
'base/range/range_win_unittest.cc',
|
||||
'base/resource/data_pack_unittest.cc',
|
||||
'base/resource/resource_bundle_unittest.cc',
|
||||
'base/text/bytes_formatting_unittest.cc',
|
||||
|
Reference in New Issue
Block a user