2 * Copyright (c) 2021 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 #include "luci/Import/CircleReader.h"
19 #include <gtest/gtest.h>
21 TEST(VectorWrapperTest, basic_pattern)
23 auto fb_builder = flatbuffers::FlatBufferBuilder();
25 const std::vector<int32_t> data = {1, 4, 2, 0, 7};
26 auto const vec_offset = fb_builder.CreateVector(data.data(), data.size());
27 auto const vec_pointer = GetTemporaryPointer(fb_builder, vec_offset);
29 auto const wrapper = luci::wrap(vec_pointer);
31 ASSERT_EQ(wrapper.size(), data.size());
32 ASSERT_TRUE(std::equal(wrapper.begin(), wrapper.end(), data.begin()));
35 TEST(VectorWrapperTest, wrong_data_NEG)
37 auto fb_builder = flatbuffers::FlatBufferBuilder();
39 std::vector<int32_t> data = {1, 4, 2, 0, 7};
40 auto const vec_offset = fb_builder.CreateVector(data.data(), data.size());
41 auto const vec_pointer = GetTemporaryPointer(fb_builder, vec_offset);
43 auto const wrapper = luci::wrap(vec_pointer);
46 std::reverse(data.begin(), data.end());
48 ASSERT_EQ(wrapper.size(), data.size());
49 ASSERT_FALSE(std::equal(wrapper.begin(), wrapper.end(), data.begin()));
52 TEST(VectorWrapperTest, null_pointer)
54 flatbuffers::Vector<int32_t> *vec_pointer = nullptr;
55 auto const wrapper = luci::wrap(vec_pointer);
57 ASSERT_TRUE(wrapper.null());
58 ASSERT_TRUE(wrapper.empty());
61 TEST(VectorWrapperTest, prohibited_access_NEG)
63 flatbuffers::Vector<uint8_t> *vec_pointer = nullptr;
64 auto const wrapper = luci::wrap(vec_pointer);
66 ASSERT_ANY_THROW(wrapper.at(0));