Home | History | Annotate | Download | only in tests
      1 // 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 
     24 using namespace android;
     25 using namespace testing;
     26 
     27 namespace android {
     28 namespace os {
     29 namespace statsd {
     30 
     31 using android::util::ProtoOutputStream;
     32 
     33 #ifdef __ANDROID__
     34 
     35 TEST(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 
     45 TEST(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 
     53 TEST(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
     62 GTEST_LOG_(INFO) << "This test does nothing.\n";
     63 #endif
     64 
     65 }  // namespace statsd
     66 }  // namespace os
     67 }  // namespace android
     68