Commit f755d8be authored by Ronan's avatar Ronan

feat(tests): add a clonable object test

parent 76c884ab
......@@ -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
......
......@@ -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_pointer<decltype(mPrivate->mPublic)>::type;
mPrivate->mPublic = new remove_pointer<decltype(mPrivate->mPublic)>::type();
(*mPrivate->mPublic)[mPrivate] = this;
mPrivate->ref();
}
......
......@@ -193,6 +193,7 @@ set(SOURCE_FILES_C
)
set(SOURCE_FILES_CXX
clonable-object-tester.cpp
cpim-tester.cpp
)
......
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
};
......@@ -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;
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment