blob: ea7739b9b80f77402f8603991920e94957c084f5 [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
Andy Hungc89c8dc2019-10-16 17:48:21 -070033 // random keys ignored when empty
Andy Hunga87e69c2019-10-18 10:07:40 -070034 std::unique_ptr<MediaAnalyticsItem> random_key(MediaAnalyticsItem::create("random_key"));
35 status = mediaMetrics->submit(random_key.get());
36 ASSERT_EQ(PERMISSION_DENIED, status);
Andy Hungc89c8dc2019-10-16 17:48:21 -070037
38 // random keys ignored with data
Andy Hungc89c8dc2019-10-16 17:48:21 -070039 random_key->setInt32("foo", 10);
Andy Hunga87e69c2019-10-18 10:07:40 -070040 status = mediaMetrics->submit(random_key.get());
41 ASSERT_EQ(PERMISSION_DENIED, status);
Andy Hungc89c8dc2019-10-16 17:48:21 -070042
43 // known keys ignored if empty
Andy Hunga87e69c2019-10-18 10:07:40 -070044 std::unique_ptr<MediaAnalyticsItem> audiotrack_key(MediaAnalyticsItem::create("audiotrack"));
45 status = mediaMetrics->submit(audiotrack_key.get());
46 ASSERT_EQ(BAD_VALUE, status);
Andy Hungc89c8dc2019-10-16 17:48:21 -070047
Andy Hunga87e69c2019-10-18 10:07:40 -070048 // known keys not ignored if not empty
49 audiotrack_key->addInt32("foo", 10);
50 status = mediaMetrics->submit(audiotrack_key.get());
51 ASSERT_EQ(NO_ERROR, status);
Andy Hungc89c8dc2019-10-16 17:48:21 -070052
53 mediaMetrics->dump(fileno(stdout), {} /* args */);
54}