Add ability to store and retrieve a list of MapBuffer

Summary:
Add ability to store and retrieve a list of MapBuffer as an entry of MapBuffer.

```
Example:

MapBuffer1
{
 key1: "test string",
 key2: MapBuffer2,
 key3: [MapBuffer3, MapBuffer4]
}
```

Changelog:
[General][Added] Add ability to store and retrieve a list of MapBuffer

Reviewed By: JoshuaGross

Differential Revision: D38460204

fbshipit-source-id: 3e721418be2dca6d5f15f665753844d6f531e31c
This commit is contained in:
Lulu Wu
2022-08-11 10:14:38 -07:00
committed by Facebook GitHub Bot
parent 7e580b97bf
commit fc065151ce
8 changed files with 123 additions and 0 deletions
@@ -6,6 +6,7 @@
*/
#include <memory>
#include <vector>
#include <gtest/gtest.h>
#include <react/renderer/mapbuffer/MapBuffer.h>
@@ -150,6 +151,30 @@ TEST(MapBufferTest, testMapEntries) {
EXPECT_EQ(readMap2.getInt(1), 1234);
}
TEST(MapBufferTest, testMapListEntries) {
std::vector<MapBuffer> mapBufferList;
auto builder = MapBufferBuilder();
builder.putString(0, "This is a test");
builder.putInt(1, 1234);
mapBufferList.push_back(builder.build());
auto builder2 = MapBufferBuilder();
builder2.putInt(2, 4321);
builder2.putDouble(3, 908.1);
mapBufferList.push_back(builder2.build());
auto builder3 = MapBufferBuilder();
builder3.putMapBufferList(5, std::move(mapBufferList));
auto map = builder3.build();
std::vector<MapBuffer> mapBufferList2 = map.getMapBufferList(5);
EXPECT_EQ(mapBufferList2.size(), 2);
EXPECT_EQ(mapBufferList2[0].getString(0), "This is a test");
EXPECT_EQ(mapBufferList2[0].getInt(1), 1234);
EXPECT_EQ(mapBufferList2[1].getDouble(3), 908.1);
}
TEST(MapBufferTest, testMapRandomAccess) {
auto builder = MapBufferBuilder();
builder.putInt(1234, 4321);