From 5ff8f80a27b08ed6b3c12e354080c6ea1b90b6ee Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 19 Aug 2015 15:25:30 +0200 Subject: [PATCH] Demonstrate comphelper::compare is useless Change-Id: I03de2d02f4814bf3425f7278ec91ed1e3b4ce1a0 --- comphelper/CppunitTest_comphelper_test.mk | 3 + comphelper/qa/test_any.cxx | 94 +++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 comphelper/qa/test_any.cxx diff --git a/comphelper/CppunitTest_comphelper_test.mk b/comphelper/CppunitTest_comphelper_test.mk index 89e071044ed7..b87ab7b11a34 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/test_any \ )) $(eval $(call gb_CppunitTest_use_api,comphelper_test, \ @@ -26,4 +27,6 @@ $(eval $(call gb_CppunitTest_use_libraries,comphelper_test, \ $(gb_UWINAPI) \ )) +$(eval $(call gb_CppunitTest_use_ure,comphelper_test)) + # vim: set noet sw=4 ts=4: diff --git a/comphelper/qa/test_any.cxx b/comphelper/qa/test_any.cxx new file mode 100644 index 000000000000..9262f672d2eb --- /dev/null +++ b/comphelper/qa/test_any.cxx @@ -0,0 +1,94 @@ +/* -*- 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 +#include +#include +#include +#include +#include + +// Demonstrate that comphelper::compare works exactly the same as +// css::uno::Any::operator ==: + +namespace { + +class Test: public CppUnit::TestFixture { +public: + void test(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void Test::test() { + css::uno::Any a1, a2; + + a1 = css::uno::makeAny(5); + a2 = css::uno::makeAny(5); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny(5); + a2 = css::uno::makeAny(6); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny({ + "A", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0, + false, true, 11}); + a2 = css::uno::makeAny({ + "A", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0, + false, true, 11}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny({ + "A", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0, + false, true, 11}); + a2 = css::uno::makeAny({ + "a", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0, + false, true, 11}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny({1, 2, 2003}); + a2 = css::uno::makeAny({1, 2, 2003}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny({1, 2, 2003}); + a2 = css::uno::makeAny({1, 3, 2003}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny({1, 2, 2003}); + a2 = css::uno::makeAny({ + 0, 0, 0, 0, 1, 2, 2003, false}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny>({0, 1, 2}); + a2 = css::uno::makeAny>({0, 1, 2}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny>({0, 1, 2}); + a2 = css::uno::makeAny>({0, 1, 3}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); + + a1 = css::uno::makeAny>({0, 1, 2}); + a2 = css::uno::makeAny>({0, 1}); + CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(Test); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */