• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Tests for the generated View class for Container and Box from
16 // nested_structure.emb.
17 //
18 // These tests check that nested structures work.
19 #include <stdint.h>
20 
21 #include <vector>
22 
23 #include "gtest/gtest.h"
24 #include "testdata/explicit_sizes.emb.h"
25 
26 namespace emboss {
27 namespace test {
28 namespace {
29 
30 static const ::std::uint8_t kUIntArrays[21] = {
31     0x21,                    // one_nibble == { 0x1, 0x2 }
32     0x10, 0x20,              // two_nibble == { 0x10, 0x20 }
33     0x10, 0x11, 0x20, 0x22,  // four_nibble == { 0x1110, 0x2220 }
34 };
35 
TEST(SizesView,CanReadSizes)36 TEST(SizesView, CanReadSizes) {
37   auto outer_view = BitArrayContainerView(kUIntArrays, sizeof kUIntArrays);
38   auto view = outer_view.uint_arrays();
39   EXPECT_EQ(0x1, view.one_nibble()[0].Read());
40   EXPECT_EQ(0x2, view.one_nibble()[1].Read());
41   EXPECT_EQ(0x10, view.two_nibble()[0].Read());
42   EXPECT_EQ(0x20, view.two_nibble()[1].Read());
43   EXPECT_EQ(0x1110, view.four_nibble()[0].Read());
44   EXPECT_EQ(0x2220, view.four_nibble()[1].Read());
45 }
46 
47 }  // namespace
48 }  // namespace test
49 }  // namespace emboss
50