Refactor how we handle resources path in Tests.
This idea emerged while doing https://codereview.chromium.org/321723002/
(commit 880914c35c8f7fc2e9c57134134c883baf66e538).
BUG=None
TEST=make tests && out/Debug/tests
R=mtklein@google.com
Author: tfarina@chromium.org
Review URL: https://codereview.chromium.org/346453002
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index bc87aaa..23625b3 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkEndian.h"
#include "SkFontStream.h"
#include "SkOSFile.h"
@@ -149,7 +150,7 @@
static void test_fontstream(skiatest::Reporter* reporter) {
// This test cannot run if there is no resource path.
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run fontstream test because resourcePath not specified.");
return;
diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp
index 3b9c194..89db399 100644
--- a/tests/ImageDecodingTest.cpp
+++ b/tests/ImageDecodingTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColor.h"
@@ -148,7 +149,7 @@
static void test_unpremul(skiatest::Reporter* reporter) {
// This test cannot run if there is no resource path.
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run unpremul test because resourcePath not specified.");
return;
@@ -230,7 +231,7 @@
}
DEF_TEST(ImageDecoding_alphaType, reporter) {
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run alphaType test because resourcePath not specified.");
return;
@@ -253,7 +254,7 @@
// Using known images, test that decoding into unpremul and premul behave as expected.
DEF_TEST(ImageDecoding_unpremul, reporter) {
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (resourcePath.isEmpty()) {
SkDebugf("Could not run unpremul test because resourcePath not specified.");
return;
@@ -502,7 +503,7 @@
* SkInstallDiscardablePixelRef functions.
*/
DEF_TEST(ImprovedBitmapFactory, reporter) {
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
SkString path = SkOSPath::SkPathJoin(
resourcePath.c_str(), "randPixels.png");
SkAutoTUnref<SkStreamRewindable> stream(
@@ -676,7 +677,7 @@
#endif
};
- SkString resourceDir = skiatest::Test::GetResourcePath();
+ SkString resourceDir = GetResourcePath();
if (!sk_exists(resourceDir.c_str())) {
return;
}
diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp
index 5cec2bf..e9c4217 100644
--- a/tests/KtxTest.cpp
+++ b/tests/KtxTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "Resources.h"
#include "SkBitmap.h"
#include "SkData.h"
#include "SkDecodingImageGenerator.h"
@@ -140,7 +141,7 @@
* the PKM to the KTX should produce an identical KTX to the one we have on file)
*/
DEF_TEST(KtxReexportPKM, reporter) {
- SkString resourcePath = skiatest::Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
SkString filename = SkOSPath::SkPathJoin(resourcePath.c_str(), "mandrill_128.pkm");
// Load PKM file into a bitmap
diff --git a/tests/Test.cpp b/tests/Test.cpp
index b904d5a..20afd45 100644
--- a/tests/Test.cpp
+++ b/tests/Test.cpp
@@ -41,8 +41,6 @@
///////////////////////////////////////////////////////////////////////////////
-const char* Test::gResourcePath;
-
Test::Test() : fReporter(NULL), fPassed(true) {}
Test::~Test() {
@@ -122,11 +120,3 @@
const char* tmpDir = FLAGS_tmpDir.isEmpty() ? NULL : FLAGS_tmpDir[0];
return SkString(tmpDir);
}
-
-void Test::SetResourcePath(const char* resourcePath) {
- gResourcePath = resourcePath;
-}
-
-SkString Test::GetResourcePath() {
- return SkString(gResourcePath);
-}
diff --git a/tests/Test.h b/tests/Test.h
index 90d072e..fc18900 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -62,9 +62,6 @@
static SkString GetTmpDir();
- static void SetResourcePath(const char*);
- static SkString GetResourcePath();
-
virtual bool isGPUTest() const { return false; }
virtual void setGrContextFactory(GrContextFactory* factory) {}
@@ -73,8 +70,6 @@
virtual void onRun(Reporter*) = 0;
private:
- static const char* gResourcePath;
-
Reporter* fReporter;
SkString fName;
bool fPassed;
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index f70a7fa..f4b67c9 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -7,6 +7,7 @@
#include "CrashHandler.h"
#include "OverwriteLine.h"
+#include "Resources.h"
#include "SkCommandLineFlags.h"
#include "SkGraphics.h"
#include "SkOSFile.h"
@@ -40,7 +41,6 @@
DEFINE_bool(gpu, true, "whether or not to run GPU tests.");
DEFINE_int32(threads, SkThreadPool::kThreadPerCore,
"Run threadsafe tests on a threadpool with this many threads.");
-DEFINE_string2(resourcePath, i, "resources", "directory for test resources.");
// need to explicitly declare this, or we get some weird infinite loop llist
template TestRegistry* TestRegistry::gHead;
@@ -136,7 +136,6 @@
SetupCrashHandler();
SkCommandLineFlags::SetUsage("");
SkCommandLineFlags::Parse(argc, argv);
- Test::SetResourcePath(FLAGS_resourcePath[0]);
#if SK_ENABLE_INST_COUNT
if (FLAGS_leaks) {
@@ -158,7 +157,7 @@
if (!tmpDir.isEmpty()) {
header.appendf(" --tmpDir %s", tmpDir.c_str());
}
- SkString resourcePath = Test::GetResourcePath();
+ SkString resourcePath = GetResourcePath();
if (!resourcePath.isEmpty()) {
header.appendf(" --resourcePath %s", resourcePath.c_str());
}