/* RESULT
=== ObjectPimpl *myobj = new ObjectPimpl() ===
-Constructor 'ObjectPimplPrivate' : example::ObjectPimplPrivate::ObjectPimplPrivate(example::ObjectPimpl*)
-Constructor 'ObjectPimpl' : example::ObjectPimpl::ObjectPimpl()
+Constructor 'ObjectPimplPrivate' : ObjectPimplPrivate::ObjectPimplPrivate(ObjectPimpl*)
+Constructor 'ObjectPimpl' : ObjectPimpl::ObjectPimpl()
=== ObjectPimpl *myobj2 = new ObjectPimpl() ===
-Constructor 'ObjectPimplPrivate' : example::ObjectPimplPrivate::ObjectPimplPrivate(example::ObjectPimpl*)
-Constructor 'ObjectPimpl' : example::ObjectPimpl::ObjectPimpl()
+Constructor 'ObjectPimplPrivate' : ObjectPimplPrivate::ObjectPimplPrivate(ObjectPimpl*)
+Constructor 'ObjectPimpl' : ObjectPimpl::ObjectPimpl()
=== delete myobj ===
-Destructor 'ObjectPimpl' : virtual example::ObjectPimpl::~ObjectPimpl()
-Destructor 'ObjectPimplPrivate' : virtual example::ObjectPimplPrivate::~ObjectPimplPrivate()
+Destructor 'ObjectPimpl' : virtual ObjectPimpl::~ObjectPimpl()
+Destructor 'ObjectPimplPrivate' : virtual ObjectPimplPrivate::~ObjectPimplPrivate()
=== delete myobj2 ===
-Destructor 'ObjectPimpl' : virtual example::ObjectPimpl::~ObjectPimpl()
-Destructor 'ObjectPimplPrivate' : virtual example::ObjectPimplPrivate::~ObjectPimplPrivate()
+Destructor 'ObjectPimpl' : virtual ObjectPimpl::~ObjectPimpl()
+Destructor 'ObjectPimplPrivate' : virtual ObjectPimplPrivate::~ObjectPimplPrivate()
*/
-namespace example {
- class ObjectPimpl;
-
- class ObjectPimplPrivate : public display_server::DSObjectPrivate {
- public:
- ObjectPimplPrivate() = delete;
- ObjectPimplPrivate(ObjectPimpl *p_ptr);
- ~ObjectPimplPrivate();
- };
-
- class ObjectPimpl : public display_server::DSObject {
- public:
- explicit ObjectPimpl();
- virtual ~ObjectPimpl();
-
- private:
- inline ObjectPimplPrivate *d_func()
- {
- return reinterpret_cast<ObjectPimplPrivate *>(__d_ptr.get());
- }
- inline const ObjectPimplPrivate *d_func() const
- {
- return reinterpret_cast<ObjectPimplPrivate *>(__d_ptr.get());
- }
- friend class ObjectPimplPrivate;
- };
-
- ObjectPimplPrivate::ObjectPimplPrivate(ObjectPimpl *p_ptr) :
- display_server::DSObjectPrivate(p_ptr)
- {
- std::cout << "Constructor 'ObjectPimplPrivate' : " << __PRETTY_FUNCTION__ << std::endl;
- }
+using namespace display_server;
- ObjectPimplPrivate::~ObjectPimplPrivate()
- {
- std::cout << "Destructor 'ObjectPimplPrivate' : " << __PRETTY_FUNCTION__ << std::endl;
- }
+class ObjectPimpl;
+
+class ObjectPimplPrivate : public DSObjectPrivate {
+public:
+ ObjectPimplPrivate() = delete;
+ ObjectPimplPrivate(ObjectPimpl *p_ptr);
+ ~ObjectPimplPrivate();
+};
+
+class ObjectPimpl : public DSObject {
+public:
+ explicit ObjectPimpl();
+ virtual ~ObjectPimpl();
- ObjectPimpl::ObjectPimpl() :
- display_server::DSObject(std::make_unique<ObjectPimplPrivate>(this))
+private:
+ inline ObjectPimplPrivate *d_func()
{
- std::cout << "Constructor 'ObjectPimpl' : " << __PRETTY_FUNCTION__ << std::endl;
+ return reinterpret_cast<ObjectPimplPrivate *>(__d_ptr.get());
}
-
- ObjectPimpl::~ObjectPimpl()
+ inline const ObjectPimplPrivate *d_func() const
{
- std::cout << "Destructor 'ObjectPimpl' : " << __PRETTY_FUNCTION__ << std::endl;
+ return reinterpret_cast<ObjectPimplPrivate *>(__d_ptr.get());
}
+ friend class ObjectPimplPrivate;
+};
- int exampleObjectPimpl(void)
- {
- std::cout << "\n=== ObjectPimpl *myobj = new ObjectPimpl() ===" << std::endl;
- ObjectPimpl *myobj = new ObjectPimpl();
+ObjectPimplPrivate::ObjectPimplPrivate(ObjectPimpl *p_ptr) :
+ DSObjectPrivate(p_ptr)
+{
+ std::cout << "Constructor 'ObjectPimplPrivate' : " << __PRETTY_FUNCTION__ << std::endl;
+}
- std::cout << "\n=== ObjectPimpl *myobj2 = new ObjectPimpl() ===" << std::endl;
- ObjectPimpl *myobj2 = new ObjectPimpl();
+ObjectPimplPrivate::~ObjectPimplPrivate()
+{
+ std::cout << "Destructor 'ObjectPimplPrivate' : " << __PRETTY_FUNCTION__ << std::endl;
+}
- std::cout << "\n=== delete myobj ===" << std::endl;
- delete myobj;
+ObjectPimpl::ObjectPimpl() :
+ DSObject(std::make_unique<ObjectPimplPrivate>(this))
+{
+ std::cout << "Constructor 'ObjectPimpl' : " << __PRETTY_FUNCTION__ << std::endl;
+}
- std::cout << "\n=== delete myobj2 ===" << std::endl;
- delete myobj2;
+ObjectPimpl::~ObjectPimpl()
+{
+ std::cout << "Destructor 'ObjectPimpl' : " << __PRETTY_FUNCTION__ << std::endl;
+}
- return 0;
- }
-} // namespace example
+int exampleObjectPimpl(void)
+{
+ std::cout << "\n=== ObjectPimpl *myobj = new ObjectPimpl() ===" << std::endl;
+ ObjectPimpl *myobj = new ObjectPimpl();
+
+ std::cout << "\n=== ObjectPimpl *myobj2 = new ObjectPimpl() ===" << std::endl;
+ ObjectPimpl *myobj2 = new ObjectPimpl();
+
+ std::cout << "\n=== delete myobj ===" << std::endl;
+ delete myobj;
+
+ std::cout << "\n=== delete myobj2 ===" << std::endl;
+ delete myobj2;
+
+ return 0;
+}
int main()
{
- return example::exampleObjectPimpl();
+ return exampleObjectPimpl();
}
/* RESULT
=== Property *myproperty = new Property() ===
-Constructor 'Property' : example::Property::Property()
+Constructor 'Property' : Property::Property()
=== Property *myproperty2 = new Property() ===
-Constructor 'Property' : example::Property::Property()
+Constructor 'Property' : Property::Property()
=== Add Property [myProperty:1234(int)] to myproperty
Try get Property (key:"myProperty", type:int) of myproperty
SUCCESS: NOT_EXIST
=== delete myproperty ===
-Destructor 'Property' : virtual example::Property::~Property()
+Destructor 'Property' : virtual Property::~Property()
=== delete myproperty2 ===
-Destructor 'Property' : virtual example::Property::~Property()
+Destructor 'Property' : virtual Property::~Property()
*/
-namespace example {
- class Property : public display_server::DSObject {
- public:
- explicit Property();
- virtual ~Property();
- };
+using namespace display_server;
- Property::Property()
- {
- std::cout << "Constructor 'Property' : " << __PRETTY_FUNCTION__ << std::endl;
+class Property : public DSObject {
+public:
+ explicit Property();
+ virtual ~Property();
+};
+
+Property::Property()
+{
+ std::cout << "Constructor 'Property' : " << __PRETTY_FUNCTION__ << std::endl;
+}
+
+Property::~Property()
+{
+ std::cout << "Destructor 'Property' : " << __PRETTY_FUNCTION__ << std::endl;
+}
+
+int main()
+{
+ std::cout << "\n=== Property *myproperty = new Property() ===" << std::endl;
+ Property *myproperty = new Property();
+
+ std::cout << "\n=== Property *myproperty2 = new Property() ===" << std::endl;
+ Property *myproperty2 = new Property();
+
+ std::cout << "\n=== Add Property [myProperty:1234(int)] to myproperty ===" << std::endl;
+ myproperty->setProperty("myProperty", 1234, DSPropertyType::INTEGER);
+ try {
+ std::cout << "Try get Property (key:\"myProperty\", type:int) of myproperty" << std::endl;
+ std::cout << "myProperty: " << std::get<int>(myproperty->getProperty("myProperty")) << std::endl;
+ }
+ catch (std::exception &e) {
+ std::cout << "ERR: " << e.what() << std::endl;
+ }
+ try {
+ std::cout << "Try get Property (key:\"myProperty\", type:float) of myproperty" << std::endl;
+ std::cout << std::get<float>(myproperty->getProperty("myProperty")) << std::endl;
+ }
+ catch (std::exception &e) {
+ std::cout << "ERR: " << e.what() << std::endl;
}
- Property::~Property()
- {
- std::cout << "Destructor 'Property' : " << __PRETTY_FUNCTION__ << std::endl;
+ std::cout << "\n=== Add Property [myProperty:" << myproperty2 << "(ptr)] to myproperty ===" << std::endl;
+ myproperty->setProperty("myProperty", static_cast<void *>(myproperty2), DSPropertyType::POINTER);
+ try {
+ std::cout << "Try get Property (key:\"myProperty\", type:int) of myproperty" << std::endl;
+ std::cout << std::get<int>(myproperty->getProperty("myProperty")) << std::endl;
+ }
+ catch (std::exception &e) {
+ std::cout << "ERR: " << e.what() << std::endl;
+ }
+ try {
+ std::cout << "Try get Property (key:\"myProperty\", type:void *) of myproperty" << std::endl;
+ Property *mypropertyptr = static_cast<Property *>(std::get<void *>(myproperty->getProperty("myProperty")));
+ std::cout << "myProperty: " << mypropertyptr << std::endl;
+ }
+ catch (std::exception &e) {
+ std::cout << "ERR: " << e.what() << std::endl;
}
- int exampleProperty(void)
- {
- std::cout << "\n=== Property *myproperty = new Property() ===" << std::endl;
- Property *myproperty = new Property();
-
- std::cout << "\n=== Property *myproperty2 = new Property() ===" << std::endl;
- Property *myproperty2 = new Property();
-
- std::cout << "\n=== Add Property [myProperty:1234(int)] to myproperty ===" << std::endl;
- myproperty->setProperty("myProperty", 1234, display_server::DSPropertyType::INTEGER);
- try {
- std::cout << "Try get Property (key:\"myProperty\", type:int) of myproperty" << std::endl;
- std::cout << "myProperty: " << std::get<int>(myproperty->getProperty("myProperty")) << std::endl;
- }
- catch (std::exception &e) {
- std::cout << "ERR: " << e.what() << std::endl;
- }
- try {
- std::cout << "Try get Property (key:\"myProperty\", type:float) of myproperty" << std::endl;
- std::cout << std::get<float>(myproperty->getProperty("myProperty")) << std::endl;
- }
- catch (std::exception &e) {
- std::cout << "ERR: " << e.what() << std::endl;
- }
-
- std::cout << "\n=== Add Property [myProperty:" << myproperty2 << "(ptr)] to myproperty ===" << std::endl;
- myproperty->setProperty("myProperty", static_cast<void *>(myproperty2), display_server::DSPropertyType::POINTER);
- try {
- std::cout << "Try get Property (key:\"myProperty\", type:int) of myproperty" << std::endl;
- std::cout << std::get<int>(myproperty->getProperty("myProperty")) << std::endl;
- }
- catch (std::exception &e) {
- std::cout << "ERR: " << e.what() << std::endl;
- }
- try {
- std::cout << "Try get Property (key:\"myProperty\", type:void *) of myproperty" << std::endl;
- Property *mypropertyptr = static_cast<Property *>(std::get<void *>(myproperty->getProperty("myProperty")));
- std::cout << "myProperty: " << mypropertyptr << std::endl;
- }
- catch (std::exception &e) {
- std::cout << "ERR: " << e.what() << std::endl;
- }
-
- try {
- std::cout << "Try get Property (key:\"yourProperty\", type:DSPropertyVariant&) of myproperty" << std::endl;
- const display_server::DSPropertyVariant &ptr = myproperty->getProperty("yourProperty");
- std::cout << " THIS LINE SHOULD BE NOT PRINTED! yourProperty: " << &ptr << std::endl;
- }
- catch (std::exception &e) {
- std::cout << "SUCCESS: " << e.what() << std::endl;
- }
-
- std::cout << "\n=== delete myproperty ===" << std::endl;
- delete myproperty;
-
- std::cout << "\n=== delete myproperty2 ===" << std::endl;
- delete myproperty2;
-
- return 0;
+ try {
+ std::cout << "Try get Property (key:\"yourProperty\", type:DSPropertyVariant&) of myproperty" << std::endl;
+ const DSPropertyVariant &ptr = myproperty->getProperty("yourProperty");
+ std::cout << " THIS LINE SHOULD BE NOT PRINTED! yourProperty: " << &ptr << std::endl;
+ }
+ catch (std::exception &e) {
+ std::cout << "SUCCESS: " << e.what() << std::endl;
}
-} // namespace example
-int main()
-{
- return example::exampleProperty();
+ std::cout << "\n=== delete myproperty ===" << std::endl;
+ delete myproperty;
+
+ std::cout << "\n=== delete myproperty2 ===" << std::endl;
+ delete myproperty2;
+
+ return 0;
}
destruct Sender
destruct Receiver(ref: 1)
*/
-namespace example {
- using SignalAType = display_server::DSSignal<int>;
- using SignalBType = display_server::DSSignal<double>;
+using namespace display_server;
- class Sender : public display_server::DSObject {
- public:
- Sender() :
- display_server::DSObject()
- {
- std::cout << "construct Sender" << std::endl;
- }
- ~Sender()
- {
- std::cout << "destruct Sender " << getName() << std::endl;
- }
+using SignalAType = DSSignal<int>;
+using SignalBType = DSSignal<double>;
- struct SignalA : public SignalAType {
- void emit(int val)
- {
- SignalAType::emit(val);
- }
- } signalA;
-
- struct SignalB : public SignalBType {
- void emit(double val)
- {
- SignalBType::emit(val);
- }
- } signalB;
- };
+class Sender : public DSObject {
+public:
+ Sender() :
+ DSObject()
+ {
+ std::cout << "construct Sender" << std::endl;
+ }
+ ~Sender()
+ {
+ std::cout << "destruct Sender " << getName() << std::endl;
+ }
- class Receiver : public display_server::DSObject, public display_server::DSRefBase {
- public:
- Receiver() :
- display_server::DSObject(), display_server::DSRefBase()
- {
- std::cout << "construct Receiver" << std::endl;
- }
- ~Receiver()
+ struct SignalA : public SignalAType {
+ void emit(int val)
{
- std::cout << "destruct Receiver(ref: " << getref() << ") " << getName() << std::endl;
+ SignalAType::emit(val);
}
+ } signalA;
- static void slotA(int a)
+ struct SignalB : public SignalBType {
+ void emit(double val)
{
- std::cout << "slotA invoked! a:" << a << std::endl;
- };
- static void slotA2(int a)
- {
- std::cout << "slotA2 invoked! a:" << a << std::endl;
+ SignalBType::emit(val);
}
- static void slotB(double a)
- {
- std::cout << "slotB invoked! a:" << a << std::endl;
- };
- };
+ } signalB;
+};
- int main(void)
+class Receiver : public DSObject, public DSRefBase {
+public:
+ Receiver() :
+ DSObject(), DSRefBase()
{
- Sender *sender = new Sender();
- Sender *sender2 = new Sender();
- Receiver *receiver = new Receiver();
- Receiver *receiver2 = new Receiver();
-
- sender->signalA.connect(receiver, Receiver::slotA);
- sender->signalA.connect(receiver2, Receiver::slotA2);
- sender->signalB.connect(receiver, Receiver::slotB);
- sender->signalB.connect(receiver2, [](double val) {
- std::cout << "Lambda slot invoked! val: " << val << std::endl;
- });
+ std::cout << "construct Receiver" << std::endl;
+ }
+ ~Receiver()
+ {
+ std::cout << "destruct Receiver(ref: " << getref() << ") " << getName() << std::endl;
+ }
- sender->signalA.emit(1234);
- sender->signalB.emit(45.67);
+ static void slotA(int a)
+ {
+ std::cout << "slotA invoked! a:" << a << std::endl;
+ };
+ static void slotA2(int a)
+ {
+ std::cout << "slotA2 invoked! a:" << a << std::endl;
+ }
+ static void slotB(double a)
+ {
+ std::cout << "slotB invoked! a:" << a << std::endl;
+ };
+};
- if (receiver2->getref() == 1) {
- receiver2->unref();
- receiver2 = nullptr;
- }
+int main(void)
+{
+ Sender *sender = new Sender();
+ Sender *sender2 = new Sender();
+ Receiver *receiver = new Receiver();
+ Receiver *receiver2 = new Receiver();
- sender->signalB.emit(5678);
- sender->signalA.emit(90.1);
+ sender->signalA.connect(receiver, Receiver::slotA);
+ sender->signalA.connect(receiver2, Receiver::slotA2);
+ sender->signalB.connect(receiver, Receiver::slotB);
+ sender->signalB.connect(receiver2, [](double val) {
+ std::cout << "Lambda slot invoked! val: " << val << std::endl;
+ });
- delete sender;
- delete sender2;
- delete receiver;
+ sender->signalA.emit(1234);
+ sender->signalB.emit(45.67);
- return 0;
+ if (receiver2->getref() == 1) {
+ receiver2->unref();
+ receiver2 = nullptr;
}
-} // namespace example
-int main()
-{
- return example::main();
+ sender->signalB.emit(5678);
+ sender->signalA.emit(90.1);
+
+ delete sender;
+ delete sender2;
+ delete receiver;
+
+ return 0;
}
#include "libds-tests.h"
#include "DSProperty.h"
+using namespace display_server;
+
class DSPropertyTest : public ::testing::Test
{
public:
TEST_F(DSPropertyTest, CreateProperty)
{
- /* display_server::DSProperty::DSProperty()*/
- display_server::DSProperty* pro = new display_server::DSProperty();
+ /* DSProperty::DSProperty()*/
+ DSProperty* pro = new DSProperty();
ASSERT_NE(pro, nullptr) << "Failed to DSProperty()";
delete pro;
- /* display_server::DSProperty::DSProperty(std::__cxx11::string, const DSPropertyVariant&, display_server::DSPropertyType) */
- pro = new display_server::DSProperty("testProperty", 2020, display_server::DSPropertyType::INTEGER);
+ /* DSProperty::DSProperty(std::__cxx11::string, const DSPropertyVariant&, DSPropertyType) */
+ pro = new DSProperty("testProperty", 2020, DSPropertyType::INTEGER);
ASSERT_NE(pro, nullptr) << "Failed to DSProperty(key, data, type)";
ASSERT_EQ(pro->getKey(), "testProperty") << "Key value mismatch!";
- ASSERT_EQ(pro->getType(), display_server::DSPropertyType::INTEGER) << "Type mistmatch!!";
+ ASSERT_EQ(pro->getType(), DSPropertyType::INTEGER) << "Type mistmatch!!";
try {
int data = std::get<int>(pro->getData());
ASSERT_TRUE(data == 2020) << "data value mismatch!!";
}
delete pro;
- /* display_server::DSProperty::DSProperty(display_server::DSProperty&) */
- display_server::DSProperty pro_s("testProperty2", 20.20, display_server::DSPropertyType::DOUBLE);
- pro = new display_server::DSProperty(pro_s);
+ /* DSProperty::DSProperty(DSProperty&) */
+ DSProperty pro_s("testProperty2", 20.20, DSPropertyType::DOUBLE);
+ pro = new DSProperty(pro_s);
ASSERT_NE(pro, nullptr) << "Failed to DSProperty(const DSProperty&)";
ASSERT_EQ(pro->getKey(), "testProperty2") << "Key value mismatch!";
- ASSERT_EQ(pro->getType(), display_server::DSPropertyType::DOUBLE) << "Type mistmatch!!";
+ ASSERT_EQ(pro->getType(), DSPropertyType::DOUBLE) << "Type mistmatch!!";
try {
double data = std::get<double>(pro->getData());
ASSERT_TRUE(data == 20.20) << "data value mismatch!!";
#include "libds-tests.h"
#include "DSRefBase.h"
+using namespace display_server;
+
class DSRefBaseTest : public ::testing::Test
{
public:
TEST_F(DSRefBaseTest, CreateRefBase)
{
- display_server::DSRefBase *refBase = new display_server::DSRefBase();
+ DSRefBase *refBase = new DSRefBase();
int count1;
int count2;