From 02345a5e8f47faeed80e62730874194575a0dc46 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 6 Jan 2016 22:49:33 +0900 Subject: [PATCH] Fix lock assertion failures in unit test. The assertion for the lock state has now activated by I9c4b1e1f09c6793e387fbdb8bb654cc0a13c65d5. This CL fixes the assertion failure in the unit tests by acquiring lock before calling the functions. Change-Id: I6a6afefb4de01e8610c2abfe6c779afa9442cc67 --- engine/src/flutter/tests/FontCollectionItemizeTest.cpp | 4 ++++ engine/src/flutter/tests/FontFamilyTest.cpp | 2 ++ engine/src/flutter/tests/FontLanguageListCacheTest.cpp | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index cf9b704efa..57409a5e62 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -20,12 +20,15 @@ #include "FontTestUtils.h" #include "ICUTestBase.h" #include "MinikinFontForTest.h" +#include "MinikinInternal.h" #include "UnicodeUtils.h" +using android::AutoMutex; using android::FontCollection; using android::FontFamily; using android::FontLanguage; using android::FontStyle; +using android::gMinikinLock; const char kItemizeFontXml[] = kTestFontDir "itemize.xml"; const char kEmojiFont[] = kTestFontDir "Emoji.ttf"; @@ -55,6 +58,7 @@ void itemize(FontCollection* collection, const char* str, FontStyle style, result->clear(); ParseUnicode(buf, BUF_SIZE, str, &len, NULL); + AutoMutex _l(gMinikinLock); collection->itemize(buf, len, style, result); } diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 5b4b28b316..6b32689081 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -31,11 +31,13 @@ typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; static FontLanguages createFontLanguages(const std::string& input) { + AutoMutex _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId); } static FontLanguage createFontLanguage(const std::string& input) { + AutoMutex _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId)[0]; } diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp index f83988c1f5..fbbd9376f0 100644 --- a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp @@ -20,17 +20,20 @@ #include "FontLanguageListCache.h" #include "ICUTestBase.h" +#include "MinikinInternal.h" namespace android { typedef ICUTestBase FontLanguageListCacheTest; TEST_F(FontLanguageListCacheTest, getId) { - EXPECT_EQ(0UL, FontLanguageListCache::getId("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); + AutoMutex _l(gMinikinLock); + EXPECT_EQ(0UL, FontLanguageListCache::getId("")); + EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); EXPECT_NE(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("jp")); @@ -47,6 +50,7 @@ TEST_F(FontLanguageListCacheTest, getId) { } TEST_F(FontLanguageListCacheTest, getById) { + AutoMutex _l(gMinikinLock); uint32_t enLangId = FontLanguageListCache::getId("en"); uint32_t jpLangId = FontLanguageListCache::getId("jp"); FontLanguage english = FontLanguageListCache::getById(enLangId)[0];