2 * Copyright (c) 2000 - 2020 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
16 #include <boost_macros_wrapper.h>
18 #include <dpl/binary_queue.h>
19 #include <ckm/ckm-raw-buffer.h>
25 const RawBuffer BUF = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
27 } // namespace anonymous
29 BOOST_AUTO_TEST_SUITE(BINARY_QUEUE_TEST)
31 POSITIVE_TEST_CASE(push)
34 BOOST_REQUIRE(bq.Size() == 0);
36 bq.Push(RawBuffer(BUF));
37 BOOST_REQUIRE(bq.Size() == BUF.size());
39 bq.Push(RawBuffer(BUF));
40 BOOST_REQUIRE(bq.Size() == 2 * BUF.size());
43 NEGATIVE_TEST_CASE(push)
48 BOOST_REQUIRE(bq.Size() == 0);
51 POSITIVE_TEST_CASE(pop)
53 const size_t PART1_SIZE = BUF.size() / 2;
57 bq.Push(RawBuffer(BUF.begin(), BUF.begin() + PART1_SIZE));
58 bq.Push(RawBuffer(BUF.begin() + PART1_SIZE, BUF.end()));
60 RawBuffer out(3 * BUF.size() / 4);
61 bq.Pop(out.data(), out.size());
62 BOOST_REQUIRE(std::equal(out.begin(), out.end(), BUF.begin()));
64 const size_t REST_SIZE = BUF.size() - out.size();
65 BOOST_REQUIRE(bq.Size() == REST_SIZE);
67 bq.Pop(out.data(), REST_SIZE);
68 BOOST_REQUIRE(std::equal(out.begin(), out.begin() + REST_SIZE, BUF.begin() + out.size()));
69 BOOST_REQUIRE(std::equal(out.begin() + REST_SIZE, out.end(), BUF.begin() + REST_SIZE));
70 BOOST_REQUIRE(bq.Size() == 0);
73 NEGATIVE_TEST_CASE(pop)
78 BOOST_REQUIRE_THROW(bq.Pop(&out, sizeof(out)), BinaryQueue::Exception::OutOfData);
80 bq.Push(RawBuffer(BUF));
83 BOOST_REQUIRE(bq.Size() == BUF.size());
85 RawBuffer out2(BUF.size() + 1);
86 BOOST_REQUIRE_THROW(bq.Pop(out2.data(), out2.size()), BinaryQueue::Exception::OutOfData);
87 BOOST_REQUIRE(bq.Size() == BUF.size());
90 BOOST_AUTO_TEST_SUITE_END()