blob: 5c8098b8b3408a37ebfc61a758230c239589d8ba [file] [log] [blame]
Yifan Hong0c4c7a32016-11-28 15:59:24 -08001#define LOG_TAG "hidl_test"
2
Yifan Hongd5b5b2e2016-10-06 13:50:49 -07003#include "Graph.h"
Mark Salyzyna4842ac2017-01-10 10:16:48 -08004
5#include <log/log.h>
6
Yifan Hong30dc3de2016-10-17 11:38:15 -07007#include <hidl-test/PointerHelper.h>
Yifan Hongd5b5b2e2016-10-06 13:50:49 -07008
9#define PUSH_ERROR_IF(__cond__) if(__cond__) { errors.push_back(std::to_string(__LINE__) + ": " + #__cond__); }
10
11namespace android {
12namespace hardware {
13namespace tests {
14namespace pointer {
15namespace V1_0 {
16namespace implementation {
17
Yifan Hongd5b5b2e2016-10-06 13:50:49 -070018// Methods from ::android::hardware::tests::pointer::V1_0::IGraph follow.
19Return<void> Graph::passAGraph(const IGraph::Graph& g) {
20 ALOGI("SERVER(Graph) passAGraph start.");
21 PUSH_ERROR_IF(!isSimpleGraph(g));
22 // logSimpleGraph("SERVER(Graph) passAGraph:", g);
23 return Void();
24}
25
26Return<void> Graph::giveAGraph(giveAGraph_cb _cb) {
27 IGraph::Graph g;
28 simpleGraph(g);
29 _cb(g);
30 return Void();
31}
32
33Return<void> Graph::passANode(const IGraph::Node& n) {
34 PUSH_ERROR_IF(n.data != 10);
35 return Void();
36}
37
38Return<void> Graph::passTwoGraphs(IGraph::Graph const* g1, IGraph::Graph const* g2) {
39 PUSH_ERROR_IF(g1 != g2);
40 PUSH_ERROR_IF(!isSimpleGraph(*g1));
41 logSimpleGraph("SERVER(Graph): passTwoGraphs", *g2);
42 return Void();
43}
44
45Return<void> Graph::passAGamma(const IGraph::Gamma& c) {
46 if(c.a_ptr == nullptr && c.b_ptr == nullptr)
47 return Void();
48 ALOGI("SERVER(Graph) passAGamma received c.a = %p, c.b = %p, c.a->s = %p, c.b->s = %p",
49 c.a_ptr, c.b_ptr, c.a_ptr->s_ptr, c.b_ptr->s_ptr);
50 ALOGI("SERVER(Graph) passAGamma received data %d, %d",
51 (int)c.a_ptr->s_ptr->data, (int)c.b_ptr->s_ptr->data);
52 PUSH_ERROR_IF(c.a_ptr->s_ptr != c.b_ptr->s_ptr);
53 return Void();
54}
55Return<void> Graph::passASimpleRef(const IGraph::Alpha * a_ptr) {
56 ALOGI("SERVER(Graph) passASimpleRef received %d", a_ptr->s_ptr->data);
57 PUSH_ERROR_IF(a_ptr->s_ptr->data != 500);
58 return Void();
59}
60Return<void> Graph::passASimpleRefS(const IGraph::Theta * s_ptr) {
61 ALOGI("SERVER(Graph) passASimpleRefS received %d @ %p", s_ptr->data, s_ptr);
62 PUSH_ERROR_IF(s_ptr->data == 10);
63 return Void();
64}
65Return<void> Graph::giveASimpleRef(giveASimpleRef_cb _cb) {
66 IGraph::Theta s; s.data = 500;
67 IGraph::Alpha a; a.s_ptr = &s;
68 _cb(&a);
69 return Void();
70}
71
72Return<int32_t> Graph::getErrors() {
73 if(!errors.empty()) {
74 for(const auto& e : errors)
75 ALOGW("SERVER(Graph) error: %s", e.c_str());
76 }
77 return errors.size();
78}
79
80IGraph* HIDL_FETCH_IGraph(const char* /* name */) {
81 return new Graph();
82}
83
84} // namespace implementation
85} // namespace V1_0
86} // namespace pointer
87} // namespace tests
88} // namespace hardware
89} // namespace android