aboutsummaryrefslogtreecommitdiffhomepage
path: root/site/dev/testing/tests.md
blob: 1b440ad7ac5f130aabf6a7e96d430c2772b25bce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Writing Unit and Rendering Tests
================================

Writing a Unit Test
-------------------

1.  Add a file `tests/NewUnitTest.cpp`:

    <!--?prettify lang=cc?-->

        /*
         * Copyright ........
         *
         * Use of this source code is governed by a BSD-style license
         * that can be found in the LICENSE file.
         */
        #include "Test.h"
        DEF_TEST(NewUnitTest, reporter) {
            if (1 + 1 != 2) {
                ERRORF(reporter, "%d + %d != %d", 1, 1, 2);
            }
            bool lifeIsGood = true;
            REPORTER_ASSERT(reporter, lifeIsGood);
        }

2.  Recompile and run test:

        python bin/sync-and-gyp
        ninja -C out/Debug dm
        out/Debug/dm --match NewUnitTest

Writing a Rendering Test
------------------------

1.  Add a file `gm/newgmtest.cpp`:

    <!--?prettify lang=cc?-->

        /*
         * Copyright ........
         *
         * Use of this source code is governed by a BSD-style license
         * that can be found in the LICENSE file.
         */
        #include "gm.h"
        DEF_SIMPLE_GM(newgmtest, canvas, 128, 128) {
            canvas->clear(SK_ColorWHITE);
            SkPaint p;
            p.setStrokeWidth(2);
            canvas->drawLine(16, 16, 112, 112, p);
        }

2.  Recompile and run test:

        python bin/sync-and-gyp
        ninja -C out/Debug dm
        out/Debug/dm --match newgmtest

3.  Run the GM inside SampleApp:

        python bin/sync-and-gyp
        ninja -C out/Debug SampleApp
        out/Debug/SampleApp --slide GM:newgmtest

    On MacOS, try this:

        out/Debug/SampleApp.app/Contents/MacOS/SampleApp --slide GM:newgmtest