skia2/tests/CPlusPlusEleven.cpp
halcanary 4871f22777 SkPDF: Glyph validation change
Instead of mapping invaid glyphIDs to zero or maxGlyphID,
don't draw them at all.

Validate glyphs when glyph is written, not ahead of time.

Don't allocate array to copy user-provided glyphs.

Easy early exit from SkPDFDevice::internalDrawText()
    GlyphPositioner::flush() called ~GlyphPositioner()
    SkScopeExit class now exists.

Assume SkTypeface* pointers are now never null in more
places.

precalculate alignmentFactor to clean up code.

SkPDFDevice::updateFont must be called with validated
glyphID.  Skip bad glyphs to make this true.

SkPDFDevice::updateFont always succeeds.

SkPDFFont::GetFontResource always succeeds (preconditions are
asserted).  If GetMetrics fails, don't call GetFontResource.

SkPDFFont::glyphsToPDFFontEncodingCount() becomes
SkPDFFont::countStretch() and is inlined.

SkPDFFont::glyphsToPDFFontEncoding now works one Glyph at a
time and is inlined.

SkPDFFont::noteGlyphUsage() operates one glyph at a time.

Add SkScopeExit.h; also a unit test for it.

SkPostConfig: Fix SK_UNUSED for Win32.

No public API changes.
TBR=reed@google.com

BUG=625995

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2278703002

Review-Url: https://codereview.chromium.org/2278703002
2016-08-26 13:17:44 -07:00

68 lines
1.6 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Test.h"
#include "SkTemplates.h"
#include "SkScopeExit.h"
#include <utility>
namespace {
class Moveable {
public:
Moveable() {}
Moveable(Moveable&&) {}
Moveable& operator=(Moveable&&) { return *this; }
private:
Moveable(const Moveable&);
Moveable& operator=(const Moveable&);
};
template <typename T> void deleter(T*) { }
template <typename T> struct Deleter {
void operator()(T* t) { delete static_cast<const Moveable*>(t); }
};
} // namespace
DEF_TEST(CPlusPlusEleven_RvalueAndMove, r) {
Moveable src1; Moveable dst1(std::move(src1));
Moveable src2, dst2; dst2 = std::move(src2);
}
DEF_TEST(CPlusPlusEleven_constexpr, r) {
static constexpr int x = Sk32ToBool(50);
REPORTER_ASSERT(r, x == 1);
static constexpr int y = SkTPin<int>(100, 0, 10);
REPORTER_ASSERT(r, y == 10);
}
namespace {
struct MoveableCopyable {
bool fCopied;
MoveableCopyable() : fCopied(false) {}
MoveableCopyable(const MoveableCopyable &o) : fCopied(true) {}
MoveableCopyable(MoveableCopyable &&o) : fCopied(o.fCopied) {}
};
struct TestClass {
MoveableCopyable fFoo;
};
} // namespace
DEF_TEST(CPlusPlusEleven_default_move, r) {
TestClass a;
TestClass b(a);
TestClass c(std::move(a));
REPORTER_ASSERT(r, b.fFoo.fCopied);
REPORTER_ASSERT(r, !c.fFoo.fCopied);
}
DEF_TEST(SkAtScopeExit, r) {
int x = 5;
{
SK_AT_SCOPE_EXIT(x--);
REPORTER_ASSERT(r, x == 5);
}
REPORTER_ASSERT(r, x == 4);
}