blob: 6ddcb87417655c99382c0668c50399c2a99d34f4 [file] [log] [blame]
Ronghua Wua8ec8fc2015-05-07 13:58:22 -07001/*
2 * Copyright 2015 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_NDEBUG 0
18#define LOG_TAG "ServiceLog_test"
19#include <utils/Log.h>
20
21#include <gtest/gtest.h>
22
23#include "ServiceLog.h"
24
25namespace android {
26
27class ServiceLogTest : public ::testing::Test {
28public:
29 ServiceLogTest() : mServiceLog(new ServiceLog(3)) {
30 }
31
32protected:
33 sp<ServiceLog> mServiceLog;
34};
35
36TEST_F(ServiceLogTest, addThenToString) {
37 mServiceLog->add(String8("log1"));
38 EXPECT_TRUE(mServiceLog->toString().contains("log1"));
39 ALOGV("toString:\n%s", mServiceLog->toString().string());
40
41 mServiceLog->add(String8("log2"));
42 EXPECT_TRUE(mServiceLog->toString().contains("log1"));
43 EXPECT_TRUE(mServiceLog->toString().contains("log2"));
44 ALOGV("toString:\n%s", mServiceLog->toString().string());
45
46 mServiceLog->add(String8("log3"));
47 EXPECT_TRUE(mServiceLog->toString().contains("log1"));
48 EXPECT_TRUE(mServiceLog->toString().contains("log2"));
49 EXPECT_TRUE(mServiceLog->toString().contains("log3"));
50 ALOGV("toString:\n%s", mServiceLog->toString().string());
51
52 mServiceLog->add(String8("log4"));
53 EXPECT_FALSE(mServiceLog->toString().contains("log1"));
54 EXPECT_TRUE(mServiceLog->toString().contains("log2"));
55 EXPECT_TRUE(mServiceLog->toString().contains("log3"));
56 EXPECT_TRUE(mServiceLog->toString().contains("log4"));
57 ALOGV("toString:\n%s", mServiceLog->toString().string());
58
59 mServiceLog->add(String8("log5"));
60 EXPECT_FALSE(mServiceLog->toString().contains("log1"));
61 EXPECT_FALSE(mServiceLog->toString().contains("log2"));
62 EXPECT_TRUE(mServiceLog->toString().contains("log3"));
63 EXPECT_TRUE(mServiceLog->toString().contains("log4"));
64 EXPECT_TRUE(mServiceLog->toString().contains("log5"));
65 ALOGV("toString:\n%s", mServiceLog->toString().string());
66}
67
68} // namespace android