From 557d387a2e25bee33a17f6e5b2e4c19a77a61cf5 Mon Sep 17 00:00:00 2001 From: Boris Tsirkin Date: Wed, 8 Jan 2025 06:00:52 -0800 Subject: [PATCH] Format /test folder Formatting done via: git ls-files | grep -E '^test\/.*\.(h|cc|mm)' | xargs clang-format -i No-Iwyu: Includes didn't change and it isn't related to formatting Bug: webrtc:42225392 Change-Id: I3a75019dee1ad9bef713d80a5f79cbc56adab472 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/373903 Reviewed-by: Mirko Bonadei Commit-Queue: Danil Chapovalov Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#43690} --- test/fake_decoder.cc | 3 +- test/fake_decoder.h | 6 +- test/fake_encoder.cc | 2 +- test/fake_vp8_decoder.h | 3 +- test/fuzzers/stun_parser_fuzzer.cc | 1 - test/ios/coverage_util_ios.mm | 10 +-- test/ios/google_test_runner.mm | 3 +- test/ios/test_support.mm | 51 ++++++++++------ test/mac/run_test.mm | 15 +++-- test/mac/video_renderer_mac.mm | 29 +++++---- test/mac_capturer.mm | 21 ++++--- test/network/network_emulation_unittest.cc | 4 +- test/peer_scenario/peer_scenario_client.cc | 64 ++++++++++---------- test/testsupport/ios_file_utils.mm | 8 +-- test/time_controller/simulated_task_queue.cc | 2 +- test/video_codec_tester.cc | 14 ++--- 16 files changed, 128 insertions(+), 108 deletions(-) diff --git a/test/fake_decoder.cc b/test/fake_decoder.cc index fc38531d29..e816eae273 100644 --- a/test/fake_decoder.cc +++ b/test/fake_decoder.cc @@ -40,8 +40,7 @@ bool FakeDecoder::Configure(const Settings& settings) { return true; } -int32_t FakeDecoder::Decode(const EncodedImage& input, - int64_t render_time_ms) { +int32_t FakeDecoder::Decode(const EncodedImage& input, int64_t render_time_ms) { if (input._encodedWidth > 0 && input._encodedHeight > 0) { width_ = input._encodedWidth; height_ = input._encodedHeight; diff --git a/test/fake_decoder.h b/test/fake_decoder.h index e14eae0228..8487e36086 100644 --- a/test/fake_decoder.h +++ b/test/fake_decoder.h @@ -34,8 +34,7 @@ class FakeDecoder : public VideoDecoder { bool Configure(const Settings& settings) override; - int32_t Decode(const EncodedImage& input, - int64_t render_time_ms) override; + int32_t Decode(const EncodedImage& input, int64_t render_time_ms) override; int32_t RegisterDecodeCompleteCallback( DecodedImageCallback* callback) override; @@ -62,8 +61,7 @@ class FakeH264Decoder : public FakeDecoder { public: virtual ~FakeH264Decoder() {} - int32_t Decode(const EncodedImage& input, - int64_t render_time_ms) override; + int32_t Decode(const EncodedImage& input, int64_t render_time_ms) override; }; } // namespace test diff --git a/test/fake_encoder.cc b/test/fake_encoder.cc index a2f49a091f..609afc5f1a 100644 --- a/test/fake_encoder.cc +++ b/test/fake_encoder.cc @@ -269,7 +269,7 @@ void FakeEncoder::SetRatesLocked(const RateControlParameters& parameters) { uint32_t bitrate = current_rate_settings_.bitrate.GetBitrate( spatial_idx, temporal_idx); bitrate = static_cast( - (bitrate* int64_t{max_target_bitrate_kbps_}) / + (bitrate * int64_t{max_target_bitrate_kbps_}) / allocated_bitrate_kbps); current_rate_settings_.bitrate.SetBitrate(spatial_idx, temporal_idx, bitrate); diff --git a/test/fake_vp8_decoder.h b/test/fake_vp8_decoder.h index 95cc4b60f7..5bfe3a4974 100644 --- a/test/fake_vp8_decoder.h +++ b/test/fake_vp8_decoder.h @@ -27,8 +27,7 @@ class FakeVp8Decoder : public VideoDecoder { bool Configure(const Settings& settings) override; - int32_t Decode(const EncodedImage& input, - int64_t render_time_ms) override; + int32_t Decode(const EncodedImage& input, int64_t render_time_ms) override; int32_t RegisterDecodeCompleteCallback( DecodedImageCallback* callback) override; diff --git a/test/fuzzers/stun_parser_fuzzer.cc b/test/fuzzers/stun_parser_fuzzer.cc index c8aad8c232..95b1b14bfa 100644 --- a/test/fuzzers/stun_parser_fuzzer.cc +++ b/test/fuzzers/stun_parser_fuzzer.cc @@ -15,7 +15,6 @@ namespace webrtc { void FuzzOneInput(const uint8_t* data, size_t size) { - // Normally we'd check the integrity first, but those checks are // fuzzed separately in stun_validator_fuzzer.cc. We still want to // fuzz this target since the integrity checks could be forged by a diff --git a/test/ios/coverage_util_ios.mm b/test/ios/coverage_util_ios.mm index c21a16def2..0486dc4a47 100644 --- a/test/ios/coverage_util_ios.mm +++ b/test/ios/coverage_util_ios.mm @@ -23,14 +23,16 @@ void ConfigureCoverageReportPath() { dispatch_once(&once_token, ^{ // Writes the profraw file to the Documents directory, where the app has // write rights. - NSArray* paths = - NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSArray* paths = NSSearchPathForDirectoriesInDomains( + NSDocumentDirectory, NSUserDomainMask, YES); NSString* documents_directory = [paths firstObject]; - NSString* file_name = [documents_directory stringByAppendingPathComponent:@"coverage.profraw"]; + NSString* file_name = [documents_directory + stringByAppendingPathComponent:@"coverage.profraw"]; // For documentation, see: // http://clang.llvm.org/docs/SourceBasedCodeCoverage.html - __llvm_profile_set_filename([file_name cStringUsingEncoding:NSUTF8StringEncoding]); + __llvm_profile_set_filename( + [file_name cStringUsingEncoding:NSUTF8StringEncoding]); // Print the path for easier retrieval. NSLog(@"Coverage data at %@.", file_name); diff --git a/test/ios/google_test_runner.mm b/test/ios/google_test_runner.mm index 87b7f7dfd7..d173b9fef6 100644 --- a/test/ios/google_test_runner.mm +++ b/test/ios/google_test_runner.mm @@ -29,7 +29,8 @@ self.continueAfterFailure = false; id appDelegate = UIApplication.sharedApplication.delegate; - XCTAssertTrue([appDelegate conformsToProtocol:@protocol(GoogleTestRunnerDelegate)]); + XCTAssertTrue( + [appDelegate conformsToProtocol:@protocol(GoogleTestRunnerDelegate)]); id runnerDelegate = static_cast>(appDelegate); diff --git a/test/ios/test_support.mm b/test/ios/test_support.mm index 80208d5f05..df8f9df843 100644 --- a/test/ios/test_support.mm +++ b/test/ios/test_support.mm @@ -38,7 +38,8 @@ // run in a row, this provides an indication of which one is currently running. // If enabled, runs unittests using the XCTest test runner. -const char kEnableRunIOSUnittestsWithXCTest[] = "enable-run-ios-unittests-with-xctest"; +const char kEnableRunIOSUnittestsWithXCTest[] = + "enable-run-ios-unittests-with-xctest"; static int (*g_test_suite)(void) = NULL; static int g_argc; @@ -97,45 +98,57 @@ static std::optional> g_metrics_to_plot; int exitStatus = g_test_suite(); - NSArray *outputDirectories = - NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSArray *outputDirectories = NSSearchPathForDirectoriesInDomains( + NSDocumentDirectory, NSUserDomainMask, YES); std::vector> exporters; if (g_export_perf_results_new_api) { - exporters.push_back(std::make_unique()); + exporters.push_back( + std::make_unique()); if (g_write_perf_output) { // Stores data into a proto file under the app's document directory. NSString *fileName = @"perftest-output.pb"; if ([outputDirectories count] != 0) { - NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; + NSString *outputPath = + [outputDirectories[0] stringByAppendingPathComponent:fileName]; - exporters.push_back(std::make_unique( - [NSString stdStringForString:outputPath])); + exporters.push_back( + std::make_unique( + [NSString stdStringForString:outputPath])); } } if (!g_webrtc_test_metrics_output_path.empty()) { - RTC_CHECK_EQ(g_webrtc_test_metrics_output_path.find('/'), std::string::npos) - << "On iOS, --webrtc_test_metrics_output_path must only be a file name."; + RTC_CHECK_EQ(g_webrtc_test_metrics_output_path.find('/'), + std::string::npos) + << "On iOS, --webrtc_test_metrics_output_path must only be a file " + "name."; if ([outputDirectories count] != 0) { - NSString *fileName = [NSString stringWithCString:g_webrtc_test_metrics_output_path.c_str() - encoding:[NSString defaultCStringEncoding]]; - NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; - exporters.push_back(std::make_unique( - webrtc::test::MetricsSetProtoFileExporter::Options( - [NSString stdStringForString:outputPath]))); + NSString *fileName = [NSString + stringWithCString:g_webrtc_test_metrics_output_path.c_str() + encoding:[NSString defaultCStringEncoding]]; + NSString *outputPath = + [outputDirectories[0] stringByAppendingPathComponent:fileName]; + exporters.push_back( + std::make_unique( + webrtc::test::MetricsSetProtoFileExporter::Options( + [NSString stdStringForString:outputPath]))); } } } else { - exporters.push_back(std::make_unique()); + exporters.push_back( + std::make_unique()); } - webrtc::test::ExportPerfMetric(*webrtc::test::GetGlobalMetricsLogger(), std::move(exporters)); + webrtc::test::ExportPerfMetric(*webrtc::test::GetGlobalMetricsLogger(), + std::move(exporters)); if (!g_export_perf_results_new_api) { if (g_write_perf_output) { // Stores data into a proto file under the app's document directory. NSString *fileName = @"perftest-output.pb"; if ([outputDirectories count] != 0) { - NSString *outputPath = [outputDirectories[0] stringByAppendingPathComponent:fileName]; + NSString *outputPath = + [outputDirectories[0] stringByAppendingPathComponent:fileName]; - if (!webrtc::test::WritePerfResults([NSString stdStringForString:outputPath])) { + if (!webrtc::test::WritePerfResults( + [NSString stdStringForString:outputPath])) { return 1; } } diff --git a/test/mac/run_test.mm b/test/mac/run_test.mm index 38c6c8f8c1..b6d60ecd10 100644 --- a/test/mac/run_test.mm +++ b/test/mac/run_test.mm @@ -13,9 +13,11 @@ #include "test/run_test.h" // Converting a C++ function pointer to an Objective-C block. -typedef void(^TestBlock)(); -TestBlock functionToBlock(void(*function)()) { - return [^(void) { function(); } copy]; +typedef void (^TestBlock)(); +TestBlock functionToBlock(void (*function)()) { + return [^(void) { + function(); + } copy]; } // Class calling the test function on the platform specific thread. @@ -50,7 +52,7 @@ TestBlock functionToBlock(void(*function)()) { namespace webrtc { namespace test { -void RunTest(void(*test)()) { +void RunTest(void (*test)()) { @autoreleasepool { [NSApplication sharedApplication]; @@ -63,8 +65,9 @@ void RunTest(void(*test)()) { withObject:testBlock]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - while ([testRunner running] && [runLoop runMode:NSDefaultRunLoopMode - beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]) + while ([testRunner running] && + [runLoop runMode:NSDefaultRunLoopMode + beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]) ; } } diff --git a/test/mac/video_renderer_mac.mm b/test/mac/video_renderer_mac.mm index c8ba232993..04e4b76444 100644 --- a/test/mac/video_renderer_mac.mm +++ b/test/mac/video_renderer_mac.mm @@ -31,8 +31,8 @@ @end @implementation CocoaWindow - static NSInteger nextXOrigin_; - static NSInteger nextYOrigin_; +static NSInteger nextXOrigin_; +static NSInteger nextYOrigin_; - (id)initWithTitle:(NSString *)title width:(int)width height:(int)height { self = [super init]; @@ -67,7 +67,8 @@ defer:NO]; NSRect viewFrame = NSMakeRect(0, 0, width_, height_); - NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:viewFrame pixelFormat:nil]; + NSOpenGLView *view = [[NSOpenGLView alloc] initWithFrame:viewFrame + pixelFormat:nil]; context_ = [view openGLContext]; [[window_ contentView] addSubview:view]; @@ -84,10 +85,10 @@ namespace webrtc { namespace test { -VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title, +VideoRenderer *VideoRenderer::CreatePlatformRenderer(const char *window_title, size_t width, size_t height) { - MacRenderer* renderer = new MacRenderer(); + MacRenderer *renderer = new MacRenderer(); if (!renderer->Init(window_title, width, height)) { delete renderer; return NULL; @@ -95,20 +96,18 @@ VideoRenderer* VideoRenderer::CreatePlatformRenderer(const char* window_title, return renderer; } -MacRenderer::MacRenderer() - : window_(NULL) {} +MacRenderer::MacRenderer() : window_(NULL) {} MacRenderer::~MacRenderer() { GlRenderer::Destroy(); } -bool MacRenderer::Init(const char* window_title, int width, int height) { +bool MacRenderer::Init(const char *window_title, int width, int height) { window_ = [[CocoaWindow alloc] initWithTitle:[NSString stringWithUTF8String:window_title] - width:width - height:height]; - if (!window_) - return false; + width:width + height:height]; + if (!window_) return false; [window_ performSelectorOnMainThread:@selector(createWindow:) withObject:nil waitUntilDone:YES]; @@ -119,10 +118,10 @@ bool MacRenderer::Init(const char* window_title, int width, int height) { return true; } -void MacRenderer::OnFrame(const VideoFrame& frame) { +void MacRenderer::OnFrame(const VideoFrame &frame) { [window_ makeCurrentContext]; GlRenderer::OnFrame(frame); } -} // test -} // webrtc +} // namespace test +} // namespace webrtc diff --git a/test/mac_capturer.mm b/test/mac_capturer.mm index 9b14f28c2a..bc9ea77da2 100644 --- a/test/mac_capturer.mm +++ b/test/mac_capturer.mm @@ -15,7 +15,8 @@ #import "sdk/objc/native/api/video_capturer.h" #import "sdk/objc/native/src/objc_frame_buffer.h" -@interface RTCTestVideoSourceAdapter : NSObject +@interface RTCTestVideoSourceAdapter + : NSObject @property(nonatomic) webrtc::test::MacCapturer *capturer; @end @@ -38,15 +39,18 @@ namespace { -AVCaptureDeviceFormat *SelectClosestFormat(AVCaptureDevice *device, size_t width, size_t height) { +AVCaptureDeviceFormat *SelectClosestFormat(AVCaptureDevice *device, + size_t width, + size_t height) { NSArray *formats = [RTC_OBJC_TYPE(RTCCameraVideoCapturer) supportedFormatsForDevice:device]; AVCaptureDeviceFormat *selectedFormat = nil; int currentDiff = INT_MAX; for (AVCaptureDeviceFormat *format in formats) { - CMVideoDimensions dimension = CMVideoFormatDescriptionGetDimensions(format.formatDescription); - int diff = - std::abs((int64_t)width - dimension.width) + std::abs((int64_t)height - dimension.height); + CMVideoDimensions dimension = + CMVideoFormatDescriptionGetDimensions(format.formatDescription); + int diff = std::abs((int64_t)width - dimension.width) + + std::abs((int64_t)height - dimension.height); if (diff < currentDiff) { selectedFormat = format; currentDiff = diff; @@ -74,8 +78,8 @@ MacCapturer::MacCapturer(size_t width, [[RTC_OBJC_TYPE(RTCCameraVideoCapturer) alloc] initWithDelegate:adapter]; capturer_ = (__bridge_retained void *)capturer; - AVCaptureDevice *device = - [[RTC_OBJC_TYPE(RTCCameraVideoCapturer) captureDevices] objectAtIndex:capture_device_index]; + AVCaptureDevice *device = [[RTC_OBJC_TYPE(RTCCameraVideoCapturer) + captureDevices] objectAtIndex:capture_device_index]; AVCaptureDeviceFormat *format = SelectClosestFormat(device, width, height); [capturer startCaptureWithDevice:device format:format fps:target_fps]; } @@ -90,7 +94,8 @@ MacCapturer *MacCapturer::Create(size_t width, void MacCapturer::Destroy() { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-variable" - RTCTestVideoSourceAdapter *adapter = (__bridge_transfer RTCTestVideoSourceAdapter *)adapter_; + RTCTestVideoSourceAdapter *adapter = + (__bridge_transfer RTCTestVideoSourceAdapter *)adapter_; RTC_OBJC_TYPE(RTCCameraVideoCapturer) *capturer = (__bridge_transfer RTC_OBJC_TYPE(RTCCameraVideoCapturer) *)capturer_; [capturer stopCapture]; diff --git a/test/network/network_emulation_unittest.cc b/test/network/network_emulation_unittest.cc index d8455b937f..a1243afa59 100644 --- a/test/network/network_emulation_unittest.cc +++ b/test/network/network_emulation_unittest.cc @@ -113,7 +113,9 @@ class MockNetworkBehaviourInterface : public NetworkBehaviorInterface { DequeueDeliverablePackets, (int64_t), (override)); - MOCK_METHOD(std::optional, NextDeliveryTimeUs, (), + MOCK_METHOD(std::optional, + NextDeliveryTimeUs, + (), (const, override)); MOCK_METHOD(void, RegisterDeliveryTimeChangedCallback, diff --git a/test/peer_scenario/peer_scenario_client.cc b/test/peer_scenario/peer_scenario_client.cc index 5a490edfec..2a73cf2636 100644 --- a/test/peer_scenario/peer_scenario_client.cc +++ b/test/peer_scenario/peer_scenario_client.cc @@ -380,43 +380,43 @@ void PeerScenarioClient::SetSdpOfferAndGetAnswer( std::function remote_description_set, std::function answer_handler) { if (!signaling_thread_->IsCurrent()) { - signaling_thread_->PostTask([this, remote_offer, remote_description_set, - answer_handler] { - SetSdpOfferAndGetAnswer(remote_offer, remote_description_set, - answer_handler); - }); + signaling_thread_->PostTask( + [this, remote_offer, remote_description_set, answer_handler] { + SetSdpOfferAndGetAnswer(remote_offer, remote_description_set, + answer_handler); + }); return; } RTC_DCHECK_RUN_ON(signaling_thread_); peer_connection_->SetRemoteDescription( CreateSessionDescription(SdpType::kOffer, remote_offer), - rtc::make_ref_counted< - LambdaSetRemoteDescriptionObserver>([this, remote_description_set, - answer_handler](RTCError) { - RTC_DCHECK_RUN_ON(signaling_thread_); - if (remote_description_set) { - // Allow the caller to modify transceivers - // before creating the answer. - remote_description_set(); - } - peer_connection_->CreateAnswer( - rtc::make_ref_counted( - [this, answer_handler]( - std::unique_ptr answer) { - RTC_DCHECK_RUN_ON(signaling_thread_); - std::string sdp_answer; - answer->ToString(&sdp_answer); - RTC_LOG(LS_INFO) << sdp_answer; - peer_connection_->SetLocalDescription( - std::move(answer), - rtc::make_ref_counted( - [answer_handler, sdp_answer](RTCError) { - answer_handler(sdp_answer); - })); - }) - .get(), - PeerConnectionInterface::RTCOfferAnswerOptions()); - })); + rtc::make_ref_counted( + [this, remote_description_set, answer_handler](RTCError) { + RTC_DCHECK_RUN_ON(signaling_thread_); + if (remote_description_set) { + // Allow the caller to modify transceivers + // before creating the answer. + remote_description_set(); + } + peer_connection_->CreateAnswer( + rtc::make_ref_counted( + [this, answer_handler]( + std::unique_ptr answer) { + RTC_DCHECK_RUN_ON(signaling_thread_); + std::string sdp_answer; + answer->ToString(&sdp_answer); + RTC_LOG(LS_INFO) << sdp_answer; + peer_connection_->SetLocalDescription( + std::move(answer), + rtc::make_ref_counted< + LambdaSetLocalDescriptionObserver>( + [answer_handler, sdp_answer](RTCError) { + answer_handler(sdp_answer); + })); + }) + .get(), + PeerConnectionInterface::RTCOfferAnswerOptions()); + })); } void PeerScenarioClient::SetSdpAnswer( diff --git a/test/testsupport/ios_file_utils.mm b/test/testsupport/ios_file_utils.mm index ef36937e6a..5c5c7f092a 100644 --- a/test/testsupport/ios_file_utils.mm +++ b/test/testsupport/ios_file_utils.mm @@ -24,7 +24,8 @@ namespace test { // For iOS, resource files are added to the application bundle in the root // and not in separate folders as is the case for other platforms. This method // therefore removes any prepended folders and uses only the actual file name. -std::string IOSResourcePath(absl::string_view name, absl::string_view extension) { +std::string IOSResourcePath(absl::string_view name, + absl::string_view extension) { @autoreleasepool { NSString* path = [NSString stringForAbslStringView:name]; NSString* fileName = path.lastPathComponent; @@ -46,11 +47,10 @@ std::string IOSRootPath() { // For iOS, we don't have access to the output directory. Return the path to the // temporary directory instead. This is mostly used by tests that need to write // output files to disk. -std::string IOSOutputPath() { +std::string IOSOutputPath() { @autoreleasepool { NSString* tempDir = NSTemporaryDirectory(); - if (tempDir == nil) - tempDir = @"/tmp"; + if (tempDir == nil) tempDir = @"/tmp"; return [NSString stdStringForString:tempDir]; } } diff --git a/test/time_controller/simulated_task_queue.cc b/test/time_controller/simulated_task_queue.cc index 66b3fd8087..3d786dfdcc 100644 --- a/test/time_controller/simulated_task_queue.cc +++ b/test/time_controller/simulated_task_queue.cc @@ -52,7 +52,7 @@ void SimulatedTaskQueue::RunReady(Timestamp at_time) { } CurrentTaskQueueSetter set_current(this); while (!ready_tasks_.empty()) { - absl::AnyInvocable ready = std::move(ready_tasks_.front()); + absl::AnyInvocable ready = std::move(ready_tasks_.front()); ready_tasks_.pop_front(); lock_.Unlock(); std::move(ready)(); diff --git a/test/video_codec_tester.cc b/test/video_codec_tester.cc index 2782a6627c..192bb4ea6a 100644 --- a/test/video_codec_tester.cc +++ b/test/video_codec_tester.cc @@ -1674,13 +1674,13 @@ VideoCodecTester::RunEncodeDecodeTest( frame_settings.layers_settings.rbegin()->second; VideoFrame source_frame = video_source.PullFrame( timestamp_rtp, top_layer.resolution, top_layer.framerate); - encoder.Encode(source_frame, frame_settings, - [&decoders, - source_frame](const EncodedImage& encoded_frame) { - int sidx = encoded_frame.SpatialIndex().value_or( - encoded_frame.SimulcastIndex().value_or(0)); - decoders.at(sidx)->Decode(encoded_frame, source_frame); - }); + encoder.Encode( + source_frame, frame_settings, + [&decoders, source_frame](const EncodedImage& encoded_frame) { + int sidx = encoded_frame.SpatialIndex().value_or( + encoded_frame.SimulcastIndex().value_or(0)); + decoders.at(sidx)->Decode(encoded_frame, source_frame); + }); } encoder.Flush();