Skip to content

Commit

Permalink
Remove set_request from ConversionRequest.
Browse files Browse the repository at this point in the history
* Use ConversionRequestBuilder instead of set_request().

PiperOrigin-RevId: 698368547
  • Loading branch information
hiroyuki-komatsu committed Nov 20, 2024
1 parent 6d77e59 commit 38fec15
Show file tree
Hide file tree
Showing 18 changed files with 96 additions and 95 deletions.
21 changes: 7 additions & 14 deletions src/converter/immutable_converter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,37 +456,30 @@ bool AutoPartialSuggestionTestHelper(const ConversionRequest &request) {
} // namespace

TEST(ImmutableConverterTest, EnableAutoPartialSuggestion) {
const commands::Request request;
ConversionRequest conversion_request;
conversion_request.set_request(&request);
conversion_request.set_create_partial_candidates(true);

EXPECT_TRUE(AutoPartialSuggestionTestHelper(conversion_request));
}

TEST(ImmutableConverterTest, DisableAutoPartialSuggestion) {
const commands::Request request;
ConversionRequest conversion_request;
conversion_request.set_request(&request);
conversion_request.set_create_partial_candidates(false);

EXPECT_FALSE(AutoPartialSuggestionTestHelper(conversion_request));
}

TEST(ImmutableConverterTest, AutoPartialSuggestionDefault) {
const commands::Request request;
ConversionRequest conversion_request;
conversion_request.set_request(&request);

const ConversionRequest conversion_request;
EXPECT_FALSE(AutoPartialSuggestionTestHelper(conversion_request));
}

TEST(ImmutableConverterTest, FirstInnerSegment) {
commands::Request request;
request_test_util::FillMobileRequest(&request);
ConversionRequest conversion_request;
ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();
conversion_request.set_request_type(ConversionRequest::PREDICTION);
conversion_request.set_request(&request);
conversion_request.set_create_partial_candidates(true);
conversion_request.set_max_conversion_candidates_size(100);

Expand All @@ -512,9 +505,9 @@ TEST(ImmutableConverterTest, FirstInnerSegmentFiltering) {
request_test_util::FillMobileRequest(&request);
request.mutable_decoder_experiment_params()
->set_enable_realtime_conversion_candidate_checker(true);
ConversionRequest conversion_request;
ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();
conversion_request.set_request_type(ConversionRequest::PREDICTION);
conversion_request.set_request(&request);
conversion_request.set_create_partial_candidates(true);
conversion_request.set_max_conversion_candidates_size(100);

Expand Down Expand Up @@ -582,9 +575,9 @@ TEST(ImmutableConverterTest, FirstInnerSegmentFilteringParams) {
request.mutable_decoder_experiment_params()
->set_realtime_conversion_candidate_checker_cost_max_diff(
4605); // 500*log(10000);
ConversionRequest conversion_request;
ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();
conversion_request.set_request_type(ConversionRequest::PREDICTION);
conversion_request.set_request(&request);
conversion_request.set_create_partial_candidates(true);
conversion_request.set_max_conversion_candidates_size(100);

Expand Down
5 changes: 1 addition & 4 deletions src/prediction/user_history_predictor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2144,10 +2144,7 @@ TEST_F(UserHistoryPredictorTest, IsValidSuggestion) {

TEST_F(UserHistoryPredictorTest, IsValidSuggestionForMixedConversion) {
UserHistoryPredictor::Entry entry;

commands::Request request;
ConversionRequest conversion_request;
conversion_request.set_request(&request);
const ConversionRequest conversion_request;

entry.set_suggestion_freq(1);
EXPECT_TRUE(UserHistoryPredictor::IsValidSuggestionForMixedConversion(
Expand Down
1 change: 0 additions & 1 deletion src/request/conversion_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class ConversionRequest {
DCHECK(request_);
return *request_;
}
void set_request(const commands::Request *request) { request_ = request; }

const commands::Context &context() const {
DCHECK(context_);
Expand Down
11 changes: 6 additions & 5 deletions src/rewriter/a11y_description_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,23 @@ class A11yDescriptionRewriterTest : public ::testing::Test {
};

TEST_F(A11yDescriptionRewriterTest, WithoutData) {
ConversionRequest a11y_conv_request;
commands::Request a11y_request;

a11y_request.set_enable_a11y_description(true);
a11y_conv_request.set_request(&a11y_request);

const ConversionRequest a11y_conv_request =
ConversionRequestBuilder().SetRequest(a11y_request).Build();

EXPECT_EQ(GetRewriterWithoutData()->capability(a11y_conv_request),
RewriterInterface::NOT_AVAILABLE);
}

TEST_F(A11yDescriptionRewriterTest, FeatureDisabled) {
ConversionRequest a11y_conv_request, non_a11y_conv_request;
ConversionRequest non_a11y_conv_request;
commands::Request a11y_request;

a11y_request.set_enable_a11y_description(true);
a11y_conv_request.set_request(&a11y_request);
const ConversionRequest a11y_conv_request =
ConversionRequestBuilder().SetRequest(a11y_request).Build();

EXPECT_EQ(GetRewriter()->capability(a11y_conv_request),
RewriterInterface::ALL);
Expand Down
6 changes: 4 additions & 2 deletions src/rewriter/date_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -972,18 +972,20 @@ TEST_F(DateRewriterTest, NumberRewriterFromRawInputTest) {
}

TEST_F(DateRewriterTest, MobileEnvironmentTest) {
ConversionRequest convreq;
commands::Request request;
convreq.set_request(&request);
DateRewriter rewriter;

{
request.set_mixed_conversion(true);
const ConversionRequest convreq =
ConversionRequestBuilder().SetRequest(request).Build();
EXPECT_EQ(rewriter.capability(convreq), RewriterInterface::ALL);
}

{
request.set_mixed_conversion(false);
const ConversionRequest convreq =
ConversionRequestBuilder().SetRequest(request).Build();
EXPECT_EQ(rewriter.capability(convreq), RewriterInterface::CONVERSION);
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/rewriter/english_variants_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ TEST_F(EnglishVariantsRewriterTest, RewriteTest) {
// 'Google Japan'
{
Segments segments;
ConversionRequest conversion_request;
commands::Request request;
request.mutable_decoder_experiment_params()
->set_english_variation_space_insertion_mode(1);
conversion_request.set_request(&request);
const ConversionRequest conversion_request = ConversionRequestBuilder()
.SetRequest(request)
.Build();

Segment *seg1 = segments.push_back_segment();
Segment *seg2 = segments.push_back_segment();
Expand Down Expand Up @@ -216,11 +217,12 @@ TEST_F(EnglishVariantsRewriterTest, RewriteTest) {
// '<NO CANDIDATE> Japan'
{
Segments segments;
ConversionRequest conversion_request;
commands::Request request;
request.mutable_decoder_experiment_params()
->set_english_variation_space_insertion_mode(1);
conversion_request.set_request(&request);
const ConversionRequest conversion_request = ConversionRequestBuilder()
.SetRequest(request)
.Build();

Segment *seg1 = segments.push_back_segment();
Segment *seg2 = segments.push_back_segment();
Expand Down Expand Up @@ -249,11 +251,12 @@ TEST_F(EnglishVariantsRewriterTest, RewriteTest) {
// 'ぐーぐるJapan'
{
Segments segments;
ConversionRequest conversion_request;
commands::Request request;
request.mutable_decoder_experiment_params()
->set_english_variation_space_insertion_mode(1);
conversion_request.set_request(&request);
const ConversionRequest conversion_request = ConversionRequestBuilder()
.SetRequest(request)
.Build();

Segment *seg1 = segments.push_back_segment();
Segment *seg2 = segments.push_back_segment();
Expand Down Expand Up @@ -566,17 +569,20 @@ TEST_F(EnglishVariantsRewriterTest, FillConsumedKeySize) {
}

TEST_F(EnglishVariantsRewriterTest, MobileEnvironmentTest) {
ConversionRequest convreq;
commands::Request request;
convreq.set_request(&request);

{
request.set_mixed_conversion(true);
const ConversionRequest convreq = ConversionRequestBuilder()
.SetRequest(request)
.Build();
EXPECT_EQ(rewriter_->capability(convreq), RewriterInterface::ALL);
}

{
request.set_mixed_conversion(false);
const ConversionRequest convreq =
ConversionRequestBuilder().SetRequest(request).Build();
EXPECT_EQ(rewriter_->capability(convreq), RewriterInterface::CONVERSION);
}
}
Expand Down
32 changes: 14 additions & 18 deletions src/rewriter/environmental_filter_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ TEST_F(EnvironmentalFilterRewriterTest, EmojiFilterTest) {
commands::Request request;
request.add_additional_renderable_character_groups(
commands::Request::EMOJI_13_0);
ConversionRequest conversion_request;
const ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();
Segments segments;
conversion_request.set_request(&request);

segments.Clear();
AddSegment("a", {"🛻", "🤵‍♀", "🥸"}, &segments);
Expand Down Expand Up @@ -315,9 +315,9 @@ TEST_F(EnvironmentalFilterRewriterTest, EmojiFilterE160Test) {
commands::Request request;
request.add_additional_renderable_character_groups(
commands::Request::EMOJI_16_0);
ConversionRequest conversion_request;
Segments segments;
conversion_request.set_request(&request);
const ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();

segments.Clear();
AddSegment("えもじ", {"🪏", "🫆", "🫟"}, &segments);
Expand Down Expand Up @@ -349,9 +349,7 @@ TEST_F(EnvironmentalFilterRewriterTest, NoRemoveTest) {

TEST_F(EnvironmentalFilterRewriterTest, CandidateFilterTest) {
{
commands::Request request;
ConversionRequest conversion_request;
conversion_request.set_request(&request);
const ConversionRequest conversion_request;

Segments segments;
segments.Clear();
Expand All @@ -365,9 +363,7 @@ TEST_F(EnvironmentalFilterRewriterTest, CandidateFilterTest) {
}

{
commands::Request request;
ConversionRequest conversion_request;
conversion_request.set_request(&request);
const ConversionRequest conversion_request;

Segments segments;
segments.Clear();
Expand All @@ -389,8 +385,8 @@ TEST_F(EnvironmentalFilterRewriterTest, CandidateFilterTest) {
commands::Request request;
request.add_additional_renderable_character_groups(
commands::Request::EMPTY);
ConversionRequest conversion_request;
conversion_request.set_request(&request);
const ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();

Segments segments;
segments.Clear();
Expand All @@ -407,8 +403,8 @@ TEST_F(EnvironmentalFilterRewriterTest, CandidateFilterTest) {
commands::Request request;
request.add_additional_renderable_character_groups(
commands::Request::KANA_SUPPLEMENT_6_0);
ConversionRequest conversion_request;
conversion_request.set_request(&request);
const ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();

Segments segments;
segments.Clear();
Expand All @@ -427,8 +423,8 @@ TEST_F(EnvironmentalFilterRewriterTest, CandidateFilterTest) {
commands::Request::KANA_SUPPLEMENT_6_0);
request.add_additional_renderable_character_groups(
commands::Request::KANA_SUPPLEMENT_AND_KANA_EXTENDED_A_10_0);
ConversionRequest conversion_request;
conversion_request.set_request(&request);
const ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();

Segments segments;
segments.Clear();
Expand All @@ -449,8 +445,8 @@ TEST_F(EnvironmentalFilterRewriterTest, CandidateFilterTest) {
commands::Request::KANA_SUPPLEMENT_AND_KANA_EXTENDED_A_10_0);
request.add_additional_renderable_character_groups(
commands::Request::KANA_EXTENDED_A_14_0);
ConversionRequest conversion_request;
conversion_request.set_request(&request);
const ConversionRequest conversion_request =
ConversionRequestBuilder().SetRequest(request).Build();

Segments segments;
segments.Clear();
Expand Down
4 changes: 2 additions & 2 deletions src/rewriter/merger_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ TEST_F(MergerRewriterTest, RewriteSuggestionWithMixedConversion) {
// should result that the merger rewriter does not trim exceeded suggestions.
commands::Request commands_request;
commands_request.set_mixed_conversion(true);
ConversionRequest request;
request.set_request(&commands_request);
ConversionRequest request =
ConversionRequestBuilder().SetRequest(commands_request).Build();
request.set_request_type(ConversionRequest::SUGGESTION);
EXPECT_TRUE(request.request().mixed_conversion());

Expand Down
6 changes: 4 additions & 2 deletions src/rewriter/number_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -909,18 +909,20 @@ TEST_F(NumberRewriterTest, PreserveUserDictionaryAttribute) {
TEST_F(NumberRewriterTest, DuplicateCandidateTest) {
// To reproduce issue b/6714268.
std::unique_ptr<NumberRewriter> number_rewriter(CreateNumberRewriter());
ConversionRequest convreq;
commands::Request request;
convreq.set_request(&request);
std::unique_ptr<NumberRewriter> rewriter(CreateNumberRewriter());

{
request.set_mixed_conversion(true);
const ConversionRequest convreq =
ConversionRequestBuilder().SetRequest(request).Build();
EXPECT_EQ(rewriter->capability(convreq), RewriterInterface::ALL);
}

{
request.set_mixed_conversion(false);
const ConversionRequest convreq =
ConversionRequestBuilder().SetRequest(request).Build();
EXPECT_EQ(rewriter->capability(convreq), RewriterInterface::CONVERSION);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/rewriter/order_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class OrderRewriterTest : public testing::TestWithTempUserProfile {
}

ConversionRequest CreateConversionRequest(const commands::Request &request) {
ConversionRequest convreq;
convreq.set_request(&request);
return convreq;
return ConversionRequestBuilder().SetRequest(request).Build();
}

std::unique_ptr<OrderRewriter> rewriter_;
Expand Down
10 changes: 7 additions & 3 deletions src/rewriter/remove_redundant_candidate_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ TEST(RemoveRedundantCandidateRewriterTest, NoRemoveTest) {

TEST(RemoveRedundantCandidateRewriterTest, CapabilityTest) {
RemoveRedundantCandidateRewriter rewriter;
ConversionRequest convreq;
commands::Request request;
convreq.set_request(&request);
{ EXPECT_EQ(rewriter.capability(convreq), RewriterInterface::NOT_AVAILABLE); }
{
const ConversionRequest convreq =
ConversionRequestBuilder().SetRequest(request).Build();
EXPECT_EQ(rewriter.capability(convreq), RewriterInterface::NOT_AVAILABLE);
}

{
request.set_mixed_conversion(true);
const ConversionRequest convreq =
ConversionRequestBuilder().SetRequest(request).Build();
EXPECT_EQ(rewriter.capability(convreq), RewriterInterface::ALL);
}
}
Expand Down
Loading

0 comments on commit 38fec15

Please sign in to comment.