src/modular/bin/sessionmgr/storage/session_storage_unittest.cc
// Verifies that an on_annotations_updated callback is called only once when annotations are
// updated multiple times.
Verifies that an on_annotations_updated callback is called only once when annotations are
updated multiple times.
Verifies that an on_annotations_updated callback is called only once when annotations are updated multiple times .
TEST_F(SessionStorageTest, OnAnnotationsUpdatedCallbackCalledOnce) {
  static constexpr auto story_name = "story";
  auto storage = CreateStorage();
  storage->CreateStory(story_name, {});
  int updated_count = 0;
  storage->add_on_annotations_updated_once(
      story_name, [&](std::string story_id, std::vector<fuchsia::modular::Annotation> annotations) {
        updated_count++;
      });
  std::vector<fuchsia::modular::Annotation> first_annotations{};
  fuchsia::modular::AnnotationValue first_annotation_value;
  first_annotation_value.set_text("first_test_annotation_value");
  auto first_annotation =
      fuchsia::modular::Annotation{.key = "first_test_annotation_key",
                                   .value = fidl::MakeOptional(std::move(first_annotation_value))};
  first_annotations.push_back(fidl::Clone(first_annotation));
  storage->MergeStoryAnnotations(story_name, std::move(first_annotations));
  EXPECT_EQ(1, updated_count);
  std::vector<fuchsia::modular::Annotation> second_annotations{};
  fuchsia::modular::AnnotationValue second_annotation_value;
  second_annotation_value.set_text("second_test_annotation_value");
  auto second_annotation =
      fuchsia::modular::Annotation{.key = "second_test_annotation_key",
                                   .value = fidl::MakeOptional(std::move(second_annotation_value))};
  second_annotations.push_back(fidl::Clone(second_annotation));
  storage->MergeStoryAnnotations(story_name, std::move(second_annotations));
  EXPECT_EQ(1, updated_count);
}
TEST_F ( SessionStorageTest , OnAnnotationsUpdatedCallbackCalledOnce ) { static constexpr auto story_name = " " ; auto storage = CreateStorage ( ) ; storage -> CreateStory ( story_name , { } ) ; int updated_count = 0 ; storage -> add_on_annotations_updated_once ( story_name , [ & ] ( std :: string story_id , std :: vector < fuchsia :: modular :: Annotation > annotations ) { updated_count ++ ; } ) ; std :: vector < fuchsia :: modular :: Annotation > first_annotations { } ; fuchsia :: modular :: AnnotationValue first_annotation_value ; first_annotation_value . set_text ( " " ) ; auto first_annotation = fuchsia :: modular :: Annotation { . key = " " , . value = fidl :: MakeOptional ( std :: move ( first_annotation_value ) ) } ; first_annotations . push_back ( fidl :: Clone ( first_annotation ) ) ; storage -> MergeStoryAnnotations ( story_name , std :: move ( first_annotations ) ) ; EXPECT_EQ ( 1 , updated_count ) ; std :: vector < fuchsia :: modular :: Annotation > second_annotations { } ; fuchsia :: modular :: AnnotationValue second_annotation_value ; second_annotation_value . set_text ( " " ) ; auto second_annotation = fuchsia :: modular :: Annotation { . key = " " , . value = fidl :: MakeOptional ( std :: move ( second_annotation_value ) ) } ; second_annotations . push_back ( fidl :: Clone ( second_annotation ) ) ; storage -> MergeStoryAnnotations ( story_name , std :: move ( second_annotations ) ) ; EXPECT_EQ ( 1 , updated_count ) ; }
Verifies that an on_annotations_updated callback is called only once when annotations are
updated multiple times.
Verifies that an on_annotations_updated callback is called only once when annotations are updated multiple times .
// Create a story with no annotations. /*annotations=*/ // Add a callback. // Annotate the story. // The callback should have been called. // Annotate the story again. // The callback should not have been called again.