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 SkISize onGetSize() override { return SkISize{100, 100}; } | |
102 void onDraw(int loops, SkCanvas* canvas) override { | |
103 for (int i = 0; i < loops; i++) { | |
104 canvas->drawLine(10.0f + i % 17, 10.0f + i % 13, | |
mtklein
2016/02/12 15:22:34
This is probably not setting a good example. It's
hal.canary
2016/02/12 15:51:58
done and done.
| |
105 90.0f - i % 19, 90.0f - i % 5, SkPaint()); | |
106 } | |
107 } | |
108 }; | |
109 } // namespace | |
110 DEF_BENCH(return new FooBench;) | |
111 | |
112 | |
113 2. Recompile and run nanobench: | |
114 | |
115 python bin/sync-and-gyp | |
116 ninja -C out/Release nanobench | |
117 out/Release/nanobench --match Foo | |
OLD | NEW |