diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-20 17:55:55 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-20 17:55:55 +0000 |
commit | 4ae30d08d2df7fdb8b236b6c650a1a29a84ee562 (patch) | |
tree | 97a77e2c9bbab02533378c88aa3311cd2353562b /printing | |
parent | de4024067816c20a69189c1e0d7728aa2cf16d66 (diff) | |
download | chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.zip chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.tar.gz chromium_src-4ae30d08d2df7fdb8b236b6c650a1a29a84ee562.tar.bz2 |
Move units to new module printing. Add printing_unittests on Windows too. Make test_shell and chrome_dll dependent on printing.
Review URL: http://codereview.chromium.org/21475
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10105 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/DEPS | 3 | ||||
-rw-r--r-- | printing/printing.vcproj | 147 | ||||
-rw-r--r-- | printing/printing.vsprops | 8 | ||||
-rw-r--r-- | printing/printing_unittests.vcproj | 165 | ||||
-rw-r--r-- | printing/units.cc | 42 | ||||
-rw-r--r-- | printing/units.h | 27 | ||||
-rw-r--r-- | printing/units_unittest.cc | 54 |
7 files changed, 446 insertions, 0 deletions
diff --git a/printing/DEPS b/printing/DEPS new file mode 100644 index 0000000..5cd0867 --- /dev/null +++ b/printing/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+base", +] diff --git a/printing/printing.vcproj b/printing/printing.vcproj new file mode 100644 index 0000000..bfc7f95 --- /dev/null +++ b/printing/printing.vcproj @@ -0,0 +1,147 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="printing" + ProjectGUID="{9E5416B9-B91B-4029-93F4-102C1AD5CAF4}" + RootNamespace="printing" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + ConfigurationType="4" + InheritedPropertySheets="$(SolutionDir)..\build\debug.vsprops;.\printing.vsprops" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + ConfigurationType="4" + InheritedPropertySheets="$(SolutionDir)..\build\release.vsprops;.\printing.vsprops" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLibrarianTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\units.cc" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\units.h" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/printing/printing.vsprops b/printing/printing.vsprops new file mode 100644 index 0000000..5be0f76 --- /dev/null +++ b/printing/printing.vsprops @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioPropertySheet + ProjectType="Visual C++" + Version="8.00" + Name="printing" + InheritedPropertySheets="$(SolutionDir)..\testing\using_gtest.vsprops" + > +</VisualStudioPropertySheet> diff --git a/printing/printing_unittests.vcproj b/printing/printing_unittests.vcproj new file mode 100644 index 0000000..1683999 --- /dev/null +++ b/printing/printing_unittests.vcproj @@ -0,0 +1,165 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="printing_unittests" + ProjectGUID="{8B2EE5D9-41BC-4AA2-A401-2DC143A05D2E}" + RootNamespace="printing_unittests" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + ConfigurationType="1" + InheritedPropertySheets="$(SolutionDir)..\build\debug.vsprops;.\printing.vsprops" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + ConfigurationType="1" + InheritedPropertySheets="$(SolutionDir)..\build\release.vsprops;.\printing.vsprops" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="support" + > + <File + RelativePath="..\base\run_all_unittests.cc" + > + </File> + <File + RelativePath="..\base\test_suite.h" + > + </File> + </Filter> + <Filter + Name="tests" + > + <File + RelativePath=".\units_unittest.cc" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/printing/units.cc b/printing/units.cc new file mode 100644 index 0000000..5f543fe --- /dev/null +++ b/printing/units.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2006-2008 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 "printing/units.h" + +#include "base/logging.h" + +namespace printing { + +int ConvertUnit(int value, int old_unit, int new_unit) { + DCHECK_GT(new_unit, 0); + DCHECK_GT(old_unit, 0); + // With integer arithmetic, to divide a value with correct rounding, you need + // to add half of the divisor value to the dividend value. You need to do the + // reverse with negative number. + if (value >= 0) { + return ((value * new_unit) + (old_unit / 2)) / old_unit; + } else { + return ((value * new_unit) - (old_unit / 2)) / old_unit; + } +} + +double ConvertUnitDouble(double value, double old_unit, double new_unit) { + DCHECK_GT(new_unit, 0); + DCHECK_GT(old_unit, 0); + return value * new_unit / old_unit; +} + +int ConvertMilliInchToHundredThousanthMeter(int milli_inch) { + // 1" == 25.4 mm + // 1" == 25400 um + // 0.001" == 25.4 um + // 0.001" == 2.54 cmm + return ConvertUnit(milli_inch, 100, 254); +} + +int ConvertHundredThousanthMeterToMilliInch(int cmm) { + return ConvertUnit(cmm, 254, 100); +} + +} // namespace printing diff --git a/printing/units.h b/printing/units.h new file mode 100644 index 0000000..d23e268 --- /dev/null +++ b/printing/units.h @@ -0,0 +1,27 @@ +// Copyright (c) 2006-2008 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. + +#ifndef PRINTING_UNITS_H_ +#define PRINTING_UNITS_H_ + +namespace printing { + +// Length of a thousanth of inches in 0.01mm unit. +const int kHundrethsMMPerInch = 2540; + +// Converts from one unit system to another using integer arithmetics. +int ConvertUnit(int value, int old_unit, int new_unit); + +// Converts from one unit system to another using doubles. +double ConvertUnitDouble(double value, double old_unit, double new_unit); + +// Converts from 0.001 inch unit to 0.00001 meter. +int ConvertMilliInchToHundredThousanthMeter(int milli_inch); + +// Converts from 0.00001 meter unit to 0.001 inch. +int ConvertHundredThousanthMeterToMilliInch(int cmm); + +} // namespace printing + +#endif // PRINTING_UNITS_H_ diff --git a/printing/units_unittest.cc b/printing/units_unittest.cc new file mode 100644 index 0000000..e042cf3 --- /dev/null +++ b/printing/units_unittest.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2006-2008 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 "printing/units.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/gtest/include/gtest/gtest-spi.h" + +using namespace printing; + +TEST(UnitsTest, Convertions) { + EXPECT_EQ(100, ConvertUnit(100, 100, 100)); + EXPECT_EQ(-100, ConvertUnit(-100, 100, 100)); + EXPECT_EQ(0, ConvertUnit(0, 100, 100)); + EXPECT_EQ(99, ConvertUnit(99, 100, 100)); + EXPECT_EQ(101, ConvertUnit(101, 100, 100)); + EXPECT_EQ(99900, ConvertUnit(999, 10, 1000)); + EXPECT_EQ(100100, ConvertUnit(1001, 10, 1000)); + + // Rounding. + EXPECT_EQ(10, ConvertUnit(999, 1000, 10)); + EXPECT_EQ(10, ConvertUnit(950, 1000, 10)); + EXPECT_EQ(9, ConvertUnit(949, 1000, 10)); + EXPECT_EQ(10, ConvertUnit(1001, 1000, 10)); + EXPECT_EQ(10, ConvertUnit(1049, 1000, 10)); + EXPECT_EQ(11, ConvertUnit(1050, 1000, 10)); + EXPECT_EQ(-10, ConvertUnit(-999, 1000, 10)); + EXPECT_EQ(-10, ConvertUnit(-950, 1000, 10)); + EXPECT_EQ(-9, ConvertUnit(-949, 1000, 10)); + EXPECT_EQ(-10, ConvertUnit(-1001, 1000, 10)); + EXPECT_EQ(-10, ConvertUnit(-1049, 1000, 10)); + EXPECT_EQ(-11, ConvertUnit(-1050, 1000, 10)); + + EXPECT_EQ(0, ConvertUnit(2, 1000000000, 1)); + EXPECT_EQ(2000000000, ConvertUnit(2, 1, 1000000000)); + EXPECT_EQ(4000000000U, + static_cast<unsigned int>(ConvertUnit(2, 1, 2000000000))); + + EXPECT_EQ(100, ConvertUnitDouble(100, 100, 100)); + EXPECT_EQ(-100, ConvertUnitDouble(-100, 100, 100)); + EXPECT_EQ(0, ConvertUnitDouble(0, 100, 100)); + EXPECT_EQ(0.000002, ConvertUnitDouble(2, 1000, 0.001)); + EXPECT_EQ(2000000, ConvertUnitDouble(2, 0.001, 1000)); + + EXPECT_EQ(kHundrethsMMPerInch, ConvertMilliInchToHundredThousanthMeter(1000)); + EXPECT_EQ(-kHundrethsMMPerInch, + ConvertMilliInchToHundredThousanthMeter(-1000)); + EXPECT_EQ(0, ConvertMilliInchToHundredThousanthMeter(0)); + EXPECT_EQ(1000, ConvertHundredThousanthMeterToMilliInch(kHundrethsMMPerInch)); + EXPECT_EQ(-1000, + ConvertHundredThousanthMeterToMilliInch(-kHundrethsMMPerInch)); + EXPECT_EQ(0, ConvertHundredThousanthMeterToMilliInch(0)); +} + |