Title: [204558] trunk
Revision
204558
Author
[email protected]
Date
2016-08-17 07:39:23 -0700 (Wed, 17 Aug 2016)

Log Message

[Win] Add tests for linked fonts.
https://bugs.webkit.org/show_bug.cgi?id=160898

Reviewed by Brent Fulgham.

Add tests for https://trac.webkit.org/changeset/204502.

Source/WebCore:

* platform/graphics/win/FontCacheWin.cpp:
(WebCore::appendLinkedFonts):
(WebCore::getLinkedFonts):

Tools:

* TestWebKitAPI/PlatformWin.cmake:
* TestWebKitAPI/Tests/WebCore/win/LinkedFonts.cpp: Added.
(TestWebKitAPI::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (204557 => 204558)


--- trunk/Source/WebCore/ChangeLog	2016-08-17 11:12:46 UTC (rev 204557)
+++ trunk/Source/WebCore/ChangeLog	2016-08-17 14:39:23 UTC (rev 204558)
@@ -1,3 +1,16 @@
+2016-08-17  Per Arne Vollan  <[email protected]>
+
+        [Win] Add tests for linked fonts.
+        https://bugs.webkit.org/show_bug.cgi?id=160898
+
+        Reviewed by Brent Fulgham.
+
+        Add tests for https://trac.webkit.org/changeset/204502.
+
+        * platform/graphics/win/FontCacheWin.cpp:
+        (WebCore::appendLinkedFonts):
+        (WebCore::getLinkedFonts):
+
 2016-08-17  Carlos Garcia Campos  <[email protected]>
 
         Unreviewed. Fix GObject DOM bindings API break after r204449, r204450 and r204451.

Modified: trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp (204557 => 204558)


--- trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2016-08-17 11:12:46 UTC (rev 204557)
+++ trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2016-08-17 14:39:23 UTC (rev 204558)
@@ -96,6 +96,24 @@
     return false;
 }
 
+WEBCORE_EXPORT void appendLinkedFonts(WCHAR* linkedFonts, unsigned length, Vector<String>* result)
+{
+    unsigned i = 0;
+    while (i < length) {
+        while (i < length && linkedFonts[i] != ',')
+            i++;
+        // Break if we did not find a comma.
+        if (i == length)
+            break;
+        i++;
+        unsigned j = i;
+        while (j < length && linkedFonts[j])
+            j++;
+        result->append(String(linkedFonts + i, j - i));
+        i = j + 1;
+    }
+}
+
 static const Vector<String>* getLinkedFonts(String& family)
 {
     static HashMap<String, Vector<String>*> systemLinkMap;
@@ -106,7 +124,7 @@
     result = new Vector<String>;
     systemLinkMap.set(family, result);
     HKEY fontLinkKey = nullptr;
-    if (FAILED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\FontLink\\SystemLink", 0, KEY_READ, &fontLinkKey)))
+    if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\FontLink\\SystemLink", 0, KEY_READ, &fontLinkKey) != ERROR_SUCCESS)
         return result;
 
     DWORD linkedFontsBufferSize = 0;
@@ -117,21 +135,8 @@
 
     WCHAR* linkedFonts = reinterpret_cast<WCHAR*>(malloc(linkedFontsBufferSize));
     if (::RegQueryValueEx(fontLinkKey, family.charactersWithNullTermination().data(), 0, nullptr, reinterpret_cast<BYTE*>(linkedFonts), &linkedFontsBufferSize) == ERROR_SUCCESS) {
-        unsigned i = 0;
         unsigned length = linkedFontsBufferSize / sizeof(*linkedFonts);
-        while (i < length) {
-            while (i < length && linkedFonts[i] != ',')
-                i++;
-            // Break if we did not find a comma.
-            if (i == length)
-                break;
-            i++;
-            unsigned j = i;
-            while (j < length && linkedFonts[j])
-                j++;
-            result->append(String(linkedFonts + i, j - i));
-            i = j + 1;
-        }
+        appendLinkedFonts(linkedFonts, length, result);
     }
     free(linkedFonts);
     RegCloseKey(fontLinkKey);

Modified: trunk/Tools/ChangeLog (204557 => 204558)


--- trunk/Tools/ChangeLog	2016-08-17 11:12:46 UTC (rev 204557)
+++ trunk/Tools/ChangeLog	2016-08-17 14:39:23 UTC (rev 204558)
@@ -1,3 +1,16 @@
+2016-08-17  Per Arne Vollan  <[email protected]>
+
+        [Win] Add tests for linked fonts.
+        https://bugs.webkit.org/show_bug.cgi?id=160898
+
+        Reviewed by Brent Fulgham.
+
+        Add tests for https://trac.webkit.org/changeset/204502.
+
+        * TestWebKitAPI/PlatformWin.cmake:
+        * TestWebKitAPI/Tests/WebCore/win/LinkedFonts.cpp: Added.
+        (TestWebKitAPI::TEST):
+
 2016-08-16  Daniel Bates  <[email protected]>
 
         prepare-ChangeLog: Extract logic from generateFunctionLists() into a function that takes a delegate object

Modified: trunk/Tools/TestWebKitAPI/PlatformWin.cmake (204557 => 204558)


--- trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2016-08-17 11:12:46 UTC (rev 204557)
+++ trunk/Tools/TestWebKitAPI/PlatformWin.cmake	2016-08-17 14:39:23 UTC (rev 204558)
@@ -50,6 +50,7 @@
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/URL.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/URLParser.cpp
     ${TESTWEBKITAPI_DIR}/Tests/WebCore/win/DIBPixelData.cpp
+    ${TESTWEBKITAPI_DIR}/Tests/WebCore/win/LinkedFonts.cpp
 )
 
 if (${WTF_PLATFORM_WIN_CAIRO})

Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/win/LinkedFonts.cpp (0 => 204558)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/win/LinkedFonts.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/win/LinkedFonts.cpp	2016-08-17 14:39:23 UTC (rev 204558)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <WebCore/FontCache.h>
+
+using namespace WebCore;
+
+namespace WebCore {
+void appendLinkedFonts(WCHAR* linkedFonts, unsigned length, Vector<String>* result);
+}
+
+namespace TestWebKitAPI {
+
+// Test the appendLinkedFonts function with normal input data (string with pairs of font filenames and font names separated with \0).
+TEST(WebCore, appendLinkedFontsTest)
+{
+    Vector<String> result;
+    WCHAR linkedFonts[] = L"MICROSS.TTF,Microsoft Sans Serif,128,140\0MICROSS.TTF,Microsoft Sans Serif\0MSGOTHIC.TTC,MS UI Gothic\0MINGLIU.TTC,PMingLiU\0SIMSUN.TTC,SimSun";
+
+    appendLinkedFonts(linkedFonts,  sizeof(linkedFonts) / sizeof(WCHAR), &result);
+    ASSERT(result.size() == 5);
+    ASSERT(result[0] == String(L"Microsoft Sans Serif,128,140"));
+    ASSERT(result[1] == String(L"Microsoft Sans Serif"));
+    ASSERT(result[2] == String(L"MS UI Gothic"));
+    ASSERT(result[3] == String(L"PMingLiU"));
+    ASSERT(result[4] == String(L"SimSun"));
+}
+
+// Test the appendLinkedFonts function when the input data does not contain the expected comma separator.
+TEST(WebCore, appendLinkedFontsWithMissingCommaTest)
+{
+    Vector<String> result;
+    WCHAR linkedFonts[] = L"MICROSS.TTF Microsoft Sans Serif";
+
+    appendLinkedFonts(linkedFonts, sizeof(linkedFonts) / sizeof(WCHAR), &result);
+    ASSERT(!result.size());
+}
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to