skia2/tests/VptrTest.cpp
John Stiles a6841be235 Enable ClangTidy check llvm-namespace-comment.
This fixes a large number of SkSL namespaces which were labeled as if
they were anonymous, and also a handful of other mislabeled namespaces.
Missing namespace-end comments have been added throughout.
A number of diffs are just indentation-related (adjusting 1- or 3-
space indents to 2-space).

Change-Id: I6c62052a0d3aea4ae12ca07e0c2a8587b2fce4ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308503
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-06 19:07:52 +00:00

61 lines
1.6 KiB
C++

/*
* Copyright 2017 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/SkVptr.h"
#include "tests/Test.h"
namespace {
struct Base {
virtual ~Base() = default;
virtual size_t val() const = 0;
};
struct SubclassA : public Base {
SubclassA(size_t val) : fVal(val) {}
size_t val() const override { return fVal; }
size_t fVal;
};
struct SubclassB : public Base {
SubclassB() {}
size_t val() const override { return 42; }
};
} // namespace
DEF_TEST(Vptr, r) {
std::unique_ptr<Base> a = std::make_unique<SubclassA>(21),
b = std::make_unique<SubclassB>(),
c = std::make_unique<SubclassA>(22),
d = std::make_unique<SubclassB>();
// These 4 objects all have unique identities.
REPORTER_ASSERT(r, a != b);
REPORTER_ASSERT(r, a != c);
REPORTER_ASSERT(r, a != d);
REPORTER_ASSERT(r, b != c);
REPORTER_ASSERT(r, b != d);
REPORTER_ASSERT(r, c != d);
// Only b and d have the same val().
REPORTER_ASSERT(r, a->val() != b->val());
REPORTER_ASSERT(r, a->val() != c->val());
REPORTER_ASSERT(r, a->val() != d->val());
REPORTER_ASSERT(r, b->val() != c->val());
REPORTER_ASSERT(r, b->val() == d->val());
REPORTER_ASSERT(r, c->val() != d->val());
// SkVptr() returns the same value for objects of the same concrete type.
REPORTER_ASSERT(r, SkVptr(*a) == SkVptr(*c));
REPORTER_ASSERT(r, SkVptr(*b) == SkVptr(*d));
REPORTER_ASSERT(r, SkVptr(*a) != SkVptr(*b));
}