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 namespace { |
| 95 class FooBench : public Benchmark { |
| 96 public: |
| 97 FooBench() {} |
| 98 virtual ~FooBench() {} |
| 99 protected: |
| 100 const char* onGetName() override { return "Foo"; } |
| 101 SkIPoint onGetSize() override { return SkIPoint{100, 100}; } |
| 102 void onDraw(int loops, SkCanvas* canvas) override { |
| 103 while (loops-- > 0) { |
| 104 canvas->drawLine(0.0f, 0.0f, 100.0f, 100.0f, SkPaint()); |
| 105 } |
| 106 } |
| 107 }; |
| 108 } // namespace |
| 109 DEF_BENCH(return new FooBench;) |
| 110 |
| 111 |
| 112 2. Recompile and run nanobench: |
| 113 |
| 114 python bin/sync-and-gyp |
| 115 ninja -C out/Release nanobench |
| 116 out/Release/nanobench --match Foo |
OLD | NEW |