Camera2: Add test for construct_default_request.

Bug: 6243944
Change-Id: I59b03d7ebece2a4b7672b265bd9f960b3faea621
diff --git a/include/hardware/camera2.h b/include/hardware/camera2.h
index 7f06c52..0764cb1 100644
--- a/include/hardware/camera2.h
+++ b/include/hardware/camera2.h
@@ -400,7 +400,10 @@
      * full-resolution images without compromising preview frame rate. 3A on
      * auto.
      */
-    CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG
+    CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG,
+
+    /* Total number of templates */
+    CAMERA2_TEMPLATE_COUNT
 };
 
 
diff --git a/tests/camera2/camera2.cpp b/tests/camera2/camera2.cpp
index cc2face..6c22426 100644
--- a/tests/camera2/camera2.cpp
+++ b/tests/camera2/camera2.cpp
@@ -572,4 +572,34 @@
     }
 }
 
+TEST_F(Camera2Test, ConstructDefaultRequests) {
+    status_t res;
+
+    for (int id = 0; id < getNumCameras(); id++) {
+        if (!isHal2Supported(id)) continue;
+
+        ASSERT_NO_FATAL_FAILURE(setUpCamera(id));
+
+        for (int i = CAMERA2_TEMPLATE_PREVIEW; i < CAMERA2_TEMPLATE_COUNT;
+             i++) {
+            camera_metadata_t *request = NULL;
+            res = mDevice->ops->construct_default_request(mDevice,
+                    i,
+                    &request);
+            EXPECT_EQ(NO_ERROR, res) <<
+                    "Unable to construct request from template type %d", i;
+            EXPECT_TRUE(request != NULL);
+            EXPECT_LT((size_t)0, get_camera_metadata_entry_count(request));
+            EXPECT_LT((size_t)0, get_camera_metadata_data_count(request));
+
+            IF_ALOGV() {
+                std::cout << "  ** Template type " << i << ":"<<std::endl;
+                dump_camera_metadata(request, 0, 2);
+            }
+
+            free_camera_metadata(request);
+        }
+    }
+}
+
 } // namespace android