MediaMetrics: Add Elem getter to Item

And minor edits.

Test: atest mediametrics_tests
Bug: 138583596
Change-Id: I9161f98f4c17516ea04fc143eb1ccbd656f17796
gugelfrei
Andy Hung 5 years ago
parent 565cc485a0
commit 692870bd73

@ -128,7 +128,7 @@ static inline constexpr const char *BUNDLE_PROPERTY_COUNT = "_propertyCount";
template<size_t N>
static inline bool startsWith(const std::string &s, const char (&comp)[N]) {
return !strncmp(s.c_str(), comp, N-1);
return !strncmp(s.c_str(), comp, N - 1);
}
/**
@ -798,14 +798,14 @@ public:
Item& operator=(Item&& other) = default;
bool operator==(const Item& other) const {
if (mPid != other.mPid
|| mUid != other.mUid
|| mPkgName != other.mPkgName
|| mPkgVersionCode != other.mPkgVersionCode
|| mKey != other.mKey
|| mTimestamp != other.mTimestamp
|| mProps != other.mProps) return false;
return true;
return mPid == other.mPid
&& mUid == other.mUid
&& mPkgName == other.mPkgName
&& mPkgVersionCode == other.mPkgVersionCode
&& mKey == other.mKey
&& mTimestamp == other.mTimestamp
&& mProps == other.mProps
;
}
bool operator!=(const Item& other) const {
return !(*this == other);
@ -935,6 +935,11 @@ public:
return get(key, value);
}
const Prop::Elem* get(const char *key) const {
const Prop *prop = findProp(key);
return prop == nullptr ? nullptr : &prop->get();
}
// Deliver the item to MediaMetrics
bool selfrecord();

@ -262,27 +262,32 @@ TEST(mediametrics_tests, item_iteration) {
int32_t i32;
ASSERT_TRUE(prop.get(&i32));
ASSERT_EQ(1, i32);
ASSERT_EQ(1, std::get<int32_t>(prop.get()));
mask |= 1;
} else if (!strcmp(name, "i64")) {
int64_t i64;
ASSERT_TRUE(prop.get(&i64));
ASSERT_EQ(2, i64);
ASSERT_EQ(2, std::get<int64_t>(prop.get()));
mask |= 2;
} else if (!strcmp(name, "double")) {
double d;
ASSERT_TRUE(prop.get(&d));
ASSERT_EQ(3.125, d);
ASSERT_EQ(3.125, std::get<double>(prop.get()));
mask |= 4;
} else if (!strcmp(name, "string")) {
std::string s;
ASSERT_TRUE(prop.get(&s));
ASSERT_EQ("abc", s);
ASSERT_EQ(s, std::get<std::string>(prop.get()));
mask |= 8;
} else if (!strcmp(name, "rate")) {
std::pair<int64_t, int64_t> r;
ASSERT_TRUE(prop.get(&r));
ASSERT_EQ(11, r.first);
ASSERT_EQ(12, r.second);
ASSERT_EQ(r, std::get<decltype(r)>(prop.get()));
mask |= 16;
} else {
FAIL();

Loading…
Cancel
Save