OLD | NEW |
1 Writing Unit and Rendering Tests | 1 Writing Unit and Rendering Tests |
2 ================================ | 2 ================================ |
3 | 3 |
4 Writing a Unit Test | 4 Writing a Unit Test |
5 ------------------- | 5 ------------------- |
6 | 6 |
7 1. Add a file `tests/NewUnitTest.cpp`: | 7 1. Add a file `tests/NewUnitTest.cpp`: |
8 | 8 |
9 <!--?prettify lang=cc?--> | 9 <!--?prettify lang=cc?--> |
10 | 10 |
11 /* | 11 /* |
12 * Copyright ........ | 12 * Copyright ........ |
13 * | 13 * |
14 * Use of this source code is governed by a BSD-style license | 14 * Use of this source code is governed by a BSD-style license |
15 * that can be found in the LICENSE file. | 15 * that can be found in the LICENSE file. |
16 */ | 16 */ |
17 #include "Test.h" | 17 #include "Test.h" |
18 DEF_TEST(NewUnitTest, reporter) { | 18 DEF_TEST(NewUnitTest, reporter) { |
19 if (1 + 1 != 2) { | 19 if (1 + 1 != 2) { |
20 ERRORF(reporter, "%d + %d != %d", 1, 1, 2); | 20 ERRORF(reporter, "%d + %d != %d", 1, 1, 2); |
21 } | 21 } |
22 bool lifeIsGood = true; | 22 bool lifeIsGood = true; |
23 REPORTER_ASSERT(reporter, lifeIsGood); | 23 REPORTER_ASSERT(reporter, lifeIsGood); |
24 } | 24 } |
25 | 25 |
26 2. Add a line to `gyp/tests.gypi`: | 26 2. Recompile and run test: |
27 | |
28 '../tests/NewUnitTest.cpp', | |
29 | |
30 3. Recompile and run test: | |
31 | 27 |
32 ./gyp_skia | 28 ./gyp_skia |
33 ninja -C out/Debug dm | 29 ninja -C out/Debug dm |
34 out/Debug/dm --match NewUnitTest | 30 out/Debug/dm --match NewUnitTest |
35 | 31 |
36 Writing a Rendering Test | 32 Writing a Rendering Test |
37 ------------------------ | 33 ------------------------ |
38 | 34 |
39 1. Add a file `gm/newgmtest.cpp`: | 35 1. Add a file `gm/newgmtest.cpp`: |
40 | 36 |
41 <!--?prettify lang=cc?--> | 37 <!--?prettify lang=cc?--> |
42 | 38 |
43 /* | 39 /* |
44 * Copyright ........ | 40 * Copyright ........ |
45 * | 41 * |
46 * Use of this source code is governed by a BSD-style license | 42 * Use of this source code is governed by a BSD-style license |
47 * that can be found in the LICENSE file. | 43 * that can be found in the LICENSE file. |
48 */ | 44 */ |
49 #include "gm.h" | 45 #include "gm.h" |
50 DEF_SIMPLE_GM(newgmtest, canvas, 128, 128) { | 46 DEF_SIMPLE_GM(newgmtest, canvas, 128, 128) { |
51 canvas->clear(SK_ColorWHITE); | 47 canvas->clear(SK_ColorWHITE); |
52 SkPaint p; | 48 SkPaint p; |
53 p.setStrokeWidth(2); | 49 p.setStrokeWidth(2); |
54 canvas->drawLine(16, 16, 112, 112, p); | 50 canvas->drawLine(16, 16, 112, 112, p); |
55 } | 51 } |
56 | 52 |
57 2. Add a line to `gyp/gmslides.gypi`: | 53 2. Recompile and run test: |
58 | |
59 '../gm/newgmtest.cpp', | |
60 | |
61 3. Recompile and run test: | |
62 | 54 |
63 ./gyp_skia | 55 ./gyp_skia |
64 ninja -C out/Debug dm | 56 ninja -C out/Debug dm |
65 out/Debug/dm --match newgmtest | 57 out/Debug/dm --match newgmtest |
66 | 58 |
67 4. Run the GM inside SampleApp: | 59 3. Run the GM inside SampleApp: |
68 | 60 |
69 ./gyp_skia | 61 ./gyp_skia |
70 ninja -C out/Debug SampleApp | 62 ninja -C out/Debug SampleApp |
71 out/Debug/SampleApp --slide GM:newgmtest | 63 out/Debug/SampleApp --slide GM:newgmtest |
72 | 64 |
73 On MacOS, try this: | 65 On MacOS, try this: |
74 | 66 |
75 out/Debug/SampleApp.app/Contents/MacOS/SampleApp --slide GM:newgmtest | 67 out/Debug/SampleApp.app/Contents/MacOS/SampleApp --slide GM:newgmtest |
OLD | NEW |