aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-08-16 15:45:58 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-08-16 15:45:58 +0000
commita8e686eb6cadb74039d3b624ece0d3ccb0684dcc (patch)
tree824644b407dbd4e81577b4102550f363c7d721f3 /tests
parentbbfa1000e750667540f5660e363ad185b0fa3cdb (diff)
Make program unit test run clean and add it to tests program
Review URL: http://codereview.appspot.com/4898049/ git-svn-id: http://skia.googlecode.com/svn/trunk@2121 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r--tests/GLProgramsTest.cpp21
-rw-r--r--tests/Test.cpp21
-rw-r--r--tests/Test.h14
-rw-r--r--tests/TestClassDef.h13
4 files changed, 69 insertions, 0 deletions
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
new file mode 100644
index 0000000000..5cacadefe3
--- /dev/null
+++ b/tests/GLProgramsTest.cpp
@@ -0,0 +1,21 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "Test.h"
+#include "GrContext.h"
+#include "GrGpuGLShaders.h"
+
+static void GLProgramsTest(skiatest::Reporter* reporter, GrContext* context) {
+ GrGpuGLShaders* shadersGpu = (GrGpuGLShaders*) context->getGpu();
+ REPORTER_ASSERT(reporter, shadersGpu->programUnitTest());
+}
+
+
+#include "TestClassDef.h"
+DEFINE_GPUTESTCLASS("GLPrograms", GLProgramsTestClass, GLProgramsTest)
+
diff --git a/tests/Test.cpp b/tests/Test.cpp
index e1246c34d6..e8a16f4d50 100644
--- a/tests/Test.cpp
+++ b/tests/Test.cpp
@@ -7,6 +7,10 @@
*/
#include "Test.h"
+#include "GrContext.h"
+#include "SkEGLContext.h"
+#include "SkTLazy.h"
+
using namespace skiatest;
Reporter::Reporter() {
@@ -70,3 +74,20 @@ bool Test::run() {
return fReporter->getCurrSuccess();
}
+///////////////////////////////////////////////////////////////////////////////
+
+
+GrContext* GpuTest::GetContext() {
+ // preserve this order, we want gGrContext destroyed after gEGLContext
+ static SkTLazy<SkEGLContext> gEGLContext;
+ static SkAutoTUnref<GrContext> gGrContext;
+
+ if (NULL == gGrContext.get()) {
+ gEGLContext.init();
+ if (gEGLContext.get()->init(800, 600)) {
+ gGrContext.reset(GrContext::Create(kOpenGL_Shaders_GrEngine, NULL));
+ }
+ }
+ return gGrContext.get();
+}
+
diff --git a/tests/Test.h b/tests/Test.h
index c27f12012a..2c28b00b3c 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -12,6 +12,9 @@
#include "SkString.h"
#include "SkTRegistry.h"
+class GrContext;
+class SkEGLContext;
+
namespace skiatest {
class Test;
@@ -94,6 +97,17 @@ namespace skiatest {
SkString fName;
};
+ class GpuTest : public Test{
+ public:
+ GpuTest() : Test() {
+ fContext = GetContext();
+ }
+ protected:
+ GrContext* fContext;
+ private:
+ static GrContext* GetContext();
+ };
+
typedef SkTRegistry<Test*, void*> TestRegistry;
}
diff --git a/tests/TestClassDef.h b/tests/TestClassDef.h
index ce9cff4651..34f899feda 100644
--- a/tests/TestClassDef.h
+++ b/tests/TestClassDef.h
@@ -29,3 +29,16 @@
static TestRegistry gReg(classname::Factory); \
}
+#define DEFINE_GPUTESTCLASS(uiname, classname, function) \
+ namespace skiatest { \
+ class classname : public GpuTest { \
+ public: \
+ static Test* Factory(void*) { return SkNEW(classname); } \
+ protected: \
+ virtual void onGetName(SkString* name) { name->set(uiname); } \
+ virtual void onRun(Reporter* reporter) { \
+ function(reporter, fContext); \
+ } \
+ }; \
+ static TestRegistry gReg(classname::Factory); \
+ }