2011-07-28 14:26:00 +00: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.
|
|
|
|
*/
|
2013-12-12 21:11:12 +00:00
|
|
|
|
2011-01-25 23:36:05 +00:00
|
|
|
#include "SkRefDict.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2011-01-25 23:36:05 +00:00
|
|
|
|
|
|
|
class TestRC : public SkRefCnt {
|
2012-08-16 14:58:06 +00:00
|
|
|
public:
|
|
|
|
SK_DECLARE_INST_COUNT(TestRC)
|
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
2011-01-25 23:36:05 +00:00
|
|
|
};
|
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(RefDict, reporter) {
|
2011-01-25 23:36:05 +00:00
|
|
|
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"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
2011-01-25 23:36:05 +00:00
|
|
|
|
|
|
|
dict.set("foo", &data0);
|
|
|
|
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
2011-01-25 23:36:05 +00:00
|
|
|
|
|
|
|
dict.set("foo", &data1);
|
|
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
|
|
REPORTER_ASSERT(reporter, !data1.unique());
|
2011-01-25 23:36:05 +00:00
|
|
|
|
|
|
|
dict.set("foo", NULL);
|
|
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
|
|
REPORTER_ASSERT(reporter, data1.unique());
|
2011-01-25 23:36:05 +00:00
|
|
|
|
|
|
|
dict.set("foo", &data0);
|
|
|
|
dict.set("bar", &data1);
|
|
|
|
REPORTER_ASSERT(reporter, &data0 == dict.find("foo"));
|
|
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
|
|
|
REPORTER_ASSERT(reporter, !data1.unique());
|
2011-01-25 23:36:05 +00:00
|
|
|
|
|
|
|
dict.set("foo", &data1);
|
|
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("foo"));
|
|
|
|
REPORTER_ASSERT(reporter, &data1 == dict.find("bar"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
|
|
REPORTER_ASSERT(reporter, !data1.unique());
|
2011-01-25 23:36:05 +00:00
|
|
|
|
|
|
|
dict.removeAll();
|
|
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("foo"));
|
|
|
|
REPORTER_ASSERT(reporter, NULL == dict.find("bar"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
|
|
|
REPORTER_ASSERT(reporter, data1.unique());
|
2011-01-25 23:50:57 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
SkRefDict d;
|
|
|
|
REPORTER_ASSERT(reporter, NULL == d.find("foo"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
2011-01-25 23:50:57 +00:00
|
|
|
d.set("foo", &data0);
|
|
|
|
REPORTER_ASSERT(reporter, &data0 == d.find("foo"));
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, !data0.unique());
|
2011-01-25 23:50:57 +00:00
|
|
|
// 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
|
2014-11-24 21:09:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, data0.unique());
|
2011-01-25 23:36:05 +00:00
|
|
|
}
|