Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 Writing Unit and Rendering Tests | 1 Writing Skia Tests |
| 2 ================================ | 2 ================== |
| 3 | 3 |
| 4 + [Unit Tests](#test) | |
| 5 + [Rendering Tests](#gm) | |
| 6 + [Benchmark Tests](#bench) | |
| 7 | |
| 8 <span id="test"></span> | |
| 9 | |
| 4 Writing a Unit Test | 10 Writing a Unit Test |
| 5 ------------------- | 11 ------------------- |
| 6 | 12 |
| 7 1. Add a file `tests/NewUnitTest.cpp`: | 13 1. Add a file `tests/NewUnitTest.cpp`: |
| 8 | 14 |
| 9 <!--?prettify lang=cc?--> | 15 <!--?prettify lang=cc?--> |
| 10 | 16 |
| 11 /* | 17 /* |
| 12 * Copyright ........ | 18 * Copyright ........ |
| 13 * | 19 * |
| 14 * Use of this source code is governed by a BSD-style license | 20 * Use of this source code is governed by a BSD-style license |
| 15 * that can be found in the LICENSE file. | 21 * that can be found in the LICENSE file. |
| 16 */ | 22 */ |
| 17 #include "Test.h" | 23 #include "Test.h" |
| 18 DEF_TEST(NewUnitTest, reporter) { | 24 DEF_TEST(NewUnitTest, reporter) { |
| 19 if (1 + 1 != 2) { | 25 if (1 + 1 != 2) { |
| 20 ERRORF(reporter, "%d + %d != %d", 1, 1, 2); | 26 ERRORF(reporter, "%d + %d != %d", 1, 1, 2); |
| 21 } | 27 } |
| 22 bool lifeIsGood = true; | 28 bool lifeIsGood = true; |
| 23 REPORTER_ASSERT(reporter, lifeIsGood); | 29 REPORTER_ASSERT(reporter, lifeIsGood); |
| 24 } | 30 } |
| 25 | 31 |
| 26 2. Recompile and run test: | 32 2. Recompile and run test: |
| 27 | 33 |
| 28 python bin/sync-and-gyp | 34 python bin/sync-and-gyp |
| 29 ninja -C out/Debug dm | 35 ninja -C out/Debug dm |
| 30 out/Debug/dm --match NewUnitTest | 36 out/Debug/dm --match NewUnitTest |
| 31 | 37 |
| 38 <span id="gm"></span> | |
| 39 | |
| 32 Writing a Rendering Test | 40 Writing a Rendering Test |
| 33 ------------------------ | 41 ------------------------ |
| 34 | 42 |
| 35 1. Add a file `gm/newgmtest.cpp`: | 43 1. Add a file `gm/newgmtest.cpp`: |
| 36 | 44 |
| 37 <!--?prettify lang=cc?--> | 45 <!--?prettify lang=cc?--> |
| 38 | 46 |
| 39 /* | 47 /* |
| 40 * Copyright ........ | 48 * Copyright ........ |
| 41 * | 49 * |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 58 | 66 |
| 59 3. Run the GM inside SampleApp: | 67 3. Run the GM inside SampleApp: |
| 60 | 68 |
| 61 python bin/sync-and-gyp | 69 python bin/sync-and-gyp |
| 62 ninja -C out/Debug SampleApp | 70 ninja -C out/Debug SampleApp |
| 63 out/Debug/SampleApp --slide GM:newgmtest | 71 out/Debug/SampleApp --slide GM:newgmtest |
| 64 | 72 |
| 65 On MacOS, try this: | 73 On MacOS, try this: |
| 66 | 74 |
| 67 out/Debug/SampleApp.app/Contents/MacOS/SampleApp --slide GM:newgmtest | 75 out/Debug/SampleApp.app/Contents/MacOS/SampleApp --slide GM:newgmtest |
| 76 | |
| 77 <span id="bench"></span> | |
| 78 | |
| 79 Writing a Benchmark Test | |
| 80 ------------------------ | |
| 81 | |
| 82 1. Add a file `bench/FooBench.cpp`: | |
| 83 | |
| 84 <!--?prettify lang=cc?--> | |
| 85 | |
| 86 /* | |
| 87 * Copyright ........ | |
| 88 * | |
| 89 * Use of this source code is governed by a BSD-style license | |
| 90 * that can be found in the LICENSE file. | |
| 91 */ | |
| 92 #include "Benchmark.h" | |
| 93 #include "SkCanvas.h" | |
| 94 #include "SkRandom.h" | |
| 95 namespace { | |
| 96 class FooBench : public Benchmark { | |
| 97 public: | |
| 98 FooBench() {} | |
| 99 virtual ~FooBench() {} | |
| 100 protected: | |
| 101 const char* onGetName() override { return "Foo"; } | |
| 102 SkIPoint onGetSize() override { return SkIPoint{100, 100}; } | |
| 103 void onDraw(int loops, SkCanvas* canvas) override { | |
| 104 SkRandom r; | |
| 105 while (loops-- > 0) { | |
| 106 canvas->drawLine(r.nextRangeF(0.0f, 100.0f), | |
|
mtklein
2016/02/12 15:59:32
Oh boy, this is also a bad idea. Those calls to n
hal.canary
2016/02/12 16:05:03
how's this?
| |
| 107 r.nextRangeF(0.0f, 100.0f), | |
| 108 r.nextRangeF(0.0f, 100.0f), | |
| 109 r.nextRangeF(0.0f, 100.0f), | |
| 110 SkPaint()); | |
| 111 } | |
| 112 } | |
| 113 }; | |
| 114 } // namespace | |
| 115 DEF_BENCH(return new FooBench;) | |
| 116 | |
| 117 | |
| 118 2. Recompile and run nanobench: | |
| 119 | |
| 120 python bin/sync-and-gyp | |
| 121 ninja -C out/Release nanobench | |
| 122 out/Release/nanobench --match Foo | |
| OLD | NEW |