blob: 794b2f08a450d23f567c27b0d9c075fbcfe594fa [file] [log] [blame]
Andy Hungc89c8dc2019-10-16 17:48:21 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "mediametrics_tests"
18#include <utils/Log.h>
19
20#include "MediaAnalyticsService.h"
21
22#include <stdio.h>
23
24#include <gtest/gtest.h>
25#include <media/MediaAnalyticsItem.h>
26
27using namespace android;
28
29TEST(mediametrics_tests, instantiate) {
30 sp mediaMetrics = new MediaAnalyticsService();
31 status_t status;
32
33 // NOTE: submission of items to MediaMetrics releases ownership, even on error.
34
35 // random keys ignored when empty
36 status = mediaMetrics->submit(MediaAnalyticsItem::create("random_key"), false);
37 ASSERT_EQ(MediaAnalyticsItem::SessionIDInvalid, status);
38
39 // random keys ignored with data
40 auto random_key = MediaAnalyticsItem::create("random_key");
41 random_key->setInt32("foo", 10);
42 status = mediaMetrics->submit(random_key, false);
43 ASSERT_EQ(MediaAnalyticsItem::SessionIDInvalid, status);
44
45 // known keys ignored if empty
46 status = mediaMetrics->submit(MediaAnalyticsItem::create("audiotrack"), false);
47 ASSERT_EQ(MediaAnalyticsItem::SessionIDInvalid, status);
48
49 auto audiotrack = MediaAnalyticsItem::create("audiotrack");
50 audiotrack->addInt32("foo", 10);
51 status = mediaMetrics->submit(audiotrack, false);
52 ASSERT_GT(status, MediaAnalyticsItem::SessionIDNone);
53
54 mediaMetrics->dump(fileno(stdout), {} /* args */);
55}