diff options
author | Hal Canary <halcanary@google.com> | 2018-08-03 13:29:39 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-08-06 19:17:24 +0000 |
commit | 73ec9a09f36ed1e0921c05924b63dcace069f489 (patch) | |
tree | 84c8edd2343d9a39aaa38eccd48908ea2efe65c1 /dm | |
parent | 641bf8745db12b4ab16a4fe1ce43aeb3a0ba1546 (diff) | |
download | skqp-73ec9a09f36ed1e0921c05924b63dcace069f489.tar.gz |
Test: New GMs should be nicely named
Motivation:
An issue came up a while back with SkQP where some the JUnit testing
framework dislikes test names that aren't valid Java identifiers. I am
currently replacing invalid characters with underscores before giving
them to JUnit, but that leads to some confusion when trying to grep for
the name of a failing test.
I propose that going forward, all *new* Skia unit tests and GM names be
in the form [A-Za-z][A-Za-z0-9_]* to prevent this sort of confusion. We
won't change 63 existing "bad" tests names.
This Cl encorces that rule with an assertion in DM.
Change-Id: Icedce023cd3127d499fbcdcaea485f1ec9e9196b
Reviewed-on: https://skia-review.googlesource.com/145365
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'dm')
-rw-r--r-- | dm/DM.cpp | 5 | ||||
-rw-r--r-- | dm/ValidateGMNames.cpp | 108 | ||||
-rw-r--r-- | dm/ValidateGMNames.h | 6 |
3 files changed, 118 insertions, 1 deletions
@@ -36,12 +36,13 @@ #include "SkPngEncoder.h" #include "SkScan.h" #include "SkSpinlock.h" -#include "SkTestFontMgr.h" #include "SkTHash.h" #include "SkTaskGroup.h" +#include "SkTestFontMgr.h" #include "SkTypeface_win.h" #include "Test.h" #include "Timer.h" +#include "ValidateGMNames.h" #include "ios_utils.h" #include "picture_utils.h" #include "sk_tool_utils.h" @@ -1353,6 +1354,8 @@ int main(int argc, char** argv) { SkAutoGraphics ag; SkTaskGroup::Enabler enabled(FLAGS_threads); + ValidateGMNames(); + if (nullptr == GetResourceAsData("images/color_wheel.png")) { info("Some resources are missing. Do you need to set --resourcePath?\n"); } diff --git a/dm/ValidateGMNames.cpp b/dm/ValidateGMNames.cpp new file mode 100644 index 0000000000..74e3fd5e9e --- /dev/null +++ b/dm/ValidateGMNames.cpp @@ -0,0 +1,108 @@ +// Copyright 2018 Google LLC. +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. + +#include "../gm/gm.h" +#include "SkTHash.h" +#include "ValidateGMNames.h" + +static const char* kGrandfatherClauseNames[] = { + "3dgm", + "3x3bitmaprect", + "animated-image-blurs", + "bitmap-image-srgb-legacy", + "blurroundrect-WH-100x100-unevenCorners", + "circular-clips", + "clipped-bitmap-shaders-clamp", + "clipped-bitmap-shaders-clamp-hq", + "clipped-bitmap-shaders-mirror", + "clipped-bitmap-shaders-mirror-hq", + "clipped-bitmap-shaders-tile", + "clipped-bitmap-shaders-tile-hq", + "combo-patheffects", + "convex-lineonly-paths", + "convex-lineonly-paths-stroke-and-fill", + "convex-polygon-inset", + "convex-polygon-inset-v", + "downsamplebitmap_text_high_72.00pt", + "downsamplebitmap_text_low_72.00pt", + "downsamplebitmap_text_medium_72.00pt", + "downsamplebitmap_text_none_72.00pt", + "draw-atlas", + "draw-atlas-colors", + "drawbitmaprect-imagerect", + "drawbitmaprect-imagerect-subset", + "drawbitmaprect-subset", + "encode-alpha-jpeg", + "encode-platform", + "encode-srgb-jpg", + "encode-srgb-png", + "encode-srgb-webp", + "filterbitmap_image_color_wheel.png", + "filterbitmap_image_mandrill_128.png", + "filterbitmap_image_mandrill_16.png", + "filterbitmap_image_mandrill_256.png", + "filterbitmap_image_mandrill_32.png", + "filterbitmap_image_mandrill_512.png", + "filterbitmap_image_mandrill_64.png", + "filterbitmap_image_mandrill_64.png_g8", + "filterbitmap_text_10.00pt", + "filterbitmap_text_3.00pt", + "filterbitmap_text_7.00pt", + "fontcache-mt", + "fontmgr_bounds_0.75_0", + "fontmgr_bounds_1_-0.25", + "gamma_encoded_premul_dst-v-src_from1.8", + "gamma_encoded_premul_dst-v-src_fromLinear", + "gamma_encoded_premul_dst-v-src_fromWideGamut", + "gamma_encoded_premul_dst-v-src_toLinear", + "gamma_encoded_premul_dst-v-src_toWideGamut", + "image-cacherator-from-picture", + "image-cacherator-from-raster", + "image-cacherator-from-texture", + "image-picture", + "image-shader", + "image-surface", + "jpg-color-cube", + "ninepatch-stretch", + "path-reverse", + "scale-pixels", + "simple-magnification", + "simple-offsetimagefilter", + "simple-polygon-offset", + "simple-polygon-offset-v", + "stroke-fill", +}; + +static const char kFirstOkay[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +static const char kRestOkay[] = "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + +static bool good_name(const SkString& name) { + SkASSERT(name.size() > 0); + if (NULL == strchr(kFirstOkay, name[0])) { + return false; + } + for (unsigned i = 1; i < name.size(); ++i) { + if (NULL == strchr(kRestOkay, name[i])) { + return false; + } + } + return true; +} + +void ValidateGMNames() { + SkTHashSet<SkString> okay; + for (auto name : kGrandfatherClauseNames) { + okay.add(SkString(name)); + } + SkDEBUGCODE(bool good = true); + for (skiagm::GMFactory factory : skiagm::GMRegistry::Range()) { + std::unique_ptr<skiagm::GM> gm(factory(nullptr)); + SkString name(gm->getName()); + if (!okay.contains(name) && !good_name(name)) { + SkDEBUGCODE(good = false); + SkDebugf("ERROR: '%s' is a bad name.\n", name.c_str()); + } + } + SkASSERT(good); +} diff --git a/dm/ValidateGMNames.h b/dm/ValidateGMNames.h new file mode 100644 index 0000000000..a777079cad --- /dev/null +++ b/dm/ValidateGMNames.h @@ -0,0 +1,6 @@ +// Copyright 2018 Google LLC. +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +#ifndef ValidateGMNames_DEFINED +#define ValidateGMNames_DEFINED +void ValidateGMNames(); +#endif // ValidateGMNames_DEFINED |