Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include "base/json/json_writer.h" |
| 10 | #include "base/memory/scoped_ptr.h" |
| 11 | #include "base/values.h" |
| 12 | #include "chrome/browser/extensions/api/log_private/filter_handler.h" |
| 13 | #include "chrome/browser/extensions/api/log_private/log_private_api.h" |
| 14 | #include "chrome/browser/extensions/api/log_private/syslog_parser.h" |
| 15 | #include "chrome/common/extensions/api/log_private.h" |
| 16 | #include "testing/gtest/include/gtest/gtest.h" |
| 17 | |
| 18 | namespace extensions { |
| 19 | namespace { |
| 20 | |
| 21 | const char kShillLogEntry[] = |
| 22 | "2013-07-08T11:28:12.440308-07:00 localhost shill:" |
| 23 | "[0708/112812:ERROR:manager.cc(480)] Skipping unload of service"; |
| 24 | |
| 25 | const char kWpaSupplicantLogEntry[] = |
| 26 | "2013-07-08T12:39:07.443100-07:00 localhost wpa_supplicant[894]:" |
| 27 | "dbus: Failed to construct signal"; |
| 28 | |
| 29 | } // namespace |
| 30 | |
| 31 | class ExtensionSyslogParserTest : public testing::Test { |
| 32 | }; |
| 33 | |
| 34 | TEST_F(ExtensionSyslogParserTest, ParseLog) { |
| 35 | std::vector<linked_ptr<api::log_private::LogEntry> > output; |
| 36 | api::log_private::Filter filter; |
| 37 | FilterHandler filter_handler(filter); |
| 38 | SyslogParser p; |
| 39 | // Test shill log |
| 40 | p.Parse(kShillLogEntry, &output, &filter_handler); |
| 41 | EXPECT_STREQ(output[0]->level.c_str(), "error"); |
| 42 | EXPECT_STREQ(output[0]->process.c_str(), "shill:"); |
| 43 | EXPECT_STREQ(output[0]->process_id.c_str(), "unknown"); |
| 44 | EXPECT_STREQ(output[0]->full_entry.c_str(), kShillLogEntry); |
| 45 | EXPECT_EQ(output[0]->timestamp, 1373308092440.308); |
| 46 | // Test WpaSupplicant log |
| 47 | p.Parse(kWpaSupplicantLogEntry, &output, &filter_handler); |
| 48 | EXPECT_STREQ(output[1]->level.c_str(), "unknown"); |
| 49 | EXPECT_STREQ(output[1]->process.c_str(), "wpa_supplicant"); |
| 50 | EXPECT_STREQ(output[1]->process_id.c_str(), "894"); |
| 51 | EXPECT_STREQ(output[1]->full_entry.c_str(), kWpaSupplicantLogEntry); |
| 52 | EXPECT_EQ(output[1]->timestamp, 1373312347443.1); |
| 53 | } |
| 54 | |
| 55 | } // namespace extensions |