From: halcanary Date: Fri, 30 Jan 2015 15:00:42 +0000 (-0800) Subject: documentation: Writing Unit and Rendering Tests X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~3814 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c38796634347163e04423102d7cb575606da119f;p=platform%2Fupstream%2FlibSkiaSharp.git documentation: Writing Unit and Rendering Tests Review URL: https://codereview.chromium.org/885133002 --- diff --git a/site/dev/contrib/submit.md b/site/dev/contrib/submit.md index fcbcf20..a66e727 100644 --- a/site/dev/contrib/submit.md +++ b/site/dev/contrib/submit.md @@ -32,41 +32,9 @@ Adding a unit test If you are willing to change Skia codebase, it's nice to add a test at the same time. Skia has a simple unittest framework so you can add a case to it. -Test code is located under the 'tests' directory. Assuming we are adding -tests/FooTest.cpp, The test code will look like: +Test code is located under the 'tests' directory. - -~~~~ -/* - * 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(TestFoo, reporter) { - int x = 2 * 3; - if (x != 6) { - ERRORF(reporter, "x should be 6, but is %d", x); - return; - } - REPORTER_ASSERT(reporter, 1 + 1 == 2); -} -~~~~ - -And we need to add this new file to gyp/tests.gyp. Note that file names are -sorted alphabetically. - - -~~~~ -'sources': [ - '../tests/AAClipTest.cpp' - '../tests/FooTest.cpp', - '../tests/XfermodeTest.cpp', -], -~~~~ +See [Writing Unit and Rendering Tests](tests) for details. Unit tests are best, but if your change touches rendering and you can't think of an automated way to verify the results, consider writing a GM test or a new page @@ -74,7 +42,6 @@ of SampleApp. Also, if your change is the GPU code, you may not be able to write it as part of the standard unit test suite, but there are GPU-specific testing paths you can extend. - Submitting a patch ------------------ diff --git a/site/dev/contrib/tests.md b/site/dev/contrib/tests.md new file mode 100644 index 0000000..fbe84df --- /dev/null +++ b/site/dev/contrib/tests.md @@ -0,0 +1,65 @@ +Writing Unit and Rendering Tests +================================ + +Writing a Unit Test +------------------- + +1. Add a file `tests/NewUnitTest.cpp`: + + + + /* + * 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. Add a line to `gyp/tests.gypi`: + + '../tests/NewUnitTest.cpp', + +3. Recompile and run test: + + ./gyp_skia + ninja -C out/Debug dm + out/Debug/dm --match NewUnitTest + +Writing a Rendering Test +------------------------ + +1. Add a file `gm/newgmtest.cpp`: + + + + /* + * 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. Add a line to `gyp/gmslides.gypi`: + + '../gm/newgmtest.cpp', + +3. Recompile and run test: + + ./gyp_skia + ninja -C out/Debug dm + out/Debug/dm --match newgmtest