Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions base/cvd/cuttlefish/host/commands/cvd_send_sms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,59 +1,64 @@
load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary", "cf_cc_library", "cf_cc_test")
load("//cuttlefish/bazel:rules.bzl", "cf_build_test", "cf_cc_binary", "cf_cc_library", "cf_cc_test")

package(
default_visibility = ["//:android_cuttlefish"],
)

cf_build_test(name = "cvd_send_sms_build_test")

cf_cc_binary(
name = "cvd_send_sms",
srcs = [
"main.cc",
],
depend_on_what_you_use_enabled = False,
include_cleaner_enabled = False,
srcs = ["main.cc"],
deps = [
":libcvd_send_sms",
"//cuttlefish/common/libs/fs",
"//libbase",
"//cuttlefish/host/commands/cvd_send_sms:sms_sender",
"@abseil-cpp//absl/log",
"@abseil-cpp//absl/strings",
"@gflags",
],
)

cf_cc_library(
name = "libcvd_send_sms",
srcs = [
"pdu_format_builder.cc",
"sms_sender.cc",
name = "pdu_format_builder",
srcs = ["pdu_format_builder.cc"],
hdrs = ["pdu_format_builder.h"],
deps = [
"@abseil-cpp//absl/log",
"@icu//icu4c/source/common:headers",
"@icu//icu4c/source/common:schriter",
"@icu//icu4c/source/common:utypes",
],
hdrs = [
"pdu_format_builder.h",
"sms_sender.h",
)

cf_cc_test(
name = "pdu_format_builder_test",
srcs = ["pdu_format_builder_test.cc"],
deps = [
"//cuttlefish/host/commands/cvd_send_sms:pdu_format_builder",
],
depend_on_what_you_use_enabled = False,
include_cleaner_enabled = False,
)

cf_cc_library(
name = "sms_sender",
srcs = ["sms_sender.cc"],
hdrs = ["sms_sender.h"],
deps = [
"//cuttlefish/common/libs/fs",
"//libbase",
"//cuttlefish/host/commands/cvd_send_sms:pdu_format_builder",
"@abseil-cpp//absl/log",
"@icu//icu4c/source/common:headers",
"@icu//icu4c/source/common:schriter",
"@icu//icu4c/source/common:utypes",
],
)

cf_cc_test(
name = "libcvd_send_sms_test",
srcs = [
"unittest/pdu_format_builder_test.cc",
"unittest/sms_sender_test.cc",
],
depend_on_what_you_use_enabled = False,
include_cleaner_enabled = False,
name = "sms_sender_test",
srcs = ["sms_sender_test.cc"],
deps = [
":libcvd_send_sms",
"//cuttlefish/common/libs/fs",
"//libbase",
"//cuttlefish/host/commands/cvd_send_sms:sms_sender",
"//cuttlefish/result:result_matchers",
"//cuttlefish/result:result_type",
"@abseil-cpp//absl/log:check",
],
)
11 changes: 7 additions & 4 deletions base/cvd/cuttlefish/host/commands/cvd_send_sms/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* limitations under the License.
*/

#include <string>

#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "gflags/gflags.h"

#include "cuttlefish/common/libs/fs/shared_fd.h"
Expand Down Expand Up @@ -61,10 +64,10 @@ int SendSmsMain(int argc, char** argv) {
}
// Builds the name of the corresponding modem simulator monitor socket.
// https://cs.android.com/android/platform/superproject/+/master:device/google/cuttlefish/host/commands/modem_simulator/main.cpp;l=115;drc=cbfe7dba44bfea95049152b828c1a5d35c9e0522
std::string socket_name = std::string("modem_simulator") +
std::to_string(1000 + FLAGS_instance_number);
auto client_socket = cuttlefish::SharedFD::SocketLocalClient(
socket_name.c_str(), /* abstract */ true, SOCK_STREAM);
const std::string socket_name =
absl::StrCat("modem_simulator", 1000 + FLAGS_instance_number);
SharedFD client_socket = SharedFD::SocketLocalClient(
socket_name, /* abstract */ true, SOCK_STREAM);
SmsSender sms_sender(client_socket);
if (!sms_sender.Send(argv[1], FLAGS_sender_number, FLAGS_modem_id)) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@
#include "cuttlefish/host/commands/cvd_send_sms/pdu_format_builder.h"

#include <algorithm>
#include <codecvt>
#include <cstddef>
#include <iomanip>
#include <iostream>
#include <map>
#include <iterator>
#include <regex>
#include <sstream>
#include <string>
#include <vector>

#include "absl/log/log.h"
#include "unicode/uchriter.h"
#include "unicode/umachine.h"
#include "unicode/unistr.h"
#include "unicode/ustring.h"
#include "unicode/urename.h"
#include "unicode/ustring.h" // IWYU pragma: keep: u_strToUTF8
#include "unicode/utypes.h"

namespace cuttlefish {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include "cuttlefish/host/commands/cvd_send_sms/pdu_format_builder.h"

#include <string>

#include "gtest/gtest.h"

namespace cuttlefish {
Expand All @@ -23,19 +25,15 @@ namespace {
TEST(PDUFormatBuilderTest, EmptyUserDataFails) {
PDUFormatBuilder builder;

std::string result = builder.Build();

EXPECT_EQ(result, "");
EXPECT_EQ(builder.Build(), "");
}

TEST(PDUFormatBuilderTest, NotInAlphabetCharacterFails) {
PDUFormatBuilder builder;
builder.SetUserData("ccccccc☺");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "");
EXPECT_EQ(builder.Build(), "");
}

TEST(PDUFormatBuilderTest, With161CharactersFails) {
Expand All @@ -46,39 +44,31 @@ TEST(PDUFormatBuilderTest, With161CharactersFails) {
"ccccccccccccccccccccccccccccccccccccccccc");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "");
EXPECT_EQ(builder.Build(), "");
}

TEST(PDUFormatBuilderTest, With1CharacterSucceeds) {
PDUFormatBuilder builder;
builder.SetUserData("c");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "0001000b916105214365f700000163");
EXPECT_EQ(builder.Build(), "0001000b916105214365f700000163");
}

TEST(PDUFormatBuilderTest, With7CharactersSucceeds) {
PDUFormatBuilder builder;
builder.SetUserData("ccccccc");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "0001000b916105214365f7000007e3f1783c1e8f01");
EXPECT_EQ(builder.Build(), "0001000b916105214365f7000007e3f1783c1e8f01");
}

TEST(PDUFormatBuilderTest, With8CharactersSucceeds) {
PDUFormatBuilder builder;
builder.SetUserData("cccccccc");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "0001000b916105214365f7000008e3f1783c1e8fc7");
EXPECT_EQ(builder.Build(), "0001000b916105214365f7000008e3f1783c1e8fc7");
}

TEST(PDUFormatBuilderTest, With160CharactersSucceeds) {
Expand All @@ -89,9 +79,7 @@ TEST(PDUFormatBuilderTest, With160CharactersSucceeds) {
"cccccccccccccccccccccccccccccccccccccccc");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result,
EXPECT_EQ(builder.Build(),
"0001000b916105214365f70000a0"
"e3f1783c1e8fc7"
"e3f1783c1e8fc7"
Expand Down Expand Up @@ -123,9 +111,7 @@ TEST(PDUFormatBuilderTest, With160MultiByteCharactersSucceeds) {
"ΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩ");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result,
EXPECT_EQ(builder.Build(),
"0001000b916105214365f70000a0"
"954aa552a9542a"
"954aa552a9542a"
Expand Down Expand Up @@ -158,10 +144,8 @@ TEST(PDUFormatBuilderTest, FullAlphabetSucceeds) {
"¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(
result,
builder.Build(),
"0001000b916105214365f70000808080604028180e888462c168381e90886442a9582e98"
"8c66c3e9783ea09068442a994ea8946ac56ab95eb0986c46abd96eb89c6ec7ebf97ec0a0"
"70482c1a8fc8a472c96c3a9fd0a8744aad5aafd8ac76cbed7abfe0b0784c2e9bcfe8b47a"
Expand All @@ -173,18 +157,15 @@ TEST(PDUFormatBuilderTest, WithEmptySenderPhoneNumberFails) {
builder.SetUserData("c");
builder.SetSenderNumber("");

std::string result = builder.Build();

EXPECT_EQ(result, "");
EXPECT_EQ(builder.Build(), "");
}

TEST(PDUFormatBuilderTest, WithInvalidSenderPhoneNumberFails) {
std::vector<std::string> numbers{"06501234567", "1", "1650603619399999"};
PDUFormatBuilder builder;
builder.SetUserData("c");

for (auto n : numbers) {
builder.SetSenderNumber(n);
for (const std::string& number : {"06501234567", "1", "1650603619399999"}) {
builder.SetSenderNumber(number);
EXPECT_EQ(builder.Build(), "");
}
}
Expand All @@ -194,29 +175,23 @@ TEST(PDUFormatBuilderTest, WithoutLeadingPlusSignSucceeds) {
builder.SetUserData("c");
builder.SetSenderNumber("16501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "0001000b916105214365f700000163");
EXPECT_EQ(builder.Build(), "0001000b916105214365f700000163");
}

TEST(PDUFormatBuilderTest, WithOddSenderPhoneNumberLengthSucceeds) {
PDUFormatBuilder builder;
builder.SetUserData("c");
builder.SetSenderNumber("+16501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "0001000b916105214365f700000163");
EXPECT_EQ(builder.Build(), "0001000b916105214365f700000163");
}

TEST(PDUFormatBuilderTest, WithEvenSenderPhoneNumberLengthSucceeds) {
PDUFormatBuilder builder;
builder.SetUserData("c");
builder.SetSenderNumber("+526501234567");

std::string result = builder.Build();

EXPECT_EQ(result, "0001000c9125561032547600000163");
EXPECT_EQ(builder.Build(), "0001000c9125561032547600000163");
}

} // namespace
Expand Down
12 changes: 4 additions & 8 deletions base/cvd/cuttlefish/host/commands/cvd_send_sms/sms_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
*/
#include "cuttlefish/host/commands/cvd_send_sms/sms_sender.h"

#include <algorithm>
#include <codecvt>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#include <stdint.h>

#include <string>

#include "absl/log/log.h"

#include "cuttlefish/common/libs/fs/shared_buf.h"
#include "cuttlefish/common/libs/fs/shared_fd.h"
#include "cuttlefish/host/commands/cvd_send_sms/pdu_format_builder.h"

namespace cuttlefish {
Expand Down
Loading
Loading