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 // Test for the generated View class for StartSize from start_size_range.emb.
16
17 #include <stdint.h>
18
19 #include "gtest/gtest.h"
20 #include "testdata/start_size_range.emb.h"
21
22 namespace emboss {
23 namespace test {
24 namespace {
25
26 static const ::std::uint8_t kStartSizeRange[9] = {
27 0x02, // 0:1 0:1 size == 4
28 0xe8, 0x03, // 1:3 1 [+2] start_size_constants == 1000
29 0x11, 0x22, // 3:5 3 [+s] payload
30 0x21, 0x43, 0x65, 0x87, // 5:9 3+s [+4] counter == 0x87654321
31 };
32
TEST(StartSizeView,EverythingInPlace)33 TEST(StartSizeView, EverythingInPlace) {
34 auto view = StartSizeView(kStartSizeRange, sizeof kStartSizeRange);
35 EXPECT_EQ(9U, view.SizeInBytes());
36 EXPECT_EQ(2, view.size().Read());
37 EXPECT_EQ(1000, view.start_size_constants().Read());
38 EXPECT_EQ(0x11, view.payload()[0].Read());
39 EXPECT_EQ(0x22, view.payload()[1].Read());
40 EXPECT_EQ(0x87654321, view.counter().Read());
41 }
42
43 } // namespace
44 } // namespace test
45 } // namespace emboss
46