1 /*
2 * Copyright 2020 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 #include "bluetooth_flatbuffer_test_generated.h"
21 #include "flatbuffers/flatbuffers.h"
22 #include "flatbuffers/idl.h"
23 #include "flatbuffers/util.h"
24
25 namespace bluetooth {
26 namespace dumpsys {
27
28 class BluetoothFlatbufferTest : public ::testing::Test {
29 protected:
SetUp()30 void SetUp() override {}
31
TearDown()32 void TearDown() override {}
33 };
34
TEST_F(BluetoothFlatbufferTest,precondition)35 TEST_F(BluetoothFlatbufferTest, precondition) {}
36
TEST_F(BluetoothFlatbufferTest,BuilderTest)37 TEST_F(BluetoothFlatbufferTest, BuilderTest) {
38 flatbuffers::FlatBufferBuilder builder(1024);
39 auto string_private = builder.CreateString("String private");
40 auto string_opaque = builder.CreateString("String opaque");
41 auto string_anonymized = builder.CreateString("String anonymized");
42 auto string_any = builder.CreateString("String any");
43
44 TestTableBuilder table_builder(builder);
45 table_builder.add_string_private(string_private);
46 table_builder.add_string_opaque(string_opaque);
47 table_builder.add_string_anonymized(string_anonymized);
48 table_builder.add_string_any(string_any);
49
50 table_builder.add_int_private(123);
51 table_builder.add_int_opaque(456);
52 table_builder.add_int_anonymized(789);
53 table_builder.add_int_any(0xabc);
54
55 builder.Finish(table_builder.Finish());
56
57 const TestTable* test_table = GetTestTable(builder.GetBufferPointer());
58
59 ASSERT_EQ("String private", test_table->string_private()->str());
60 ASSERT_EQ("String opaque", test_table->string_opaque()->str());
61 ASSERT_EQ("String anonymized", test_table->string_anonymized()->str());
62 ASSERT_EQ("String any", test_table->string_any()->str());
63
64 ASSERT_EQ(123, test_table->int_private());
65 ASSERT_EQ(456, test_table->int_opaque());
66 ASSERT_EQ(789, test_table->int_anonymized());
67 ASSERT_EQ(0xabc, test_table->int_any());
68 }
69
70 } // namespace dumpsys
71 } // namespace bluetooth
72