2766c00fc0
It's been outclassed by Valgrind and leak sanitizer, and it seems to be causing problems for external folks building Skia. I'm not sure why our own builds seem unaffected. Latest thread: https://groups.google.com/forum/#!topic/skia-discuss/oj9FsQwwSF0 BUG=skia: Review URL: https://codereview.chromium.org/1217573002
75 lines
2.3 KiB
C++
75 lines
2.3 KiB
C++
/*
|
|
* 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 "SkRefDict.h"
|
|
#include "Test.h"
|
|
|
|
class TestRC : public SkRefCnt {
|
|
public:
|
|
|
|
private:
|
|
typedef SkRefCnt INHERITED;
|
|
};
|
|
|
|
DEF_TEST(RefDict, reporter) {
|
|
TestRC data0, data1;
|
|
SkRefDict dict;
|
|
|
|
REPORTER_ASSERT(reporter, NULL == dict.find(NULL));
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("bar"));
|
|
|
|
dict.set("foo", &data0);
|
|
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
|
|
|
dict.set("foo", &data0);
|
|
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
|
|
|
dict.set("foo", &data1);
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
REPORTER_ASSERT(reporter, !data1.unique());
|
|
|
|
dict.set("foo", NULL);
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
REPORTER_ASSERT(reporter, data1.unique());
|
|
|
|
dict.set("foo", &data0);
|
|
dict.set("bar", &data1);
|
|
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
|
REPORTER_ASSERT(reporter, !data1.unique());
|
|
|
|
dict.set("foo", &data1);
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
REPORTER_ASSERT(reporter, !data1.unique());
|
|
|
|
dict.removeAll();
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("bar"));
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
REPORTER_ASSERT(reporter, data1.unique());
|
|
|
|
{
|
|
SkRefDict d;
|
|
REPORTER_ASSERT(reporter, NULL == d.find("foo"));
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
d.set("foo", &data0);
|
|
REPORTER_ASSERT(reporter, &data0 == d.find("foo"));
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
|
// let d go out of scope still with a ref on data0
|
|
}
|
|
// be sure d's destructor lowered data0's owner count back to 1
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
}
|