skia2/tests/TLazyTest.cpp
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

78 lines
2.0 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/core/SkTLazy.h"
#include "tests/Test.h"
DEF_TEST(TLazy_copy, r) {
SkTLazy<int> lazy;
REPORTER_ASSERT(r, !lazy.isValid());
REPORTER_ASSERT(r, lazy.getMaybeNull() == nullptr);
{
SkTLazy<int> lazy_copy(lazy);
REPORTER_ASSERT(r, !lazy_copy.isValid());
REPORTER_ASSERT(r, lazy_copy.getMaybeNull() == nullptr);
}
lazy.init(42);
REPORTER_ASSERT(r, lazy.isValid());
REPORTER_ASSERT(r, 42 == *lazy.get());
{
SkTLazy<int> lazy_copy(lazy);
REPORTER_ASSERT(r, lazy_copy.isValid());
REPORTER_ASSERT(r, 42 == *lazy_copy.get());
REPORTER_ASSERT(r, lazy.get() != lazy_copy.get());
}
}
DEF_TEST(TCopyOnFirstWrite_copy, r) {
const int v = 42;
SkTCopyOnFirstWrite<int> cow(v);
REPORTER_ASSERT(r, 42 == *cow);
REPORTER_ASSERT(r, &v == cow.get());
{
SkTCopyOnFirstWrite<int> cow_copy(cow);
REPORTER_ASSERT(r, 42 == *cow_copy);
REPORTER_ASSERT(r, &v == cow_copy.get());
REPORTER_ASSERT(r, cow.get() == cow_copy.get());
*cow_copy.writable() = 43;
REPORTER_ASSERT(r, 42 == *cow);
REPORTER_ASSERT(r, &v == cow.get());
REPORTER_ASSERT(r, 43 == *cow_copy);
REPORTER_ASSERT(r, &v != cow_copy.get());
REPORTER_ASSERT(r, cow.get() != cow_copy.get());
}
*cow.writable() = 43;
REPORTER_ASSERT(r, 43 == *cow);
REPORTER_ASSERT(r, &v != cow.get());
{
SkTCopyOnFirstWrite<int> cow_copy(cow);
REPORTER_ASSERT(r, 43 == *cow_copy);
REPORTER_ASSERT(r, &v != cow_copy.get());
REPORTER_ASSERT(r, cow.get() != cow_copy.get());
*cow_copy.writable() = 44;
REPORTER_ASSERT(r, 43 == *cow);
REPORTER_ASSERT(r, &v != cow.get());
REPORTER_ASSERT(r, 44 == *cow_copy);
REPORTER_ASSERT(r, &v != cow_copy.get());
REPORTER_ASSERT(r, cow.get() != cow_copy.get());
}
}