2015-04-26 20:40:01 +02:00
|
|
|
// Copyright (c) 2015 The Chromium Embedded Framework 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 "include/test/cef_translator_test.h"
|
2017-02-07 22:25:11 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
// Test getting/setting primitive types.
|
|
|
|
TEST(TranslatorTest, Primitive) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
|
|
|
obj->GetVoid(); // Does nothing, but shouldn't crash.
|
|
|
|
EXPECT_EQ(TEST_BOOL_VAL, obj->GetBool());
|
|
|
|
EXPECT_EQ(TEST_INT_VAL, obj->GetInt());
|
|
|
|
EXPECT_EQ(TEST_DOUBLE_VAL, obj->GetDouble());
|
|
|
|
EXPECT_EQ(TEST_LONG_VAL, obj->GetLong());
|
|
|
|
EXPECT_EQ(TEST_SIZET_VAL, obj->GetSizet());
|
|
|
|
EXPECT_TRUE(obj->SetVoid()); // Does nothing, but shouldn't crash.
|
|
|
|
EXPECT_TRUE(obj->SetBool(TEST_BOOL_VAL));
|
|
|
|
EXPECT_TRUE(obj->SetInt(TEST_INT_VAL));
|
|
|
|
EXPECT_TRUE(obj->SetDouble(TEST_DOUBLE_VAL));
|
|
|
|
EXPECT_TRUE(obj->SetLong(TEST_LONG_VAL));
|
|
|
|
EXPECT_TRUE(obj->SetSizet(TEST_SIZET_VAL));
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting primitive list types.
|
|
|
|
TEST(TranslatorTest, PrimitiveList) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
std::vector<int> list;
|
|
|
|
list.push_back(TEST_INT_VAL);
|
|
|
|
list.push_back(TEST_INT_VAL2);
|
|
|
|
EXPECT_TRUE(obj->SetIntList(list));
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
EXPECT_TRUE(obj->GetIntListByRef(list));
|
|
|
|
EXPECT_EQ(2U, list.size());
|
|
|
|
EXPECT_EQ(TEST_INT_VAL, list[0]);
|
|
|
|
EXPECT_EQ(TEST_INT_VAL2, list[1]);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting string types.
|
|
|
|
TEST(TranslatorTest, String) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
|
|
|
EXPECT_STREQ(TEST_STRING_VAL, obj->GetString().ToString().c_str());
|
|
|
|
EXPECT_TRUE(obj->SetString(TEST_STRING_VAL));
|
|
|
|
|
|
|
|
CefString str;
|
|
|
|
obj->GetStringByRef(str);
|
|
|
|
EXPECT_STREQ(TEST_STRING_VAL, str.ToString().c_str());
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting string list types.
|
|
|
|
TEST(TranslatorTest, StringList) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
std::vector<CefString> list;
|
|
|
|
list.push_back(TEST_STRING_VAL);
|
|
|
|
list.push_back(TEST_STRING_VAL2);
|
|
|
|
list.push_back(TEST_STRING_VAL3);
|
|
|
|
EXPECT_TRUE(obj->SetStringList(list));
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
EXPECT_TRUE(obj->GetStringListByRef(list));
|
|
|
|
EXPECT_EQ(3U, list.size());
|
|
|
|
EXPECT_STREQ(TEST_STRING_VAL, list[0].ToString().c_str());
|
|
|
|
EXPECT_STREQ(TEST_STRING_VAL2, list[1].ToString().c_str());
|
|
|
|
EXPECT_STREQ(TEST_STRING_VAL3, list[2].ToString().c_str());
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting string map types.
|
|
|
|
TEST(TranslatorTest, StringMap) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
CefTranslatorTest::StringMap map;
|
|
|
|
map.insert(std::make_pair(TEST_STRING_KEY, TEST_STRING_VAL));
|
|
|
|
map.insert(std::make_pair(TEST_STRING_KEY2, TEST_STRING_VAL2));
|
|
|
|
map.insert(std::make_pair(TEST_STRING_KEY3, TEST_STRING_VAL3));
|
|
|
|
EXPECT_TRUE(obj->SetStringMap(map));
|
|
|
|
|
|
|
|
map.clear();
|
|
|
|
EXPECT_TRUE(obj->GetStringMapByRef(map));
|
|
|
|
EXPECT_EQ(3U, map.size());
|
|
|
|
|
|
|
|
CefTranslatorTest::StringMap::const_iterator it;
|
|
|
|
|
|
|
|
it = map.find(TEST_STRING_KEY);
|
|
|
|
EXPECT_TRUE(it != map.end() && it->second == TEST_STRING_VAL);
|
|
|
|
it = map.find(TEST_STRING_KEY2);
|
|
|
|
EXPECT_TRUE(it != map.end() && it->second == TEST_STRING_VAL2);
|
|
|
|
it = map.find(TEST_STRING_KEY3);
|
|
|
|
EXPECT_TRUE(it != map.end() && it->second == TEST_STRING_VAL3);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting string multimap types.
|
|
|
|
TEST(TranslatorTest, StringMultimap) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
CefTranslatorTest::StringMultimap map;
|
|
|
|
map.insert(std::make_pair(TEST_STRING_KEY, TEST_STRING_VAL));
|
|
|
|
map.insert(std::make_pair(TEST_STRING_KEY2, TEST_STRING_VAL2));
|
|
|
|
map.insert(std::make_pair(TEST_STRING_KEY3, TEST_STRING_VAL3));
|
|
|
|
EXPECT_TRUE(obj->SetStringMultimap(map));
|
|
|
|
|
|
|
|
map.clear();
|
|
|
|
EXPECT_TRUE(obj->GetStringMultimapByRef(map));
|
|
|
|
EXPECT_EQ(3U, map.size());
|
|
|
|
|
|
|
|
CefTranslatorTest::StringMultimap::const_iterator it;
|
|
|
|
|
|
|
|
it = map.find(TEST_STRING_KEY);
|
|
|
|
EXPECT_TRUE(it != map.end() && it->second == TEST_STRING_VAL);
|
|
|
|
it = map.find(TEST_STRING_KEY2);
|
|
|
|
EXPECT_TRUE(it != map.end() && it->second == TEST_STRING_VAL2);
|
|
|
|
it = map.find(TEST_STRING_KEY3);
|
|
|
|
EXPECT_TRUE(it != map.end() && it->second == TEST_STRING_VAL3);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting struct types.
|
|
|
|
TEST(TranslatorTest, Struct) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
|
|
|
|
|
|
|
CefPoint point(TEST_X_VAL, TEST_Y_VAL);
|
|
|
|
EXPECT_EQ(point, obj->GetPoint());
|
|
|
|
EXPECT_TRUE(obj->SetPoint(point));
|
|
|
|
|
|
|
|
CefPoint point2;
|
|
|
|
obj->GetPointByRef(point2);
|
|
|
|
EXPECT_EQ(point, point2);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting struct list types.
|
|
|
|
TEST(TranslatorTest, StructList) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
std::vector<CefPoint> list;
|
|
|
|
list.push_back(CefPoint(TEST_X_VAL, TEST_Y_VAL));
|
|
|
|
list.push_back(CefPoint(TEST_X_VAL2, TEST_Y_VAL2));
|
|
|
|
EXPECT_TRUE(obj->SetPointList(list));
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
EXPECT_TRUE(obj->GetPointListByRef(list));
|
|
|
|
EXPECT_EQ(2U, list.size());
|
|
|
|
EXPECT_EQ(CefPoint(TEST_X_VAL, TEST_Y_VAL), list[0]);
|
|
|
|
EXPECT_EQ(CefPoint(TEST_X_VAL2, TEST_Y_VAL2), list[1]);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
// Test getting/setting library-side RefPtr types.
|
|
|
|
TEST(TranslatorTest, RefPtrLibrary) {
|
2015-04-26 20:40:01 +02:00
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kTestVal = 12;
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<CefTranslatorTestRefPtrLibrary> test_obj =
|
|
|
|
CefTranslatorTestRefPtrLibrary::Create(kTestVal);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
2017-02-07 22:25:11 +01:00
|
|
|
int retval = obj->SetRefPtrLibrary(test_obj);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kTestVal2 = 30;
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<CefTranslatorTestRefPtrLibrary> test_obj2 =
|
|
|
|
obj->GetRefPtrLibrary(kTestVal2);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetValue());
|
2017-02-07 22:25:11 +01:00
|
|
|
int retval2 = obj->SetRefPtrLibrary(test_obj2);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal2, retval2);
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetValue());
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(test_obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(test_obj2->HasOneRef());
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
// Test getting/setting inherited library-side RefPtr types.
|
|
|
|
TEST(TranslatorTest, RefPtrLibraryInherit) {
|
2015-04-26 20:40:01 +02:00
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kTestVal = 12;
|
|
|
|
const int kTestVal2 = 40;
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<CefTranslatorTestRefPtrLibraryChild> test_obj =
|
|
|
|
CefTranslatorTestRefPtrLibraryChild::Create(kTestVal, kTestVal2);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
2017-02-07 22:25:11 +01:00
|
|
|
int retval = obj->SetRefPtrLibrary(test_obj);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildRefPtrLibrary(test_obj));
|
|
|
|
EXPECT_EQ(kTestVal,
|
|
|
|
obj->SetChildRefPtrLibraryAndReturnParent(test_obj)->GetValue());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kTestVal3 = 100;
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<CefTranslatorTestRefPtrLibraryChildChild> test_obj2 =
|
|
|
|
CefTranslatorTestRefPtrLibraryChildChild::Create(kTestVal, kTestVal2,
|
|
|
|
kTestVal3);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, test_obj2->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
|
|
|
|
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
|
2017-02-07 22:25:11 +01:00
|
|
|
int retval2 = obj->SetRefPtrLibrary(test_obj2);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, retval2);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj2->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
|
|
|
|
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildRefPtrLibrary(test_obj2));
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal,
|
2017-02-07 22:25:11 +01:00
|
|
|
obj->SetChildRefPtrLibraryAndReturnParent(test_obj2)->GetValue());
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(test_obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(test_obj2->HasOneRef());
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
// Test getting/setting library-side RefPtr list types.
|
|
|
|
TEST(TranslatorTest, RefPtrLibraryList) {
|
2015-04-26 20:40:01 +02:00
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kVal1 = 34;
|
|
|
|
const int kVal2 = 10;
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<CefTranslatorTestRefPtrLibrary> val1 =
|
|
|
|
CefTranslatorTestRefPtrLibrary::Create(kVal1);
|
|
|
|
CefRefPtr<CefTranslatorTestRefPtrLibrary> val2 =
|
|
|
|
CefTranslatorTestRefPtrLibraryChild::Create(kVal2, 0);
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::vector<CefRefPtr<CefTranslatorTestRefPtrLibrary>> list;
|
2015-04-26 20:40:01 +02:00
|
|
|
list.push_back(val1);
|
|
|
|
list.push_back(val2);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(obj->SetRefPtrLibraryList(list, kVal1, kVal2));
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
list.clear();
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(obj->GetRefPtrLibraryListByRef(list, kVal1, kVal2));
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(2U, list.size());
|
|
|
|
EXPECT_EQ(kVal1, list[0]->GetValue());
|
|
|
|
EXPECT_EQ(kVal2, list[1]->GetValue());
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(val1->HasOneRef());
|
|
|
|
EXPECT_TRUE(val2->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
class TranslatorTestRefPtrClient : public CefTranslatorTestRefPtrClient {
|
2015-04-26 20:40:01 +02:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit TranslatorTestRefPtrClient(const int val) : val_(val) {}
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual int GetValue() override { return val_; }
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const int val_;
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
IMPLEMENT_REFCOUNTING(TranslatorTestRefPtrClient);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TranslatorTestRefPtrClient);
|
2015-04-26 20:40:01 +02:00
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class TranslatorTestRefPtrClientChild
|
|
|
|
: public CefTranslatorTestRefPtrClientChild {
|
2015-04-26 20:40:01 +02:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
TranslatorTestRefPtrClientChild(const int val, const int other_val)
|
|
|
|
: val_(val), other_val_(other_val) {}
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual int GetValue() override { return val_; }
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual int GetOtherValue() override { return other_val_; }
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const int val_;
|
|
|
|
const int other_val_;
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
IMPLEMENT_REFCOUNTING(TranslatorTestRefPtrClientChild);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TranslatorTestRefPtrClientChild);
|
2015-04-26 20:40:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
// Test getting/setting client-side RefPtr types.
|
|
|
|
TEST(TranslatorTest, RefPtrClient) {
|
2015-04-26 20:40:01 +02:00
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kTestVal = 12;
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<TranslatorTestRefPtrClient> test_obj =
|
|
|
|
new TranslatorTestRefPtrClient(kTestVal);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_EQ(kTestVal, obj->SetRefPtrClient(test_obj.get()));
|
|
|
|
CefRefPtr<CefTranslatorTestRefPtrClient> handler =
|
|
|
|
obj->SetRefPtrClientAndReturn(test_obj.get());
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(test_obj.get(), handler.get());
|
|
|
|
EXPECT_EQ(kTestVal, handler->GetValue());
|
2020-01-15 14:34:01 +01:00
|
|
|
handler = nullptr;
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(test_obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
// Test getting/setting inherited client-side RefPtr types.
|
|
|
|
TEST(TranslatorTest, RefPtrClientInherit) {
|
2015-04-26 20:40:01 +02:00
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kTestVal = 12;
|
|
|
|
const int kTestVal2 = 86;
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<TranslatorTestRefPtrClientChild> test_obj =
|
|
|
|
new TranslatorTestRefPtrClientChild(kTestVal, kTestVal2);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
2017-02-07 22:25:11 +01:00
|
|
|
int retval = obj->SetRefPtrClient(test_obj);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildRefPtrClient(test_obj));
|
|
|
|
CefRefPtr<CefTranslatorTestRefPtrClient> handler =
|
|
|
|
obj->SetChildRefPtrClientAndReturnParent(test_obj);
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(kTestVal, handler->GetValue());
|
|
|
|
EXPECT_EQ(test_obj.get(), handler.get());
|
2020-01-15 14:34:01 +01:00
|
|
|
handler = nullptr;
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(test_obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
// Test getting/setting client-side RefPtr list types.
|
|
|
|
TEST(TranslatorTest, RefPtrClientList) {
|
2015-04-26 20:40:01 +02:00
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-04-26 20:40:01 +02:00
|
|
|
const int kVal1 = 34;
|
|
|
|
const int kVal2 = 10;
|
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
CefRefPtr<CefTranslatorTestRefPtrClient> val1 =
|
|
|
|
new TranslatorTestRefPtrClient(kVal1);
|
|
|
|
CefRefPtr<CefTranslatorTestRefPtrClient> val2 =
|
|
|
|
new TranslatorTestRefPtrClientChild(kVal2, 0);
|
2015-04-26 20:40:01 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::vector<CefRefPtr<CefTranslatorTestRefPtrClient>> list;
|
2015-04-26 20:40:01 +02:00
|
|
|
list.push_back(val1);
|
|
|
|
list.push_back(val2);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(obj->SetRefPtrClientList(list, kVal1, kVal2));
|
2015-04-26 20:40:01 +02:00
|
|
|
|
|
|
|
list.clear();
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(obj->GetRefPtrClientListByRef(list, val1, val2));
|
2015-04-26 20:40:01 +02:00
|
|
|
EXPECT_EQ(2U, list.size());
|
|
|
|
EXPECT_EQ(kVal1, list[0]->GetValue());
|
|
|
|
EXPECT_EQ(val1.get(), list[0].get());
|
|
|
|
EXPECT_EQ(kVal2, list[1]->GetValue());
|
|
|
|
EXPECT_EQ(val2.get(), list[1].get());
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
EXPECT_TRUE(val1->HasOneRef());
|
|
|
|
EXPECT_TRUE(val2->HasOneRef());
|
|
|
|
}
|
2017-02-07 22:25:11 +01:00
|
|
|
|
|
|
|
// Test getting/setting library-side OwnPtr types.
|
|
|
|
TEST(TranslatorTest, OwnPtrLibrary) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibrary> test_obj =
|
|
|
|
CefTranslatorTestScopedLibrary::Create(kTestVal);
|
|
|
|
EXPECT_TRUE(test_obj.get());
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
int retval = obj->SetOwnPtrLibrary(test_obj.Pass());
|
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal2 = 30;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibrary> test_obj2 =
|
|
|
|
obj->GetOwnPtrLibrary(kTestVal2);
|
|
|
|
EXPECT_TRUE(test_obj2.get());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetValue());
|
|
|
|
int retval2 = obj->SetOwnPtrLibrary(test_obj2.Pass());
|
|
|
|
EXPECT_EQ(kTestVal2, retval2);
|
|
|
|
EXPECT_FALSE(test_obj2.get());
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting inherited library-side OwnPtr types.
|
|
|
|
TEST(TranslatorTest, OwnPtrLibraryInherit) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
const int kTestVal2 = 40;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibraryChild> test_obj =
|
|
|
|
CefTranslatorTestScopedLibraryChild::Create(kTestVal, kTestVal2);
|
|
|
|
EXPECT_TRUE(test_obj.get());
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
2017-05-17 11:29:28 +02:00
|
|
|
int retval =
|
|
|
|
obj->SetOwnPtrLibrary(test_obj.PassAs<CefTranslatorTestScopedLibrary>());
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
|
|
|
|
test_obj = CefTranslatorTestScopedLibraryChild::Create(kTestVal, kTestVal2);
|
|
|
|
EXPECT_TRUE(test_obj.get());
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildOwnPtrLibrary(test_obj.Pass()));
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
|
|
|
|
test_obj = CefTranslatorTestScopedLibraryChild::Create(kTestVal, kTestVal2);
|
|
|
|
EXPECT_TRUE(test_obj.get());
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibrary> test_obj_parent =
|
|
|
|
obj->SetChildOwnPtrLibraryAndReturnParent(test_obj.Pass());
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
EXPECT_TRUE(test_obj_parent.get());
|
|
|
|
EXPECT_EQ(kTestVal, test_obj_parent->GetValue());
|
2020-01-15 14:34:01 +01:00
|
|
|
test_obj_parent.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
|
|
|
|
const int kTestVal3 = 100;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibraryChildChild> test_obj2 =
|
|
|
|
CefTranslatorTestScopedLibraryChildChild::Create(kTestVal, kTestVal2,
|
|
|
|
kTestVal3);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj2->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
|
|
|
|
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
|
2017-05-17 11:29:28 +02:00
|
|
|
int retval2 =
|
|
|
|
obj->SetOwnPtrLibrary(test_obj2.PassAs<CefTranslatorTestScopedLibrary>());
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_EQ(kTestVal, retval2);
|
|
|
|
EXPECT_FALSE(test_obj2.get());
|
|
|
|
|
|
|
|
test_obj2 = CefTranslatorTestScopedLibraryChildChild::Create(
|
|
|
|
kTestVal, kTestVal2, kTestVal3);
|
2017-05-17 11:29:28 +02:00
|
|
|
EXPECT_EQ(kTestVal,
|
|
|
|
obj->SetChildOwnPtrLibrary(
|
|
|
|
test_obj2.PassAs<CefTranslatorTestScopedLibraryChild>()));
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_FALSE(test_obj2.get());
|
|
|
|
|
|
|
|
test_obj2 = CefTranslatorTestScopedLibraryChildChild::Create(
|
|
|
|
kTestVal, kTestVal2, kTestVal3);
|
|
|
|
test_obj_parent = obj->SetChildOwnPtrLibraryAndReturnParent(
|
|
|
|
test_obj2.PassAs<CefTranslatorTestScopedLibraryChild>());
|
|
|
|
EXPECT_FALSE(test_obj2.get());
|
|
|
|
EXPECT_TRUE(test_obj_parent.get());
|
|
|
|
EXPECT_EQ(kTestVal, test_obj_parent->GetValue());
|
2020-01-15 14:34:01 +01:00
|
|
|
test_obj_parent.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class TranslatorTestScopedClient : public CefTranslatorTestScopedClient {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
TranslatorTestScopedClient(const int val, TrackCallback* got_delete)
|
|
|
|
: val_(val), got_delete_(got_delete) {}
|
|
|
|
~TranslatorTestScopedClient() override { got_delete_->yes(); }
|
|
|
|
|
|
|
|
virtual int GetValue() override { return val_; }
|
2017-02-07 22:25:11 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
const int val_;
|
|
|
|
TrackCallback* got_delete_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TranslatorTestScopedClient);
|
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class TranslatorTestScopedClientChild
|
|
|
|
: public CefTranslatorTestScopedClientChild {
|
2017-02-07 22:25:11 +01:00
|
|
|
public:
|
|
|
|
TranslatorTestScopedClientChild(const int val,
|
|
|
|
const int other_val,
|
|
|
|
TrackCallback* got_delete)
|
2017-05-17 11:29:28 +02:00
|
|
|
: val_(val), other_val_(other_val), got_delete_(got_delete) {}
|
|
|
|
~TranslatorTestScopedClientChild() override { got_delete_->yes(); }
|
|
|
|
|
|
|
|
virtual int GetValue() override { return val_; }
|
|
|
|
|
|
|
|
virtual int GetOtherValue() override { return other_val_; }
|
2017-02-07 22:25:11 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
const int val_;
|
|
|
|
const int other_val_;
|
|
|
|
TrackCallback* got_delete_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TranslatorTestScopedClientChild);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test getting/setting client-side OwnPtr types.
|
|
|
|
TEST(TranslatorTest, OwnPtrClient) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
TrackCallback got_delete;
|
|
|
|
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedClient> test_obj(
|
|
|
|
new TranslatorTestScopedClient(kTestVal, &got_delete));
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetOwnPtrClient(test_obj.Pass()));
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
EXPECT_TRUE(got_delete);
|
|
|
|
|
|
|
|
got_delete.reset();
|
|
|
|
test_obj.reset(new TranslatorTestScopedClient(kTestVal, &got_delete));
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedClient> handler =
|
|
|
|
obj->SetOwnPtrClientAndReturn(test_obj.Pass());
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
EXPECT_TRUE(handler.get());
|
|
|
|
EXPECT_FALSE(got_delete);
|
|
|
|
EXPECT_EQ(kTestVal, handler->GetValue());
|
2020-01-15 14:34:01 +01:00
|
|
|
handler.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(got_delete);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting inherited client-side OwnPtr types.
|
|
|
|
TEST(TranslatorTest, OwnPtrClientInherit) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
const int kTestVal2 = 86;
|
|
|
|
TrackCallback got_delete;
|
|
|
|
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedClientChild> test_obj(
|
|
|
|
new TranslatorTestScopedClientChild(kTestVal, kTestVal2, &got_delete));
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetOwnPtrClient(
|
2017-05-17 11:29:28 +02:00
|
|
|
test_obj.PassAs<CefTranslatorTestScopedClient>()));
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
EXPECT_TRUE(got_delete);
|
|
|
|
|
|
|
|
got_delete.reset();
|
|
|
|
test_obj.reset(
|
|
|
|
new TranslatorTestScopedClientChild(kTestVal, kTestVal2, &got_delete));
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildOwnPtrClient(test_obj.Pass()));
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
EXPECT_TRUE(got_delete);
|
|
|
|
|
|
|
|
got_delete.reset();
|
|
|
|
test_obj.reset(
|
|
|
|
new TranslatorTestScopedClientChild(kTestVal, kTestVal2, &got_delete));
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedClient> handler(
|
|
|
|
obj->SetChildOwnPtrClientAndReturnParent(test_obj.Pass()));
|
|
|
|
EXPECT_EQ(kTestVal, handler->GetValue());
|
|
|
|
EXPECT_FALSE(test_obj.get());
|
|
|
|
EXPECT_FALSE(got_delete);
|
2020-01-15 14:34:01 +01:00
|
|
|
handler.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(got_delete);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting library-side RawPtr types.
|
|
|
|
TEST(TranslatorTest, RawPtrLibrary) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibrary> test_obj(
|
|
|
|
CefTranslatorTestScopedLibrary::Create(kTestVal));
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
int retval = obj->SetRawPtrLibrary(test_obj.get());
|
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
|
|
|
|
const int kTestVal2 = 30;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibrary> test_obj2(
|
|
|
|
obj->GetOwnPtrLibrary(kTestVal2));
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetValue());
|
|
|
|
int retval2 = obj->SetRawPtrLibrary(test_obj2.get());
|
|
|
|
EXPECT_EQ(kTestVal2, retval2);
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetValue());
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting inherited library-side RawPtr types.
|
|
|
|
TEST(TranslatorTest, RawPtrLibraryInherit) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
const int kTestVal2 = 40;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibraryChild> test_obj(
|
|
|
|
CefTranslatorTestScopedLibraryChild::Create(kTestVal, kTestVal2));
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
|
|
|
int retval = obj->SetRawPtrLibrary(test_obj.get());
|
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
|
|
|
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildRawPtrLibrary(test_obj.get()));
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal3 = 100;
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibraryChildChild> test_obj2(
|
|
|
|
CefTranslatorTestScopedLibraryChildChild::Create(kTestVal, kTestVal2,
|
|
|
|
kTestVal3));
|
|
|
|
EXPECT_EQ(kTestVal, test_obj2->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
|
|
|
|
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
|
|
|
|
int retval2 = obj->SetRawPtrLibrary(test_obj2.get());
|
|
|
|
EXPECT_EQ(kTestVal, retval2);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj2->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj2->GetOtherValue());
|
|
|
|
EXPECT_EQ(kTestVal3, test_obj2->GetOtherOtherValue());
|
|
|
|
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildRawPtrLibrary(test_obj2.get()));
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting library-side RawPtr list types.
|
|
|
|
TEST(TranslatorTest, RawPtrLibraryList) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kVal1 = 34;
|
|
|
|
const int kVal2 = 10;
|
|
|
|
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibrary> val1(
|
|
|
|
CefTranslatorTestScopedLibrary::Create(kVal1));
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedLibraryChild> val2(
|
|
|
|
CefTranslatorTestScopedLibraryChild::Create(kVal2, 0));
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::vector<CefRawPtr<CefTranslatorTestScopedLibrary>> list;
|
2017-02-07 22:25:11 +01:00
|
|
|
list.push_back(val1.get());
|
|
|
|
list.push_back(val2.get());
|
|
|
|
EXPECT_TRUE(obj->SetRawPtrLibraryList(list, kVal1, kVal2));
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting client-side RawPtr types.
|
|
|
|
TEST(TranslatorTest, RawPtrClient) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
TrackCallback got_delete;
|
|
|
|
|
|
|
|
CefOwnPtr<TranslatorTestScopedClient> test_obj(
|
|
|
|
new TranslatorTestScopedClient(kTestVal, &got_delete));
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetRawPtrClient(test_obj.get()));
|
|
|
|
EXPECT_FALSE(got_delete);
|
2020-01-15 14:34:01 +01:00
|
|
|
test_obj.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(got_delete);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting inherited client-side RawPtr types.
|
|
|
|
TEST(TranslatorTest, RawPtrClientInherit) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kTestVal = 12;
|
|
|
|
const int kTestVal2 = 86;
|
|
|
|
TrackCallback got_delete;
|
|
|
|
|
|
|
|
CefOwnPtr<TranslatorTestScopedClientChild> test_obj(
|
|
|
|
new TranslatorTestScopedClientChild(kTestVal, kTestVal2, &got_delete));
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
|
|
|
int retval = obj->SetRawPtrClient(test_obj.get());
|
|
|
|
EXPECT_EQ(kTestVal, retval);
|
|
|
|
EXPECT_EQ(kTestVal, test_obj->GetValue());
|
|
|
|
EXPECT_EQ(kTestVal2, test_obj->GetOtherValue());
|
|
|
|
EXPECT_FALSE(got_delete);
|
|
|
|
|
|
|
|
EXPECT_EQ(kTestVal, obj->SetChildRawPtrClient(test_obj.get()));
|
|
|
|
EXPECT_FALSE(got_delete);
|
2020-01-15 14:34:01 +01:00
|
|
|
test_obj.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(got_delete);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test getting/setting client-side RawPtr list types.
|
|
|
|
TEST(TranslatorTest, RawPtrClientList) {
|
|
|
|
CefRefPtr<CefTranslatorTest> obj = CefTranslatorTest::Create();
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-07 22:25:11 +01:00
|
|
|
const int kVal1 = 34;
|
|
|
|
const int kVal2 = 10;
|
|
|
|
TrackCallback got_delete1, got_delete2;
|
|
|
|
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedClient> val1(
|
|
|
|
new TranslatorTestScopedClient(kVal1, &got_delete1));
|
|
|
|
CefOwnPtr<CefTranslatorTestScopedClient> val2(
|
|
|
|
new TranslatorTestScopedClientChild(kVal2, 0, &got_delete2));
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
std::vector<CefRawPtr<CefTranslatorTestScopedClient>> list;
|
2017-02-07 22:25:11 +01:00
|
|
|
list.push_back(val1.get());
|
|
|
|
list.push_back(val2.get());
|
|
|
|
EXPECT_TRUE(obj->SetRawPtrClientList(list, kVal1, kVal2));
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
EXPECT_FALSE(got_delete1);
|
2020-01-15 14:34:01 +01:00
|
|
|
val1.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(got_delete1);
|
|
|
|
|
|
|
|
EXPECT_FALSE(got_delete2);
|
2020-01-15 14:34:01 +01:00
|
|
|
val2.reset(nullptr);
|
2017-02-07 22:25:11 +01:00
|
|
|
EXPECT_TRUE(got_delete2);
|
|
|
|
|
|
|
|
// Only one reference to the object should exist.
|
|
|
|
EXPECT_TRUE(obj->HasOneRef());
|
|
|
|
}
|