• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Checks that all of the inline methods on IncidentReportRequest and the real C functions
24 // result in a working IncidentReportArgs.
TEST(IncidentReportArgsTest,testSerialization)25 TEST(IncidentReportArgsTest, testSerialization) {
26     IncidentReportArgs args;
27     args.setAll(0);
28     args.addSection(1000);
29     args.addSection(1001);
30 
31     vector<uint8_t> header1;
32     header1.push_back(0x1);
33     header1.push_back(0x2);
34     vector<uint8_t> header2;
35     header1.push_back(0x22);
36     header1.push_back(0x33);
37 
38     args.addHeader(header1);
39     args.addHeader(header2);
40 
41     args.setPrivacyPolicy(1);
42 
43     args.setReceiverPkg("com.android.os");
44     args.setReceiverCls("com.android.os.Receiver");
45 
46     Parcel out;
47     status_t err = args.writeToParcel(&out);
48     EXPECT_EQ(NO_ERROR, err);
49 
50     out.setDataPosition(0);
51 
52     IncidentReportArgs args2;
53     err = args2.readFromParcel(&out);
54     EXPECT_EQ(NO_ERROR, err);
55 
56     EXPECT_EQ(0, args2.all());
57     set<int> sections;
58     sections.insert(1000);
59     sections.insert(1001);
60     EXPECT_EQ(sections, args2.sections());
61     EXPECT_EQ(1, args2.getPrivacyPolicy());
62 
63     EXPECT_EQ(string("com.android.os"), args2.receiverPkg());
64     EXPECT_EQ(string("com.android.os.Receiver"), args2.receiverCls());
65 
66     vector<vector<uint8_t>> headers;
67     headers.push_back(header1);
68     headers.push_back(header2);
69     EXPECT_EQ(headers, args2.headers());
70 }
71 
72 }  // namespace statsd
73 }  // namespace os
74 }  // namespace android
75