flutter_flutter/engine/wtf/RefPtrTest.cpp
Eric Seidel 5bdc6515b9 Re-land 714393002 after fixing android build.
Original CL:
https://codereview.chromium.org/714393002

Reverted in:
https://codereview.chromium.org/719063002

One fix was to use static_assert instead
of _Static_assert in COMPILE_ASSERT.

_Static_assert is C11, static_assert is C++11
and Android's stdlib doesn't have C11 support,
but we don't care since we never use COMPILE_ASSERT
in plain C code.

The second fix was also for the android STL
and was adding back the nullptr_t type
definition in NullPtr.h for old versions of STL.

I compile this locally for android to verify
that it works
mojo/tools/mojob.py build --android

TBR=jamesr@chromium.org,qsr@chromium.org

Review URL: https://codereview.chromium.org/722723003
2014-11-12 12:16:05 -08:00

35 lines
908 B
C++

// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "wtf/RefPtr.h"
#include "wtf/text/StringImpl.h"
#include <gtest/gtest.h>
namespace {
TEST(RefPtrTest, Basic)
{
RefPtr<StringImpl> string;
EXPECT_TRUE(!string);
string = StringImpl::create("test");
EXPECT_TRUE(!!string);
string.clear();
EXPECT_TRUE(!string);
}
TEST(RefPtrTest, MoveAssignmentOperator)
{
RefPtr<StringImpl> a = StringImpl::create("a");
RefPtr<StringImpl> b = StringImpl::create("b");
// FIXME: Instead of explicitly casting to RefPtr<StringImpl>&& here, we should use std::move, but that
// requires us to have a standard library that supports move semantics.
b = static_cast<RefPtr<StringImpl>&&>(a);
EXPECT_TRUE(!!b);
EXPECT_TRUE(!a);
}
}