MCPcopy Create free account
hub / github.com/Snapchat/Valdi / TEST

Function TEST

valdi/test/runtime/DaemonClient_tests.cpp:75–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73};
74
75TEST(DaemonClient, canReceiveUpdatedResources) {
76 MockDaemonClientListener listener;
77 auto daemonClient =
78 Valdi::makeShared<DaemonClient>(&listener, 0, Valdi::strongSmallRef(&ConsoleLogger::getLogger()));
79
80 auto updatedResources = ValueArray::make(2);
81 Value resource1;
82 auto base64Data1 = Value(snap::utils::encoding::binaryToBase64("hello"));
83 resource1.setMapValue("data_base64", base64Data1)
84 .setMapValue("bundle_name", Value("bundle1"))
85 .setMapValue("file_path_within_bundle", Value("src/file1.js"));
86 updatedResources->emplace(0, resource1);
87
88 Value resource2;
89 auto base64Data2 = Value(snap::utils::encoding::binaryToBase64("hello2"));
90 resource2.setMapValue("data_base64", base64Data2)
91 .setMapValue("bundle_name", Value("bundle2"))
92 .setMapValue("file_path_within_bundle", Value("src/file2.js"));
93 updatedResources->emplace(1, resource2);
94
95 Value resources;
96 resources.setMapValue("resources", Value(updatedResources));
97 Value event;
98 event.setMapValue("updated_resources", resources);
99 Value payload;
100 payload.setMapValue("event", event);
101 auto output = valueToJson(payload);
102
103 auto out = makeShared<ByteBuffer>();
104
105 ValdiPacket::write(reinterpret_cast<const Byte*>(output->data()), output->size(), *out);
106
107 daemonClient->onDataReceived(out->toBytesView());
108
109 ASSERT_TRUE(listener.daemonClientDidDisconnectParams.empty());
110 ASSERT_EQ(static_cast<size_t>(1), listener.didReceiveUpdatedResourcesParams.size());
111
112 auto receivedResources = listener.didReceiveUpdatedResourcesParams[0];
113 ASSERT_TRUE(receivedResources != nullptr);
114
115 ASSERT_EQ(static_cast<size_t>(2), receivedResources->size());
116
117 ASSERT_EQ(ResourceId(STRING_LITERAL("bundle1"), STRING_LITERAL("src/file1.js")),
118 (*receivedResources)[0]->resourceId);
119 ASSERT_EQ(STRING_LITERAL("hello").toStringView(), BytesView((*receivedResources)[0]->data).asStringView());
120 ASSERT_EQ(ResourceId(STRING_LITERAL("bundle2"), STRING_LITERAL("src/file2.js")),
121 (*receivedResources)[1]->resourceId);
122 ASSERT_EQ(STRING_LITERAL("hello2").toStringView(), BytesView((*receivedResources)[1]->data).asStringView());
123}
124
125TEST(DaemonClient, canHandleGroupedPackets) {
126 MockDaemonClientListener listener;

Callers

nothing calls this directly

Calls 15

strongSmallRefFunction · 0.85
binaryToBase64Function · 0.85
valueToJsonFunction · 0.85
ResourceIdClass · 0.85
asStringViewMethod · 0.80
setDataSenderMethod · 0.80
sendConfigurationMethod · 0.80
descriptionMethod · 0.80
getMapValueMethod · 0.80
sendLogMethod · 0.80
endMethod · 0.65
appendMethod · 0.65

Tested by

no test coverage detected