int main(int argc, char **argv) { int flag; const char *lockfile = NULL; while (1) { flag = getopt(argc, argv, OPTARGS); if (flag == -1) break; switch (flag) { case 'f': lockfile = optarg; break; default: printf("Unknown option: -%c\n", flag); break; } } if (lockfile) { test_locking(lockfile); } else { printf("ERROR: NO LOCK FILE GIVEN. usage: -f <lock file>\n"); } return 0; }
/* * SkCachedData behaves differently (regarding its locked/unlocked state) depending on * when it is in the cache or not. Being in the cache is signaled by calling attachToCacheAndRef() * instead of ref(). (and balanced by detachFromCacheAndUnref). * * Thus, among other things, we test the end-of-life behavior when the client is the last owner * and when the cache is. */ DEF_TEST(CachedData, reporter) { SkAutoTUnref<SkDiscardableMemoryPool> pool(SkDiscardableMemoryPool::Create(1000)); for (int useDiscardable = 0; useDiscardable <= 1; ++useDiscardable) { const size_t size = 100; // test with client as last owner SkCachedData* data = test_locking(reporter, size, useDiscardable ? pool.get() : nullptr); check_data(reporter, data, 2, kInCache, kLocked); data->detachFromCacheAndUnref(); check_data(reporter, data, 1, kNotInCache, kLocked); data->unref(); // test with cache as last owner data = test_locking(reporter, size, useDiscardable ? pool.get() : nullptr); check_data(reporter, data, 2, kInCache, kLocked); data->unref(); check_data(reporter, data, 1, kInCache, kUnlocked); data->detachFromCacheAndUnref(); } }