skia2/tests/RuntimeConfigTest.cpp
halcanary@google.com 1f0121af49 New SkRTConf macro SK_CONF_TRY_SET: no complaint on missing configuration
SK_CONF_TRY_SET() is like SK_CONF_SET(), but doesn't complain if
confname can't be found.  This is useful if the SK_CONF_DECLARE is
inside a source file whose linkage is dependent on the system.

Internally to the SkRTConf system, SkRTConfRegistry::set() was given
an additional parameter controling wanrings.

A new RuntimeConfig unit test was introduced.  It should run silently.
In the future, it should be expanded to cover all of the SkRTConf
functionality.

(For example, the images.jpeg.suppressDecoderWarnings variable is
defined and used only in SkImageDecoder_libjpeg.cpp, but on MacOS, we
use Core Graphics via SkImageDecoder_CG.cpp - SkImageDecoder_libjpeg
is never linked in.  The same is true of the Windows Imaging Component
on Windows.)

BUG=
R=reed@google.com

Review URL: https://codereview.chromium.org/54503007

git-svn-id: http://skia.googlecode.com/svn/trunk@12155 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-11-06 15:07:44 +00:00

30 lines
938 B
C++

/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkRTConf.h"
#include "Test.h"
#include "TestClassDef.h"
SK_CONF_DECLARE(int, c_RTConfTestVariable,
"test.utils.rtconf.testVariable", 1,
"This is only a test. Do not be alarmed.");
// TODO(skia-team): more comprehensive unit tests of the SkRTConf
// system.
DEF_TEST(RuntimeConfig, reporter) {
REPORTER_ASSERT(reporter, 1 == c_RTConfTestVariable);
SK_CONF_SET("test.utils.rtconf.testVariable", 2);
#ifdef SK_DEVELOPER
REPORTER_ASSERT(reporter, 2 == c_RTConfTestVariable);
#else // not SK_DEVELOPER
// Can not change RTConf variables in Release.
REPORTER_ASSERT(reporter, 1 == c_RTConfTestVariable);
#endif // SK_DEVELOPER
// This should not give a warning.
SK_CONF_TRY_SET("test.utils.rtconf.nonexistentVariable", 7);
}