Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3dd7dab authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "codec2: add a constructor of C2FieldSupportedValues w/ input vector"

parents 068ba821 ba25eeb9
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -1164,6 +1164,15 @@ struct C2FieldSupportedValues {
        }
    }

    template<typename T>
    C2FieldSupportedValues(bool flags, const std::vector<T>& list)
        : type(flags ? FLAGS : VALUES),
          range{(T)0, (T)0, (T)0, (T)0, (T)0} {
        for(T value : list) {
            values.emplace_back(value);
        }
    }

    template<typename T, typename E=decltype(C2FieldDescriptor::namedValuesFor(*(T*)0))>
    C2FieldSupportedValues(bool flags, const T*)
        : type(flags ? FLAGS : VALUES),
+18 −2
Original line number Diff line number Diff line
@@ -2405,7 +2405,7 @@ typename lax_underlying_type<E>::type get(
template<typename T>
void dumpFSV(const C2FieldSupportedValues &sv, T*t) {
    using namespace std;
    cout << (std::is_enum<T>::value ? (std::is_signed<typename std::underlying_type<T>::type>::value ? "i" : "u")
    cout << (std::is_enum<T>::value ? (std::is_signed<typename lax_underlying_type<T>::type>::value ? "i" : "u")
             : std::is_integral<T>::value ? std::is_signed<T>::value ? "i" : "u" : "f")
         << (8 * sizeof(T));
    if (sv.type == sv.RANGE) {
@@ -2552,6 +2552,22 @@ TEST_F(C2ParamTest, ReflectorTest) {
    }
}

TEST_F(C2ParamTest, FieldSupportedValuesTest) {
    typedef C2GlobalParam<C2Info, C2Uint32Value, 0> Uint32TestInfo;
    Uint32TestInfo t;
    std::vector<C2FieldSupportedValues> values;
    values.push_back(C2FieldSupportedValues(0, 10, 1));  // min, max, step
    values.push_back(C2FieldSupportedValues(1, 64, 2, 1));  // min, max, nom, den
    values.push_back(C2FieldSupportedValues(false, {1, 2, 3}));  // flags, std::initializer_list
    uint32_t val[] = {1, 3, 5, 7};
    std::vector<uint32_t> v(std::begin(val), std::end(val));
    values.push_back(C2FieldSupportedValues(false, v));  // flags, std::vector

    for (const C2FieldSupportedValues &sv : values) {
        dumpFSV(sv, &t.mValue);
    }
}

C2ENUM(Enum1, uint32_t,
    Enum1Value1,
    Enum1Value2,