moz-skia/tests/MetaDataTest.cpp

120 строки
4.0 KiB
C++
Исходник Обычный вид История

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 18:26:00 +04:00
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Test.h"
#include "SkMetaData.h"
static void test_ptrs(skiatest::Reporter* reporter) {
SkRefCnt ref;
REPORTER_ASSERT(reporter, 1 == ref.getRefCnt());
{
SkMetaData md0, md1;
const char name[] = "refcnt";
md0.setRefCnt(name, &ref);
REPORTER_ASSERT(reporter, md0.findRefCnt(name));
REPORTER_ASSERT(reporter, md0.hasRefCnt(name, &ref));
REPORTER_ASSERT(reporter, 2 == ref.getRefCnt());
md1 = md0;
REPORTER_ASSERT(reporter, md1.findRefCnt(name));
REPORTER_ASSERT(reporter, md1.hasRefCnt(name, &ref));
REPORTER_ASSERT(reporter, 3 == ref.getRefCnt());
REPORTER_ASSERT(reporter, md0.removeRefCnt(name));
REPORTER_ASSERT(reporter, !md0.findRefCnt(name));
REPORTER_ASSERT(reporter, !md0.hasRefCnt(name, &ref));
REPORTER_ASSERT(reporter, 2 == ref.getRefCnt());
}
REPORTER_ASSERT(reporter, 1 == ref.getRefCnt());
}
static void TestMetaData(skiatest::Reporter* reporter) {
SkMetaData m1;
REPORTER_ASSERT(reporter, !m1.findS32("int"));
REPORTER_ASSERT(reporter, !m1.findScalar("scalar"));
REPORTER_ASSERT(reporter, !m1.findString("hello"));
REPORTER_ASSERT(reporter, !m1.removeS32("int"));
REPORTER_ASSERT(reporter, !m1.removeScalar("scalar"));
REPORTER_ASSERT(reporter, !m1.removeString("hello"));
REPORTER_ASSERT(reporter, !m1.removeString("true"));
REPORTER_ASSERT(reporter, !m1.removeString("false"));
m1.setS32("int", 12345);
m1.setScalar("scalar", SK_Scalar1 * 42);
m1.setString("hello", "world");
m1.setPtr("ptr", &m1);
m1.setBool("true", true);
m1.setBool("false", false);
int32_t n;
SkScalar s;
m1.setScalar("scalar", SK_Scalar1/2);
REPORTER_ASSERT(reporter, m1.findS32("int", &n) && n == 12345);
REPORTER_ASSERT(reporter, m1.findScalar("scalar", &s) && s == SK_Scalar1/2);
REPORTER_ASSERT(reporter, !strcmp(m1.findString("hello"), "world"));
REPORTER_ASSERT(reporter, m1.hasBool("true", true));
REPORTER_ASSERT(reporter, m1.hasBool("false", false));
SkMetaData::Iter iter(m1);
const char* name;
static const struct {
const char* fName;
SkMetaData::Type fType;
int fCount;
} gElems[] = {
{ "int", SkMetaData::kS32_Type, 1 },
{ "scalar", SkMetaData::kScalar_Type, 1 },
{ "ptr", SkMetaData::kPtr_Type, 1 },
{ "hello", SkMetaData::kString_Type, sizeof("world") },
{ "true", SkMetaData::kBool_Type, 1 },
{ "false", SkMetaData::kBool_Type, 1 }
};
int loop = 0;
int count;
SkMetaData::Type t;
while ((name = iter.next(&t, &count)) != NULL)
{
int match = 0;
for (unsigned i = 0; i < SK_ARRAY_COUNT(gElems); i++)
{
if (!strcmp(name, gElems[i].fName))
{
match += 1;
REPORTER_ASSERT(reporter, gElems[i].fType == t);
REPORTER_ASSERT(reporter, gElems[i].fCount == count);
}
}
REPORTER_ASSERT(reporter, match == 1);
loop += 1;
}
REPORTER_ASSERT(reporter, loop == SK_ARRAY_COUNT(gElems));
REPORTER_ASSERT(reporter, m1.removeS32("int"));
REPORTER_ASSERT(reporter, m1.removeScalar("scalar"));
REPORTER_ASSERT(reporter, m1.removeString("hello"));
REPORTER_ASSERT(reporter, m1.removeBool("true"));
REPORTER_ASSERT(reporter, m1.removeBool("false"));
REPORTER_ASSERT(reporter, !m1.findS32("int"));
REPORTER_ASSERT(reporter, !m1.findScalar("scalar"));
REPORTER_ASSERT(reporter, !m1.findString("hello"));
REPORTER_ASSERT(reporter, !m1.findBool("true"));
REPORTER_ASSERT(reporter, !m1.findBool("false"));
test_ptrs(reporter);
}
#include "TestClassDef.h"
DEFINE_TESTCLASS("MetaData", TestMetaDataClass, TestMetaData)