xref: /aosp_15_r20/external/emboss/compiler/back_end/cpp/testcode/complex_structure_test.cc (revision 99e0aae7469b87d12f0ad23e61142c2d74c1ef70)
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 of generated code for text format.
16 #include <stdint.h>
17 
18 #include <type_traits>
19 #include <utility>
20 #include <vector>
21 
22 #include "gtest/gtest.h"
23 #include "testdata/complex_structure.emb.h"
24 
25 namespace emboss_test {
26 namespace {
27 
TEST(InvalidTextInput,PrematureEnd)28 TEST(InvalidTextInput, PrematureEnd) {
29   ::std::array<char, 64> values = {0};
30   const auto view = ::emboss_test::MakeComplexView(&values);
31   ::emboss::UpdateFromText(view, "{a:");
32 }
33 
TEST(InvalidTextInput,ReallyPrematureEnd)34 TEST(InvalidTextInput, ReallyPrematureEnd) {
35   ::std::array<char, 64> values = {0};
36   const auto view = ::emboss_test::MakeComplexView(&values);
37   ::emboss::UpdateFromText(view, "\x01");
38 }
39 
TEST(InvalidTextInput,WeirdInputDoesNotHang)40 TEST(InvalidTextInput, WeirdInputDoesNotHang) {
41   ::std::string text{0x7b, 0x78, 0x32, 0x3a, 0x30, 0x0d, 0x0d, 0x62, 0x32,
42                      0x7f, 0x30, 0x0d, 0x0d, 0x62, 0x32, 0x3a, 0x30, 0x0d,
43                      0x0d, 0x62, 0x32, 0x3a, 0x30, 0x0d, 0x0c, 0x30, 0x0d,
44                      0x0d, 0x63, 0x32, 0x3a, 0x30, 0x0d, 0x0d, 0x62, 0x36,
45                      0x3a, 0x30, 0x0d, 0x32, 0x3a, 0x30, 0x0d};
46   ::std::array<char, 64> values = {0};
47   const auto view = ::emboss_test::MakeComplexView(&values);
48   ::emboss::UpdateFromText(view, text);
49 }
50 
51 }  // namespace
52 }  // namespace emboss_test
53