[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa comphelper/source

2022-05-19 Thread Tomaž Vajngerl (via logerrit)
 comphelper/CppunitTest_comphelper_test.mk  |7 
 comphelper/qa/string/NaturalStringSortTest.cxx |   95 
 comphelper/qa/string/test_string.cxx   |  188 -
 comphelper/source/misc/string.cxx  |   37 +++-
 4 files changed, 129 insertions(+), 198 deletions(-)

New commits:
commit 09822cf77cdbe32b03553cd05154100b5f2591d0
Author: Tomaž Vajngerl 
AuthorDate: Thu May 19 00:11:17 2022 +0900
Commit: Tomaž Vajngerl 
CommitDate: Fri May 20 01:19:41 2022 +0200

comphelper: fix natural string compare function + reorganize tests

Natural string compare function doesn't take into account that
the string can start with a number and in this case it treats it
like a conventional string compare. This change takes this case
into account.

This change also refactores the tests for NaturalStringSorter
class. The previous tet used a mock XBreakIterator and XCollator
implementations to test the functionallity. This is not needed as
we can just use a real one instead, which makes the test more
real as it actually uses a real implementation instead of a mock
implementation, which could differ. This change removes the mock
XCollator and XBreakIterator implementations and moves the test
into a new file - NaturalStringSortTest.cxx

The test is also extended with the new use case where the string
starts with a number.

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

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index d530f4577806..17de701aca26 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -11,6 +11,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,comphelper_test))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/string/test_string \
+comphelper/qa/string/NaturalStringSortTest \
 comphelper/qa/container/testifcontainer \
 comphelper/qa/container/testifcontainer3 \
 comphelper/qa/unit/test_hash \
@@ -21,6 +22,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/unit/test_traceevent \
 ))
 
+$(eval $(call gb_CppunitTest_use_ure,comphelper_test))
 $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test))
 
 $(eval $(call gb_CppunitTest_use_libraries,comphelper_test, \
@@ -28,6 +30,7 @@ $(eval $(call gb_CppunitTest_use_libraries,comphelper_test, \
 cppuhelper \
 cppu \
 sal \
+unotest \
 ))
 
 ifeq ($(TLS),NSS)
@@ -37,4 +40,8 @@ $(eval $(call gb_CppunitTest_use_externals,comphelper_test,\
 ))
 endif
 
+$(eval $(call gb_CppunitTest_use_components,comphelper_test,\
+   i18npool/util/i18npool \
+))
+
 # vim: set noet sw=4 ts=4:
diff --git a/comphelper/qa/string/NaturalStringSortTest.cxx 
b/comphelper/qa/string/NaturalStringSortTest.cxx
new file mode 100644
index ..bfdcaff6e13c
--- /dev/null
+++ b/comphelper/qa/string/NaturalStringSortTest.cxx
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace css;
+
+namespace
+{
+class TestStringNaturalCompare : public test::BootstrapFixtureBase
+{
+public:
+void testNatural()
+{
+lang::Locale aLocale;
+aLocale.Language = "en";
+aLocale.Country = "US";
+
+comphelper::string::NaturalStringSorter 
aSorter(comphelper::getProcessComponentContext(),
+aLocale);
+
+CPPUNIT_ASSERT_EQUAL(sal_Int32(+0), aSorter.compare("ABC", "ABC"));
+CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare("ABC", "abc"));
+CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aSorter.compare("abc", "ABC"));
+CPPUNIT_ASSERT_EQUAL(sal_Int32(+1), aSorter.compare("alongstring", 
"alongerstring"));
+

[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa

2021-12-18 Thread Noel Grandin (via logerrit)
 comphelper/CppunitTest_comphelper_test.mk|1 
 comphelper/qa/container/testifcontainer3.cxx |  170 +++
 2 files changed, 171 insertions(+)

New commits:
commit 9366a40b7ee4d422b283467caf7c130fee611140
Author: Noel Grandin 
AuthorDate: Fri Dec 17 15:49:29 2021 +0200
Commit: Noel Grandin 
CommitDate: Sat Dec 18 20:50:34 2021 +0100

add unit tests for OInterfaceContainerHelper3

Change-Id: I2baf512a3b5edd3ce29e302e444dfa5e65724613
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127007
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index ab2f893a0866..d530f4577806 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -12,6 +12,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,comphelper_test))
 $(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/string/test_string \
 comphelper/qa/container/testifcontainer \
+comphelper/qa/container/testifcontainer3 \
 comphelper/qa/unit/test_hash \
 comphelper/qa/unit/base64_test \
 comphelper/qa/unit/propertyvalue \
diff --git a/comphelper/qa/container/testifcontainer3.cxx 
b/comphelper/qa/container/testifcontainer3.cxx
new file mode 100644
index ..e300adeda12e
--- /dev/null
+++ b/comphelper/qa/container/testifcontainer3.cxx
@@ -0,0 +1,170 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace ::osl;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::uno;
+
+namespace
+{
+class TestInterfaceContainer3 : public CppUnit::TestFixture
+{
+public:
+void test1();
+
+CPPUNIT_TEST_SUITE(TestInterfaceContainer3);
+CPPUNIT_TEST(test1);
+CPPUNIT_TEST_SUITE_END();
+};
+
+class TestListener : public cppu::WeakImplHelper
+{
+public:
+// Methods
+virtual void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) 
override {}
+
+virtual void SAL_CALL vetoableChange(const 
css::beans::PropertyChangeEvent& /*aEvent*/) override
+{
+}
+};
+
+void TestInterfaceContainer3::test1()
+{
+Mutex mutex;
+
+{
+comphelper::OInterfaceContainerHelper3 
helper(mutex);
+
+Reference r1 = new TestListener;
+Reference r2 = new TestListener;
+Reference r3 = new TestListener;
+
+helper.addInterface(r1);
+helper.addInterface(r2);
+helper.addInterface(r3);
+
+helper.disposeAndClear(EventObject());
+}
+
+{
+comphelper::OInterfaceContainerHelper3 
helper(mutex);
+
+Reference r1 = new TestListener;
+Reference r2 = new TestListener;
+Reference r3 = new TestListener;
+
+helper.addInterface(r1);
+helper.addInterface(r2);
+helper.addInterface(r3);
+
+comphelper::OInterfaceIteratorHelper3 iterator(helper);
+
+while (iterator.hasMoreElements())
+iterator.next()->vetoableChange(PropertyChangeEvent());
+
+helper.disposeAndClear(EventObject());
+}
+
+{
+comphelper::OInterfaceContainerHelper3 
helper(mutex);
+
+Reference r1 = new TestListener;
+Reference r2 = new TestListener;
+Reference r3 = new TestListener;
+
+helper.addInterface(r1);
+helper.addInterface(r2);
+helper.addInterface(r3);
+
+comphelper::OInterfaceIteratorHelper3 iterator(helper);
+
+iterator.next()->vetoableChange(PropertyChangeEvent());
+iterator.remove();
+iterator.next()->vetoableChange(PropertyChangeEvent());
+iterator.remove();
+iterator.next()->vetoableChange(PropertyChangeEvent());
+iterator.remove();
+
+CPPUNIT_ASSERT_EQUAL(static_cast(0), helper.getLength());
+helper.disposeAndClear(EventObject());
+}
+
+{
+comphelper::OInterfaceContainerHelper3 
helper(mutex);
+
+Reference r1 = new 

[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa include/comphelper

2021-10-19 Thread Stephan Bergmann (via logerrit)
 comphelper/CppunitTest_comphelper_test.mk |1 
 comphelper/qa/unit/propertyvalue.cxx  |   60 ++
 include/comphelper/propertyvalue.hxx  |2 -
 3 files changed, 62 insertions(+), 1 deletion(-)

New commits:
commit 5e8479a38f0c342979520018f79a6f79d40e99e3
Author: Stephan Bergmann 
AuthorDate: Tue Oct 19 11:12:25 2021 +0200
Commit: Stephan Bergmann 
CommitDate: Tue Oct 19 15:12:35 2021 +0200

Remove a std::remove_reference_t

...which is unnecessary (short of dubious explicit invocations like
`makePropertyValue(i)`) as T can never be deduced to be a 
reference
type there.  And add some test code (that also tests the bit-field scenario
mentioned in the commit message of 23cded985ba0131f85ee445492c04871fbfb6351
"Specialize comphelper::makePropertyValue for arithmetic types").

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

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index de4ee90818f2..ab2f893a0866 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -14,6 +14,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/container/testifcontainer \
 comphelper/qa/unit/test_hash \
 comphelper/qa/unit/base64_test \
+comphelper/qa/unit/propertyvalue \
 comphelper/qa/unit/types_test \
 comphelper/qa/unit/test_guards \
 comphelper/qa/unit/test_traceevent \
diff --git a/comphelper/qa/unit/propertyvalue.cxx 
b/comphelper/qa/unit/propertyvalue.cxx
new file mode 100644
index ..40f60bb0463d
--- /dev/null
+++ b/comphelper/qa/unit/propertyvalue.cxx
@@ -0,0 +1,60 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+namespace
+{
+class MakePropertyValueTest : public CppUnit::TestFixture
+{
+CPPUNIT_TEST_SUITE(MakePropertyValueTest);
+CPPUNIT_TEST(testLvalue);
+CPPUNIT_TEST(testRvalue);
+CPPUNIT_TEST(testBitField);
+CPPUNIT_TEST_SUITE_END();
+
+void testLvalue()
+{
+sal_Int32 const i = 123;
+auto const v = comphelper::makePropertyValue("test", i);
+CPPUNIT_ASSERT_EQUAL(cppu::UnoType::get(), 
v.Value.getValueType());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(123), 
*o3tl::doAccess(v.Value));
+}
+
+void testRvalue()
+{
+auto const v = comphelper::makePropertyValue("test", sal_Int32(456));
+CPPUNIT_ASSERT_EQUAL(cppu::UnoType::get(), 
v.Value.getValueType());
+CPPUNIT_ASSERT_EQUAL(sal_Int32(456), 
*o3tl::doAccess(v.Value));
+}
+
+void testBitField()
+{
+struct
+{
+bool b : 1;
+} s = { false };
+auto const v = comphelper::makePropertyValue("test", s.b);
+CPPUNIT_ASSERT_EQUAL(cppu::UnoType::get(), 
v.Value.getValueType());
+CPPUNIT_ASSERT_EQUAL(false, *o3tl::doAccess(v.Value));
+}
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MakePropertyValueTest);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/include/comphelper/propertyvalue.hxx 
b/include/comphelper/propertyvalue.hxx
index 9d0d94d3256a..de71791100b1 100644
--- a/include/comphelper/propertyvalue.hxx
+++ b/include/comphelper/propertyvalue.hxx
@@ -33,7 +33,7 @@ css::beans::PropertyValue makePropertyValue(const OUString& 
rName, T&& rValue)
  css::beans::PropertyState_DIRECT_VALUE };
 }
 // Allows to pass e.g. bit fields
-template >, int> = 0>
+template , int> = 0>
 css::beans::PropertyValue makePropertyValue(const OUString& rName, T aValue)
 {
 return makePropertyValue(rName, css::uno::toAny(aValue));


[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa comphelper/source include/comphelper

2021-04-29 Thread Tor Lillqvist (via logerrit)
 comphelper/CppunitTest_comphelper_test.mk |1 
 comphelper/qa/unit/test_traceevent.cxx|  121 ++
 comphelper/source/misc/traceevent.cxx |   31 +++
 include/comphelper/profilezone.hxx|6 -
 include/comphelper/traceevent.hxx |  115 
 5 files changed, 251 insertions(+), 23 deletions(-)

New commits:
commit 89c0d087c657c31a3198c481a63ca0549b8a4503
Author: Tor Lillqvist 
AuthorDate: Tue Apr 27 18:43:16 2021 +0300
Commit: Tor Lillqvist 
CommitDate: Thu Apr 29 08:45:07 2021 +0200

Introduce Async trace events and a unit test

Async events are ones that emit separate 'b' (begin) and 'e' (end)
traces. (Compare to the Complete event that emit a single 'X' trace
that contains both the start timstamp and the duration.)

There are two kinds of Async events: Freestanding ones that are not
related to other events at all, and nested ones that have to be nested
between the 'b' and 'e' events of a parent Async event.

Still needs some work, at least a way to end a nested AsyncEvent
(cause it to emit the 'e' event) before it gets destructed thanks to
the parent being destructed.

Change-Id: I3721fa701ad32639b1edc1cfa8db7acde5caf9b4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114756
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist 

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index ef795f1664d1..de4ee90818f2 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -16,6 +16,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/unit/base64_test \
 comphelper/qa/unit/types_test \
 comphelper/qa/unit/test_guards \
+comphelper/qa/unit/test_traceevent \
 ))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test))
diff --git a/comphelper/qa/unit/test_traceevent.cxx 
b/comphelper/qa/unit/test_traceevent.cxx
new file mode 100644
index ..e7e97b2032a5
--- /dev/null
+++ b/comphelper/qa/unit/test_traceevent.cxx
@@ -0,0 +1,121 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+
+class TestTraceEvent : public CppUnit::TestFixture
+{
+public:
+void test();
+
+CPPUNIT_TEST_SUITE(TestTraceEvent);
+CPPUNIT_TEST(test);
+CPPUNIT_TEST_SUITE_END();
+};
+
+namespace
+{
+void trace_event_test()
+{
+// When we start recording is off and this will not generate any 'X' event
+comphelper::ProfileZone aZone0("test().0");
+
+// This will not generate any 'b' and 'e' events either
+auto pAsync1(std::make_shared("async 1"));
+
+std::weak_ptr pAsync2;
+{
+// No 'X' by this either
+comphelper::ProfileZone aZone1("block 1");
+
+// Now we turn on recording
+comphelper::TraceEvent::startRecording();
+
+// As this is nested in the parent that was created with recording 
turned off,
+// this will not generate any 'b' and 'e' events either
+pAsync2 = comphelper::AsyncEvent::createWithParent("async 2", pAsync1);
+}
+
+// This will generate an 'i' event
+comphelper::TraceEvent::addInstantEvent("instant 1");
+
+std::shared_ptr pAsync25;
+{
+comphelper::ProfileZone aZone2("block 2");
+
+// This does not generate any 'e' event as it was created when 
recording was off
+// And the nested "async 2" object will thus not generate anything 
either
+pAsync1.reset();
+
+// This will generate 'b' event and an 'e' event when the pointer is 
reset or goes out of scope
+pAsync25 = std::make_shared("async 2.5");
+
+// Leaving this scope will generate an 'X' event for "block 2"
+}
+
+// Verify that the weak_ptr to pAsync2 has expired as its parent pAsync1 
has been finished off
+CPPUNIT_ASSERT(pAsync2.expired());
+
+// This will generate a 'b' event
+auto pAsync3(std::make_shared("async 3"));
+
+std::weak_ptr pAsync4;
+{
+comphelper::ProfileZone aZone3("block 3");
+
+pAsync4 = comphelper::AsyncEvent::createWithParent("async 4", pAsync3);
+
+// Leaving this scope will generate an 'X' event for "block 3"
+}
+
+// This will generate an 'e' event for "async 2.5"
+pAsync25.reset();
+
+comphelper::ProfileZone aZone4("test().2");
+
+// This will generate an 'i' event
+comphelper::TraceEvent::addInstantEvent("instant 2");
+
+// Leaving this scope will generate 'X' events for "test().2" and a 'e' 
event for pAsync4 and pAsync3
+}

[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa

2020-05-04 Thread Noel Grandin (via logerrit)
 comphelper/CppunitTest_comphelper_test.mk |7 +++
 comphelper/qa/unit/test_hash.cxx  |   12 
 2 files changed, 19 insertions(+)

New commits:
commit 02323e893a2bd426ee8a07d25ac7d4a1e66d3be1
Author: Noel Grandin 
AuthorDate: Mon May 4 16:44:55 2020 +0200
Commit: Noel Grandin 
CommitDate: Mon May 4 20:13:12 2020 +0200

fix leak in comphelper::TestHash

by shutting down NSS at end of test

Change-Id: I63694e9bc54e8c142592005be353af7ed95d444d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93427
Tested-by: Jenkins
Reviewed-by: Noel Grandin 

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index 8bb335aa24dc..ef795f1664d1 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -27,4 +27,11 @@ $(eval $(call gb_CppunitTest_use_libraries,comphelper_test, \
 sal \
 ))
 
+ifeq ($(TLS),NSS)
+$(eval $(call gb_CppunitTest_use_externals,comphelper_test,\
+   plc4 \
+   nss3 \
+))
+endif
+
 # vim: set noet sw=4 ts=4:
diff --git a/comphelper/qa/unit/test_hash.cxx b/comphelper/qa/unit/test_hash.cxx
index 650cd6fc6976..99ce5bfd1751 100644
--- a/comphelper/qa/unit/test_hash.cxx
+++ b/comphelper/qa/unit/test_hash.cxx
@@ -7,6 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include 
+#include 
 #include 
 #include 
 
@@ -16,6 +18,10 @@
 #include 
 #include 
 
+#if USE_TLS_NSS
+#include 
+#endif
+
 class TestHash : public CppUnit::TestFixture
 {
 public:
@@ -26,6 +32,12 @@ public:
 void testSHA512_NoSaltNoSpin();
 void testSHA512_saltspin();
 
+virtual void tearDown()
+{
+#if USE_TLS_NSS
+NSS_Shutdown();
+#endif
+}
 CPPUNIT_TEST_SUITE(TestHash);
 CPPUNIT_TEST(testMD5);
 CPPUNIT_TEST(testSHA1);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa

2019-04-26 Thread Mike Kaganski (via logerrit)
 comphelper/CppunitTest_comphelper_test.mk |1 
 comphelper/qa/unit/test_guards.cxx|   57 ++
 2 files changed, 58 insertions(+)

New commits:
commit 6ec6d013227e66156e00c1d5ac9d0d2ddd208fae
Author: Mike Kaganski 
AuthorDate: Fri Apr 26 13:29:28 2019 +0300
Commit: Mike Kaganski 
CommitDate: Fri Apr 26 15:33:55 2019 +0200

Add a unit test for comphelper's guards

Change-Id: Ia9a9c5694d3982a87b720071b74220d572ef1a78
Reviewed-on: https://gerrit.libreoffice.org/71355
Tested-by: Jenkins
Reviewed-by: Mike Kaganski 

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index 20503e65bd06..8bb335aa24dc 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -15,6 +15,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/unit/test_hash \
 comphelper/qa/unit/base64_test \
 comphelper/qa/unit/types_test \
+comphelper/qa/unit/test_guards \
 ))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test))
diff --git a/comphelper/qa/unit/test_guards.cxx 
b/comphelper/qa/unit/test_guards.cxx
new file mode 100644
index ..39d8f80e0c68
--- /dev/null
+++ b/comphelper/qa/unit/test_guards.cxx
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+#include 
+#include 
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, test_comphelperGuards)
+{
+bool bFlag = true;
+{
+// Test that comphelper::ScopeGuard executes its parameter on 
destruction
+comphelper::ScopeGuard aGuard([] { bFlag = false; });
+CPPUNIT_ASSERT(bFlag);
+}
+CPPUNIT_ASSERT(!bFlag);
+
+{
+// Test that comphelper::FlagGuard properly sets and resets the flag
+comphelper::FlagGuard aGuard(bFlag);
+CPPUNIT_ASSERT(bFlag);
+}
+CPPUNIT_ASSERT(!bFlag);
+
+bFlag = true;
+{
+// Test that comphelper::FlagGuard properly sets and resets the flag
+comphelper::FlagGuard aGuard(bFlag);
+CPPUNIT_ASSERT(bFlag);
+}
+// comphelper::FlagGuard must reset flag to false on destruction 
unconditionally
+CPPUNIT_ASSERT(!bFlag);
+
+{
+// Test that comphelper::FlagRestorationGuard properly sets and resets 
the flag
+comphelper::FlagRestorationGuard aGuard(bFlag, true);
+CPPUNIT_ASSERT(bFlag);
+}
+CPPUNIT_ASSERT(!bFlag);
+
+bFlag = true;
+{
+// Test that comphelper::FlagRestorationGuard properly sets and resets 
the flag
+comphelper::FlagRestorationGuard aGuard(bFlag, false);
+CPPUNIT_ASSERT(!bFlag);
+}
+// comphelper::FlagGuard must reset flag to initial state on destruction
+CPPUNIT_ASSERT(bFlag);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa comphelper/source

2019-04-26 Thread Jens Carl (via logerrit)
 comphelper/CppunitTest_comphelper_test.mk |1 
 comphelper/qa/unit/types_test.cxx |   97 ++
 comphelper/source/misc/types.cxx  |   19 -
 3 files changed, 111 insertions(+), 6 deletions(-)

New commits:
commit 516983b7798a3ecc4d9e443ef5d8e573e01f5e53
Author: Jens Carl 
AuthorDate: Wed Apr 24 10:52:00 2019 -0700
Commit: Stephan Bergmann 
CommitDate: Fri Apr 26 09:48:18 2019 +0200

tdf#43157 Clean up OSL_VERIFY (replace with SAL_WARN)

Replace OSL_VERIFY with SAL_WARN_IF and add some unit tests to ensure
the replacements don't some side effects.

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

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index 956aeb374a63..20503e65bd06 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -14,6 +14,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/container/testifcontainer \
 comphelper/qa/unit/test_hash \
 comphelper/qa/unit/base64_test \
+comphelper/qa/unit/types_test \
 ))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test))
diff --git a/comphelper/qa/unit/types_test.cxx 
b/comphelper/qa/unit/types_test.cxx
new file mode 100644
index ..89ad6cae870f
--- /dev/null
+++ b/comphelper/qa/unit/types_test.cxx
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+using namespace css;
+
+namespace
+{
+class TypesTest : public CppUnit::TestFixture
+{
+public:
+void testGetINT64();
+void testGetINT32();
+void testGetINT16();
+void testGetDouble();
+void testGetFloat();
+void testGetString();
+
+CPPUNIT_TEST_SUITE(TypesTest);
+
+CPPUNIT_TEST(testGetINT64);
+CPPUNIT_TEST(testGetINT32);
+CPPUNIT_TEST(testGetINT16);
+CPPUNIT_TEST(testGetDouble);
+CPPUNIT_TEST(testGetFloat);
+CPPUNIT_TEST(testGetString);
+
+CPPUNIT_TEST_SUITE_END();
+};
+
+void TypesTest::testGetINT64()
+{
+CPPUNIT_ASSERT_EQUAL(sal_Int64(1337), 
::comphelper::getINT64(uno::makeAny(sal_Int64(1337;
+
+uno::Any aValue;
+CPPUNIT_ASSERT_EQUAL(sal_Int64(0), ::comphelper::getINT64(aValue));
+}
+
+void TypesTest::testGetINT32()
+{
+CPPUNIT_ASSERT_EQUAL(sal_Int32(1337), 
::comphelper::getINT32(uno::makeAny(sal_Int32(1337;
+
+uno::Any aValue;
+CPPUNIT_ASSERT_EQUAL(sal_Int32(0), ::comphelper::getINT32(aValue));
+}
+
+void TypesTest::testGetINT16()
+{
+CPPUNIT_ASSERT_EQUAL(sal_Int16(1337), 
::comphelper::getINT16(uno::makeAny(sal_Int16(1337;
+
+uno::Any aValue;
+CPPUNIT_ASSERT_EQUAL(sal_Int16(0), ::comphelper::getINT16(aValue));
+}
+
+void TypesTest::testGetDouble()
+{
+CPPUNIT_ASSERT_EQUAL(1337.1337, 
::comphelper::getDouble(uno::makeAny(1337.1337)));
+
+uno::Any aValue;
+CPPUNIT_ASSERT_EQUAL(0.0, ::comphelper::getDouble(aValue));
+}
+
+void TypesTest::testGetFloat()
+{
+CPPUNIT_ASSERT_EQUAL(static_cast(1337.0),
+ 
::comphelper::getFloat(uno::makeAny(static_cast(1337.0;
+
+uno::Any aValue;
+CPPUNIT_ASSERT_EQUAL(static_cast(0.0), 
::comphelper::getFloat(aValue));
+}
+
+void TypesTest::testGetString()
+{
+CPPUNIT_ASSERT_EQUAL(OUString("1337"), 
::comphelper::getString(uno::makeAny(OUString("1337";
+
+uno::Any aValue;
+CPPUNIT_ASSERT_EQUAL(OUString(""), ::comphelper::getString(aValue));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TypesTest);
+
+} // namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/comphelper/source/misc/types.cxx b/comphelper/source/misc/types.cxx
index eb5eec0b5343..291c590ba488 100644
--- a/comphelper/source/misc/types.cxx
+++ b/comphelper/source/misc/types.cxx
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 namespace comphelper
@@ -38,7 +39,8 @@ using namespace ::com::sun::star::lang;
 sal_Int64 getINT64(const Any& _rAny)
 {
 sal_Int64 nReturn = 0;
-OSL_VERIFY( _rAny >>= nReturn );
+if(!(_rAny >>= nReturn))
+SAL_WARN("comphelper", "conversion from Any to sal_Int64 failed");
 return nReturn;
 }
 
@@ -46,7 +48,8 @@ sal_Int64 getINT64(const Any& _rAny)
 sal_Int32 getINT32(const Any& _rAny)
 {
 sal_Int32 nReturn = 0;
-OSL_VERIFY( _rAny >>= nReturn );
+if(!(_rAny >>= nReturn))
+SAL_WARN("comphelper", "conversion from Any to sal_Int32 failed");
 

[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa filter/source include/sax oox/source package/source sax/qa sax/source sc/source sd/source sfx2/source solenv/cla

2018-03-05 Thread Noel Grandin
 comphelper/CppunitTest_comphelper_test.mk  |1 
 comphelper/qa/unit/base64_test.cxx |  106 +
 filter/source/svg/svgwriter.cxx|3 
 filter/source/xsltfilter/OleHandler.cxx|9 -
 include/sax/tools/converter.hxx|   12 -
 oox/source/crypto/DocumentDecryption.cxx   |   11 -
 package/source/manifest/ManifestExport.cxx |   13 -
 package/source/manifest/ManifestImport.cxx |   13 -
 sax/qa/cppunit/test_converter.cxx  |   42 -
 sax/source/tools/converter.cxx |   18 --
 sc/source/filter/xml/XMLTrackedChangesContext.cxx  |3 
 sc/source/filter/xml/xmlbodyi.cxx  |3 
 sc/source/filter/xml/xmlexprt.cxx  |   11 -
 sc/source/filter/xml/xmlimprt.cxx  |3 
 sc/source/filter/xml/xmlsubti.cxx  |3 
 sd/source/ui/remotecontrol/ImagePreparer.cxx   |3 
 sfx2/source/appl/sfxpicklist.cxx   |3 
 sfx2/source/control/recentdocsview.cxx |3 
 solenv/clang-format/blacklist  |1 
 svgio/Library_svgio.mk |1 
 svgio/source/svgreader/svgimagenode.cxx|3 
 svx/source/xoutdev/_xoutbmp.cxx|5 
 tools/Library_tl.mk|1 
 tools/source/fsys/urlobj.cxx   |3 
 xmloff/source/core/DocumentSettingsContext.cxx |3 
 xmloff/source/core/SettingsExportHelper.cxx|3 
 xmloff/source/core/XMLBase64Export.cxx |3 
 xmloff/source/core/XMLBase64ImportContext.cxx  |3 
 xmloff/source/text/XMLSectionExport.cxx|3 
 xmloff/source/text/XMLSectionImportContext.cxx |3 
 xmloff/source/text/XMLTextFrameContext.cxx |3 
 xmloff/source/transform/OOo2Oasis.cxx  |3 
 xmloff/source/transform/Oasis2OOo.cxx  |5 
 xmlsecurity/source/component/documentdigitalsignatures.cxx |3 
 xmlsecurity/source/helper/documentsignaturemanager.cxx |   11 -
 35 files changed, 190 insertions(+), 127 deletions(-)

New commits:
commit ddd43218e9900536381733735adf8681d345e775
Author: Noel Grandin 
Date:   Mon Mar 5 12:19:05 2018 +0200

drop sax::tools::*base64 methods

and use the underlying comphelper methods rather. This is so that I can
break the dependency that tools has on sax, and can add methods that
make sax depend on tools.

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

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index 00dc27e5e7b1..956aeb374a63 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -13,6 +13,7 @@ $(eval $(call 
gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/string/test_string \
 comphelper/qa/container/testifcontainer \
 comphelper/qa/unit/test_hash \
+comphelper/qa/unit/base64_test \
 ))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test))
diff --git a/comphelper/qa/unit/base64_test.cxx 
b/comphelper/qa/unit/base64_test.cxx
new file mode 100644
index ..b3f2143d4a41
--- /dev/null
+++ b/comphelper/qa/unit/base64_test.cxx
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::util;
+
+
+namespace 

[Libreoffice-commits] core.git: comphelper/CppunitTest_comphelper_test.mk comphelper/qa

2017-04-21 Thread Markus Mohrhard
 comphelper/CppunitTest_comphelper_test.mk |1 
 comphelper/qa/unit/test_hash.cxx  |   80 ++
 2 files changed, 81 insertions(+)

New commits:
commit 512ba28e297ec74fe280308c0a091c7c308a5e55
Author: Markus Mohrhard 
Date:   Fri Apr 21 05:39:07 2017 +0200

add test for generic digest class

Change-Id: Ibe3f033ebec5f832eee7420013c7083ab224e65e
Reviewed-on: https://gerrit.libreoffice.org/36791
Reviewed-by: Markus Mohrhard 
Tested-by: Markus Mohrhard 

diff --git a/comphelper/CppunitTest_comphelper_test.mk 
b/comphelper/CppunitTest_comphelper_test.mk
index 1d16366d6bc6..00dc27e5e7b1 100644
--- a/comphelper/CppunitTest_comphelper_test.mk
+++ b/comphelper/CppunitTest_comphelper_test.mk
@@ -12,6 +12,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,comphelper_test))
 $(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \
 comphelper/qa/string/test_string \
 comphelper/qa/container/testifcontainer \
+comphelper/qa/unit/test_hash \
 ))
 
 $(eval $(call gb_CppunitTest_use_sdk_api,comphelper_test))
diff --git a/comphelper/qa/unit/test_hash.cxx b/comphelper/qa/unit/test_hash.cxx
new file mode 100644
index ..d31d1764
--- /dev/null
+++ b/comphelper/qa/unit/test_hash.cxx
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include 
+
+#include 
+#include 
+
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+
+class TestHash : public CppUnit::TestFixture
+{
+public:
+void testSHA1();
+void testSHA256();
+void testSHA512();
+
+CPPUNIT_TEST_SUITE(TestHash);
+CPPUNIT_TEST(testSHA1);
+CPPUNIT_TEST(testSHA256);
+CPPUNIT_TEST(testSHA512);
+CPPUNIT_TEST_SUITE_END();
+};
+
+namespace {
+
+std::string tostring(const std::vector& a)
+{
+std::stringstream aStrm;
+for (auto& i:a)
+{
+aStrm << std::setw(2) << std::setfill('0') << std::hex << (int)i;
+}
+
+return aStrm.str();
+}
+
+}
+
+void TestHash::testSHA1()
+{
+comphelper::Hash aHash(comphelper::HashType::SHA1);
+const char* const pInput = "";
+aHash.update(reinterpret_cast(pInput), 0);
+std::vector calculate_hash = aHash.finalize();
+CPPUNIT_ASSERT_EQUAL(size_t(20), calculate_hash.size());
+
CPPUNIT_ASSERT_EQUAL(std::string("da39a3ee5e6b4b0d3255bfef95601890afd80709"), 
tostring(calculate_hash));
+}
+
+void TestHash::testSHA256()
+{
+comphelper::Hash aHash(comphelper::HashType::SHA256);
+const char* const pInput = "";
+aHash.update(reinterpret_cast(pInput), 0);
+std::vector calculate_hash = aHash.finalize();
+CPPUNIT_ASSERT_EQUAL(size_t(32), calculate_hash.size());
+
CPPUNIT_ASSERT_EQUAL(std::string("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"),
 tostring(calculate_hash));
+}
+
+void TestHash::testSHA512()
+{
+comphelper::Hash aHash(comphelper::HashType::SHA512);
+const char* const pInput = "";
+aHash.update(reinterpret_cast(pInput), 0);
+std::vector calculate_hash = aHash.finalize();
+CPPUNIT_ASSERT_EQUAL(size_t(64), calculate_hash.size());
+std::string 
aStr("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e");
+CPPUNIT_ASSERT_EQUAL(aStr, tostring(calculate_hash));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestHash);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits