Home | History | Annotate | Download | only in hidl-test
      1 #ifndef ANDROID_HIDL_TEST_FOO_HELPER_H
      2 #define ANDROID_HIDL_TEST_FOO_HELPER_H
      3 #include <string>
      4 #include <android/hardware/tests/foo/1.0/IFoo.h>
      5 #include <utils/Timers.h>
      6 
      7 namespace android {
      8 
      9 using std::to_string;
     10 using hardware::hidl_string;
     11 using hardware::hidl_vec;
     12 using hardware::hidl_array;
     13 using hardware::tests::foo::V1_0::IFoo;
     14 
     15 static constexpr nsecs_t DELAY_S = 1;
     16 static constexpr nsecs_t DELAY_NS = seconds_to_nanoseconds(DELAY_S);
     17 static constexpr nsecs_t TOLERANCE_NS = milliseconds_to_nanoseconds(10);
     18 static constexpr nsecs_t ONEWAY_TOLERANCE_NS = milliseconds_to_nanoseconds(1);
     19 
     20 std::string to_string(const IFoo::StringMatrix5x3 &M);
     21 std::string to_string(const IFoo::StringMatrix3x5 &M);
     22 // Add quotes around s. For testing purposes only.
     23 std::string to_string(const hidl_string &s);
     24 
     25 template<typename T>
     26 std::string to_string(const T *elems, size_t n) {
     27     std::string out;
     28     out = "[";
     29     for (size_t i = 0; i < n; ++i) {
     30         if (i > 0) {
     31             out += ", ";
     32         }
     33         out += to_string(elems[i]);
     34     }
     35     out += "]";
     36 
     37     return out;
     38 }
     39 
     40 template<typename T, size_t SIZE>
     41 std::string to_string(const hidl_array<T, SIZE> &array) {
     42     return to_string(&array[0], SIZE);
     43 }
     44 
     45 template<typename T, size_t SIZE1, size_t SIZE2>
     46 std::string to_string(const hidl_array<T, SIZE1, SIZE2> &array) {
     47     std::string out;
     48     out = "[";
     49     for (size_t i = 0; i < SIZE1; ++i) {
     50         if (i > 0) {
     51             out += ", ";
     52         }
     53 
     54         out += "[";
     55         for (size_t j = 0; j < SIZE2; ++j) {
     56             if (j > 0) {
     57                 out += ", ";
     58             }
     59 
     60             out += to_string(array[i][j]);
     61         }
     62         out += "]";
     63     }
     64     out += "]";
     65 
     66     return out;
     67 }
     68 
     69 template<typename T>
     70 std::string to_string(const hidl_vec<T> &vec) {
     71     return to_string(&vec[0], vec.size());
     72 }
     73 
     74 std::string QuuxToString(const IFoo::Quux &val);
     75 
     76 std::string MultiDimensionalToString(const IFoo::MultiDimensional &val);
     77 
     78 } // namespace android
     79 #endif // ANDROID_HIDL_TEST_TEST_HELPER_H
     80