Simple dump for Virtual Caemra device
Bug: 301023410
Test: atest VirtualCameraDeviceTest#dump
Change-Id: I917c73c587ea246aeb44f8d6ca0ba03ca43f87dc
diff --git a/services/camera/virtualcamera/tests/VirtualCameraDeviceTest.cc b/services/camera/virtualcamera/tests/VirtualCameraDeviceTest.cc
index 5c9b3b9..3fe7c11 100644
--- a/services/camera/virtualcamera/tests/VirtualCameraDeviceTest.cc
+++ b/services/camera/virtualcamera/tests/VirtualCameraDeviceTest.cc
@@ -363,6 +363,33 @@
ElementsAre(Resolution(0, 0), Resolution(240, 180)));
}
+TEST_F(VirtualCameraDeviceTest, dump) {
+ std::string expected = R"( virtual_camera 42 belongs to virtual device 0
+ SupportedStreamConfiguration:
+ SupportedStreamConfiguration{width: 640, height: 480, pixelFormat: YUV_420_888, maxFps: 30})";
+ int expectedSize = expected.size() * sizeof(char);
+ char buffer[expectedSize];
+
+ // Create an in memory fd
+ int fd = memfd_create("tmpFile", 0);
+ mCamera->dump(fd, {}, 0);
+
+ // Check that we wrote the expected size
+ int dumpSize = lseek(fd, 0, SEEK_END);
+
+ // Rewind and read from the fd
+ lseek(fd, 0, SEEK_SET);
+ read(fd, buffer, expectedSize);
+ close(fd);
+
+ // Check the content of the dump
+ std::string name = std::string(buffer, expectedSize);
+ ASSERT_EQ(expected, name);
+ // Check the size after the content to display the string mismatch when a
+ // failure occurs
+ ASSERT_EQ(expectedSize, dumpSize);
+}
+
} // namespace
} // namespace virtualcamera
} // namespace companion