Andy Hung | c89c8dc | 2019-10-16 17:48:21 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 27 | using namespace android; |
| 28 | |
| 29 | TEST(mediametrics_tests, instantiate) { |
| 30 | sp mediaMetrics = new MediaAnalyticsService(); |
| 31 | status_t status; |
| 32 | |
Andy Hung | c89c8dc | 2019-10-16 17:48:21 -0700 | [diff] [blame] | 33 | // random keys ignored when empty |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame^] | 34 | std::unique_ptr<MediaAnalyticsItem> random_key(MediaAnalyticsItem::create("random_key")); |
| 35 | status = mediaMetrics->submit(random_key.get()); |
| 36 | ASSERT_EQ(PERMISSION_DENIED, status); |
Andy Hung | c89c8dc | 2019-10-16 17:48:21 -0700 | [diff] [blame] | 37 | |
| 38 | // random keys ignored with data |
Andy Hung | c89c8dc | 2019-10-16 17:48:21 -0700 | [diff] [blame] | 39 | random_key->setInt32("foo", 10); |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame^] | 40 | status = mediaMetrics->submit(random_key.get()); |
| 41 | ASSERT_EQ(PERMISSION_DENIED, status); |
Andy Hung | c89c8dc | 2019-10-16 17:48:21 -0700 | [diff] [blame] | 42 | |
| 43 | // known keys ignored if empty |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame^] | 44 | std::unique_ptr<MediaAnalyticsItem> audiotrack_key(MediaAnalyticsItem::create("audiotrack")); |
| 45 | status = mediaMetrics->submit(audiotrack_key.get()); |
| 46 | ASSERT_EQ(BAD_VALUE, status); |
Andy Hung | c89c8dc | 2019-10-16 17:48:21 -0700 | [diff] [blame] | 47 | |
Andy Hung | a87e69c | 2019-10-18 10:07:40 -0700 | [diff] [blame^] | 48 | // 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 Hung | c89c8dc | 2019-10-16 17:48:21 -0700 | [diff] [blame] | 52 | |
| 53 | mediaMetrics->dump(fileno(stdout), {} /* args */); |
| 54 | } |