Add more tests for FPDFBitmap_CreateEx().

Show that it works when an external buffer is not provided.

Change-Id: I8f32a09af59bed962c22a4b923a0759cfa27b753
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/95254
Reviewed-by: Nigi <nigi@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp
index 54be626..92fb97d 100644
--- a/fpdfsdk/fpdf_view_embeddertest.cpp
+++ b/fpdfsdk/fpdf_view_embeddertest.cpp
@@ -128,6 +128,23 @@
     CompareBitmap(bitmap.get(), bitmap_width, bitmap_height, expected_md5);
   }
 
+  void TestRenderPageBitmapWithInternalMemory(FPDF_PAGE page,
+                                              int format,
+                                              const char* expected_md5) {
+    int bitmap_width = static_cast<int>(FPDF_GetPageWidth(page));
+    int bitmap_height = static_cast<int>(FPDF_GetPageHeight(page));
+    int bytes_per_pixel = BytesPerPixelForFormat(format);
+    ASSERT_NE(0, bytes_per_pixel);
+
+    ScopedFPDFBitmap bitmap(
+        FPDFBitmap_CreateEx(bitmap_width, bitmap_height, format, nullptr, 0));
+    FPDFBitmap_FillRect(bitmap.get(), 0, 0, bitmap_width, bitmap_height,
+                        0xFFFFFFFF);
+    FPDF_RenderPageBitmap(bitmap.get(), page, 0, 0, bitmap_width, bitmap_height,
+                          0, 0);
+    CompareBitmap(bitmap.get(), bitmap_width, bitmap_height, expected_md5);
+  }
+
   void TestRenderPageBitmapWithExternalMemory(FPDF_PAGE page,
                                               int format,
                                               const char* expected_md5) {
@@ -1356,7 +1373,7 @@
   UnloadPage(page);
 }
 
-TEST_F(FPDFViewEmbedderTest, RenderManyRectanglesWithExternalMemory) {
+TEST_F(FPDFViewEmbedderTest, RenderManyRectanglesWithAndWithoutExternalMemory) {
   ASSERT_TRUE(OpenDocument("many_rectangles.pdf"));
   FPDF_PAGE page = LoadPage(0);
   ASSERT_TRUE(page);
@@ -1370,11 +1387,17 @@
   static const char kGrayMD5[] = "b561c11edc44dc3972125a9b8744fa2f";
   static const char kBgrMD5[] = "ab6312e04c0d3f4e46fb302a45173d05";
 
+  TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_BGR, kBgrMD5);
   TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGR, kBgrMD5);
 #endif
+  TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_Gray, kGrayMD5);
   TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_Gray, kGrayMD5);
+  TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_BGRx,
+                                         kManyRectanglesChecksum);
   TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGRx,
                                          kManyRectanglesChecksum);
+  TestRenderPageBitmapWithInternalMemory(page, FPDFBitmap_BGRA,
+                                         kManyRectanglesChecksum);
   TestRenderPageBitmapWithExternalMemory(page, FPDFBitmap_BGRA,
                                          kManyRectanglesChecksum);