[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2023-06-23 Thread Eike Rathke (via logerrit)
 include/tools/duration.hxx |   12 ++
 tools/qa/cppunit/test_duration.cxx |   65 +-
 tools/source/datetime/duration.cxx |   70 +
 3 files changed, 115 insertions(+), 32 deletions(-)

New commits:
commit c968d8989004301b49d67a093a6eb8a629533837
Author: Eike Rathke 
AuthorDate: Fri Jun 23 12:42:29 2023 +0200
Commit: Eike Rathke 
CommitDate: Fri Jun 23 18:32:17 2023 +0200

Introduce tools::Duration individual time values ctor

Change-Id: I516d3727cbcf6667b32dc963febbf4b753ef6a91
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153497
Reviewed-by: Eike Rathke 
Tested-by: Jenkins

diff --git a/include/tools/duration.hxx b/include/tools/duration.hxx
index a027cd671cd1..ea33953751b8 100644
--- a/include/tools/duration.hxx
+++ b/include/tools/duration.hxx
@@ -39,6 +39,14 @@ public:
 unless one is 0. */
 Duration(sal_Int32 nDays, const Time& rTime);
 
+/** Individual time values can be out-of-range, all will be normalized.
+Additionally, the resulting time overall hour value is not restricted
+to sal_uInt16 like it is with Time, as values >=24 flow over into days.
+For a negative duration only a negative nDays can be given, thus a
+negative duration of less than one day is not possible. */
+Duration(sal_Int32 nDays, sal_uInt32 nHours, sal_uInt32 nMinutes, 
sal_uInt32 nSeconds,
+ sal_uInt64 nNanoseconds);
+
 bool IsNegative() const { return mnDays < 0 || maTime.GetTime() < 0; }
 sal_Int32 GetDays() const { return mnDays; }
 const Time& GetTime() const { return maTime; }
@@ -60,6 +68,10 @@ private:
 /** Internal days and Time values. */
 Duration(sal_Int32 nDays, sal_Int64 nTime);
 
+/** Prerequisite: mnDays is already set. */
+void Normalize(sal_uInt64 nHours, sal_uInt64 nMinutes, sal_uInt64 nSeconds,
+   sal_uInt64 nNanoseconds, bool bNegative);
+
 /** Prerequisite: mnDays is already correctly set and absolute value of
 nanoseconds less than one day. */
 void ApplyTime(sal_Int64 nNS);
diff --git a/tools/qa/cppunit/test_duration.cxx 
b/tools/qa/cppunit/test_duration.cxx
index c328db7cec38..c4032be83a03 100644
--- a/tools/qa/cppunit/test_duration.cxx
+++ b/tools/qa/cppunit/test_duration.cxx
@@ -114,12 +114,73 @@ void DurationTest::testDuration()
 }
 {
 // 235929599 seconds == SAL_MAX_UINT16 hours + 59 minutes + 59 seconds
-const Duration aD(0, Time(0, 0, 235929599));
+const Duration aD(0, Time(0, 0, 235929599, Time::nanoSecPerSec - 1));
 CPPUNIT_ASSERT_EQUAL(static_cast(2730), aD.GetDays());
 CPPUNIT_ASSERT_EQUAL(static_cast(15), 
aD.GetTime().GetHour());
 CPPUNIT_ASSERT_EQUAL(static_cast(59), 
aD.GetTime().GetMin());
 CPPUNIT_ASSERT_EQUAL(static_cast(59), 
aD.GetTime().GetSec());
-CPPUNIT_ASSERT_EQUAL(static_cast(0), 
aD.GetTime().GetNanoSec());
+CPPUNIT_ASSERT_EQUAL(static_cast(9), 
aD.GetTime().GetNanoSec());
+}
+{
+// 235929599 seconds == SAL_MAX_UINT16 hours + 59 minutes + 59 seconds
+const Duration aD(0, 0, 0, 235929599, Time::nanoSecPerSec - 1);
+CPPUNIT_ASSERT_EQUAL(static_cast(2730), aD.GetDays());
+CPPUNIT_ASSERT_EQUAL(static_cast(15), 
aD.GetTime().GetHour());
+CPPUNIT_ASSERT_EQUAL(static_cast(59), 
aD.GetTime().GetMin());
+CPPUNIT_ASSERT_EQUAL(static_cast(59), 
aD.GetTime().GetSec());
+CPPUNIT_ASSERT_EQUAL(static_cast(9), 
aD.GetTime().GetNanoSec());
+}
+{
+const Duration aD(1, 2, 3, 4, 5);
+CPPUNIT_ASSERT_EQUAL(static_cast(1), aD.GetDays());
+CPPUNIT_ASSERT_EQUAL(static_cast(2), 
aD.GetTime().GetHour());
+CPPUNIT_ASSERT_EQUAL(static_cast(3), 
aD.GetTime().GetMin());
+CPPUNIT_ASSERT_EQUAL(static_cast(4), 
aD.GetTime().GetSec());
+CPPUNIT_ASSERT_EQUAL(static_cast(5), 
aD.GetTime().GetNanoSec());
+}
+{
+const Duration aD(-1, 2, 3, 4, 5);
+CPPUNIT_ASSERT(aD.IsNegative());
+CPPUNIT_ASSERT_EQUAL(static_cast(-1), aD.GetDays());
+CPPUNIT_ASSERT_EQUAL(static_cast(2), 
aD.GetTime().GetHour());
+CPPUNIT_ASSERT_EQUAL(static_cast(3), 
aD.GetTime().GetMin());
+CPPUNIT_ASSERT_EQUAL(static_cast(4), 
aD.GetTime().GetSec());
+CPPUNIT_ASSERT_EQUAL(static_cast(5), 
aD.GetTime().GetNanoSec());
+}
+{
+const Duration aD(1, SAL_MAX_UINT32, SAL_MAX_UINT32, SAL_MAX_UINT32, 
SAL_MAX_UINT64);
+CPPUNIT_ASSERT_EQUAL(static_cast(182202802), aD.GetDays());
+CPPUNIT_ASSERT_EQUAL(static_cast(1), 
aD.GetTime().GetHour());
+CPPUNIT_ASSERT_EQUAL(static_cast(17), 
aD.GetTime().GetMin());
+CPPUNIT_ASSERT_EQUAL(static_cast(48), 
aD.GetTime().GetSec());
+CPPUNIT_ASSERT_EQUAL(static_cast(709551615), 
aD.GetTime().GetNanoSec());
+}
+{
+const Duration aD(-1, SAL_MAX_

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2023-06-21 Thread Eike Rathke (via logerrit)
 include/tools/duration.hxx |5 +++
 tools/qa/cppunit/test_duration.cxx |   17 ++
 tools/source/datetime/duration.cxx |   58 +
 3 files changed, 80 insertions(+)

New commits:
commit 986c2d86a7b53a6599d014db7327f47cb33d4fea
Author: Eike Rathke 
AuthorDate: Wed Jun 21 21:56:56 2023 +0200
Commit: Eike Rathke 
CommitDate: Thu Jun 22 01:40:00 2023 +0200

Introduce tools::Duration(sal_Int32 nDays, const Time& rTime) ctor

Change-Id: If002e04536149b49b2249103ac914d17dec3fae6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153409
Reviewed-by: Eike Rathke 
Tested-by: Jenkins

diff --git a/include/tools/duration.hxx b/include/tools/duration.hxx
index 83b9d12a77b3..a027cd671cd1 100644
--- a/include/tools/duration.hxx
+++ b/include/tools/duration.hxx
@@ -34,6 +34,11 @@ public:
 /** Difference in days, like DateTime()-DateTime(). */
 explicit Duration(double fTimeInDays);
 
+/** Time can be a limited duration as well and can have out-of-range
+values, it will be normalized. Sign of both days and Time must be equal
+unless one is 0. */
+Duration(sal_Int32 nDays, const Time& rTime);
+
 bool IsNegative() const { return mnDays < 0 || maTime.GetTime() < 0; }
 sal_Int32 GetDays() const { return mnDays; }
 const Time& GetTime() const { return maTime; }
diff --git a/tools/qa/cppunit/test_duration.cxx 
b/tools/qa/cppunit/test_duration.cxx
index 0f5a4e002219..c328db7cec38 100644
--- a/tools/qa/cppunit/test_duration.cxx
+++ b/tools/qa/cppunit/test_duration.cxx
@@ -104,6 +104,23 @@ void DurationTest::testDuration()
 const Duration aN = -aD;
 CPPUNIT_ASSERT_EQUAL(1.5, aN.GetInDays());
 }
+{
+const Duration aD(1, Time(2, 3, 4, 5));
+CPPUNIT_ASSERT_EQUAL(static_cast(1), aD.GetDays());
+CPPUNIT_ASSERT_EQUAL(static_cast(2), 
aD.GetTime().GetHour());
+CPPUNIT_ASSERT_EQUAL(static_cast(3), 
aD.GetTime().GetMin());
+CPPUNIT_ASSERT_EQUAL(static_cast(4), 
aD.GetTime().GetSec());
+CPPUNIT_ASSERT_EQUAL(static_cast(5), 
aD.GetTime().GetNanoSec());
+}
+{
+// 235929599 seconds == SAL_MAX_UINT16 hours + 59 minutes + 59 seconds
+const Duration aD(0, Time(0, 0, 235929599));
+CPPUNIT_ASSERT_EQUAL(static_cast(2730), aD.GetDays());
+CPPUNIT_ASSERT_EQUAL(static_cast(15), 
aD.GetTime().GetHour());
+CPPUNIT_ASSERT_EQUAL(static_cast(59), 
aD.GetTime().GetMin());
+CPPUNIT_ASSERT_EQUAL(static_cast(59), 
aD.GetTime().GetSec());
+CPPUNIT_ASSERT_EQUAL(static_cast(0), 
aD.GetTime().GetNanoSec());
+}
 { // Add()
 const DateTime aS(Date(23, 11, 1999), Time(0, 0, 0));
 const DateTime aE(Date(23, 11, 1999), Time(1, 23, 45));
diff --git a/tools/source/datetime/duration.cxx 
b/tools/source/datetime/duration.cxx
index 3aa195cfbda5..255706f0486a 100644
--- a/tools/source/datetime/duration.cxx
+++ b/tools/source/datetime/duration.cxx
@@ -86,6 +86,64 @@ Duration::Duration(double fTimeInDays)
 }
 }
 
+Duration::Duration(sal_Int32 nDays, const Time& rTime)
+: mnDays(nDays)
+{
+assert(nDays == 0 || rTime.GetTime() == 0 || (nDays < 0) == 
(rTime.GetTime() < 0));
+sal_uInt64 nN = rTime.GetNanoSec();
+sal_uInt64 nS = rTime.GetSec();
+if (nN >= Time::nanoSecPerSec)
+{
+nS += nN / Time::nanoSecPerSec;
+nN %= Time::nanoSecPerSec;
+}
+sal_uInt64 nM = rTime.GetMin();
+if (nS >= Time::secondPerMinute)
+{
+nM += nS / Time::secondPerMinute;
+nS %= Time::secondPerMinute;
+}
+sal_uInt64 nH = rTime.GetHour();
+if (nM >= Time::minutePerHour)
+{
+nH += nM / Time::minutePerHour;
+nM %= Time::minutePerHour;
+}
+if (nH >= Time::hourPerDay)
+{
+sal_Int64 nDiff = nH / Time::hourPerDay;
+nH %= Time::hourPerDay;
+bool bOverflow = false;
+if (rTime.GetTime() < 0)
+{
+nDiff = -nDiff;
+bOverflow = (nDiff < SAL_MIN_INT32);
+bOverflow |= o3tl::checked_add(mnDays, 
static_cast(nDiff), mnDays);
+if (bOverflow)
+mnDays = SAL_MIN_INT32;
+}
+else
+{
+bOverflow = (nDiff > SAL_MAX_INT32);
+bOverflow |= o3tl::checked_add(mnDays, 
static_cast(nDiff), mnDays);
+if (bOverflow)
+mnDays = SAL_MAX_INT32;
+}
+assert(!bOverflow);
+if (bOverflow)
+{
+nH = Time::hourPerDay - 1;
+nM = Time::minutePerHour - 1;
+nS = Time::secondPerMinute - 1;
+nN = Time::nanoSecPerSec - 1;
+}
+}
+maTime = Time(nH, nM, nS, nN);
+if (rTime.GetTime() < 0)
+maTime = -maTime;
+assert(mnDays == 0 || maTime.GetTime() == 0 || (mnDays < 0) == 
(maTime.GetTime() < 0));
+}
+
 Duration::Duration(sal_Int32 nDays, sal_Int64 nTime)
 : maTime(nTime)
 

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2021-11-29 Thread Miklos Vajna (via logerrit)
 include/tools/color.hxx |8 
 tools/qa/cppunit/test_color.cxx |   13 +
 tools/source/generic/color.cxx  |   32 
 3 files changed, 53 insertions(+)

New commits:
commit 8662293d17a875f4389ea21be00e768e3de3d048
Author: Miklos Vajna 
AuthorDate: Mon Nov 29 08:28:28 2021 +0100
Commit: Miklos Vajna 
CommitDate: Mon Nov 29 09:51:16 2021 +0100

tools Color: implement MSO-style luminance modulation/offset filter

To be used when a filtered theme color will be applied on the UI, and
not at PPTX import time.

Change-Id: Ifb56e38e59b529ef436063c407ee156d76a77f9c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126011
Reviewed-by: Miklos Vajna 
Tested-by: Jenkins

diff --git a/include/tools/color.hxx b/include/tools/color.hxx
index a34b55863701..6ab0fa3ba67d 100644
--- a/include/tools/color.hxx
+++ b/include/tools/color.hxx
@@ -335,6 +335,14 @@ public:
  **/
 void ApplyTintOrShade(sal_Int16 n100thPercent);
 
+/**
+ * Apply luminance offset and/or modulation.
+ *
+ * The input values are in percentages (in 100th percents). 100% 
modulation and 0% offset
+ * results in no change.
+ */
+void ApplyLumModOff(sal_Int16 nMod, sal_Int16 nOff);
+
 /** Inverts color. 1 and 0 are switched.
   * Note that the result will be the complementary color.
   * For example, if you have red, you will get cyan: FF -> 00.
diff --git a/tools/qa/cppunit/test_color.cxx b/tools/qa/cppunit/test_color.cxx
index f3ffd9c692cd..3dd4225cb20f 100644
--- a/tools/qa/cppunit/test_color.cxx
+++ b/tools/qa/cppunit/test_color.cxx
@@ -22,6 +22,7 @@ public:
 void testVariables();
 void test_asRGBColor();
 void test_ApplyTintOrShade();
+void test_ApplyLumModOff();
 void testGetColorError();
 void testInvert();
 void testBColor();
@@ -31,6 +32,7 @@ public:
 CPPUNIT_TEST(testVariables);
 CPPUNIT_TEST(test_asRGBColor);
 CPPUNIT_TEST(test_ApplyTintOrShade);
+CPPUNIT_TEST(test_ApplyLumModOff);
 CPPUNIT_TEST(testGetColorError);
 CPPUNIT_TEST(testInvert);
 CPPUNIT_TEST(testBColor);
@@ -163,6 +165,17 @@ void Test::test_ApplyTintOrShade()
 CPPUNIT_ASSERT_EQUAL(OUString("00"), createTintShade(0x80, 0x80, 0x80, 
u"808080", -1));
 }
 
+void Test::test_ApplyLumModOff()
+{
+// Kind of blue.
+Color aColor(0x44, 0x72, 0xC4);
+
+// PowerPoint calls this "Ligher 40%".
+aColor.ApplyLumModOff(6000, 4000);
+
+CPPUNIT_ASSERT_EQUAL(OUString("8faadc"), aColor.AsRGBHexString());
+}
+
 void Test::testGetColorError()
 {
 CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), Color(0xAA, 0xBB, 
0xCC).GetColorError(Color(0xAA, 0xBB, 0xCC)));
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx
index cf4e084b722f..5df32719eb2c 100644
--- a/tools/source/generic/color.cxx
+++ b/tools/source/generic/color.cxx
@@ -230,4 +230,36 @@ void Color::ApplyTintOrShade(sal_Int16 n100thPercent)
 B = sal_uInt8(std::lround(aBColor.getBlue()  * 255.0));
 }
 
+void Color::ApplyLumModOff(sal_Int16 nMod, sal_Int16 nOff)
+{
+if (nMod == 1 && nOff == 0)
+{
+return;
+}
+// Switch to HSL, where applying these transforms is easier.
+basegfx::BColor aBColor = basegfx::utils::rgb2hsl(getBColor());
+
+// 50% is half luminance, 200% is double luminance. Unit is 100th percent.
+aBColor.setBlue(std::clamp(aBColor.getBlue() * nMod / 1, 0.0, 1.0));
+// If color changes to black or white, it will stay gray if luminance 
changes again.
+if ((aBColor.getBlue() == 0.0) || (aBColor.getBlue() == 1.0))
+{
+aBColor.setGreen(0.0);
+}
+
+// Luminance offset means hue and saturation is left unchanged. Unit is 
100th percent.
+aBColor.setBlue(std::clamp(aBColor.getBlue() + static_cast(nOff) / 
1, 0.0, 1.0));
+// If color changes to black or white, it will stay gray if luminance 
changes again.
+if ((aBColor.getBlue() == 0.0) || (aBColor.getBlue() == 1.0))
+{
+aBColor.setGreen(0.0);
+}
+
+// Switch back to RGB.
+aBColor = basegfx::utils::hsl2rgb(aBColor);
+R = sal_uInt8(std::lround(aBColor.getRed()   * 255.0));
+G = sal_uInt8(std::lround(aBColor.getGreen() * 255.0));
+B = sal_uInt8(std::lround(aBColor.getBlue()  * 255.0));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


[Libreoffice-commits] core.git: include/tools tools/qa tools/source vcl/source

2021-04-02 Thread Tomaž Vajngerl (via logerrit)
 include/tools/GenericTypeSerializer.hxx |4 ++
 include/tools/fract.hxx |9 +++--
 tools/qa/cppunit/test_GenericTypeSerializer.cxx |   43 
 tools/source/generic/fract.cxx  |   33 --
 tools/source/stream/GenericTypeSerializer.cxx   |   30 +++-
 vcl/source/gdi/TypeSerializer.cxx   |8 ++--
 6 files changed, 85 insertions(+), 42 deletions(-)

New commits:
commit 711ec7b6c71410b850cdf6d1411d054ca34ec5a0
Author: Tomaž Vajngerl 
AuthorDate: Fri Apr 2 11:37:42 2021 +0900
Commit: Tomaž Vajngerl 
CommitDate: Fri Apr 2 15:23:26 2021 +0200

vcl: move Fraction reading/writing to GenericTypeSerializer

Change-Id: Iccacaa7fd9cffe1d99f76def854c2150bb4d94f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113499
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/include/tools/GenericTypeSerializer.hxx 
b/include/tools/GenericTypeSerializer.hxx
index cb54e693c118..f67d92c845c5 100644
--- a/include/tools/GenericTypeSerializer.hxx
+++ b/include/tools/GenericTypeSerializer.hxx
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace tools
 {
@@ -47,6 +48,9 @@ public:
 
 void readRectangle(Rectangle& rRectangle);
 void writeRectangle(const Rectangle& rRectangle);
+
+void readFraction(Fraction& rFraction);
+void writeFraction(Fraction const& rFraction);
 };
 
 } // end namespace tools
diff --git a/include/tools/fract.hxx b/include/tools/fract.hxx
index c37859d7c17a..73d22fcaf430 100644
--- a/include/tools/fract.hxx
+++ b/include/tools/fract.hxx
@@ -33,7 +33,6 @@ class SAL_WARN_UNUSED TOOLS_DLLPUBLIC Fraction final
 sal_Int32   mnNumerator = 0;
 sal_Int32   mnDenominator = 1;
 boolmbValid = true;
-
 public:
 Fraction() = default;
 Fraction( const Fraction & rFrac ) = default;
@@ -85,8 +84,12 @@ public:
 TOOLS_DLLPUBLIC friend bool operator<=( const Fraction& rVal1, const 
Fraction& rVal2 );
 TOOLS_DLLPUBLIC friend bool operator>=( const Fraction& rVal1, const 
Fraction& rVal2 );
 
-TOOLS_DLLPUBLIC friend SvStream& ReadFraction( SvStream& rIStream, 
Fraction & rFract );
-TOOLS_DLLPUBLIC friend SvStream& WriteFraction( SvStream& rOStream, const 
Fraction& rFract );
+static Fraction createInvalid()
+{
+Fraction aFraction;
+aFraction.mbValid = false;
+return aFraction;
+}
 };
 
 TOOLS_DLLPUBLIC Fraction operator+( const Fraction& rVal1, const Fraction& 
rVal2 );
diff --git a/tools/qa/cppunit/test_GenericTypeSerializer.cxx 
b/tools/qa/cppunit/test_GenericTypeSerializer.cxx
index 24d1497f92d2..d378dd7c304d 100644
--- a/tools/qa/cppunit/test_GenericTypeSerializer.cxx
+++ b/tools/qa/cppunit/test_GenericTypeSerializer.cxx
@@ -87,10 +87,53 @@ public:
 }
 }
 
+void testRoundtripFraction()
+{
+{
+Fraction aFraction(2, 5);
+CPPUNIT_ASSERT_EQUAL(true, aFraction.IsValid());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aFraction.GetNumerator());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aFraction.GetDenominator());
+
+SvMemoryStream aStream;
+aStream.Seek(STREAM_SEEK_TO_BEGIN);
+GenericTypeSerializer aSerializer(aStream);
+aSerializer.writeFraction(aFraction);
+
+aStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+Fraction aReadFraction(1, 2);
+aSerializer.readFraction(aReadFraction);
+CPPUNIT_ASSERT_EQUAL(true, aReadFraction.IsValid());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aReadFraction.GetNumerator());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aReadFraction.GetDenominator());
+}
+{
+Fraction aFraction(1, 0);
+CPPUNIT_ASSERT_EQUAL(false, aFraction.IsValid());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aFraction.GetNumerator());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aFraction.GetDenominator());
+
+SvMemoryStream aStream;
+aStream.Seek(STREAM_SEEK_TO_BEGIN);
+GenericTypeSerializer aSerializer(aStream);
+aSerializer.writeFraction(aFraction);
+
+aStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+Fraction aReadFraction(1, 2);
+aSerializer.readFraction(aReadFraction);
+CPPUNIT_ASSERT_EQUAL(false, aReadFraction.IsValid());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aReadFraction.GetNumerator());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), 
aReadFraction.GetDenominator());
+}
+}
+
 CPPUNIT_TEST_SUITE(GenericTypeSerializerTest);
 CPPUNIT_TEST(testRoundtripPoint);
 CPPUNIT_TEST(testRoundtripSize);
 CPPUNIT_TEST(testRoundtripRectangle);
+CPPUNIT_TEST(testRoundtripFraction);
 CPPUNIT_TEST_SUITE_END();
 };
 
diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx
index 448a7

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2021-01-16 Thread Tomaž Vajngerl (via logerrit)
 include/tools/XmlWalker.hxx |2 ++
 tools/qa/cppunit/test_xmlwalker.cxx |5 +
 tools/qa/data/test.xml  |2 ++
 tools/source/xml/XmlWalker.cxx  |   10 ++
 4 files changed, 19 insertions(+)

New commits:
commit cd65d6c06760caf0109664d2a320cfb29d634ab2
Author: Tomaž Vajngerl 
AuthorDate: Sun Jan 17 00:08:08 2021 +0900
Commit: Tomaž Vajngerl 
CommitDate: Sun Jan 17 01:07:29 2021 +0100

tools: support reading xml namespace with XmlWalker

Adds methods namespaceHref and namespacePrefix for reading the
current element's namespace prefix and the href.

Change-Id: I1c16857c6fc0bdfde2d983d8f42f15319029
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109442
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl 

diff --git a/include/tools/XmlWalker.hxx b/include/tools/XmlWalker.hxx
index 204d71b5f48c..65beb4531003 100644
--- a/include/tools/XmlWalker.hxx
+++ b/include/tools/XmlWalker.hxx
@@ -41,6 +41,8 @@ public:
 bool open(SvStream* pStream);
 
 OString name();
+OString namespaceHref();
+OString namespacePrefix();
 
 OString content();
 void children();
diff --git a/tools/qa/cppunit/test_xmlwalker.cxx 
b/tools/qa/cppunit/test_xmlwalker.cxx
index 9f442c73c347..ec0a695b62d1 100644
--- a/tools/qa/cppunit/test_xmlwalker.cxx
+++ b/tools/qa/cppunit/test_xmlwalker.cxx
@@ -74,6 +74,11 @@ void XmlWalkerTest::testReadXML()
 }
 aWalker.parent();
 }
+else if (aWalker.name() == "with-namespace")
+{
+CPPUNIT_ASSERT_EQUAL(OString("adobe:ns:meta/"), 
aWalker.namespaceHref());
+CPPUNIT_ASSERT_EQUAL(OString("xx"), aWalker.namespacePrefix());
+}
 aWalker.next();
 }
 aWalker.parent();
diff --git a/tools/qa/data/test.xml b/tools/qa/data/test.xml
index 7a0473d7f8f9..c2736e8bb6ac 100644
--- a/tools/qa/data/test.xml
+++ b/tools/qa/data/test.xml
@@ -8,4 +8,6 @@
 
 
 
+
+
 
diff --git a/tools/source/xml/XmlWalker.cxx b/tools/source/xml/XmlWalker.cxx
index 219bf10c8bb5..34a3d8746f6b 100644
--- a/tools/source/xml/XmlWalker.cxx
+++ b/tools/source/xml/XmlWalker.cxx
@@ -61,6 +61,16 @@ bool XmlWalker::open(SvStream* pStream)
 
 OString XmlWalker::name() { return reinterpret_cast(mpImpl->mpCurrent->name); }
 
+OString XmlWalker::namespaceHref()
+{
+return reinterpret_cast(mpImpl->mpCurrent->ns->href);
+}
+
+OString XmlWalker::namespacePrefix()
+{
+return reinterpret_cast(mpImpl->mpCurrent->ns->prefix);
+}
+
 OString XmlWalker::content()
 {
 OString aContent;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2020-11-17 Thread Noel (via logerrit)
 include/tools/bigint.hxx |8 +---
 tools/qa/cppunit/test_bigint.cxx |6 --
 tools/source/generic/bigint.cxx  |7 ---
 3 files changed, 1 insertion(+), 20 deletions(-)

New commits:
commit 9536098ff107f1096e7f710c6f1e76c5659a5482
Author: Noel 
AuthorDate: Tue Nov 17 10:15:11 2020 +0200
Commit: Noel Grandin 
CommitDate: Tue Nov 17 14:31:01 2020 +0100

simplify BigInt, remove isSet

no need for such a thing to be "nullable", just default it to zero,
as one would be expect for such a type.

Change-Id: Ic8b78ca3288355c90820135b9ced2c865ff7606e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105970
Tested-by: Noel Grandin 
Reviewed-by: Noel Grandin 

diff --git a/include/tools/bigint.hxx b/include/tools/bigint.hxx
index db8c3bcd1b1c..a8d8575fb53b 100644
--- a/include/tools/bigint.hxx
+++ b/include/tools/bigint.hxx
@@ -32,8 +32,7 @@ private:
 sal_uInt16  nNum[MAX_DIGITS];
 sal_uInt8   nLen: 5;// current length
 boolbIsNeg  : 1,// Is Sign negative?
-bIsBig  : 1,// sal_True == BigInt
-bIsSet  : 1;// Not "Null" (not "not 0")
+bIsBig  : 1;// if true , value is in nNum array
 
 TOOLS_DLLPRIVATE void MakeBigInt(BigInt const &);
 TOOLS_DLLPRIVATE void Normalize();
@@ -53,7 +52,6 @@ public:
 , nLen(0)
 , bIsNeg(false)
 , bIsBig(false)
-, bIsSet(false)
 {
 }
 
@@ -62,7 +60,6 @@ public:
 , nLen(0)
 , bIsNeg(false)
 , bIsBig(false)
-, bIsSet(true)
 {
 }
 
@@ -72,7 +69,6 @@ public:
 , nLen(0)
 , bIsNeg(false)
 , bIsBig(false)
-, bIsSet(true)
 {
 }
 #endif
@@ -92,7 +88,6 @@ public:
 operatortools::Long() const;
 #endif
 
-boolIsSet() const { return bIsSet; }
 boolIsNeg() const;
 boolIsZero() const;
 boolIsLong() const { return !bIsBig; }
@@ -169,7 +164,6 @@ inline BigInt::operator tools::Long() const
 
 inline BigInt& BigInt::operator =( sal_Int32 nValue )
 {
-bIsSet = true;
 bIsBig = false;
 nVal   = nValue;
 
diff --git a/tools/qa/cppunit/test_bigint.cxx b/tools/qa/cppunit/test_bigint.cxx
index a91d16f93def..140562df0e23 100644
--- a/tools/qa/cppunit/test_bigint.cxx
+++ b/tools/qa/cppunit/test_bigint.cxx
@@ -39,7 +39,6 @@ void BigIntTest::testConstructionFromLongLong()
 // small positive number
 {
 BigInt bi(static_cast(42));
-CPPUNIT_ASSERT(bi.IsSet());
 CPPUNIT_ASSERT(!bi.IsZero());
 CPPUNIT_ASSERT(!bi.IsNeg());
 CPPUNIT_ASSERT(bi.IsLong());
@@ -49,7 +48,6 @@ void BigIntTest::testConstructionFromLongLong()
 // small negative number
 {
 BigInt bi(static_cast(-42));
-CPPUNIT_ASSERT(bi.IsSet());
 CPPUNIT_ASSERT(!bi.IsZero());
 CPPUNIT_ASSERT(bi.IsNeg());
 CPPUNIT_ASSERT(bi.IsLong());
@@ -60,7 +58,6 @@ void BigIntTest::testConstructionFromLongLong()
 // positive number just fitting to sal_Int32
 {
 BigInt 
bi(static_cast(std::numeric_limits::max()));
-CPPUNIT_ASSERT(bi.IsSet());
 CPPUNIT_ASSERT(!bi.IsZero());
 CPPUNIT_ASSERT(!bi.IsNeg());
 CPPUNIT_ASSERT(bi.IsLong());
@@ -70,7 +67,6 @@ void BigIntTest::testConstructionFromLongLong()
 // negative number just fitting to sal_Int32
 {
 BigInt 
bi(static_cast(std::numeric_limits::min()));
-CPPUNIT_ASSERT(bi.IsSet());
 CPPUNIT_ASSERT(!bi.IsZero());
 CPPUNIT_ASSERT(bi.IsNeg());
 CPPUNIT_ASSERT(bi.IsLong());
@@ -80,7 +76,6 @@ void BigIntTest::testConstructionFromLongLong()
 // positive number not fitting to sal_Int32
 {
 BigInt 
bi(static_cast(std::numeric_limits::max()) + 1);
-CPPUNIT_ASSERT(bi.IsSet());
 CPPUNIT_ASSERT(!bi.IsZero());
 CPPUNIT_ASSERT(!bi.IsNeg());
 CPPUNIT_ASSERT(!bi.IsLong());
@@ -89,7 +84,6 @@ void BigIntTest::testConstructionFromLongLong()
 // negative number not fitting to sal_Int32
 {
 BigInt 
bi(static_cast(std::numeric_limits::min()) - 1);
-CPPUNIT_ASSERT(bi.IsSet());
 CPPUNIT_ASSERT(!bi.IsZero());
 CPPUNIT_ASSERT(bi.IsNeg());
 CPPUNIT_ASSERT(!bi.IsLong());
diff --git a/tools/source/generic/bigint.cxx b/tools/source/generic/bigint.cxx
index d90ac2447fa1..62350a30c311 100644
--- a/tools/source/generic/bigint.cxx
+++ b/tools/source/generic/bigint.cxx
@@ -477,7 +477,6 @@ BigInt::BigInt( const BigInt& rBigInt )
 memcpy( static_cast(this), static_cast(&rBigInt), 
sizeof( BigInt ) );
 else
 {
-bIsSet = rBigInt.bIsSet;
 bIsBig = false;
 nVal   = rBigInt.nVal;
 }
@@ -486,7 +485,6 @@ BigInt::BigInt( const BigInt& rBigInt )
 BigInt::BigInt( const OUString& rString )
 : nLen(0)
 {
-bIsSet = true;
 bIsNeg = fal

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2020-06-19 Thread Noel Grandin (via logerrit)
 include/tools/json_writer.hxx |   14 +++---
 tools/qa/cppunit/test_json_writer.cxx |   10 +-
 tools/source/misc/json_writer.cxx |   16 +++-
 3 files changed, 27 insertions(+), 13 deletions(-)

New commits:
commit 8df7447139b1171d8fd29f5d682b053df5936006
Author: Noel Grandin 
AuthorDate: Fri Jun 19 09:57:58 2020 +0200
Commit: Stephan Bergmann 
CommitDate: Fri Jun 19 15:38:52 2020 +0200

asan: need to use malloc instead of new for tools::JsonWriter

because the LOK API expects memory returned from those calls to be
malloc'ed

Change-Id: If6fbfb60c433bd6e58bc90a9a90a90663e2e1c60
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96676
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/tools/json_writer.hxx b/include/tools/json_writer.hxx
index c1438783de78..c0312f6c581d 100644
--- a/include/tools/json_writer.hxx
+++ b/include/tools/json_writer.hxx
@@ -11,7 +11,6 @@
 #include 
 #include 
 #include 
-#include 
 
 /** Simple JSON encoder designed specifically for LibreOfficeKit purposes.
  *
@@ -28,7 +27,7 @@ class TOOLS_DLLPUBLIC JsonWriter
 friend class ScopedJsonWriterNode;
 
 int mSpaceAllocated;
-std::unique_ptr maBuffer;
+char* mpBuffer;
 int mStartNodeCount;
 char* mPos;
 bool mbFirstFieldInNode;
@@ -54,14 +53,15 @@ private:
 
 inline void ensureSpace(int noMoreBytesRequired)
 {
-int currentUsed = mPos - maBuffer.get();
+int currentUsed = mPos - mpBuffer;
 if (currentUsed + noMoreBytesRequired >= mSpaceAllocated)
 {
 auto newSize = std::max(mSpaceAllocated * 2, (currentUsed + 
noMoreBytesRequired) * 2);
-auto pNew = new char[newSize];
-memcpy(pNew, maBuffer.get(), currentUsed);
-maBuffer.reset(pNew);
-mPos = maBuffer.get();
+char* pNew = static_cast(malloc(newSize));
+memcpy(pNew, mpBuffer, currentUsed);
+free(mpBuffer);
+mpBuffer = pNew;
+mPos = mpBuffer;
 }
 }
 };
diff --git a/tools/qa/cppunit/test_json_writer.cxx 
b/tools/qa/cppunit/test_json_writer.cxx
index c4e9331c8d17..e27afc95f712 100644
--- a/tools/qa/cppunit/test_json_writer.cxx
+++ b/tools/qa/cppunit/test_json_writer.cxx
@@ -7,6 +7,10 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include 
+
+#include 
+
 #include 
 #include 
 #include 
@@ -44,7 +48,11 @@ void JsonWriterTest::test1()
 aJson.put("int", 12);
 }
 
-std::unique_ptr result(aJson.extractData());
+struct Free
+{
+void operator()(void* p) const { std::free(p); }
+};
+std::unique_ptr result(aJson.extractData());
 
 CPPUNIT_ASSERT_EQUAL(std::string("{ \"node\": { \"oustring\": \"val1\", 
\"ostring\": \"val2\", "
  "\"charptr\": \"val3\", \"int\": 12}}"),
diff --git a/tools/source/misc/json_writer.cxx 
b/tools/source/misc/json_writer.cxx
index 81b22e92a2d1..8a57e2ac337f 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -19,9 +19,9 @@ constexpr int DEFAULT_BUFFER_SIZE = 2048;
 
 JsonWriter::JsonWriter()
 : mSpaceAllocated(DEFAULT_BUFFER_SIZE)
-, maBuffer(new char[mSpaceAllocated])
+, mpBuffer(static_cast(malloc(mSpaceAllocated)))
 , mStartNodeCount(0)
-, mPos(maBuffer.get())
+, mPos(mpBuffer)
 {
 *mPos = '{';
 ++mPos;
@@ -29,7 +29,11 @@ JsonWriter::JsonWriter()
 ++mPos;
 }
 
-JsonWriter::~JsonWriter() { assert(!maBuffer && "forgot to extract data?"); }
+JsonWriter::~JsonWriter()
+{
+assert(!mpBuffer && "forgot to extract data?");
+free(mpBuffer);
+}
 
 ScopedJsonWriterNode JsonWriter::startNode(const char* pNodeName)
 {
@@ -239,14 +243,16 @@ void JsonWriter::addCommaBeforeField()
 char* JsonWriter::extractData()
 {
 assert(mStartNodeCount == 0 && "did not close all nodes");
-assert(maBuffer && "data already extracted");
+assert(mpBuffer && "data already extracted");
 // add closing brace
 *mPos = '}';
 ++mPos;
 // null-terminate
 *mPos = 0;
 mPos = nullptr;
-return maBuffer.release();
+char* pRet = nullptr;
+std::swap(pRet, mpBuffer);
+return pRet;
 }
 
 } // namespace tools
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2019-08-28 Thread Stephan Bergmann (via logerrit)
 include/tools/urlobj.hxx |   12 --
 tools/qa/cppunit/test_urlobj.cxx |   62 --
 tools/source/fsys/urlobj.cxx |  171 ---
 3 files changed, 245 deletions(-)

New commits:
commit b82489382e18494694530874480774e2bb29830e
Author: Stephan Bergmann 
AuthorDate: Wed Aug 28 15:28:17 2019 +0200
Commit: Stephan Bergmann 
CommitDate: Wed Aug 28 17:45:05 2019 +0200

INetURLObject::setFSysPath is unused now

...after 056e1fff2ed232f2a50db933fbade1c71c0c2a65 "Simplify code removing 
the
last segment from a URL"

Change-Id: I3abe84ada119356191d8df9c0a8ee62dcf18d108
Reviewed-on: https://gerrit.libreoffice.org/78228
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann 

diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx
index 3187ea24cb92..522dcca35fcd 100644
--- a/include/tools/urlobj.hxx
+++ b/include/tools/urlobj.hxx
@@ -755,18 +755,6 @@ public:
 
 // File URLs:
 
-/** Set this INetURLObject to a file URL constructed from a file system
-path.
-
-@param rFSysPath  A file system path.  A URL is not allowed here!
-
-@param eStyle  The notation of rFSysPath.
-
-@return  True if this INetURLObject has successfully been changed.  If
-false is returned, this INetURLObject has not been modified.
- */
-bool setFSysPath(OUString const & rFSysPath, FSysStyle eStyle);
-
 /** Return the file system path represented by a file URL (ignoring any
 fragment part).
 
diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx
index 87ce9aa77758..0e25decab713 100644
--- a/tools/qa/cppunit/test_urlobj.cxx
+++ b/tools/qa/cppunit/test_urlobj.cxx
@@ -60,36 +60,6 @@ namespace tools_urlobj
 CPPUNIT_ASSERT_EQUAL(OUString("file"), aUrl.getExtension());
 }
 
-void urlobjTest_002(  )
-{
-INetURLObject aUrl;
-aUrl.
-setFSysPath( "137.65.170.24\\c$\\Img0001.jpg",
- FSysStyle::Detect );
-CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol());
-CPPUNIT_ASSERT_EQUAL(OUString("137.65.170.24"),
- 
aUrl.GetHost(INetURLObject::DecodeMechanism::NONE));
-CPPUNIT_ASSERT_EQUAL(OUString("/c$/Img0001.jpg"),
- 
aUrl.GetURLPath(INetURLObject::DecodeMechanism::NONE));
-CPPUNIT_ASSERT_EQUAL(OUString("Img0001.jpg"), aUrl.getName());
-CPPUNIT_ASSERT_EQUAL(OUString("Img0001"), aUrl.getBase());
-CPPUNIT_ASSERT_EQUAL(OUString("jpg"), aUrl.getExtension());
-}
-
-
-void urlobjTest_003(  )
-{
-INetURLObject aUrl;
-aUrl.
-setFSysPath( "hive-winxp-x86\\pmladek\\test2.odt",
- FSysStyle::Detect );
-CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol());
-CPPUNIT_ASSERT_EQUAL(OUString("hive-winxp-x86"),
- 
aUrl.GetHost(INetURLObject::DecodeMechanism::NONE));
-CPPUNIT_ASSERT_EQUAL(OUString("/pmladek/test2.odt"),
- 
aUrl.GetURLPath(INetURLObject::DecodeMechanism::NONE));
-}
-
 void urlobjTest_004(  )
 {
 INetURLObject aUrl( OUString( 
"smb://10.10.1.1/sampledir/sample.file" ) );
@@ -103,34 +73,6 @@ namespace tools_urlobj
 CPPUNIT_ASSERT_EQUAL(OUString("file"), aUrl.getExtension());
 }
 
-void urlobjTest_005(  )
-{
-INetURLObject aUrl;
-aUrl.setFSysPath( "//137.65.170.24/c$/Img0001.jpg",
-  FSysStyle::Detect );
-CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol());
-CPPUNIT_ASSERT_EQUAL(OUString("137.65.170.24"),
- 
aUrl.GetHost(INetURLObject::DecodeMechanism::NONE));
-CPPUNIT_ASSERT_EQUAL(OUString("/c$/Img0001.jpg"),
- 
aUrl.GetURLPath(INetURLObject::DecodeMechanism::NONE));
-CPPUNIT_ASSERT_EQUAL(OUString("Img0001.jpg"), aUrl.getName(  ));
-CPPUNIT_ASSERT_EQUAL(OUString("Img0001"), aUrl.getBase(  ));
-CPPUNIT_ASSERT_EQUAL(OUString("jpg"), aUrl.getExtension(  ));
-}
-
-
-void urlobjTest_006(  )
-{
-INetURLObject aUrl;
-aUrl.setFSysPath( "//hive-winxp-x86/pmladek/test2.odt",
-  FSysStyle::Detect );
-CPPUNIT_ASSERT_EQUAL(INetProtocol::File, aUrl.GetProtocol());
-CPPUNIT_ASSERT_EQUAL(OUString("hive-winxp-x86"),
- 
aUrl.GetHost(INetURLObject::DecodeMechanism::NONE));
-CPPUNIT_ASSERT_EQUAL(OUString("/pmladek/test2.odt"),
- aUrl.GetURLPath( 
INetURLObject::DecodeMechanism::NONE));
-}
-
 void urlo

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2018-05-06 Thread Chris Sherlock
 include/tools/date.hxx  |8 
 tools/qa/cppunit/test_date.cxx  |  459 ++--
 tools/source/datetime/datetimeutils.cxx |6 
 3 files changed, 454 insertions(+), 19 deletions(-)

New commits:
commit e2b72039c619b64235fc7cbf12ac40b6b968f984
Author: Chris Sherlock 
Date:   Sun May 6 06:07:18 2018 +1000

tools: date unit tests

Change-Id: I2b3eaf74173f7f456f04c734dfb7c05c95802809
Reviewed-on: https://gerrit.libreoffice.org/53895
Tested-by: Jenkins 
Reviewed-by: Noel Grandin 

diff --git a/include/tools/date.hxx b/include/tools/date.hxx
index c70d3450399c..69d9e3d03ea3 100644
--- a/include/tools/date.hxx
+++ b/include/tools/date.hxx
@@ -19,10 +19,14 @@
 #ifndef INCLUDED_TOOLS_DATE_HXX
 #define INCLUDED_TOOLS_DATE_HXX
 
+#include 
+
 #include 
+
+#include 
+
 #include 
 #include 
-#include 
 
 enum DayOfWeek { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY,
  SATURDAY, SUNDAY };
@@ -244,6 +248,8 @@ public:
 sal_Int32 GetAsNormalizedDays() const;
 };
 
+TOOLS_DLLPUBLIC std::ostream& operator<<(std::ostream& os, const Date& rDate);
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/qa/cppunit/test_date.cxx b/tools/qa/cppunit/test_date.cxx
index 74d37efe5201..7e1119e93b68 100644
--- a/tools/qa/cppunit/test_date.cxx
+++ b/tools/qa/cppunit/test_date.cxx
@@ -19,9 +19,25 @@ class DateTest : public CppUnit::TestFixture
 {
 public:
 void testDate();
+void testLeapYear();
+void testGetDaysInYear();
+void testValidGregorianDate();
+void testValidDate();
+void testNormalize();
+void testGetDayOfWeek();
+void testGetDaysInMonth();
+void testIsBetween();
 
 CPPUNIT_TEST_SUITE(DateTest);
 CPPUNIT_TEST(testDate);
+CPPUNIT_TEST(testLeapYear);
+CPPUNIT_TEST(testGetDaysInYear);
+CPPUNIT_TEST(testValidGregorianDate);
+CPPUNIT_TEST(testValidDate);
+CPPUNIT_TEST(testNormalize);
+CPPUNIT_TEST(testGetDayOfWeek);
+CPPUNIT_TEST(testGetDaysInMonth);
+CPPUNIT_TEST(testIsBetween);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -66,10 +82,7 @@ void DateTest::testDate()
 aDate.SetDay(32);
 aDate.Normalize();
 CPPUNIT_ASSERT_EQUAL( aMax.GetDate(), aDate.GetDate());
-
-// Empty date is not a valid date.
-aDate = Date( Date::EMPTY );
-CPPUNIT_ASSERT( !aDate.IsValidDate());
+CPPUNIT_ASSERT(!aDate.IsEmpty());
 
 // 0001-00-x normalized to -0001-12-x
 aDate.SetYear(1);
@@ -77,6 +90,9 @@ void DateTest::testDate()
 aDate.SetDay(22);
 aDate.Normalize();
 CPPUNIT_ASSERT_EQUAL( Date(22,12,-1).GetDate(), aDate.GetDate());
+
+sal_uInt32 nExpected = 11222;
+CPPUNIT_ASSERT_EQUAL(nExpected, aDate.GetDateUnsigned());
 // 1999-02-32 normalized to 1999-03-04
 aDate.SetYear(1999);
 aDate.SetMonth(2);
@@ -112,21 +128,428 @@ void DateTest::testDate()
 aDate.SetDay(0);
 aDate.Normalize();
 CPPUNIT_ASSERT_EQUAL( Date(31,12,-1).GetDate(), aDate.GetDate());
+}
 
-// Year -1 is a leap year.
-aDate = Date(28,2,-1);
-aDate.AddDays(1);
-CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate());
-aDate = Date(1,3,-1);
-aDate.AddDays(-1);
-CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate());
-// Year -5 is a leap year.
-aDate = Date(28,2,-5);
-aDate.AddDays(1);
-CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate());
-aDate = Date(1,3,-5);
-aDate.AddDays(-1);
-CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate());
+void DateTest::testLeapYear()
+{
+{
+Date aDate(1, 1, 2000);
+CPPUNIT_ASSERT(aDate.IsLeapYear());
+}
+
+{
+Date aDate(1, 1, 1900);
+CPPUNIT_ASSERT(!aDate.IsLeapYear());
+}
+
+{
+Date aDate(1, 1, 1999);
+CPPUNIT_ASSERT(!aDate.IsLeapYear());
+}
+
+{
+Date aDate(1, 1, 2004);
+CPPUNIT_ASSERT(aDate.IsLeapYear());
+}
+
+{
+Date aDate(1, 1, 400);
+CPPUNIT_ASSERT(aDate.IsLeapYear());
+}
+
+{
+// Year -1 is a leap year.
+Date aDate (28,2,-1);
+aDate.AddDays(1);
+CPPUNIT_ASSERT(aDate.IsLeapYear());
+CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate());
+}
+
+{
+Date aDate(1,3,-1);
+aDate.AddDays(-1);
+CPPUNIT_ASSERT(aDate.IsLeapYear());
+CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), aDate.GetDate());
+}
+
+{
+// Year -5 is a leap year.
+Date aDate(28,2,-5);
+aDate.AddDays(1);
+CPPUNIT_ASSERT(aDate.IsLeapYear());
+CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate());
+}
+
+{
+Date aDate(1,3,-5);
+aDate.AddDays(-1);
+CPPUNIT_ASSERT(aDate.IsLeapYear());
+CPPUNIT_ASSERT_EQUAL( Date(29,2,-5).GetDate(), aDate.GetDate());
+}
+}
+
+void DateTest::testGetDaysInYear()
+{
+{
+Date aDate(1, 1, 2

[Libreoffice-commits] core.git: include/tools tools/qa tools/source ucb/source

2018-03-04 Thread Stephan Bergmann
 include/tools/urlobj.hxx  |3 ++-
 tools/qa/cppunit/test_urlobj.cxx  |8 
 tools/source/fsys/urlobj.cxx  |4 ++--
 ucb/source/ucp/webdav-neon/webdavprovider.hxx |4 ++--
 ucb/source/ucp/webdav/webdavprovider.hxx  |4 ++--
 5 files changed, 12 insertions(+), 11 deletions(-)

New commits:
commit e05263e0f23af6f3fccf56f1a488baad7b3ee55f
Author: Stephan Bergmann 
Date:   Sun Mar 4 13:52:05 2018 +0100

Change INetURLObject::isSchemeEqualTo parameter to u16string_view

Change-Id: I003fa0c6f9c485d0579f3dd18331e63548a3777c
Reviewed-on: https://gerrit.libreoffice.org/50728
Tested-by: Jenkins 
Reviewed-by: Stephan Bergmann 

diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx
index dca8f6c07b74..cceab871a383 100644
--- a/include/tools/urlobj.hxx
+++ b/include/tools/urlobj.hxx
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -383,7 +384,7 @@ public:
 
 bool isSchemeEqualTo(INetProtocol scheme) const { return scheme == 
m_eScheme; }
 
-bool isSchemeEqualTo(OUString const & scheme) const;
+bool isSchemeEqualTo(o3tl::u16string_view scheme) const;
 
 /** Check if the scheme is one of the WebDAV scheme
  *  we know about.
diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx
index 71554d2d8a41..f9996172a863 100644
--- a/tools/qa/cppunit/test_urlobj.cxx
+++ b/tools/qa/cppunit/test_urlobj.cxx
@@ -322,7 +322,7 @@ namespace tools_urlobj
 
 void urlobjTest_isSchemeEqualTo() {
 
CPPUNIT_ASSERT(INetURLObject().isSchemeEqualTo(INetProtocol::NotValid));
-CPPUNIT_ASSERT(!INetURLObject().isSchemeEqualTo(""));
+CPPUNIT_ASSERT(!INetURLObject().isSchemeEqualTo(u""));
 CPPUNIT_ASSERT(
 INetURLObject("http://example.org";).isSchemeEqualTo(
 INetProtocol::Http));
@@ -330,11 +330,11 @@ namespace tools_urlobj
 !INetURLObject("http://example.org";).isSchemeEqualTo(
 INetProtocol::Https));
 CPPUNIT_ASSERT(
-INetURLObject("http://example.org";).isSchemeEqualTo("Http"));
+INetURLObject("http://example.org";).isSchemeEqualTo(u"Http"));
 CPPUNIT_ASSERT(
-!INetURLObject("http://example.org";).isSchemeEqualTo("dav"));
+!INetURLObject("http://example.org";).isSchemeEqualTo(u"dav"));
 CPPUNIT_ASSERT(
-INetURLObject("dav://example.org").isSchemeEqualTo("dav"));
+INetURLObject("dav://example.org").isSchemeEqualTo(u"dav"));
 }
 
 void urlobjTest_isAnyKnownWebDAVScheme() {
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index b72976850345..6a3b2ef712c2 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -3889,10 +3889,10 @@ OUString INetURLObject::getExternalURL() const
 return aTheExtURIRef;
 }
 
-bool INetURLObject::isSchemeEqualTo(OUString const & scheme) const {
+bool INetURLObject::isSchemeEqualTo(o3tl::u16string_view scheme) const {
 return m_aScheme.isPresent()
 && (rtl_ustr_compareIgnoreAsciiCase_WithLength(
-scheme.getStr(), scheme.getLength(),
+scheme.data(), scheme.size(),
 m_aAbsURIRef.getStr() + m_aScheme.getBegin(),
 m_aScheme.getLength())
 == 0);
diff --git a/ucb/source/ucp/webdav-neon/webdavprovider.hxx 
b/ucb/source/ucp/webdav-neon/webdavprovider.hxx
index 9794cd413bf3..3e90c7fef5ab 100644
--- a/ucb/source/ucp/webdav-neon/webdavprovider.hxx
+++ b/ucb/source/ucp/webdav-neon/webdavprovider.hxx
@@ -51,8 +51,8 @@ namespace webdav_ucp {
 #define VNDSUNSTARWEBDAVS_URL_SCHEME "vnd.sun.star.webdavs"
 #define HTTP_URL_SCHEME  "http"
 #define HTTPS_URL_SCHEME "https"
-#define DAV_URL_SCHEME   "dav"
-#define DAVS_URL_SCHEME  "davs"
+#define DAV_URL_SCHEME   u"dav"
+#define DAVS_URL_SCHEME  u"davs"
 #define WEBDAV_URL_SCHEME"webdav"
 #define WEBDAVS_URL_SCHEME   "webdavs"
 
diff --git a/ucb/source/ucp/webdav/webdavprovider.hxx 
b/ucb/source/ucp/webdav/webdavprovider.hxx
index a9375260816b..d01455b25332 100644
--- a/ucb/source/ucp/webdav/webdavprovider.hxx
+++ b/ucb/source/ucp/webdav/webdavprovider.hxx
@@ -45,8 +45,8 @@ namespace http_dav_ucp {
 #define VNDSUNSTARWEBDAVS_URL_SCHEME "vnd.sun.star.webdavs"
 #define HTTP_URL_SCHEME  "http"
 #define HTTPS_URL_SCHEME "https"
-#define DAV_URL_SCHEME   "dav"
-#define DAVS_URL_SCHEME  "davs"
+#define DAV_URL_SCHEME   u"dav"
+#define DAVS_URL_SCHEME  u"davs"
 #define WEBDAV_URL_SCHEME"webdav"
 #define WEBDAVS_URL_SCHEME   "webdavs"
 
___
Libreoffice-commits mailing list
libreo

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2017-07-02 Thread Noel Grandin
 include/tools/date.hxx  |   14 ++---
 tools/qa/cppunit/test_date.cxx  |8 +++
 tools/source/datetime/tdate.cxx |   42 
 3 files changed, 32 insertions(+), 32 deletions(-)

New commits:
commit f5b0cc2a3690ba963b3f150886e1d5ee9530
Author: Noel Grandin 
Date:   Sat Jul 1 16:01:15 2017 +0200

use sal_Int32 in tools::Date

instead of long, which has platform-dependant length
(32bits on windows, 64bit on everything else)

Change-Id: I9b5a950f56dad99a016b481c221bfd103ffa3911
Reviewed-on: https://gerrit.libreoffice.org/39433
Tested-by: Jenkins 
Reviewed-by: Noel Grandin 

diff --git a/include/tools/date.hxx b/include/tools/date.hxx
index 7ea3998314fb..3e038beb308b 100644
--- a/include/tools/date.hxx
+++ b/include/tools/date.hxx
@@ -216,14 +216,14 @@ public:
 { mnDate = rDate.mnDate; return *this; }
 Date&   operator =( const css::util::Date& rUDate )
 { setDateFromDMY( rUDate.Day, rUDate.Month, 
rUDate.Year); return *this; }
-Date&   operator +=( long nDays );
-Date&   operator -=( long nDays );
+Date&   operator +=( sal_Int32 nDays );
+Date&   operator -=( sal_Int32 nDays );
 Date&   operator ++();
 Date&   operator --();
 
-TOOLS_DLLPUBLIC friend Date operator +( const Date& rDate, long nDays 
);
-TOOLS_DLLPUBLIC friend Date operator -( const Date& rDate, long nDays 
);
-TOOLS_DLLPUBLIC friend long operator -( const Date& rDate1, const 
Date& rDate2 );
+TOOLS_DLLPUBLIC friend Date  operator +( const Date& rDate, sal_Int32 
nDays );
+TOOLS_DLLPUBLIC friend Date  operator -( const Date& rDate, sal_Int32 
nDays );
+TOOLS_DLLPUBLIC friend sal_Int32 operator -( const Date& rDate1, const 
Date& rDate2 );
 
 /** Obtain number of days in a month of a year.
 
@@ -233,7 +233,7 @@ public:
 static sal_uInt16 GetDaysInMonth( sal_uInt16 nMonth, sal_Int16 nYear );
 
 /// Internally normalizes values.
-static long DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 
nYear );
+static sal_Int32 DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 
nYear );
 /// Semantically identical to IsValidDate() member method.
 static bool IsValidDate( sal_uInt16 nDay, sal_uInt16 nMonth, sal_Int16 
nYear );
 /// Semantically identical to Normalize() member method.
@@ -241,7 +241,7 @@ public:
 
  private:
 /// An accelerated form of DateToDays on this date
-long GetAsNormalizedDays() const;
+sal_Int32 GetAsNormalizedDays() const;
 };
 
 #endif
diff --git a/tools/qa/cppunit/test_date.cxx b/tools/qa/cppunit/test_date.cxx
index 054b38b1a727..4f36baa07564 100644
--- a/tools/qa/cppunit/test_date.cxx
+++ b/tools/qa/cppunit/test_date.cxx
@@ -32,12 +32,12 @@ void DateTest::testDate()
 const Date aMin(1,1,-32768);// minimum date
 const Date aMax(31,12,32767);   // maximum date
 Date aDate(Date::EMPTY);
-const long kMinDays = -11968265;
-const long kMaxDays =  11967900;
+const sal_Int32 kMinDays = -11968265;
+const sal_Int32 kMaxDays =  11967900;
 
 // Last day BCE to first day CE is 1 day difference.
-CPPUNIT_ASSERT_EQUAL( static_cast(1), aCE - aBCE);
-CPPUNIT_ASSERT_EQUAL( static_cast(-1), aBCE - aCE);
+CPPUNIT_ASSERT_EQUAL( static_cast(1), aCE - aBCE);
+CPPUNIT_ASSERT_EQUAL( static_cast(-1), aBCE - aCE);
 aDate = aBCE;
 CPPUNIT_ASSERT_EQUAL( aCE.GetDate(), (aDate += 1).GetDate());
 aDate = aCE;
diff --git a/tools/source/datetime/tdate.cxx b/tools/source/datetime/tdate.cxx
index 06c1d0e24454..4206b13c2dd1 100644
--- a/tools/source/datetime/tdate.cxx
+++ b/tools/source/datetime/tdate.cxx
@@ -42,8 +42,8 @@ static const sal_uInt16 aDaysInMonth[12] = { 31, 28, 31, 30, 
31, 30,
 /* XXX can that dbconversion cope with years >  or negative years at all?
  * Database fields may be limited to positive 4 digits. */
 
-static const long MIN_DAYS = -11968265; // -32768-01-01
-static const long MAX_DAYS =  11967900; //  32767-12-31
+static const sal_Int32 MIN_DAYS = -11968265; // -32768-01-01
+static const sal_Int32 MAX_DAYS =  11967900; //  32767-12-31
 
 namespace
 {
@@ -54,11 +54,11 @@ const sal_Int16 kYearMin = SAL_MIN_INT16;
 // Days until start of year from zero, so month and day of month can be added.
 // year 1 => 0 days, year 2 => 365 days, ...
 // year -1 => -366 days, year -2 => -731 days, ...
-inline long ImpYearToDays( sal_Int16 nYear )
+inline sal_Int32 ImpYearToDays( sal_Int16 nYear )
 {
 assert( nYear != 0 );
-long nOffset;
-long nYr;
+sal_Int32 nOffset;
+sal_Int32 nYr;
 if (nYear < 0)
 {
 nOffset = -366;
@@ -135,7 +135,7 @@ sal_uInt16 Date::GetDaysInMonth( sal_uInt16 nMonth, 
sal_Int16 nYear )
 return ImplDaysInMonth( nMonth, nYear);
 }
 
-long Date::GetAsNormalizedDays() const
+sal_Int32 Date::G

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2017-04-26 Thread Jochen Nitschke
 include/tools/inetmime.hxx |   21 +++
 tools/qa/cppunit/test_inetmime.cxx |  103 ++---
 tools/source/inet/inetmime.cxx |   21 ---
 3 files changed, 128 insertions(+), 17 deletions(-)

New commits:
commit bef9fe6e3decc92bdcec6415b1898e4a0202cc6a
Author: Jochen Nitschke 
Date:   Tue Apr 18 15:23:56 2017 +0200

extend unit test for INetMIME::scanContentType

This reverts parts of commit 631b67952909a73ba1851417bd2edbe02ad7be5a
and commit abc6071b7a8af354a56c91e4caecd8afc79f55cc.

some of the removed fields are usefull,
m_bConverted should be checked by callers

fixed 2 bugs and added test cases:
* extended attributes with more than 2 sections were not parsed
* extended attributes with more than 1 section were not parsed
  if there was an other attribute

Change-Id: I61ab2af7c5151ef1bcd80cc159fa2b99559374a8
Reviewed-on: https://gerrit.libreoffice.org/36913
Tested-by: Jenkins 
Reviewed-by: Stephan Bergmann 

diff --git a/include/tools/inetmime.hxx b/include/tools/inetmime.hxx
index e2c58b5ea056..cd66173a8d6c 100644
--- a/include/tools/inetmime.hxx
+++ b/include/tools/inetmime.hxx
@@ -30,6 +30,16 @@
 
 struct INetContentTypeParameter
 {
+/** The optional character set specification (see RFC 2231), in US-ASCII
+encoding and converted to lower case.
+ */
+OString m_sCharset;
+
+/** The optional language specification (see RFC 2231), in US-ASCII
+encoding and converted to lower case.
+ */
+OString m_sLanguage;
+
 /** The attribute value.  If the value is a quoted-string, it is
 'unpacked.'  If a character set is specified, and the value can be
 converted to Unicode, this is done.  Also, if no character set is
@@ -49,9 +59,18 @@ struct INetContentTypeParameter
  */
 OUString m_sValue;
 
+/** This is true if the value is successfully converted to Unicode, and
+false if the value is a special mixture of ISO-LATIN-1 characters and
+characters from Unicode's Private Use Area.
+ */
+bool m_bConverted;
 };
 
-// the key is the m_sAttribute again; all keys are lower case:
+/** The key is the name of the attribute, in US-ASCII encoding and converted
+to lower case.  If a parameter value is split as described in RFC 2231,
+there will only be one item for the complete parameter, with the attribute
+name lacking any section suffix.
+ */
 typedef std::unordered_map
 INetContentTypeParameterList;
 
diff --git a/tools/qa/cppunit/test_inetmime.cxx 
b/tools/qa/cppunit/test_inetmime.cxx
index 1a5d16b5aba6..8b953526778c 100644
--- a/tools/qa/cppunit/test_inetmime.cxx
+++ b/tools/qa/cppunit/test_inetmime.cxx
@@ -35,11 +35,13 @@ namespace
 public:
 void test_decodeHeaderFieldBody();
 
-void test_scanContentType();
+void test_scanContentType_basic();
+void test_scanContentType_rfc2231();
 
 CPPUNIT_TEST_SUITE(Test);
 CPPUNIT_TEST(test_decodeHeaderFieldBody);
-CPPUNIT_TEST(test_scanContentType);
+CPPUNIT_TEST(test_scanContentType_basic);
+CPPUNIT_TEST(test_scanContentType_rfc2231);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -56,17 +58,61 @@ namespace
 CPPUNIT_ASSERT(testDecode("=?iso-8859-1?B?QUJD?=", "ABC"));
 }
 
-void Test::test_scanContentType()
+void Test::test_scanContentType_basic()
 {
 {
 OUString input
-= "TEST/subTST; parm1*0*=US-ASCII'En'5%25%20; 
Parm1*1*=of%2010";
+= "TEST/subTST; parm1=Value1; Parm2=\"unpacked value; %20\"";
+// Just scan input for valid string:
+auto end = INetMIME::scanContentType(input.getStr(), 
input.getStr()+input.getLength());
+CPPUNIT_ASSERT(end != nullptr);
+CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
+// Scan input and parse type, subType and parameters:
+OUString type;
+OUString subType;
+INetContentTypeParameterList parameters;
+end = INetMIME::scanContentType(input.getStr(), input.getStr() + 
input.getLength(),
+&type, &subType, ¶meters);
+CPPUNIT_ASSERT(end != nullptr);
+CPPUNIT_ASSERT_EQUAL(OUString(), OUString(end));
+CPPUNIT_ASSERT_EQUAL(OUString("test"), type);
+CPPUNIT_ASSERT_EQUAL(OUString("subtst"), subType);
+CPPUNIT_ASSERT_EQUAL(
+INetContentTypeParameterList::size_type(2), parameters.size());
+auto i = parameters.find("parm1");
+CPPUNIT_ASSERT(i != parameters.end());
+CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sCharset);
+CPPUNIT_ASSERT_EQUAL(OString(), i->second.m_sLanguage);
+CPPUNIT_ASSERT_EQUAL(OUString("Value1"), i->second.m_sValue);
+CPPUNIT_ASSERT(i->second.m_bConverted);
+i = param

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2015-10-05 Thread Giuseppe Castagno
 include/tools/urlobj.hxx |   11 ++
 tools/qa/cppunit/test_urlobj.cxx |   40 +++
 tools/source/fsys/urlobj.cxx |   16 +++
 3 files changed, 67 insertions(+)

New commits:
commit 8ea85c264f22c76d393c0f78e9db7df51e2c868d
Author: Giuseppe Castagno 
Date:   Sun Aug 30 20:24:39 2015 +0200

Add isSchemeEqualTo(), isAnyKnownWebDAVScheme() to INetURLObject

...which will be used when rebasing

"tdf#82744: fix WebDAV lock/unlock behaviour - part 3" on top of
 d3de490437df4c9093f32e97fc185066d64c0f46
 "Add vnd.sun.star.webdavs URL scheme."

Change-Id: I19bd715d755a6f070b95ce897d8a1bbb4910d537
Reviewed-on: https://gerrit.libreoffice.org/18151
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx
index 7778666..d487851 100644
--- a/include/tools/urlobj.hxx
+++ b/include/tools/urlobj.hxx
@@ -390,6 +390,17 @@ public:
 
 inline INetProtocol GetProtocol() const { return m_eScheme; }
 
+bool isSchemeEqualTo(INetProtocol scheme) const { return scheme == 
m_eScheme; }
+
+bool isSchemeEqualTo(OUString const & scheme) const;
+
+/** Check if the scheme is one of the WebDAV scheme
+ *  we know about.
+ *
+ *  @return true is one othe scheme either public scheme or private scheme.
+ */
+bool isAnyKnownWebDAVScheme() const;
+
 /** Return the URL 'prefix' for a given scheme.
 
 @param eTheScheme  One of the supported URL schemes.
diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx
index b591156..6115bc8 100644
--- a/tools/qa/cppunit/test_urlobj.cxx
+++ b/tools/qa/cppunit/test_urlobj.cxx
@@ -329,6 +329,44 @@ namespace tools_urlobj
 CPPUNIT_ASSERT(strm == 0);
 }
 
+void urlobjTest_isSchemeEqualTo() {
+
CPPUNIT_ASSERT(INetURLObject().isSchemeEqualTo(INetProtocol::NotValid));
+CPPUNIT_ASSERT(!INetURLObject().isSchemeEqualTo(""));
+CPPUNIT_ASSERT(
+INetURLObject("http://example.org";).isSchemeEqualTo(
+INetProtocol::Http));
+CPPUNIT_ASSERT(
+!INetURLObject("http://example.org";).isSchemeEqualTo(
+INetProtocol::Https));
+CPPUNIT_ASSERT(
+INetURLObject("http://example.org";).isSchemeEqualTo("Http"));
+CPPUNIT_ASSERT(
+!INetURLObject("http://example.org";).isSchemeEqualTo("dav"));
+CPPUNIT_ASSERT(
+INetURLObject("dav://example.org").isSchemeEqualTo("dav"));
+}
+
+void urlobjTest_isAnyKnownWebDAVScheme() {
+CPPUNIT_ASSERT(
+INetURLObject("http://example.org";).isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+INetURLObject("https://example.org";).isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+
INetURLObject("vnd.sun.star.webdav://example.org").isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+
INetURLObject("vnd.sun.star.webdavs://example.org").isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+!INetURLObject("ftp://example.org";).isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+!INetURLObject("file://example.org").isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+!INetURLObject("dav://example.org").isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+!INetURLObject("davs://example.org").isAnyKnownWebDAVScheme());
+CPPUNIT_ASSERT(
+
!INetURLObject("vnd.sun.star.pkg://example.org").isAnyKnownWebDAVScheme());
+}
+
 // Change the following lines only, if you add, remove or rename
 // member functions of the current class,
 // because these macros are need by auto register mechanism.
@@ -343,6 +381,8 @@ namespace tools_urlobj
 CPPUNIT_TEST( urlobjCmisTest );
 CPPUNIT_TEST( urlobjTest_emptyPath );
 CPPUNIT_TEST( urlobjTest_data );
+CPPUNIT_TEST( urlobjTest_isSchemeEqualTo );
+CPPUNIT_TEST( urlobjTest_isAnyKnownWebDAVScheme );
 CPPUNIT_TEST_SUITE_END(  );
 };  // class createPool
 
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index 51887b7..115d676 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -3911,6 +3911,22 @@ OUString INetURLObject::getExternalURL(DecodeMechanism 
eMechanism,
 return aTheExtURIRef;
 }
 
+bool INetURLObject::isSchemeEqualTo(OUString const & scheme) const {
+return m_aScheme.isPresent()
+&& (rtl_ustr_compareIgnoreAsciiCase_WithLength(
+scheme.getStr(), scheme.getLength(),
+m_aAbsURIRef.getStr() + m_aScheme.getBegin(),
+m_aScheme.getLength())

[Libreoffice-commits] core.git: include/tools tools/qa tools/source

2014-10-28 Thread Juan Picca
 include/tools/fract.hxx |   54 +++-
 tools/qa/cppunit/test_fract.cxx |7 
 tools/source/generic/fract.cxx  |  487 +++-
 3 files changed, 231 insertions(+), 317 deletions(-)

New commits:
commit 2ce0aededea43231d91a0955fc0676120dcc4f13
Author: Juan Picca 
Date:   Fri Oct 24 11:43:52 2014 -0200

fdo#81356: use boost::rational internally in Fraction

Change-Id: I6f40eafee7652209395bd471e3508fe3a3d19d73
Reviewed-on: https://gerrit.libreoffice.org/12085
Reviewed-by: David Tardon 
Tested-by: David Tardon 

diff --git a/include/tools/fract.hxx b/include/tools/fract.hxx
index 10e810e..0e81155 100644
--- a/include/tools/fract.hxx
+++ b/include/tools/fract.hxx
@@ -19,26 +19,32 @@
 #ifndef INCLUDED_TOOLS_FRACT_HXX
 #define INCLUDED_TOOLS_FRACT_HXX
 
+#include 
+#include 
 #include 
 
 class SvStream;
 
+// This class uses the platform defined type 'long' as valid values but do all
+// calculations using sal_Int64 with checks for 'long' overflows.
 class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Fraction
 {
 private:
-longnNumerator;
-longnDenominator;
+boolvalid;
+boost::rational  value;
+
+boolHasOverflowValue();
 
 public:
-Fraction() { nNumerator = 0; nDenominator = 1; }
+Fraction() { valid = true; }
 Fraction( const Fraction & rFrac );
 Fraction( long nNum, long nDen=1 );
 Fraction( double dVal );
 
 boolIsValid() const;
 
-longGetNumerator() const { return nNumerator; }
-longGetDenominator() const { return nDenominator; }
+longGetNumerator() const;
+longGetDenominator() const;
 
 operatorlong() const;
 operatordouble() const;
@@ -70,28 +76,50 @@ public:
 
 inline Fraction::Fraction( const Fraction& rFrac )
 {
-nNumerator   = rFrac.nNumerator;
-nDenominator = rFrac.nDenominator;
+valid = rFrac.valid;
+if ( valid )
+value.assign( rFrac.value.numerator(), rFrac.value.denominator() );
+}
+
+inline long Fraction::GetNumerator() const
+{
+if ( !valid ) {
+SAL_WARN( "tools.fraction", "'GetNumerator()' on invalid fraction" );
+return 0;
+}
+return value.numerator();
+}
+
+inline long Fraction::GetDenominator() const {
+if ( !valid ) {
+SAL_WARN( "tools.fraction", "'GetDenominator()' on invalid fraction" );
+return -1;
+}
+return value.denominator();
 }
 
 inline Fraction& Fraction::operator=( const Fraction& rFrac )
 {
-nNumerator   = rFrac.nNumerator;
-nDenominator = rFrac.nDenominator;
+if ( this != &rFrac ) {
+valid = rFrac.valid;
+if ( valid )
+value.assign( rFrac.value.numerator(), rFrac.value.denominator() );
+}
 return *this;
 }
 
 inline bool Fraction::IsValid() const
 {
-return (nDenominator > 0);
+return valid;
 }
 
 inline Fraction::operator long() const
 {
-if ( nDenominator > 0 )
-return (nNumerator / nDenominator);
-else
+if ( !valid ) {
+SAL_WARN( "tools.fraction", "'operator long()' on invalid fraction" );
 return 0;
+}
+return boost::rational_cast(value);
 }
 
 inline Fraction operator+( const Fraction& rVal1, const Fraction& rVal2 )
diff --git a/tools/qa/cppunit/test_fract.cxx b/tools/qa/cppunit/test_fract.cxx
index febece0..6352588 100644
--- a/tools/qa/cppunit/test_fract.cxx
+++ b/tools/qa/cppunit/test_fract.cxx
@@ -96,9 +96,16 @@ public:
 CPPUNIT_ASSERT_EQUAL(1L, f.GetDenominator());
 }
 
+void testCreateFromDoubleIn32BitsPlatform() {
+// This pass in 64 bits but fail in 32 bits
+Fraction f(0.960945);
+CPPUNIT_ASSERT_EQUAL(true, f.IsValid());
+}
+
 CPPUNIT_TEST_SUITE(FractionTest);
 CPPUNIT_TEST(testFraction);
 CPPUNIT_TEST(testMinLongDouble);
+CPPUNIT_TEST(testCreateFromDoubleIn32BitsPlatform);
 CPPUNIT_TEST_SUITE_END();
 };
 
diff --git a/tools/source/generic/fract.cxx b/tools/source/generic/fract.cxx
index ec219d8..45d54a4 100644
--- a/tools/source/generic/fract.cxx
+++ b/tools/source/generic/fract.cxx
@@ -26,81 +26,12 @@
 #include 
 #include 
 #include 
-#include 
 
-/** Compute greates common divisor using Euclidian algorithm
+template
+static boost::rational rational_FromDouble(double dVal);
 
-As the algorithm works on positive values only, the absolute value
-of each parameter is used.
-
-@param nVal1
-@param nVal2
-
-@note: If one parameter is {0,1}, GetGGT returns 1.
-*/
-static long GetGGT( long nVal1, long nVal2 )
-{
-nVal1 = std::abs( nVal1 );
-nVal2 = std::abs( nVal2 );
-
-if ( nVal1 <= 1 || nVal2 <= 1 )
-return 1;
-
-while ( nVal1 != nVal2 )
-{
-if ( nVal1 > nVal2 )
-{
-nVal1 %= nVal2;
-if ( nVal1 == 0 )
-