mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Add a basic test for the logger writer
PiperOrigin-RevId: 764774015
This commit is contained in:
committed by
Copybara-Service
parent
be830a5fef
commit
20fcca4e95
@@ -28,6 +28,7 @@ cc_library(
|
||||
"@com_google_absl//absl/log",
|
||||
"@com_google_absl//absl/log:check",
|
||||
"@com_google_absl//absl/log:globals",
|
||||
"@com_google_absl//absl/log:log_sink_registry",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -287,6 +288,7 @@ cc_library(
|
||||
"@com_google_absl//absl/log",
|
||||
"@com_google_absl//absl/log:check",
|
||||
"@com_google_absl//absl/log:globals",
|
||||
"@com_google_absl//absl/log:log_sink_registry",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/synchronization",
|
||||
"@com_google_absl//absl/time",
|
||||
|
||||
@@ -70,11 +70,27 @@ objc_library(
|
||||
],
|
||||
)
|
||||
|
||||
objc_library(
|
||||
name = "LoggerWriterTestslib",
|
||||
testonly = True,
|
||||
srcs = [
|
||||
"nearby_logger_writer_test.mm",
|
||||
],
|
||||
deps = [
|
||||
"//internal/platform:logging",
|
||||
"//internal/platform/implementation/apple:logger_writer",
|
||||
"//third_party/apple_frameworks:Foundation",
|
||||
"//third_party/apple_frameworks:XCTest",
|
||||
"//third_party/objective_c/google_toolbox_for_mac:GTM_Logger",
|
||||
],
|
||||
)
|
||||
|
||||
ios_unit_test(
|
||||
name = "PlatformTests",
|
||||
minimum_os_version = IOS_MINIMUM_OS,
|
||||
runner = IOS_LATEST_TEST_RUNNER,
|
||||
deps = [
|
||||
":LoggerWriterTestslib",
|
||||
":PlatformTestslib",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2025 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "GoogleToolboxForMac/GTMLogger.h"
|
||||
|
||||
#include "internal/platform/implementation/apple/nearby_logger_writer.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "internal/platform/logging.h"
|
||||
|
||||
class AbslFileLogSink : public absl::LogSink {
|
||||
public:
|
||||
AbslFileLogSink() = default;
|
||||
~AbslFileLogSink() override = default;
|
||||
void Send(const absl::LogEntry& entry) override {
|
||||
logMessage_ = std::string(entry.text_message());
|
||||
severity_ = entry.log_severity();
|
||||
}
|
||||
|
||||
std::string GetLogMessage() const { return logMessage_; }
|
||||
absl::LogSeverity GetSeverity() const { return severity_; }
|
||||
|
||||
private:
|
||||
std::string logMessage_;
|
||||
absl::LogSeverity severity_ = absl::LogSeverity::kInfo;
|
||||
};
|
||||
|
||||
@interface NearbyLoggerWriterTest : XCTestCase
|
||||
@end
|
||||
|
||||
@implementation NearbyLoggerWriterTest {
|
||||
std::unique_ptr<AbslFileLogSink> _logSink;
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
_logSink = std::make_unique<AbslFileLogSink>();
|
||||
absl::SetGlobalVLogLevel(1);
|
||||
absl::AddLogSink(_logSink.get());
|
||||
nearby::apple::EnableNearbyLoggerWriter();
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
absl::RemoveLogSink(_logSink.get());
|
||||
_logSink.reset();
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testInfoLogMessage {
|
||||
GTMLoggerInfo(@"Hello, world!");
|
||||
XCTAssertEqual(_logSink->GetLogMessage(), "Hello, world!");
|
||||
XCTAssertEqual(_logSink->GetSeverity(), absl::LogSeverity::kInfo);
|
||||
}
|
||||
|
||||
- (void)testErrorLogMessage {
|
||||
GTMLoggerError(@"Error!");
|
||||
XCTAssertEqual(_logSink->GetLogMessage(), "Error!");
|
||||
XCTAssertEqual(_logSink->GetSeverity(), absl::LogSeverity::kError);
|
||||
}
|
||||
|
||||
- (void)testVerboseLogMessage {
|
||||
GTMLoggerDebug(@"Verbose!");
|
||||
XCTAssertEqual(_logSink->GetLogMessage(), "Verbose!");
|
||||
XCTAssertEqual(_logSink->GetSeverity(), absl::LogSeverity::kInfo);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -20,13 +20,14 @@
|
||||
#include "base/check.h"
|
||||
#include "base/check_op.h"
|
||||
#include "base/logging.h"
|
||||
#else // defined(NEARBY_CHROMIUM)
|
||||
#else // defined(NEARBY_CHROMIUM)
|
||||
// IWYU pragma: begin_exports
|
||||
#include "absl/log/check.h" // nogncheck
|
||||
#include "absl/log/globals.h" // nogncheck
|
||||
#include "absl/log/log.h" // nogncheck
|
||||
#include "absl/log/check.h" // nogncheck
|
||||
#include "absl/log/globals.h" // nogncheck
|
||||
#include "absl/log/log.h" // nogncheck
|
||||
#include "absl/log/log_sink_registry.h" // nogncheck
|
||||
// IWYU pragma: end_exports
|
||||
#endif // defined(NEARBY_CHROMIUM)
|
||||
#endif // defined(NEARBY_CHROMIUM)
|
||||
|
||||
// Public APIs
|
||||
// The stream statement must come last, or it won't compile.
|
||||
|
||||
Reference in New Issue
Block a user