blob: a7b41366626601efd954dc223c5d7251efff76dc [file] [log] [blame]
David Chen9fdd4032018-03-20 14:38:56 -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#include "StatsService.h"
16#include "config/ConfigKey.h"
17#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
18
19#include <gmock/gmock.h>
20#include <gtest/gtest.h>
21
22#include <stdio.h>
23
24using namespace android;
25using namespace testing;
26
27namespace android {
28namespace os {
29namespace statsd {
30
31using android::util::ProtoOutputStream;
32
33#ifdef __ANDROID__
34
35TEST(StatsServiceTest, TestAddConfig_simple) {
36 StatsService service(nullptr);
37 StatsdConfig config;
38 config.set_id(12345);
39 string serialized = config.SerializeAsString();
40
41 EXPECT_TRUE(
42 service.addConfigurationChecked(123, 12345, {serialized.begin(), serialized.end()}));
43}
44
45TEST(StatsServiceTest, TestAddConfig_empty) {
46 StatsService service(nullptr);
47 string serialized = "";
48
49 EXPECT_TRUE(
50 service.addConfigurationChecked(123, 12345, {serialized.begin(), serialized.end()}));
51}
52
53TEST(StatsServiceTest, TestAddConfig_invalid) {
54 StatsService service(nullptr);
55 string serialized = "Invalid config!";
56
57 EXPECT_FALSE(
58 service.addConfigurationChecked(123, 12345, {serialized.begin(), serialized.end()}));
59}
60
61#else
62GTEST_LOG_(INFO) << "This test does nothing.\n";
63#endif
64
65} // namespace statsd
66} // namespace os
67} // namespace android