2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file test_message_queue.cpp
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the implementation file of message queue tests
22 #include <dpl/test_runner.h>
23 #include <dpl/abstract_waitable_input_adapter.h>
24 #include <dpl/abstract_waitable_output_adapter.h>
25 #include <dpl/message_queue.h>
26 #include <dpl/binary_queue.h>
29 #include <dpl/application.h>
30 #include <dpl/controller.h>
31 #include <dpl/generic_event.h>
33 DECLARE_GENERIC_EVENT_0(QuitEvent)
35 class QuitController :
36 public DPL::Controller<DPL::TypeListDecl<QuitEvent>::Type>,
37 public DPL::ApplicationExt
40 QuitController() : DPL::ApplicationExt(1, NULL, "test-app")
46 virtual void OnEventReceived(const QuitEvent &)
52 RUNNER_TEST_GROUP_INIT(DPL)
59 DPL::AbstractWaitableInput *m_input;
60 DPL::AbstractWaitableOutput *m_output;
61 std::size_t m_dataSize;
64 CopyThread(DPL::AbstractWaitableInput *input,
65 DPL::AbstractWaitableOutput *output,
66 std::size_t dataSize) :
72 LogInfo("Thread created");
76 virtual int ThreadEntry()
78 LogInfo("Entering copy thread");
82 DPL::Copy(m_input, m_output, m_dataSize);
84 Catch(DPL::CopyFailed)
88 LogWarning("Copy failed!");
92 LogInfo("Copy finished");
97 inline std::string BinaryQueueToString(const DPL::BinaryQueue &queue)
99 char *buffer = new char[queue.Size()];
100 queue.Flatten(buffer, queue.Size());
101 std::string result = std::string(buffer, buffer + queue.Size());
106 RUNNER_TEST(MessageQueue_DoubleCopy)
108 DPL::BinaryQueue dataA;
109 DPL::MessageQueue dataB("/test_mqueue_dataB", true, false, 0660, true);
110 DPL::MessageQueue dataC("/test_mqueue_dataC", true, false, 0660, true);
111 DPL::BinaryQueue dataD;
113 DPL::AbstractWaitableInputAdapter dataAdapterA(&dataA);
114 DPL::AbstractWaitableOutputAdapter dataAdapterD(&dataD);
116 const std::string testData =
117 "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
118 "Cras elementum venenatis velit, sit amet vehicula odio gravida a."
119 "Curabitur id nibh id ante adipiscing sollicitudin."
120 "Maecenas in tellus vel augue vehicula pharetra hendrerit cursus est."
122 "Ut malesuada quam porttitor dui euismod lacinia."
123 "Phasellus quis lectus sed lectus dictum tincidunt et vitae leo."
124 "Fusce id est massa, condimentum bibendum urna."
125 "Donec venenatis quam eget sapien vulputate egestas."
126 "Maecenas scelerisque lorem a neque molestie a varius erat condimentum."
127 "Maecenas varius hendrerit ligula, sed iaculis justo pretium id."
128 "Nunc sit amet nisl vitae justo tristique suscipit id eget tortor."
130 "Pellentesque sollicitudin nulla at metus dapibus tincidunt."
131 "Integer consequat justo eget dui imperdiet iaculis."
132 "Sed vestibulum ipsum vitae libero accumsan non molestie metus adipiscing."
134 "Vivamus quis dui enim, in blandit urna."
135 "In imperdiet lacus at orci elementum a scelerisque dui blandit."
136 "Donec vulputate enim metus, eget convallis ante."
137 "Etiam mollis enim eget eros pulvinar nec sagittis justo fermentum."
139 "Vestibulum sed nunc eu leo lobortis ultrices."
140 "Nullam placerat nulla et est blandit nec interdum nunc pulvinar."
141 "Vivamus a lectus eget dui fermentum hendrerit.";
143 QuitController quitter;
144 quitter.PostTimedEvent(QuitEvent(), 1.0);
146 CopyThread threadA(&dataAdapterA, &dataB, testData.size());
147 CopyThread threadB(&dataB, &dataC, testData.size());
148 CopyThread threadC(&dataC, &dataAdapterD, testData.size());
150 dataA.AppendCopy(testData.c_str(), testData.size());
162 // Now, test data should be in dataD
163 RUNNER_ASSERT(BinaryQueueToString(dataD) == testData);