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