Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1256)

Unified Diff: tests/FontConfigParser.cpp

Issue 1027373002: Font variations. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkTypeface_win_dw.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/FontConfigParser.cpp
diff --git a/tests/FontConfigParser.cpp b/tests/FontConfigParser.cpp
index e58d35c625bb4bf52573c7f7c511b51f613bc250..218aa9a09ae675b4d367c2d44b5318fab0c72435 100644
--- a/tests/FontConfigParser.cpp
+++ b/tests/FontConfigParser.cpp
@@ -10,6 +10,9 @@
#include "SkFontConfigParser_android.h"
#include "Test.h"
+#include <cmath>
+#include <cstdio>
+
DECLARE_bool(verboseFontMgr);
int CountFallbacks(SkTDArray<FontFamily*> fontFamilies) {
@@ -91,7 +94,55 @@ void DumpLoadedFonts(SkTDArray<FontFamily*> fontFamilies, const char* label) {
SkDebugf("\n\n");
}
+template <int N, typename T> static double test_parse_fixed_r(skiatest::Reporter* reporter,
+ double low, double high, double inc)
+{
+ double SK_FixedMax_double = nextafter(1 << (sizeof(T) * CHAR_BIT - N - 1), 0.0);
+ double SK_FixedEpsilon_double = (1.0 / (1 << N));
+ double maxError = 0;
+ char buffer[64];
+ for (double f = low; f < high; f += inc) {
+ SkString s;
+ // 'sprintf' formatting as expected depends on the current locale being "C".
+ // We currently expect tests and tools to run in the "C" locale.
+ sprintf(buffer, "%.20f", f);
+ T fix;
+ bool b = parse_fixed<N>(buffer, &fix);
+ if (b) {
+ double f2 = fix * SK_FixedEpsilon_double;
+ double error = fabs(f - f2);
+ REPORTER_ASSERT(reporter, error <= SK_FixedEpsilon_double);
+ maxError = SkTMax(maxError, error);
+ } else {
+ REPORTER_ASSERT(reporter, f < -SK_FixedMax_double || SK_FixedMax_double < f);
+ }
+ }
+
+ //SkDebugf("maxError: %.20f\n", maxError);
+ return maxError;
+}
+
+static void test_parse_fixed(skiatest::Reporter* reporter) {
+ test_parse_fixed_r<27, int32_t>(reporter, -8.1, -7.9, 0.000001);
+ test_parse_fixed_r<27, int32_t>(reporter, -0.1, 0.1, 0.000001);
+ test_parse_fixed_r<27, int32_t>(reporter, 7.9, 8.1, 0.000001);
+ test_parse_fixed_r<16, int32_t>(reporter, -0.125, 0.125, 1.0 / (1 << 19));
+ test_parse_fixed_r<16, int32_t>(reporter, -32768.125, -32766.875, 1.0 / (1 << 17));
+ test_parse_fixed_r<16, int32_t>(reporter, 32766.875, 32768.125, 1.0 / (1 << 17));
+ test_parse_fixed_r<16, int32_t>(reporter, -1.1, 1.1, 0.0001);
+
+ SkFixed fix;
+ REPORTER_ASSERT(reporter, !parse_fixed<27>("-17.1", &fix));
+ REPORTER_ASSERT(reporter, !parse_fixed<16>("32768", &fix));
+ REPORTER_ASSERT(reporter, !parse_fixed<16>("", &fix));
+ REPORTER_ASSERT(reporter, !parse_fixed<16>(".", &fix));
+ REPORTER_ASSERT(reporter, !parse_fixed<16>("123.", &fix));
+ REPORTER_ASSERT(reporter, !parse_fixed<16>("a", &fix));
+ REPORTER_ASSERT(reporter, !parse_fixed<16>(".123a", &fix));
+}
+
DEF_TEST(FontConfigParserAndroid, reporter) {
+ test_parse_fixed(reporter);
bool resourcesMissing = false;
@@ -137,7 +188,7 @@ DEF_TEST(FontConfigParserAndroid, reporter) {
NULL);
if (v22FontFamilies.count() > 0) {
- REPORTER_ASSERT(reporter, v22FontFamilies.count() == 53);
+ REPORTER_ASSERT(reporter, v22FontFamilies.count() == 54);
REPORTER_ASSERT(reporter, CountFallbacks(v22FontFamilies) == 42);
DumpLoadedFonts(v22FontFamilies, "version 22");
« no previous file with comments | « src/ports/SkTypeface_win_dw.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698