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" |
Mark Salyzyn | a4842ac | 2017-01-10 10:16:48 -0800 | [diff] [blame] | 4 | |
| 5 | #include <log/log.h> |
| 6 | |
Yifan Hong | 30dc3de | 2016-10-17 11:38:15 -0700 | [diff] [blame] | 7 | #include <hidl-test/PointerHelper.h> |
Yifan Hong | d5b5b2e | 2016-10-06 13:50:49 -0700 | [diff] [blame] | 8 | |
| 9 | #define PUSH_ERROR_IF(__cond__) if(__cond__) { errors.push_back(std::to_string(__LINE__) + ": " + #__cond__); } |
| 10 | |
| 11 | namespace android { |
| 12 | namespace hardware { |
| 13 | namespace tests { |
| 14 | namespace pointer { |
| 15 | namespace V1_0 { |
| 16 | namespace implementation { |
| 17 | |
Yifan Hong | d5b5b2e | 2016-10-06 13:50:49 -0700 | [diff] [blame] | 18 | // Methods from ::android::hardware::tests::pointer::V1_0::IGraph follow. |
| 19 | Return<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 | |
| 26 | Return<void> Graph::giveAGraph(giveAGraph_cb _cb) { |
| 27 | IGraph::Graph g; |
| 28 | simpleGraph(g); |
| 29 | _cb(g); |
| 30 | return Void(); |
| 31 | } |
| 32 | |
| 33 | Return<void> Graph::passANode(const IGraph::Node& n) { |
| 34 | PUSH_ERROR_IF(n.data != 10); |
| 35 | return Void(); |
| 36 | } |
| 37 | |
| 38 | Return<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 | |
| 45 | Return<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 | } |
| 55 | Return<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 | } |
| 60 | Return<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 | } |
| 65 | Return<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 | |
| 72 | Return<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 | |
| 80 | IGraph* 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 |