From 878c4a2586e5ade2a4d0ce848c7b614985f1628c Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 8 May 2017 12:40:16 -0700 Subject: [PATCH] Build txt_unittests Many of these fail because they assume they're being executed on Android, but at least they build. Change-Id: I5d86e3d2632a0d6fa4219d3f5182f2683c9dd314 --- engine/src/flutter/BUILD.gn | 3 + engine/src/flutter/libs/minikin/BUILD.gn | 2 +- engine/src/flutter/shims/BUILD.gn | 1 + .../src/flutter/shims/utils/JenkinsHash.cpp | 73 +++++++++++++++++++ engine/src/flutter/tests/unittest/BUILD.gn | 39 ++++++++++ .../unittest/FontCollectionItemizeTest.cpp | 6 +- .../tests/unittest/FontCollectionTest.cpp | 2 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 4 +- .../unittest/FontLanguageListCacheTest.cpp | 4 +- .../tests/unittest/HbFontCacheTest.cpp | 4 +- .../tests/unittest/LayoutUtilsTest.cpp | 2 +- engine/src/flutter/tests/util/BUILD.gn | 40 ++++++++++ engine/src/flutter/tests/util/FileUtils.cpp | 2 +- .../src/flutter/tests/util/FontTestUtils.cpp | 2 +- .../src/flutter/tests/util/UnicodeUtils.cpp | 2 +- 15 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 engine/src/flutter/shims/utils/JenkinsHash.cpp create mode 100644 engine/src/flutter/tests/unittest/BUILD.gn create mode 100644 engine/src/flutter/tests/util/BUILD.gn diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 8a8166708b..c496555dc0 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -3,7 +3,10 @@ # found in the LICENSE file. group("txt") { + testonly = true + deps = [ "libs/minikin", + "tests/unittest($host_toolchain)", ] } diff --git a/engine/src/flutter/libs/minikin/BUILD.gn b/engine/src/flutter/libs/minikin/BUILD.gn index d4104e38a5..5ce005f45a 100644 --- a/engine/src/flutter/libs/minikin/BUILD.gn +++ b/engine/src/flutter/libs/minikin/BUILD.gn @@ -47,6 +47,7 @@ static_library("minikin") { public_configs = [ ":minikin_config" ] public_deps = [ + "//lib/txt/shims", "//third_party/freetype2", "//third_party/harfbuzz", "//third_party/icu:icuuc", @@ -54,6 +55,5 @@ static_library("minikin") { deps = [ "//third_party/zlib", - "//lib/txt/shims", ] } diff --git a/engine/src/flutter/shims/BUILD.gn b/engine/src/flutter/shims/BUILD.gn index a09a56ab33..7e1e1f7e0c 100644 --- a/engine/src/flutter/shims/BUILD.gn +++ b/engine/src/flutter/shims/BUILD.gn @@ -20,6 +20,7 @@ source_set("shims") { sources = [ "log/log.h", "log/log.cc", + "utils/JenkinsHash.cpp", "utils/JenkinsHash.h", "utils/LruCache.h", "utils/TypeHelpers.h", diff --git a/engine/src/flutter/shims/utils/JenkinsHash.cpp b/engine/src/flutter/shims/utils/JenkinsHash.cpp new file mode 100644 index 0000000000..76b04883b1 --- /dev/null +++ b/engine/src/flutter/shims/utils/JenkinsHash.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* Implementation of Jenkins one-at-a-time hash function. These choices are + * optimized for code size and portability, rather than raw speed. But speed + * should still be quite good. + **/ + +#include +#include + +namespace android { + +#ifdef __clang__ +__attribute__((no_sanitize("integer"))) +#endif +hash_t JenkinsHashWhiten(uint32_t hash) { + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + return hash; +} + +uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t* bytes, size_t size) { + if (size > UINT32_MAX) { + abort(); + } + hash = JenkinsHashMix(hash, (uint32_t)size); + size_t i; + for (i = 0; i < (size & -4); i += 4) { + uint32_t data = bytes[i] | (bytes[i+1] << 8) | (bytes[i+2] << 16) | (bytes[i+3] << 24); + hash = JenkinsHashMix(hash, data); + } + if (size & 3) { + uint32_t data = bytes[i]; + data |= ((size & 3) > 1) ? (bytes[i+1] << 8) : 0; + data |= ((size & 3) > 2) ? (bytes[i+2] << 16) : 0; + hash = JenkinsHashMix(hash, data); + } + return hash; +} + +uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t* shorts, size_t size) { + if (size > UINT32_MAX) { + abort(); + } + hash = JenkinsHashMix(hash, (uint32_t)size); + size_t i; + for (i = 0; i < (size & -2); i += 2) { + uint32_t data = shorts[i] | (shorts[i+1] << 16); + hash = JenkinsHashMix(hash, data); + } + if (size & 1) { + uint32_t data = shorts[i]; + hash = JenkinsHashMix(hash, data); + } + return hash; +} + +} diff --git a/engine/src/flutter/tests/unittest/BUILD.gn b/engine/src/flutter/tests/unittest/BUILD.gn new file mode 100644 index 0000000000..851f36379c --- /dev/null +++ b/engine/src/flutter/tests/unittest/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +executable("unittest") { + output_name = "txt_unittests" + + testonly = true + + sources = [ + "CmapCoverageTest.cpp", + "EmojiTest.cpp", + "FontCollectionItemizeTest.cpp", + "FontCollectionTest.cpp", + "FontFamilyTest.cpp", + "FontLanguageListCacheTest.cpp", + "GraphemeBreakTests.cpp", + "HbFontCacheTest.cpp", + "HyphenatorTest.cpp", + "ICUTestBase.h", + "LayoutTest.cpp", + "LayoutUtilsTest.cpp", + "MeasurementTests.cpp", + "SparseBitSetTest.cpp", + "UnicodeUtilsTest.cpp", + "WordBreakerTests.cpp", + "//lib/ftl/test/run_all_unittests.cc", + ] + + defines = [ + "kTestFontDir=\"/data/nativetest/minikin_tests/data/\"", + ] + + deps = [ + "//lib/txt/tests/util", + "//lib/txt/libs/minikin", + "//third_party/gtest", + ] +} diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 974a202e51..6715227818 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -18,12 +18,12 @@ #include -#include "FontLanguageListCache.h" -#include "FontLanguage.h" +#include "lib/txt/libs/minikin/FontLanguageListCache.h" +#include "lib/txt/libs/minikin/FontLanguage.h" #include "FontTestUtils.h" #include "ICUTestBase.h" #include "MinikinFontForTest.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" #include "UnicodeUtils.h" #include "minikin/FontFamily.h" diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index bef1c63088..9480079dac 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -19,7 +19,7 @@ #include #include "FontTestUtils.h" #include "MinikinFontForTest.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" namespace minikin { diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 072d3bf87b..21810d78d3 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -19,10 +19,10 @@ #include #include -#include "FontLanguageListCache.h" +#include "lib/txt/libs/minikin/FontLanguageListCache.h" #include "ICUTestBase.h" #include "MinikinFontForTest.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" namespace minikin { diff --git a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp index 27bdc09e06..69b9314340 100644 --- a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp @@ -18,9 +18,9 @@ #include -#include "FontLanguageListCache.h" +#include "lib/txt/libs/minikin/FontLanguageListCache.h" #include "ICUTestBase.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" namespace minikin { diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index 5816a3250c..5b306aa2ba 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "HbFontCache.h" +#include "lib/txt/libs/minikin/HbFontCache.h" #include #include @@ -24,7 +24,7 @@ #include -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" #include "MinikinFontForTest.h" #include diff --git a/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp b/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp index e7e6c273d6..8aa3a21ef9 100644 --- a/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp +++ b/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp @@ -17,7 +17,7 @@ #include #include -#include "LayoutUtils.h" +#include "lib/txt/libs/minikin/LayoutUtils.h" namespace minikin { diff --git a/engine/src/flutter/tests/util/BUILD.gn b/engine/src/flutter/tests/util/BUILD.gn new file mode 100644 index 0000000000..d8906e969d --- /dev/null +++ b/engine/src/flutter/tests/util/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright 2017 Google Inc. +# +# Licensed 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 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +config("util_config") { + include_dirs = [ "." ] +} + +source_set("util") { + sources = [ + "FileUtils.cpp", + "FileUtils.h", + "FontTestUtils.cpp", + "FontTestUtils.h", + "MinikinFontForTest.cpp", + "MinikinFontForTest.h", + "UnicodeUtils.cpp", + "UnicodeUtils.h", + ] + + public_configs = [ ":util_config" ] + + public_deps = [ + "//lib/txt/libs/minikin", + ] + + deps = [ + "//third_party/libxml2", + ] +} diff --git a/engine/src/flutter/tests/util/FileUtils.cpp b/engine/src/flutter/tests/util/FileUtils.cpp index 68cc45cf4d..92cf9191bc 100644 --- a/engine/src/flutter/tests/util/FileUtils.cpp +++ b/engine/src/flutter/tests/util/FileUtils.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 13360d4aa2..e754a5f615 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -21,7 +21,7 @@ #include -#include "FontLanguage.h" +#include "lib/txt/libs/minikin/FontLanguage.h" #include "MinikinFontForTest.h" #include #include diff --git a/engine/src/flutter/tests/util/UnicodeUtils.cpp b/engine/src/flutter/tests/util/UnicodeUtils.cpp index e66ff93489..a6595cee7b 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.cpp +++ b/engine/src/flutter/tests/util/UnicodeUtils.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include