• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #include "upb/message/map.h"
9 
10 #include <gtest/gtest.h>
11 #include "upb/base/string_view.h"
12 #include "upb/mem/arena.hpp"
13 
TEST(MapTest,DeleteRegression)14 TEST(MapTest, DeleteRegression) {
15   upb::Arena arena;
16   upb_Map* map = upb_Map_New(arena.ptr(), kUpb_CType_Int32, kUpb_CType_String);
17 
18   upb_MessageValue key;
19   key.int32_val = 0;
20 
21   upb_MessageValue insert_value;
22   insert_value.str_val = upb_StringView_FromString("abcde");
23 
24   upb_MapInsertStatus st = upb_Map_Insert(map, key, insert_value, arena.ptr());
25   EXPECT_EQ(kUpb_MapInsertStatus_Inserted, st);
26 
27   upb_MessageValue delete_value;
28   bool removed = upb_Map_Delete(map, key, &delete_value);
29   EXPECT_TRUE(removed);
30 
31   EXPECT_TRUE(
32       upb_StringView_IsEqual(insert_value.str_val, delete_value.str_val));
33 }
34