summaryrefslogtreecommitdiff
path: root/cmds/incidentd/tests/section_list.cpp
blob: 60f7fb788837d3ebb6f37e8443ff6d0259831058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// This file is a stub section_list.cpp used for test only.
#include "section_list.h"

#include "frameworks/base/cmds/incidentd/tests/test_proto.pb.h"


namespace android {
namespace os {
namespace incidentd {

class TestSection: public Section {
public:
    TestSection(int id);
    ~TestSection();
    virtual status_t Execute(ReportWriter* writer) const;
};

TestSection::TestSection(int id)
        :Section(id, 5000 /* ms timeout */) {
}

TestSection::~TestSection() {
}

status_t TestSection::Execute(ReportWriter* writer) const {
    uint8_t buf[1024];
    status_t err;

    TestSectionProto proto;
    proto.set_field_1(this->id);
    proto.set_field_2(this->id * 10);

    // Not infinitely scalable, but we know that our TestSectionProto will always
    // fit in this many bytes.
    if (!proto.SerializeToArray(buf, sizeof(buf))) {
        return -1;
    }
    FdBuffer buffer;
    err = buffer.write(buf, proto.ByteSize());
    if (err != NO_ERROR) {
        return err;
    }

    return writer->writeSection(buffer);
}

TestSection section1(1);
TestSection section2(2);

const Section* SECTION_LIST[] = {
    &section1,
    &section2,
    NULL
};

Privacy sub_field_1{1, 1, NULL, PRIVACY_POLICY_LOCAL, NULL};
Privacy sub_field_2{2, 9, NULL, PRIVACY_POLICY_AUTOMATIC, NULL};

Privacy* list[] = {&sub_field_1, &sub_field_2, NULL};

Privacy field_0{0, 11, list, PRIVACY_POLICY_EXPLICIT, NULL};
Privacy field_1{1, 9, NULL, PRIVACY_POLICY_AUTOMATIC, NULL};

Privacy* final_list[] = {&field_0, &field_1};

const Privacy** PRIVACY_POLICY_LIST = const_cast<const Privacy**>(final_list);

const int PRIVACY_POLICY_COUNT = 2;

}  // namespace incidentd
}  // namespace os
}  // namespace android