1 /*
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
25 namespace android {
26
27 class ServiceLogTest : public ::testing::Test {
28 public:
ServiceLogTest()29 ServiceLogTest() : mServiceLog(new ServiceLog(3)) {
30 }
31
32 protected:
33 sp<ServiceLog> mServiceLog;
34 };
35
TEST_F(ServiceLogTest,addThenToString)36 TEST_F(ServiceLogTest, addThenToString) {
37 String8 logString;
38
39 mServiceLog->add(String8("log1"));
40 logString = mServiceLog->toString();
41 EXPECT_TRUE(logString.contains("log1"));
42 ALOGV("toString:\n%s", logString.string());
43
44 static const char kTestLogPrefix[] = "testlogprefix: ";
45 logString = mServiceLog->toString(kTestLogPrefix);
46 EXPECT_TRUE(logString.contains(kTestLogPrefix));
47 EXPECT_TRUE(logString.contains("log1"));
48 ALOGV("toString:\n%s", logString.string());
49
50 mServiceLog->add(String8("log2"));
51 logString = mServiceLog->toString();
52 EXPECT_TRUE(logString.contains("log1"));
53 EXPECT_TRUE(logString.contains("log2"));
54 ALOGV("toString:\n%s", logString.string());
55
56 mServiceLog->add(String8("log3"));
57 logString = mServiceLog->toString();
58 EXPECT_TRUE(logString.contains("log1"));
59 EXPECT_TRUE(logString.contains("log2"));
60 EXPECT_TRUE(logString.contains("log3"));
61 ALOGV("toString:\n%s", logString.string());
62
63 mServiceLog->add(String8("log4"));
64 logString = mServiceLog->toString();
65 EXPECT_FALSE(logString.contains("log1"));
66 EXPECT_TRUE(logString.contains("log2"));
67 EXPECT_TRUE(logString.contains("log3"));
68 EXPECT_TRUE(logString.contains("log4"));
69 ALOGV("toString:\n%s", logString.string());
70
71 mServiceLog->add(String8("log5"));
72 logString = mServiceLog->toString();
73 EXPECT_FALSE(logString.contains("log1"));
74 EXPECT_FALSE(logString.contains("log2"));
75 EXPECT_TRUE(logString.contains("log3"));
76 EXPECT_TRUE(logString.contains("log4"));
77 EXPECT_TRUE(logString.contains("log5"));
78 ALOGV("toString:\n%s", logString.string());
79 }
80
81 } // namespace android
82