blob: b6f14493cb3600524ca7c4ecaa8d43bbbd8460b5 [file] [log] [blame]
David Chende701692017-10-05 13:16:02 -07001// Copyright (C) 2017 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#define LOG_TAG "statsd_test"
16
17#include <gtest/gtest.h>
18#include "../src/UidMap.h"
19#include <stdio.h>
20
21using namespace android;
22using namespace android::os::statsd;
23
24#ifdef __ANDROID__
25const string kApp1 = "app1.sharing.1";
26const string kApp2 = "app2.sharing.1";
27
28TEST(UidMapTest, TestMatching) {
29 UidMap m;
30 vector<int32_t> uids;
31 vector<int32_t> versions;
32 vector<String16> apps;
33
34 uids.push_back(1000);
35 uids.push_back(1000);
36 apps.push_back(String16(kApp1.c_str()));
37 apps.push_back(String16(kApp2.c_str()));
38 versions.push_back(4);
39 versions.push_back(5);
40 m.updateMap(uids, versions, apps);
41 EXPECT_TRUE(m.hasApp(1000, kApp1));
42 EXPECT_TRUE(m.hasApp(1000, kApp2));
43 EXPECT_FALSE(m.hasApp(1000, "not.app"));
44}
45
46TEST(UidMapTest, TestAddAndRemove) {
47 UidMap m;
48 vector<int32_t> uids;
49 vector<int32_t> versions;
50 vector<String16> apps;
51
52 uids.push_back(1000);
53 uids.push_back(1000);
54 apps.push_back(String16(kApp1.c_str()));
55 apps.push_back(String16(kApp2.c_str()));
56 versions.push_back(4);
57 versions.push_back(5);
58 m.updateMap(uids, versions, apps);
59
60 m.updateApp(String16(kApp1.c_str()), 1000, 40);
61 EXPECT_EQ(40, m.getAppVersion(1000, kApp1));
62
63 m.removeApp(String16(kApp1.c_str()), 1000);
64 EXPECT_FALSE(m.hasApp(1000, kApp1));
65 EXPECT_TRUE(m.hasApp(1000, kApp2));
66}
67#else
68GTEST_LOG_(INFO) << "This test does nothing.\n";
69#endif