2016-01-25 03:49:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2018-04-17 18:14:51 +00:00
|
|
|
|
2016-08-26 20:17:44 +00:00
|
|
|
#include "SkScopeExit.h"
|
2018-04-17 18:14:51 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2016-01-25 03:49:24 +00:00
|
|
|
#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);
|
|
|
|
}
|
2016-05-23 16:11:58 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2016-08-03 18:16:56 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2016-08-26 20:17:44 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkAtScopeExit, r) {
|
|
|
|
int x = 5;
|
|
|
|
{
|
|
|
|
SK_AT_SCOPE_EXIT(x--);
|
|
|
|
REPORTER_ASSERT(r, x == 5);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(r, x == 4);
|
|
|
|
}
|