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 constexpr unsigned char buf[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
26 constexpr size_t bufSize = sizeof(buf);
28 } // namespace anonymous
30 BOOST_AUTO_TEST_SUITE(BINARY_QUEUE_TEST)
32 POSITIVE_TEST_CASE(append_copy)
35 BOOST_REQUIRE(bq.Size() == 0);
37 bq.AppendCopy(buf, bufSize);
39 BOOST_REQUIRE(bq.Size() == bufSize);
41 bq.AppendCopy(buf, bufSize);
43 BOOST_REQUIRE(bq.Size() == 2 * bufSize);
46 NEGATIVE_TEST_CASE(append_copy)
50 bq.AppendCopy(buf, 0);
52 BOOST_REQUIRE(bq.Size() == 0);
55 POSITIVE_TEST_CASE(flatten_consume)
59 constexpr size_t part1Size = bufSize / 2;
61 bq.AppendCopy(buf, part1Size);
62 bq.AppendCopy(buf + part1Size, bufSize - part1Size);
64 char out[3 * bufSize / 4];
65 bq.FlattenConsume(out, sizeof(out));
66 BOOST_REQUIRE(memcmp(buf, out, sizeof(out)) == 0);
68 constexpr size_t remainingSize = bufSize - sizeof(out);
69 BOOST_REQUIRE(bq.Size() == remainingSize);
71 bq.FlattenConsume(out, remainingSize);
73 BOOST_REQUIRE(memcmp(buf + sizeof(out), out, remainingSize) == 0);
74 BOOST_REQUIRE(memcmp(buf + remainingSize,
76 sizeof(out) - remainingSize) == 0);
78 BOOST_REQUIRE(bq.Size() == 0);
81 NEGATIVE_TEST_CASE(flatten_consume)
86 BOOST_REQUIRE_THROW(bq.FlattenConsume(&out, sizeof(out)),
87 BinaryQueue::Exception::OutOfData);
89 bq.AppendCopy(buf, bufSize);
91 bq.FlattenConsume(&out, 0);
92 BOOST_REQUIRE(bq.Size() == bufSize);
94 char out2[bufSize + 1];
95 BOOST_REQUIRE_THROW(bq.FlattenConsume(out2, sizeof(out2)),
96 BinaryQueue::Exception::OutOfData);
97 BOOST_REQUIRE(bq.Size() == bufSize);
100 BOOST_AUTO_TEST_SUITE_END()