summaryrefslogtreecommitdiff
path: root/vcl/qa/cppunit/physicalfontcollection.cxx
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2021-09-14 00:17:06 +1000
committerMike Kaganski <mike.kaganski@collabora.com>2021-10-08 19:22:59 +0200
commit3f5fb07565d0e08773ddfcda4d5acbb1446aa2f2 (patch)
treec0830ab69aac8f1424e6788448bb68690883ab9e /vcl/qa/cppunit/physicalfontcollection.cxx
parent677434a572b8f07a386937b2f7edf2e9b801bbd0 (diff)
vcl: test PhysicalFontCollection and move to vcl::font namespace
- tested PhysicalFontCollection, noted odd behaviour with search names and normalization - moved PhysicalFontCollection.hxx to vcl/inc/font - moved PhysicalFontCollection into vcl::font namespace Note that I needed to regenerate the pch file otherwise errors were generated. Change-Id: Ifa0c7b871c40687bd15002565d2f7a3e408218f8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122036 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/qa/cppunit/physicalfontcollection.cxx')
-rw-r--r--vcl/qa/cppunit/physicalfontcollection.cxx118
1 files changed, 118 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/physicalfontcollection.cxx b/vcl/qa/cppunit/physicalfontcollection.cxx
new file mode 100644
index 000000000000..ea76fde542e8
--- /dev/null
+++ b/vcl/qa/cppunit/physicalfontcollection.cxx
@@ -0,0 +1,118 @@
+/* -*- 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 <sal/config.h>
+
+#include <test/bootstrapfixture.hxx>
+#include <cppunit/TestAssert.h>
+
+#include <font/PhysicalFontCollection.hxx>
+#include <font/PhysicalFontFamily.hxx>
+
+#include "fontmocks.hxx"
+
+#include <memory>
+
+class VclPhysicalFontCollectionTest : public test::BootstrapFixture
+{
+public:
+ VclPhysicalFontCollectionTest()
+ : BootstrapFixture(true, false)
+ {
+ }
+
+ void testShouldCreateAndAddFontFamilyToCollection();
+ void testShouldFindFontFamily();
+ void testShouldNotFindFontFamily();
+ void testShouldFindFontFamilyByTokenNames();
+ void testShouldFindNoFamilyWithWorthlessAttributes();
+
+ CPPUNIT_TEST_SUITE(VclPhysicalFontCollectionTest);
+ CPPUNIT_TEST(testShouldCreateAndAddFontFamilyToCollection);
+ CPPUNIT_TEST(testShouldFindFontFamily);
+ CPPUNIT_TEST(testShouldNotFindFontFamily);
+ CPPUNIT_TEST(testShouldFindFontFamilyByTokenNames);
+ CPPUNIT_TEST(testShouldFindNoFamilyWithWorthlessAttributes);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void VclPhysicalFontCollectionTest::testShouldCreateAndAddFontFamilyToCollection()
+{
+ vcl::font::PhysicalFontCollection aFontCollection;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Empty font collection", static_cast<int>(0),
+ aFontCollection.Count());
+
+ // please note that fonts created this way are NOT normalized and will not be found if you search for them in the collection
+ vcl::font::PhysicalFontFamily* pFontFamily
+ = aFontCollection.FindOrCreateFontFamily("Test Font Family Name");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("One font family in collection", static_cast<int>(1),
+ aFontCollection.Count());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name correct", OUString("Test Font Family Name"),
+ pFontFamily->GetSearchName());
+
+ vcl::font::PhysicalFontFamily* pFontFamily2
+ = aFontCollection.FindOrCreateFontFamily("Test Font Family Name");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Still only one font family in collection", static_cast<int>(1),
+ aFontCollection.Count());
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name correct", OUString("Test Font Family Name"),
+ pFontFamily2->GetSearchName());
+}
+
+void VclPhysicalFontCollectionTest::testShouldFindFontFamily()
+{
+ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
+ vcl::font::PhysicalFontCollection aFontCollection;
+ aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName("Test Font Family Name"));
+
+ vcl::font::PhysicalFontFamily* pFontFamily
+ = aFontCollection.FindFontFamily("Test Font Family Name");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name correct",
+ GetEnglishSearchFontName("Test Font Family Name"),
+ pFontFamily->GetSearchName());
+}
+
+void VclPhysicalFontCollectionTest::testShouldNotFindFontFamily()
+{
+ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
+ vcl::font::PhysicalFontCollection aFontCollection;
+ aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName("Test Font Family Name"));
+
+ CPPUNIT_ASSERT(!aFontCollection.FindFontFamily("blah"));
+}
+
+void VclPhysicalFontCollectionTest::testShouldFindFontFamilyByTokenNames()
+{
+ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
+ vcl::font::PhysicalFontCollection aFontCollection;
+ aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName("Test Font Family Name"));
+
+ OUString sTokenNames(GetEnglishSearchFontName("Test Font Family Name;"));
+ sTokenNames += GetEnglishSearchFontName("Test 2");
+
+ vcl::font::PhysicalFontFamily* pFontFamily
+ = aFontCollection.FindFontFamilyByTokenNames("Test Font Family Name");
+ CPPUNIT_ASSERT_MESSAGE("Found the font family", pFontFamily);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("Font family name correct",
+ GetEnglishSearchFontName("Test Font Family Name"),
+ pFontFamily->GetSearchName());
+}
+
+void VclPhysicalFontCollectionTest::testShouldFindNoFamilyWithWorthlessAttributes()
+{
+ // note: you must normalize the search family name (first parameter of PhysicalFontFamily constructor)
+ vcl::font::PhysicalFontCollection aFontCollection;
+ aFontCollection.FindOrCreateFontFamily(GetEnglishSearchFontName("Test Font Family Name"));
+
+ CPPUNIT_ASSERT(!aFontCollection.FindFontFamilyByAttributes(ImplFontAttrs::None, WEIGHT_NORMAL,
+ WIDTH_NORMAL, ITALIC_NONE, ""));
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(VclPhysicalFontCollectionTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */