1 // Copyright (C) 2018 The Android Open Source Project 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 // http://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 #include <android/os/IncidentReportArgs.h> 16 17 #include <gtest/gtest.h> 18 19 namespace android { 20 namespace os { 21 namespace statsd { 22 23 TEST(IncidentReportArgsTest, testSerialization) { 24 IncidentReportArgs args; 25 args.setAll(0); 26 args.addSection(1000); 27 args.addSection(1001); 28 29 vector<uint8_t> header1; 30 header1.push_back(0x1); 31 header1.push_back(0x2); 32 vector<uint8_t> header2; 33 header1.push_back(0x22); 34 header1.push_back(0x33); 35 36 args.addHeader(header1); 37 args.addHeader(header2); 38 39 args.setPrivacyPolicy(1); 40 41 args.setReceiverPkg("com.android.os"); 42 args.setReceiverCls("com.android.os.Receiver"); 43 44 Parcel out; 45 status_t err = args.writeToParcel(&out); 46 EXPECT_EQ(NO_ERROR, err); 47 48 out.setDataPosition(0); 49 50 IncidentReportArgs args2; 51 err = args2.readFromParcel(&out); 52 EXPECT_EQ(NO_ERROR, err); 53 54 EXPECT_EQ(0, args2.all()); 55 set<int> sections; 56 sections.insert(1000); 57 sections.insert(1001); 58 EXPECT_EQ(sections, args2.sections()); 59 EXPECT_EQ(1, args2.getPrivacyPolicy()); 60 61 EXPECT_EQ(string("com.android.os"), args2.receiverPkg()); 62 EXPECT_EQ(string("com.android.os.Receiver"), args2.receiverCls()); 63 64 vector<vector<uint8_t>> headers; 65 headers.push_back(header1); 66 headers.push_back(header2); 67 EXPECT_EQ(headers, args2.headers()); 68 } 69 70 } // namespace statsd 71 } // namespace os 72 } // namespace android 73