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 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(copy_assignment)
34 bq1.AppendCopy(buf.data(), buf.size());
39 BOOST_REQUIRE(bq1.Size() == bq2.Size() && bq1.Size() == buf.size());
41 RawBuffer buf1(bq1.Size(), 0x00);
42 RawBuffer buf2(bq2.Size(), 0x00);
44 bq1.Flatten(buf1.data(), buf1.size());
45 bq2.Flatten(buf2.data(), buf2.size());
47 BOOST_REQUIRE(buf1 == buf2);
50 POSITIVE_TEST_CASE(append_copy_to)
53 bq1.AppendCopy(buf.data(), buf.size());
56 bq1.AppendCopyTo(bq2);
58 BOOST_REQUIRE(bq1.Size() == bq2.Size() && bq1.Size() == buf.size());
60 RawBuffer buf1(bq1.Size(), 0x00);
61 RawBuffer buf2(bq2.Size(), 0x00);
63 bq1.Flatten(buf1.data(), buf1.size());
64 bq2.Flatten(buf2.data(), buf2.size());
66 BOOST_REQUIRE(buf1 == buf2);
69 POSITIVE_TEST_CASE(append_move_to)
72 bq1.AppendCopy(buf.data(), buf.size());
75 bq1.AppendMoveTo(bq2);
77 BOOST_REQUIRE(bq2.Size() == buf.size() && bq1.Empty());
79 RawBuffer buf2(bq2.Size(), 0x00);
80 bq2.Flatten(buf2.data(), buf2.size());
81 BOOST_REQUIRE(buf == buf2);
84 POSITIVE_TEST_CASE(read)
87 bq1.AppendCopy(buf.data(), buf.size());
89 auto bq2 = bq1.Read(buf.size());
90 BOOST_REQUIRE(bq1.Empty());
92 RawBuffer buf2(bq2->Size(), 0x00);
93 bq2->Flatten(buf2.data(), buf2.size());
94 BOOST_REQUIRE(buf == buf2);
97 POSITIVE_TEST_CASE(write)
100 bq1.AppendCopy(buf.data(), buf.size());
103 bq2.Write(bq1, bq1.Size());
105 RawBuffer buf1(bq1.Size(), 0x00);
106 RawBuffer buf2(bq2.Size(), 0x00);
108 bq1.Flatten(buf1.data(), buf1.size());
109 bq2.Flatten(buf2.data(), buf2.size());
111 BOOST_REQUIRE(buf1 == buf2);
114 POSITIVE_TEST_CASE(bucket_visitor)
116 static std::vector<unsigned char> globalBuf;
118 class BucketVisitorTest : public BinaryQueue::BucketVisitor {
120 virtual void OnVisitBucket(const void *buffer, size_t bufferSize) override
122 for (size_t i = 0; i < bufferSize; ++i)
123 globalBuf.push_back(static_cast<const unsigned char *>(buffer)[i]);
127 BucketVisitorTest visitor;
129 constexpr size_t BucketNum = 3;
131 for (size_t i = 0; i < BucketNum; ++i)
132 bq.AppendCopy(buf.data(), buf.size());
134 bq.VisitBuckets(&visitor);
136 BOOST_REQUIRE(globalBuf.size() == buf.size() * BucketNum);
137 for (size_t i = 0; i < BucketNum; ++i)
138 for (size_t j = 0; j < buf.size(); ++j)
139 BOOST_REQUIRE(globalBuf[i * buf.size() + j] == buf[j]);
142 BOOST_AUTO_TEST_SUITE_END()