Internal changes.

PiperOrigin-RevId: 804560917
This commit is contained in:
Francis Tsui
2025-09-08 13:23:27 -07:00
committed by Copybara-Service
parent 1b99ec036b
commit 1d6f44e6b5
15 changed files with 86 additions and 83 deletions
+6 -6
View File
@@ -416,7 +416,7 @@ cc_test(
deps = [
":base",
":test_util",
"//internal/platform/implementation:platform_impl", # build_cleaner: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/hash:hash_testing",
"@com_google_absl//absl/status",
@@ -451,7 +451,7 @@ cc_test(
":base",
":cancellation_flag",
":test_util",
"//internal/platform/implementation:platform_impl", # build_cleaner: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -476,7 +476,7 @@ cc_test(
deps = [
":error_code_recorder",
":test_util",
"//internal/platform/implementation:platform_impl", # build_cleaner: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -513,7 +513,7 @@ cc_test(
"//connections/implementation/flags:connections_flags",
"//internal/flags:nearby_flags",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:platform_impl", # build_cleaner: keep
"//internal/platform/implementation:platform_impl",
"//proto:connections_enums_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/status",
@@ -530,7 +530,7 @@ cc_test(
deps = [
":comm",
"//internal/platform/implementation:comm",
"//internal/platform/implementation:platform_impl", # build_cleaner: keep
"//internal/platform/implementation:platform_impl",
"//internal/proto:credential_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/status",
@@ -575,7 +575,7 @@ cc_test(
"//internal/base:file_path",
"//internal/base:files",
"//internal/crypto_cros",
"//internal/platform/implementation:platform_impl", # build_cleaner: keep
"//internal/platform/implementation:platform_impl",
"//internal/platform/implementation:types",
"//internal/test",
"@com_github_protobuf_matchers//protobuf-matchers",
+1
View File
@@ -224,6 +224,7 @@ cc_library(
cc_library(
name = "platform_impl",
testonly = True,
tags = ["keep_dep"], # Prevent build_cleaner from removing the dependency.
visibility = [
"//:__subpackages__",
"//connections/implementation:__subpackages__",
+21 -27
View File
@@ -457,6 +457,7 @@ cc_test(
":test_support",
":types",
"//internal/platform:types",
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//proto:sharing_enums_cc_proto",
"//sharing/certificates",
@@ -470,14 +471,7 @@ cc_test(
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest_main",
] + select({
"@platforms//os:windows": [
"//internal/platform/implementation/windows",
],
"//conditions:default": [
"//internal/platform/implementation/g3",
],
}),
],
)
cc_test(
@@ -487,7 +481,7 @@ cc_test(
],
deps = [
":nearby_sharing_service",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -500,7 +494,7 @@ cc_test(
":incoming_frame_reader",
":nearby_connection_impl",
":test_support",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/internal/public:logging",
"//sharing/proto:wire_format_cc_proto",
@@ -520,7 +514,7 @@ cc_test(
":test_support",
"//internal/base:file_path",
"//internal/base:files",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/proto:wire_format_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
@@ -543,7 +537,7 @@ cc_test(
"//internal/base:file_path",
"//internal/base:files",
"//internal/flags:nearby_flags",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/common:enum",
"//sharing/flags/generated:generated_flags",
@@ -580,8 +574,8 @@ cc_test(
"//internal/base:file_path",
"//internal/base:files",
"//internal/flags:nearby_flags",
"//internal/platform/implementation:platform_impl",
"//internal/platform/implementation:signin_attempt",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/test",
"//internal/test:mocks",
"//sharing/analytics",
@@ -621,7 +615,7 @@ cc_test(
srcs = ["nearby_connections_stream_buffer_manager_test.cc"],
deps = [
":nearby_sharing_service",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -635,7 +629,7 @@ cc_test(
":nearby_sharing_service",
":types",
"//connections:core_types",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -648,7 +642,7 @@ cc_test(
":share_session",
"//internal/base:file_path",
"//internal/base:files",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//sharing/internal/api:mock_sharing_platform",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/synchronization",
@@ -663,7 +657,7 @@ cc_test(
deps = [
":attachments",
":nearby_sharing_service",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/internal/test:nearby_test",
"//sharing/local_device_data:test_support",
@@ -679,7 +673,7 @@ cc_test(
deps = [
":nearby_sharing_service",
"//internal/base:files",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/common",
"//sharing/common:enum",
@@ -704,7 +698,7 @@ cc_test(
":connection_types",
":share_session",
":transfer_metadata",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/proto:wire_format_cc_proto",
"@com_github_protobuf_matchers//protobuf-matchers",
@@ -744,7 +738,7 @@ cc_test(
deps = [
":connection_types",
":nearby_sharing_service",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/internal/test:nearby_test",
"@com_github_protobuf_matchers//protobuf-matchers",
@@ -779,7 +773,7 @@ cc_test(
":types",
"//internal/analytics:mock_event_logger",
"//internal/base:file_path",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/analytics",
"//sharing/certificates:test_support",
@@ -810,7 +804,7 @@ cc_test(
deps = [
":nearby_sharing_service",
":types",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -832,7 +826,7 @@ cc_test(
"//internal/analytics:mock_event_logger",
"//internal/base:file_path",
"//internal/network:url",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/analytics",
"//sharing/certificates:test_support",
@@ -861,7 +855,7 @@ cc_test(
":types",
"//internal/analytics:mock_event_logger",
"//internal/base:file_path",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//proto:sharing_enums_cc_proto",
"//sharing/analytics",
@@ -881,7 +875,7 @@ cc_test(
srcs = ["thread_timer_test.cc"],
deps = [
":thread_timer",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/synchronization",
@@ -897,7 +891,7 @@ cc_test(
":connection_types",
":nearby_sharing_service",
"//internal/platform:types",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
@@ -908,7 +902,7 @@ cc_test(
srcs = ["worker_queue_test.cc"],
deps = [
":worker_queue",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/synchronization",
+1 -1
View File
@@ -49,7 +49,7 @@ cc_test(
deps = [
":analytics",
"//internal/analytics:mock_event_logger",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//proto:sharing_enums_cc_proto",
"//sharing:attachments",
"//sharing:types",
+1 -1
View File
@@ -81,7 +81,7 @@ cc_test(
deps = [
":contacts",
"//internal/platform/implementation:account_manager",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/common",
"//sharing/internal/api:mock_sharing_platform",
+1 -1
View File
@@ -63,7 +63,7 @@ cc_test(
deps = [
":nearby_fast_initiation",
":test_support",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//sharing/internal/api:platform",
"//sharing/internal/test:nearby_test",
"@com_github_protobuf_matchers//protobuf-matchers",
+1 -2
View File
@@ -52,10 +52,9 @@ cc_test(
"encode_test.cc",
"mime_test.cc",
],
shard_count = 8,
deps = [
":base",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_googletest//:gtest_main",
],
+1 -2
View File
@@ -65,11 +65,10 @@ cc_test(
srcs = [
"connectivity_manager_impl_test.cc",
],
shard_count = 8,
deps = [
":nearby_context",
":types",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//sharing/internal/api:mock_sharing_platform",
"//sharing/internal/api:platform",
"@com_github_protobuf_matchers//protobuf-matchers",
+2 -2
View File
@@ -71,8 +71,8 @@ cc_test(
":nearby_test",
"//internal/platform:mac_address",
"//internal/platform:types",
"//internal/platform/implementation/g3", # fixdeps: keep
"//sharing/internal/api:platform", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//sharing/internal/api:platform",
"//sharing/internal/public:types",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/strings",
+24 -19
View File
@@ -17,7 +17,9 @@
#include <stdint.h>
#include <cstdio>
#include <fstream>
#include <functional>
#include <ios>
#include <memory>
#include <optional>
#include <string>
@@ -88,11 +90,13 @@ constexpr char kInvalidBluetoothMacAddress[] = {0x07, 0x07, 0x07};
constexpr absl::Duration kSynchronizationTimeOut = absl::Milliseconds(200);
void InitializeTemporaryFile(FilePath& file) {
std::FILE* output_fp = std::fopen(file.GetPath().c_str(), "wb+");
ASSERT_NE(output_fp, nullptr);
EXPECT_EQ(std::fwrite(kPayload, 1, sizeof(kPayload), output_fp),
sizeof(kPayload));
std::fclose(output_fp);
std::ofstream stream(file.GetPath(), std::ios_base::out |
std::ios_base::trunc |
std::ios_base::binary);
if (stream.good()) {
stream.write(reinterpret_cast<const char*>(kPayload), sizeof(kPayload));
}
stream.close();
}
} // namespace
@@ -404,14 +408,14 @@ class NearbyConnectionsManagerImplTest : public testing::Test {
FilePayload file_payload = std::move(payload->content.file_payload);
std::vector<uint8_t> payload_bytes(file_payload.size);
std::FILE* payload_fp =
std::fopen(file_payload.file.path.GetPath().c_str(), "rb");
ASSERT_NE(payload_fp, nullptr);
EXPECT_EQ(std::fread(payload_bytes.data(), 1, file_payload.size,
payload_fp),
file_payload.size);
std::ifstream payload_stream(file_payload.file.path.GetPath(),
std::ios::in | std::ios::binary);
ASSERT_TRUE(payload_stream.good());
payload_stream.read(reinterpret_cast<char*>(payload_bytes.data()),
file_payload.size);
ASSERT_EQ(payload_stream.gcount(), file_payload.size);
EXPECT_EQ(expected_payload, payload_bytes);
std::fclose(payload_fp);
payload_stream.close();
std::move(callback)(Status::kSuccess);
notification.Notify();
@@ -1542,13 +1546,14 @@ TEST_F(NearbyConnectionsManagerImplTest, IncomingFilePayload) {
ASSERT_NE(payload, nullptr);
ASSERT_TRUE(payload->content.is_file());
std::vector<uint8_t> payload_bytes(payload->content.file_payload.size);
std::FILE* payload_fp = std::fopen(
payload->content.file_payload.file.path.GetPath().c_str(), "rb");
ASSERT_NE(payload_fp, nullptr);
EXPECT_EQ(std::fread(payload_bytes.data(), 1,
payload->content.file_payload.size, payload_fp),
payload->content.file_payload.size);
std::fclose(payload_fp);
std::ifstream payload_stream(
payload->content.file_payload.file.path.GetPath(),
std::ios::in | std::ios::binary);
ASSERT_TRUE(payload_stream.good());
payload_stream.read(reinterpret_cast<char*>(payload_bytes.data()),
payload->content.file_payload.size);
ASSERT_EQ(payload_stream.gcount(), payload->content.file_payload.size);
payload_stream.close();
EXPECT_EQ(payload_bytes, expected_payload);
}
+6 -3
View File
@@ -16,6 +16,8 @@
#include <atomic>
#include <cstdio>
#include <fstream>
#include <ios>
#include <vector>
#include "gtest/gtest.h"
@@ -32,11 +34,12 @@ namespace {
using ::nearby::sharing::api::MockSharingPlatform;
bool CreateFile(FilePath& file_path) {
std::FILE* file = std::fopen(file_path.GetPath().c_str(), "w+");
if (file == nullptr) {
std::ofstream file(file_path.GetPath(),
std::ios_base::out | std::ios_base::trunc);
if (!file.good()) {
return false;
}
std::fclose(file);
file.close();
return true;
}
+8 -4
View File
@@ -15,12 +15,13 @@
#include "sharing/nearby_sharing_service_impl.h"
#include <stdint.h>
#include <unistd.h>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <ios>
#include <limits>
#include <memory>
#include <optional>
@@ -1241,9 +1242,12 @@ class NearbySharingServiceImplTest : public testing::Test {
FilePath CreateTestFile(absl::string_view name,
const std::vector<uint8_t>& content) {
FilePath path = Files::GetTemporaryDirectory().append(FilePath(name));
std::FILE* file = std::fopen(path.GetPath().c_str(), "w+");
std::fwrite(content.data(), 1, content.size(), file);
std::fclose(file);
std::ofstream file(path.GetPath(),
std::ios_base::out | std::ios_base::trunc);
if (file.good()) {
file.write(reinterpret_cast<const char*>(content.data()), content.size());
}
file.close();
return path;
}
+1 -1
View File
@@ -97,7 +97,7 @@ cc_test(
],
deps = [
":scheduling",
"//internal/platform/implementation/g3", # fixdeps: keep
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/internal/api:platform",
"//sharing/internal/public:types",
@@ -39,23 +39,21 @@ std::string ConvertToReadableSchedule(PreferenceManager& preference_manager,
preference_manager.GetDictionaryInt64Value(
schedule_preference, SchedulerFields::kLastAttemptTimeKeyName);
if (attempt_time.has_value()) {
std::time_t local_t =
absl::ToTimeT(absl::FromUnixNanos(attempt_time.value()));
std::tm* local_time = std::localtime(&local_t);
std::stringstream buffer;
buffer << std::put_time(local_time, "%Y-%m-%d %H:%M:%S");
absl::StrAppendFormat(&result, "attempt_time:%s, ", buffer.str());
absl::StrAppend(&result, "attempt_time:",
absl::FormatTime(absl::RFC3339_sec,
absl::FromUnixNanos(attempt_time.value()),
absl::UTCTimeZone()),
", ");
}
std::optional<int64_t> success_time =
preference_manager.GetDictionaryInt64Value(
schedule_preference, SchedulerFields::kLastSuccessTimeKeyName);
if (success_time.has_value()) {
std::time_t local_t =
absl::ToTimeT(absl::FromUnixNanos(success_time.value()));
std::tm* local_time = std::localtime(&local_t);
std::stringstream buffer;
buffer << std::put_time(local_time, "%Y-%m-%d %H:%M:%S");
absl::StrAppendFormat(&result, "success_time:%s, ", buffer.str());
absl::StrAppend(&result, "success_time:",
absl::FormatTime(absl::RFC3339_sec,
absl::FromUnixNanos(success_time.value()),
absl::UTCTimeZone()),
", ");
}
std::optional<int64_t> failed_count =
preference_manager.GetDictionaryInt64Value(
@@ -85,8 +85,8 @@ TEST_F(NearbyShareSchedulerUtilsTest, ConvertToReadableScheduleSucceeds) {
std::string debug_str =
ConvertToReadableSchedule(preference_manager(), test_pref);
EXPECT_THAT(debug_str, Eq("{attempt_time:1969-12-31 16:00:00, "
"success_time:1969-12-31 16:00:00, "
EXPECT_THAT(debug_str, Eq("{attempt_time:1970-01-01T00:00:00+00:00, "
"success_time:1970-01-01T00:00:00+00:00, "
"failed_count:123, has_pending_request:true, "
"is_waiting_for_result:false}"));
}