OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "CrashHandler.h" | 8 #include "CrashHandler.h" |
9 // #include "OverwriteLine.h" | 9 // #include "OverwriteLine.h" |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 class TestRunnableEncode : public TestRunnableFile { | 293 class TestRunnableEncode : public TestRunnableFile { |
294 public: | 294 public: |
295 TestRunnableEncode(void (*testFun)(TestState*), int dirNo, const char* name,
TestRunner* runner) | 295 TestRunnableEncode(void (*testFun)(TestState*), int dirNo, const char* name,
TestRunner* runner) |
296 : TestRunnableFile(testFun, dirNo, name, runner) { | 296 : TestRunnableFile(testFun, dirNo, name, runner) { |
297 fState.fResult.fTestStep = kEncodeFiles; | 297 fState.fResult.fTestStep = kEncodeFiles; |
298 } | 298 } |
299 }; | 299 }; |
300 | 300 |
301 TestRunner::~TestRunner() { | 301 TestRunner::~TestRunner() { |
302 for (int index = 0; index < fRunnables.count(); index++) { | 302 for (int index = 0; index < fRunnables.count(); index++) { |
303 SkDELETE(fRunnables[index]); | 303 delete fRunnables[index]; |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 void TestRunner::render() { | 307 void TestRunner::render() { |
308 // TODO: this doesn't really need to use SkRunnables any more. | 308 // TODO: this doesn't really need to use SkRunnables any more. |
309 // We can just write the code to run in the for-loop directly. | 309 // We can just write the code to run in the for-loop directly. |
310 sk_parallel_for(fRunnables.count(), [&](int i) { | 310 sk_parallel_for(fRunnables.count(), [&](int i) { |
311 fRunnables[i]->run(); | 311 fRunnables[i]->run(); |
312 }); | 312 }); |
313 } | 313 } |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 } | 792 } |
793 } | 793 } |
794 } | 794 } |
795 TestRunner testRunner; | 795 TestRunner testRunner; |
796 for (int index = 0; index < state.fPixelWorst.count(); ++index) { | 796 for (int index = 0; index < state.fPixelWorst.count(); ++index) { |
797 const TestResult& result = state.fPixelWorst[index]; | 797 const TestResult& result = state.fPixelWorst[index]; |
798 SkString filename(result.fFilename); | 798 SkString filename(result.fFilename); |
799 if (!filename.endsWith(".skp")) { | 799 if (!filename.endsWith(".skp")) { |
800 filename.append(".skp"); | 800 filename.append(".skp"); |
801 } | 801 } |
802 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableEncode, | 802 *testRunner.fRunnables.append() = new TestRunnableEncode(&testSkpClipEnc
ode, result.fDirNo, |
803 (&testSkpClipEncode, result.fDirNo, filename.c_str(), &testRunne
r)); | 803 filename.c_str(
), &testRunner); |
804 } | 804 } |
805 testRunner.render(); | 805 testRunner.render(); |
806 } | 806 } |
807 | 807 |
808 class Test { | 808 class Test { |
809 public: | 809 public: |
810 Test() {} | 810 Test() {} |
811 virtual ~Test() {} | 811 virtual ~Test() {} |
812 | 812 |
813 const char* getName() { onGetName(&fName); return fName.c_str(); } | 813 const char* getName() { onGetName(&fName); return fName.c_str(); } |
814 void run() { onRun(); } | 814 void run() { onRun(); } |
815 | 815 |
816 protected: | 816 protected: |
817 virtual void onGetName(SkString*) = 0; | 817 virtual void onGetName(SkString*) = 0; |
818 virtual void onRun() = 0; | 818 virtual void onRun() = 0; |
819 | 819 |
820 private: | 820 private: |
821 SkString fName; | 821 SkString fName; |
822 }; | 822 }; |
823 | 823 |
824 typedef SkTRegistry<Test*(*)(void*)> TestRegistry; | 824 typedef SkTRegistry<Test*(*)(void*)> TestRegistry; |
825 | 825 |
826 #define DEF_TEST(name) \ | 826 #define DEF_TEST(name) \ |
827 static void test_##name(); \ | 827 static void test_##name(); \ |
828 class name##Class : public Test { \ | 828 class name##Class : public Test { \ |
829 public: \ | 829 public: \ |
830 static Test* Factory(void*) { return SkNEW(name##Class); } \ | 830 static Test* Factory(void*) { return new name##Class; } \ |
831 protected: \ | 831 \ |
832 void onGetName(SkString* name) override { \ | 832 protected: \ |
833 name->set(#name); \ | 833 void onGetName(SkString* name) override { name->set(#name); } \ |
834 } \ | 834 void onRun() override { test_##name(); } \ |
835 void onRun() override { test_##name(); } \ | 835 }; \ |
836 }; \ | 836 static TestRegistry gReg_##name##Class(name##Class::Factory); \ |
837 static TestRegistry gReg_##name##Class(name##Class::Factory); \ | |
838 static void test_##name() | 837 static void test_##name() |
839 | 838 |
840 DEF_TEST(PathOpsSkpClip) { | 839 DEF_TEST(PathOpsSkpClip) { |
841 gDirs.setDefault(); | 840 gDirs.setDefault(); |
842 initTest(); | 841 initTest(); |
843 SkTArray<TestResult, true> errors; | 842 SkTArray<TestResult, true> errors; |
844 TestState state; | 843 TestState state; |
845 state.init(0); | 844 state.init(0); |
846 int dirNo; | 845 int dirNo; |
847 gDirs.reset(); | 846 gDirs.reset(); |
(...skipping 13 matching lines...) Expand all Loading... |
861 (void) doOneDir(data, true); | 860 (void) doOneDir(data, true); |
862 } | 861 } |
863 | 862 |
864 DEF_TEST(PathOpsSkpClipThreaded) { | 863 DEF_TEST(PathOpsSkpClipThreaded) { |
865 gDirs.setDefault(); | 864 gDirs.setDefault(); |
866 initTest(); | 865 initTest(); |
867 TestRunner testRunner; | 866 TestRunner testRunner; |
868 int dirNo; | 867 int dirNo; |
869 gDirs.reset(); | 868 gDirs.reset(); |
870 while ((dirNo = gDirs.next()) > 0) { | 869 while ((dirNo = gDirs.next()) > 0) { |
871 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableDir, | 870 *testRunner.fRunnables.append() = new TestRunnableDir(&testSkpClipMain,
dirNo, &testRunner); |
872 (&testSkpClipMain, dirNo, &testRunner)); | |
873 } | 871 } |
874 testRunner.render(); | 872 testRunner.render(); |
875 TestState state; | 873 TestState state; |
876 state.init(0); | 874 state.init(0); |
877 gDirs.reset(); | 875 gDirs.reset(); |
878 while ((dirNo = gDirs.next()) > 0) { | 876 while ((dirNo = gDirs.next()) > 0) { |
879 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState; | 877 TestState& testState = testRunner.fRunnables[dirNo - 1]->fState; |
880 SkASSERT(testState.fResult.fDirNo == dirNo); | 878 SkASSERT(testState.fResult.fDirNo == dirNo); |
881 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) { | 879 for (int inner = 0; inner < testState.fPixelWorst.count(); ++inner) { |
882 addError(&state, testState.fPixelWorst[inner]); | 880 addError(&state, testState.fPixelWorst[inner]); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 goto checkEarlyExit; | 925 goto checkEarlyExit; |
928 } | 926 } |
929 } | 927 } |
930 { | 928 { |
931 SortByName name; | 929 SortByName name; |
932 name.init(dirNo); | 930 name.init(dirNo); |
933 strncpy(name.fFilename, filename.c_str(), filename.size() - 4);
// drop .skp | 931 strncpy(name.fFilename, filename.c_str(), filename.size() - 4);
// drop .skp |
934 int count = sorted.get()[dirNo - firstDirNo].count(); | 932 int count = sorted.get()[dirNo - firstDirNo].count(); |
935 if (SkTSearch<SortByName, Less>(sorted.get()[dirNo - firstDirNo]
.begin(), | 933 if (SkTSearch<SortByName, Less>(sorted.get()[dirNo - firstDirNo]
.begin(), |
936 count, &name, sizeof(&name)) < 0) { | 934 count, &name, sizeof(&name)) < 0) { |
937 *testRunner.fRunnables.append() = SkNEW_ARGS(TestRunnableFil
e, | 935 *testRunner.fRunnables.append() = new TestRunnableFile( |
938 (&testSkpClip, dirNo, filename.c_str(), &testRunner)
); | 936 &testSkpClip, dirNo, filename.c_str(), &testRunner); |
939 } | 937 } |
940 } | 938 } |
941 checkEarlyExit: | 939 checkEarlyExit: |
942 ; | 940 ; |
943 } | 941 } |
944 | 942 |
945 } | 943 } |
946 testRunner.render(); | 944 testRunner.render(); |
947 SkAutoTDeleteArray<SkTDArray<TestResult> > results(new SkTDArray<TestResult>
[dirCount]); | 945 SkAutoTDeleteArray<SkTDArray<TestResult> > results(new SkTDArray<TestResult>
[dirCount]); |
948 if (!buildTests(results.get(), NULL)) { | 946 if (!buildTests(results.get(), NULL)) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 } | 1104 } |
1107 SkGraphics::Term(); | 1105 SkGraphics::Term(); |
1108 return 0; | 1106 return 0; |
1109 } | 1107 } |
1110 | 1108 |
1111 #if !defined(SK_BUILD_FOR_IOS) | 1109 #if !defined(SK_BUILD_FOR_IOS) |
1112 int main(int argc, char * const argv[]) { | 1110 int main(int argc, char * const argv[]) { |
1113 return tool_main(argc, (char**) argv); | 1111 return tool_main(argc, (char**) argv); |
1114 } | 1112 } |
1115 #endif | 1113 #endif |
OLD | NEW |