From f755d8bee8aa097ec786ff3ede0087e37204309f Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 5 Sep 2017 17:37:01 +0200 Subject: [PATCH] feat(tests): add a clonable object test --- src/object/clonable-object-p.h | 5 +++ src/object/clonable-object.cpp | 2 +- tester/CMakeLists.txt | 1 + tester/clonable-object-tester.cpp | 66 +++++++++++++++++++++++++++++++ tester/liblinphone_tester.h | 1 + tester/tester.c | 1 + 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tester/clonable-object-tester.cpp diff --git a/src/object/clonable-object-p.h b/src/object/clonable-object-p.h index e8ec31f98..7d507599f 100644 --- a/src/object/clonable-object-p.h +++ b/src/object/clonable-object-p.h @@ -29,6 +29,7 @@ LINPHONE_BEGIN_NAMESPACE class ClonableObjectPrivate { public: + ClonableObjectPrivate () = default; virtual ~ClonableObjectPrivate () = default; protected: @@ -41,6 +42,10 @@ private: int nRefs = 0; L_DECLARE_PUBLIC(ClonableObject); + + // It's forbidden to copy directly one Clonable object private. + // To allow copy, you must define copy constructor in inherited object. + L_DISABLE_COPY(ClonableObjectPrivate); }; LINPHONE_END_NAMESPACE diff --git a/src/object/clonable-object.cpp b/src/object/clonable-object.cpp index 1eb46a512..45412dc88 100644 --- a/src/object/clonable-object.cpp +++ b/src/object/clonable-object.cpp @@ -45,7 +45,7 @@ ClonableObject::ClonableObject (ClonableObjectPrivate &p) : mPrivate(&p) { // Q-pointer must be empty. It's a constructor that takes a new private data. L_ASSERT(!mPrivate->mPublic); - mPrivate->mPublic = new remove_pointermPublic)>::type; + mPrivate->mPublic = new remove_pointermPublic)>::type(); (*mPrivate->mPublic)[mPrivate] = this; mPrivate->ref(); } diff --git a/tester/CMakeLists.txt b/tester/CMakeLists.txt index 47af53d63..a66b026cf 100644 --- a/tester/CMakeLists.txt +++ b/tester/CMakeLists.txt @@ -193,6 +193,7 @@ set(SOURCE_FILES_C ) set(SOURCE_FILES_CXX + clonable-object-tester.cpp cpim-tester.cpp ) diff --git a/tester/clonable-object-tester.cpp b/tester/clonable-object-tester.cpp new file mode 100644 index 000000000..28264732d --- /dev/null +++ b/tester/clonable-object-tester.cpp @@ -0,0 +1,66 @@ +/* + * clonable-object-tester.cpp + * Copyright (C) 2017 Belledonne Communications SARL + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "object/clonable-object-p.h" +#include "object/clonable-object.h" + +#include "liblinphone_tester.h" + +// ============================================================================= + +using namespace std; + +using namespace LinphonePrivate; + +// ----------------------------------------------------------------------------- + +class TestObjectPrivate : public ClonableObjectPrivate { +public: + TestObjectPrivate () = default; + + TestObjectPrivate (const TestObjectPrivate &) : TestObjectPrivate() {} +}; + +class TestObject : public ClonableObject { +public: + TestObject () : ClonableObject(*new TestObjectPrivate) {} + + TestObject (const TestObject &src) : ClonableObject(*new TestObjectPrivate(*src.getPrivate())) {} + +private: + L_DECLARE_PRIVATE(TestObject); +}; + +// ----------------------------------------------------------------------------- + +static void check_clonable_object_creation () { + TestObject *object = new TestObject(); + TestObject *object2 = new TestObject(*object); + + delete object; + delete object2; +} + +test_t clonable_object_tests[] = { + TEST_NO_TAG("Check clonable object creation", check_clonable_object_creation) +}; + +test_suite_t clonable_object_test_suite = { + "ClonableObject", NULL, NULL, liblinphone_tester_before_each, liblinphone_tester_after_each, + sizeof(clonable_object_tests) / sizeof(clonable_object_tests[0]), clonable_object_tests +}; diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index 95c034e24..058aaa66e 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -42,6 +42,7 @@ extern "C" { extern test_suite_t account_creator_test_suite; extern test_suite_t call_test_suite; extern test_suite_t call_video_test_suite; +extern test_suite_t clonable_object_test_suite; extern test_suite_t cpim_test_suite; extern test_suite_t dtmf_test_suite; extern test_suite_t event_test_suite; diff --git a/tester/tester.c b/tester/tester.c index 996c99f81..a3bfdddd6 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -574,6 +574,7 @@ void liblinphone_tester_add_suites() { bc_tester_add_suite(&player_test_suite); bc_tester_add_suite(&dtmf_test_suite); bc_tester_add_suite(&cpim_test_suite); + bc_tester_add_suite(&clonable_object_test_suite); #if defined(VIDEO_ENABLED) && defined(HAVE_GTK) bc_tester_add_suite(&video_test_suite); #endif