1d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala/*
2d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * Copyright (C) 2012 The Android Open Source Project
3d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala *
4d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * Licensed under the Apache License, Version 2.0 (the "License");
5d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * you may not use this file except in compliance with the License.
6d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * You may obtain a copy of the License at
7d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala *
8d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala *      http://www.apache.org/licenses/LICENSE-2.0
9d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala *
10d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * Unless required by applicable law or agreed to in writing, software
11d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * distributed under the License is distributed on an "AS IS" BASIS,
12d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * See the License for the specific language governing permissions and
14d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala * limitations under the License.
15d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala */
16d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
17f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala#define LOG_NDEBUG 1
18f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala#define LOG_TAG "camera_metadata_tests"
19f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala#include "cutils/log.h"
20f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala
2194c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala#include <errno.h>
2294c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
23d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala#include "gtest/gtest.h"
24d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala#include "system/camera_metadata.h"
25d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
26d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala#include "camera_metadata_tests_fake_vendor.h"
27d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
28d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala#define EXPECT_NULL(x)     EXPECT_EQ((void*)0, x)
29d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala#define EXPECT_NOT_NULL(x) EXPECT_NE((void*)0, x)
30d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
31d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala#define OK    0
32d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala#define ERROR 1
3394c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala#define NOT_FOUND (-ENOENT)
34d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
35d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, allocate_normal) {
36d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
37d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
38d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 32;
39d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
40d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
41d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
42d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m);
43d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m));
44d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity, get_camera_metadata_entry_capacity(m));
45d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m));
46d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_capacity, get_camera_metadata_data_capacity(m));
47d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
48d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
49d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
50d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
51d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, allocate_nodata) {
52d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
53d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
54d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(1, 0);
55d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
56d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m);
57d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m));
58d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)1, get_camera_metadata_entry_capacity(m));
59d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m));
60d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_data_capacity(m));
61d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
62d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
63d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
64d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
65d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, allocate_nothing) {
66d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
67d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
68d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(0, 0);
69d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
70d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(m);
71d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
72d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
73d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, place_normal) {
74d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
75d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    void *buf = NULL;
76d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
77d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
78d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 32;
79d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
80d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t buf_size = calculate_camera_metadata_size(entry_capacity,
81d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            data_capacity);
82d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
83d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_TRUE(buf_size > 0);
84d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
85d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    buf = malloc(buf_size);
86d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
87d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(buf);
88d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
89d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = place_camera_metadata(buf, buf_size, entry_capacity, data_capacity);
90d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
91d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(buf, (uint8_t*)m);
92d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m));
93d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity, get_camera_metadata_entry_capacity(m));
94d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m));
95d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_capacity, get_camera_metadata_data_capacity(m));
96d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
97d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free(buf);
98d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
99d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
100d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, place_nospace) {
101d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
102d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    void *buf = NULL;
103d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
104d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
105d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 32;
106d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
107d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t buf_size = calculate_camera_metadata_size(entry_capacity,
108d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            data_capacity);
109d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
110d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_GT(buf_size, (size_t)0);
111d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
112d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    buf_size--;
113d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
114d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    buf = malloc(buf_size);
115d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
116d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(buf);
117d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
118d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = place_camera_metadata(buf, buf_size, entry_capacity, data_capacity);
119d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
120d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(m);
121d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
122d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free(buf);
123d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
124d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
125d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, place_extraspace) {
126d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
127d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    uint8_t *buf = NULL;
128d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
129d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
130d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 32;
131d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t extra_space = 10;
132d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
133d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t buf_size = calculate_camera_metadata_size(entry_capacity,
134d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            data_capacity);
135d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
136d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_GT(buf_size, (size_t)0);
137d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
138d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    buf_size += extra_space;
139d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
140d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    buf = (uint8_t*)malloc(buf_size);
141d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
142d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(buf);
143d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
144d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = place_camera_metadata(buf, buf_size, entry_capacity, data_capacity);
145d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
146d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((uint8_t*)m, buf);
147d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m));
148d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity, get_camera_metadata_entry_capacity(m));
149d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m));
150d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_capacity, get_camera_metadata_data_capacity(m));
151d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(buf + buf_size - extra_space, (uint8_t*)m + get_camera_metadata_size(m));
152d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
153d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free(buf);
154d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
155d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
156d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, get_size) {
157d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
158d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
159d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 32;
160d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
161d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
162d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
163d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(calculate_camera_metadata_size(entry_capacity, data_capacity),
164d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_size(m) );
165d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
166d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(calculate_camera_metadata_size(0,0),
167d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_compact_size(m) );
168d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
169d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
170d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
171d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
172d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, add_get_normal) {
173d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
174d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
175d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 80;
176d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
177d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
178d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
179d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
180d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t data_used = 0;
181d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t entries_used = 0;
182d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
183d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    // INT64
184d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
185d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int64_t exposure_time = 1000000000;
186d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
187d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_SENSOR_EXPOSURE_TIME,
188d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &exposure_time, 1);
189d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
190d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    data_used += calculate_camera_metadata_entry_data_size(
191d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_tag_type(ANDROID_SENSOR_EXPOSURE_TIME), 1);
192d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    entries_used++;
193d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
194d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    // INT32
195d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
196d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int32_t sensitivity = 800;
197d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
198d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_SENSOR_SENSITIVITY,
199d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &sensitivity, 1);
200d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
201d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    data_used += calculate_camera_metadata_entry_data_size(
202d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_tag_type(ANDROID_SENSOR_SENSITIVITY), 1);
203d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    entries_used++;
204d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
205d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    // FLOAT
206d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
207d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    float focusDistance = 0.5f;
208d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
209d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_LENS_FOCUS_DISTANCE,
210d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &focusDistance, 1);
211d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
212d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    data_used += calculate_camera_metadata_entry_data_size(
213d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_tag_type(ANDROID_LENS_FOCUS_DISTANCE), 1);
214d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    entries_used++;
215d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
216d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    // Array of FLOAT
217d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
218d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    float colorTransform[9] = {
219d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        0.9f, 0.0f, 0.0f,
220d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        0.2f, 0.5f, 0.0f,
221d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        0.0f, 0.1f, 0.7f
222d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    };
223d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
224d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_COLOR_TRANSFORM,
225d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            colorTransform, 9);
226d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
227d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    data_used += calculate_camera_metadata_entry_data_size(
228d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_tag_type(ANDROID_COLOR_TRANSFORM), 9);
229d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    entries_used++;
230d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
231d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    // Check added entries
232d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
233f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    camera_metadata_entry entry;
234d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = get_camera_metadata_entry(m,
235f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            0, &entry);
236d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
237f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(0, (int)entry.index);
238f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(ANDROID_SENSOR_EXPOSURE_TIME, entry.tag);
239f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(TYPE_INT64, entry.type);
240f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)1, entry.count);
241f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(exposure_time, *entry.data.i64);
242d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
243d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = get_camera_metadata_entry(m,
244f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            1, &entry);
245d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
246f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)1, entry.index);
247f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(ANDROID_SENSOR_SENSITIVITY, entry.tag);
248f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(TYPE_INT32, entry.type);
249f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)1, entry.count);
250f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(sensitivity, *entry.data.i32);
251d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
252d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = get_camera_metadata_entry(m,
253f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            2, &entry);
254d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
255f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)2, entry.index);
256f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(ANDROID_LENS_FOCUS_DISTANCE, entry.tag);
257f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(TYPE_FLOAT, entry.type);
258f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)1, entry.count);
259f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(focusDistance, *entry.data.f);
260d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
261d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = get_camera_metadata_entry(m,
262f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            3, &entry);
263d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
264f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)3, entry.index);
265f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(ANDROID_COLOR_TRANSFORM, entry.tag);
266f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(TYPE_FLOAT, entry.type);
267f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)9, entry.count);
268f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    for (unsigned int i=0; i < entry.count; i++) {
269f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(colorTransform[i], entry.data.f[i] );
270d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
271d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
272d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(calculate_camera_metadata_size(entry_capacity, data_capacity),
273d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_size(m) );
274d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
275d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(calculate_camera_metadata_size(entries_used, data_used),
276d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_compact_size(m) );
277d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
278f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    IF_ALOGV() {
279f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        dump_camera_metadata(m, 0, 2);
280f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    }
281d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
282d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
283d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
284d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
285d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvalavoid add_test_metadata(camera_metadata_t *m, int entry_count) {
286d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
287d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m);
288d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
289d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
290d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t data_used = 0;
291d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t entries_used = 0;
292d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int64_t exposure_time;
293d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (int i=0; i < entry_count; i++ ) {
294d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        exposure_time = 100 + i * 100;
295d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        result = add_camera_metadata_entry(m,
296d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                ANDROID_SENSOR_EXPOSURE_TIME,
297d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                &exposure_time, 1);
298d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
299d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        data_used += calculate_camera_metadata_entry_data_size(
300d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                get_camera_metadata_tag_type(ANDROID_SENSOR_EXPOSURE_TIME), 1);
301d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        entries_used++;
302d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
303d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_used, get_camera_metadata_data_count(m));
304d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entries_used, get_camera_metadata_entry_count(m));
305d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_GT(get_camera_metadata_data_capacity(m),
306d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_data_count(m));
307d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
308d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
309d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, add_get_toomany) {
310d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
311d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
312d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 50;
313d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
314d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
315d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
316d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
317d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    add_test_metadata(m, entry_capacity);
318d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
319d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int32_t sensitivity = 100;
320d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
321d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_SENSOR_SENSITIVITY,
322d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &sensitivity, 1);
323d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
324d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(ERROR, result);
325d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
326f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    camera_metadata_entry entry;
327d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (unsigned int i=0; i < entry_capacity; i++) {
328d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        int64_t exposure_time = 100 + i * 100;
329d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        result = get_camera_metadata_entry(m,
330f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala                i, &entry);
331d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
332f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i, entry.index);
333f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(ANDROID_SENSOR_EXPOSURE_TIME, entry.tag);
334f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(TYPE_INT64, entry.type);
335f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ((size_t)1, entry.count);
336f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(exposure_time, *entry.data.i64);
337d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
338f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    entry.tag = 1234;
339f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    entry.type = 56;
340f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    entry.data.u8 = NULL;
341f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    entry.count = 7890;
342d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = get_camera_metadata_entry(m,
343f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            entry_capacity, &entry);
344d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(ERROR, result);
345f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((uint32_t)1234, entry.tag);
346f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((uint8_t)56, entry.type);
347f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(NULL, entry.data.u8);
348f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)7890, entry.count);
349d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
350f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    IF_ALOGV() {
351f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        dump_camera_metadata(m, 0, 2);
352f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    }
353d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
354d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
355d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
356d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
357d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, copy_metadata) {
358d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
359d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 50;
360d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 450;
361d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
362d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
363d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
364d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
365d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
366d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    add_test_metadata(m, entry_capacity);
367d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
368d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t buf_size = get_camera_metadata_compact_size(m);
369d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_LT((size_t)0, buf_size);
370d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
371d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    uint8_t *buf = (uint8_t*)malloc(buf_size);
372d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(buf);
373d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
374d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m2 = copy_camera_metadata(buf, buf_size, m);
375d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m2);
376d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(buf, (uint8_t*)m2);
377d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_entry_count(m),
378d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_entry_count(m2));
379d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_count(m),
380d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_data_count(m2));
381d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_entry_capacity(m2),
382d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_entry_count(m2));
383d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_capacity(m2),
384d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_data_count(m2));
385d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
386d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) {
387f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        camera_metadata_entry e1, e2;
388d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        int result;
389f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m, i, &e1);
390d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
391f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m2, i, &e2);
392d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
393f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.index, e2.index);
394f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.tag, e2.tag);
395f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.type, e2.type);
396f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.count, e2.count);
397f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        for (unsigned int j=0;
398f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j < e1.count * camera_metadata_type_size[e1.type];
399f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j++) {
400f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            EXPECT_EQ(e1.data.u8[j], e2.data.u8[j]);
401d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        }
402d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
403d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
404d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free(buf);
405d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
406d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
407d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
408d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
409d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, copy_metadata_extraspace) {
410d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
411d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 12;
412d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 100;
413d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
414d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t extra_space = 10;
415d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
416d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
417d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
418d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
419d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
420d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    add_test_metadata(m, entry_capacity);
421d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
422d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t buf_size = get_camera_metadata_compact_size(m);
423d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_LT((size_t)0, buf_size);
424d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    buf_size += extra_space;
425d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
426d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    uint8_t *buf = (uint8_t*)malloc(buf_size);
427d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(buf);
428d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
429d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m2 = copy_camera_metadata(buf, buf_size, m);
430d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m2);
431d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(buf, (uint8_t*)m2);
432d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_entry_count(m),
433d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_entry_count(m2));
434d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_count(m),
435d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_data_count(m2));
436d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_entry_capacity(m2),
437d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_entry_count(m2));
438d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_capacity(m2),
439d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_data_count(m2));
440d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(buf + buf_size - extra_space,
441d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            (uint8_t*)m2 + get_camera_metadata_size(m2) );
442d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
443d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) {
444f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        camera_metadata_entry e1, e2;
445d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
446d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        int result;
447f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m, i, &e1);
448d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
449f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i, e1.index);
450f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m2, i, &e2);
451d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
452f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.index, e2.index);
453f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.tag, e2.tag);
454f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.type, e2.type);
455f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.count, e2.count);
456f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        for (unsigned int j=0;
457f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j < e1.count * camera_metadata_type_size[e1.type];
458f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j++) {
459f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            EXPECT_EQ(e1.data.u8[j], e2.data.u8[j]);
460d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        }
461d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
462d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
463d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free(buf);
464d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
465d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
466d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
467d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
468d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, copy_metadata_nospace) {
469d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
470d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
471d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 50;
472d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
473d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
474d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
475d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
476d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
477d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    add_test_metadata(m, entry_capacity);
478d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
479d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    size_t buf_size = get_camera_metadata_compact_size(m);
480d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_LT((size_t)0, buf_size);
481d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
482d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    buf_size--;
483d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
484d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    uint8_t *buf = (uint8_t*)malloc(buf_size);
485d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(buf);
486d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
487d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m2 = copy_camera_metadata(buf, buf_size, m);
488d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(m2);
489d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
490d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free(buf);
491d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
492d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
493d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
494d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
495d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, append_metadata) {
496d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
497d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
498d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 50;
499d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
500d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
501d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
502d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
503d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
504d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    add_test_metadata(m, entry_capacity);
505d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
506d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m2 = NULL;
507d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
508d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m2 = allocate_camera_metadata(entry_capacity*2, data_capacity*2);
509d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m2);
510d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
511d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = append_camera_metadata(m2, m);
512d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
513d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
514d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
515f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(get_camera_metadata_entry_count(m),
516f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            get_camera_metadata_entry_count(m2));
517f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_count(m),
518f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            get_camera_metadata_data_count(m2));
519d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity*2, get_camera_metadata_entry_capacity(m2));
520d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_capacity*2,  get_camera_metadata_data_capacity(m2));
521d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
522d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) {
523f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        camera_metadata_entry e1, e2;
524d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        int result;
525f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m, i, &e1);
526d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
527f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i, e1.index);
528f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m2, i, &e2);
529d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
530f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.index, e2.index);
531f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.tag, e2.tag);
532f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.type, e2.type);
533f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.count, e2.count);
534f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        for (unsigned int j=0;
535f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j < e1.count * camera_metadata_type_size[e1.type];
536f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j++) {
537f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            EXPECT_EQ(e1.data.u8[j], e2.data.u8[j]);
538d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        }
539d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
540d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
541d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = append_camera_metadata(m2, m);
542d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
543d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
544d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
545f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(get_camera_metadata_entry_count(m)*2,
546f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            get_camera_metadata_entry_count(m2));
547f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_count(m)*2,
548f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            get_camera_metadata_data_count(m2));
549d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity*2, get_camera_metadata_entry_capacity(m2));
550d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_capacity*2,  get_camera_metadata_data_capacity(m2));
551d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
552d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (unsigned int i=0; i < get_camera_metadata_entry_count(m2); i++) {
553f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        camera_metadata_entry e1, e2;
554d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
555d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        int result;
556d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        result = get_camera_metadata_entry(m,
557f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala                i % entry_capacity, &e1);
558d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
559f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i % entry_capacity, e1.index);
560d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        result = get_camera_metadata_entry(m2,
561f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala                i, &e2);
562d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
563f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i, e2.index);
564f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.tag, e2.tag);
565f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.type, e2.type);
566f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.count, e2.count);
567f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        for (unsigned int j=0;
568f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j < e1.count * camera_metadata_type_size[e1.type];
569f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j++) {
570f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            EXPECT_EQ(e1.data.u8[j], e2.data.u8[j]);
571d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        }
572d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
573d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
574d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
575d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m2);
576d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
577d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
578d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, append_metadata_nospace) {
579d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
580d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
581d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 50;
582d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
583d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
584d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
585d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
586d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
587d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    add_test_metadata(m, entry_capacity);
588d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
589d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m2 = NULL;
590d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
591d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m2 = allocate_camera_metadata(entry_capacity-1, data_capacity);
592d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m2);
593d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
594d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = append_camera_metadata(m2, m);
595d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
596d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(ERROR, result);
597d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_entry_count(m2));
598d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ((size_t)0, get_camera_metadata_data_count(m2));
599d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
600d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
601d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m2);
602d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
603d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
604d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, append_metadata_onespace) {
605d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
606d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
607d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 50;
608d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity2 = entry_capacity * 2 - 2;
609d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity2 = data_capacity * 2;
610d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
611d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
612d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
613d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
614d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    add_test_metadata(m, entry_capacity);
615d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
616d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m2 = NULL;
617d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
618d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m2 = allocate_camera_metadata(entry_capacity2, data_capacity2);
619d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NOT_NULL(m2);
620d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
621d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = append_camera_metadata(m2, m);
622d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
623d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
624d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
625f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(get_camera_metadata_entry_count(m),
626f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            get_camera_metadata_entry_count(m2));
627f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_count(m),
628f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            get_camera_metadata_data_count(m2));
629d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity2, get_camera_metadata_entry_capacity(m2));
630d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_capacity2,  get_camera_metadata_data_capacity(m2));
631d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
632d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (unsigned int i=0; i < get_camera_metadata_entry_count(m); i++) {
633f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        camera_metadata_entry e1, e2;
634d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
635d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        int result;
636f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m, i, &e1);
637d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
638f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i, e1.index);
639f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m2, i, &e2);
640d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
641f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.index, e2.index);
642f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.tag, e2.tag);
643f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.type, e2.type);
644f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.count, e2.count);
645f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        for (unsigned int j=0;
646f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j < e1.count * camera_metadata_type_size[e1.type];
647f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j++) {
648f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            EXPECT_EQ(e1.data.u8[j], e2.data.u8[j]);
649d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        }
650d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
651d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
652d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = append_camera_metadata(m2, m);
653d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
654d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(ERROR, result);
655d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity, get_camera_metadata_entry_count(m2));
656d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(get_camera_metadata_data_count(m),
657d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_data_count(m2));
658d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(entry_capacity2, get_camera_metadata_entry_capacity(m2));
659d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(data_capacity2,  get_camera_metadata_data_capacity(m2));
660d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
661d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (unsigned int i=0; i < get_camera_metadata_entry_count(m2); i++) {
662f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        camera_metadata_entry e1, e2;
663d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
664d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        int result;
665d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        result = get_camera_metadata_entry(m,
666f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala                i % entry_capacity, &e1);
667d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
668f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i % entry_capacity, e1.index);
669f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        result = get_camera_metadata_entry(m2, i, &e2);
670d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        EXPECT_EQ(OK, result);
671f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(i, e2.index);
672f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.tag, e2.tag);
673f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.type, e2.type);
674f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        EXPECT_EQ(e1.count, e2.count);
675f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        for (unsigned int j=0;
676f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j < e1.count * camera_metadata_type_size[e1.type];
677f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala             j++) {
678f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            EXPECT_EQ(e1.data.u8[j], e2.data.u8[j]);
679d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        }
680d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
681d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
682d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
683d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m2);
684d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
685d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
686d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, vendor_tags) {
687d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    camera_metadata_t *m = NULL;
688d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t entry_capacity = 5;
689d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    const size_t data_capacity = 50;
690d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
691d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
692d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
693d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
694d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    uint8_t superMode = 5;
695d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
696d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            FAKEVENDOR_SENSOR_SUPERMODE,
697d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &superMode, 1);
698d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(ERROR, result);
699d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
700d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
701d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_REQUEST_METADATA_MODE,
702d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &superMode, 1);
703d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
704d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
705d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(get_camera_metadata_section_name(FAKEVENDOR_SENSOR_SUPERMODE));
706d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(get_camera_metadata_tag_name(FAKEVENDOR_SENSOR_SUPERMODE));
707d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(-1, get_camera_metadata_tag_type(FAKEVENDOR_SENSOR_SUPERMODE));
708d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
709d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    set_camera_metadata_vendor_tag_ops(&fakevendor_query_ops);
710d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
711d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
712d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            FAKEVENDOR_SENSOR_SUPERMODE,
713d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &superMode, 1);
714d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
715d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
716d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
717d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_REQUEST_METADATA_MODE,
718d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &superMode, 1);
719d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
720d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
721d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
722d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            FAKEVENDOR_SCALER_END,
723d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &superMode, 1);
724d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(ERROR, result);
725d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
726d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_STREQ("com.fakevendor.sensor",
727d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_section_name(FAKEVENDOR_SENSOR_SUPERMODE));
728d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_STREQ("superMode",
729d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_tag_name(FAKEVENDOR_SENSOR_SUPERMODE));
730d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(TYPE_BYTE,
731d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_tag_type(FAKEVENDOR_SENSOR_SUPERMODE));
732d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
733d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_STREQ("com.fakevendor.scaler",
734d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            get_camera_metadata_section_name(FAKEVENDOR_SCALER_END));
735d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(get_camera_metadata_tag_name(FAKEVENDOR_SCALER_END));
736d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(-1, get_camera_metadata_tag_type(FAKEVENDOR_SCALER_END));
737d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
738d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    set_camera_metadata_vendor_tag_ops(NULL);
739d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
740d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
741d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            FAKEVENDOR_SENSOR_SUPERMODE,
742d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &superMode, 1);
743d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(ERROR, result);
744d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
745d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    result = add_camera_metadata_entry(m,
746d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ANDROID_REQUEST_METADATA_MODE,
747d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            &superMode, 1);
748d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(OK, result);
749d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
750d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(get_camera_metadata_section_name(FAKEVENDOR_SENSOR_SUPERMODE));
751d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_NULL(get_camera_metadata_tag_name(FAKEVENDOR_SENSOR_SUPERMODE));
752d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    EXPECT_EQ(-1, get_camera_metadata_tag_type(FAKEVENDOR_SENSOR_SUPERMODE));
753d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
754d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    free_camera_metadata(m);
755d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala}
756d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
757d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville TalvalaTEST(camera_metadata, add_all_tags) {
758d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int total_tag_count = 0;
759d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (int i = 0; i < ANDROID_SECTION_COUNT; i++) {
760d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        total_tag_count += camera_metadata_section_bounds[i][1] -
761d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                camera_metadata_section_bounds[i][0];
762d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
763d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int entry_data_count = 3;
764d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int conservative_data_space = total_tag_count * entry_data_count * 8;
765d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    uint8_t data[entry_data_count * 8];
766d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int32_t *data_int32 = (int32_t *)data;
767d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    float *data_float   = (float *)data;
768d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int64_t *data_int64 = (int64_t *)data;
769d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    double *data_double = (double *)data;
770f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    camera_metadata_rational_t *data_rational =
771f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            (camera_metadata_rational_t *)data;
772d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
773f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    camera_metadata_t *m = allocate_camera_metadata(total_tag_count,
774f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            conservative_data_space);
775d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
776d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    ASSERT_NE((void*)NULL, (void*)m);
777d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
778d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int result;
779d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
780d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    int counter = 0;
781d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    for (int i = 0; i < ANDROID_SECTION_COUNT; i++) {
782d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        for (uint32_t tag = camera_metadata_section_bounds[i][0];
783d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                tag < camera_metadata_section_bounds[i][1];
784d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala             tag++, counter++) {
785d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            int type = get_camera_metadata_tag_type(tag);
786d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ASSERT_NE(-1, type);
787d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
788d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            switch (type) {
789d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                case TYPE_BYTE:
790d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data[0] = tag & 0xFF;
791d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data[1] = (tag >> 8) & 0xFF;
792d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data[2] = (tag >> 16) & 0xFF;
793d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    break;
794d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                case TYPE_INT32:
795d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_int32[0] = tag;
796d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_int32[1] = i;
797d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_int32[2] = counter;
798d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    break;
799d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                case TYPE_FLOAT:
800d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_float[0] = tag;
801d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_float[1] = i;
802d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_float[2] = counter / (float)total_tag_count;
803d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    break;
804d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                case TYPE_INT64:
805d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_int64[0] = (int64_t)tag | ( (int64_t)tag << 32);
806d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_int64[1] = i;
807d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_int64[2] = counter;
808d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    break;
809d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                case TYPE_DOUBLE:
810d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_double[0] = tag;
811d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_double[1] = i;
812d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_double[2] = counter / (double)total_tag_count;
813d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    break;
814d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                case TYPE_RATIONAL:
815d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_rational[0].numerator = tag;
816d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_rational[0].denominator = 1;
817d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_rational[1].numerator = i;
818d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_rational[1].denominator = 1;
819d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_rational[2].numerator = counter;
820d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data_rational[2].denominator = total_tag_count;
821d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    break;
822d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                default:
823d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    FAIL() << "Unknown type field encountered:" << type;
824d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    break;
825d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            }
826d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            result = add_camera_metadata_entry(m,
827d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    tag,
828d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    data,
829d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala                    entry_data_count);
830d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala            ASSERT_EQ(OK, result);
831d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
832d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala        }
833d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala    }
834d8afb4d1a4245b2a9d722cbb358a4d6febed89cfEino-Ville Talvala
835f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    IF_ALOGV() {
836f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala        dump_camera_metadata(m, 0, 2);
837f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    }
83894c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
83994c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    free_camera_metadata(m);
84094c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala}
84194c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
84294c1901a96c268f55012809f8261f2ec89c16deaEino-Ville TalvalaTEST(camera_metadata, sort_metadata) {
84394c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    camera_metadata_t *m = NULL;
84494c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    const size_t entry_capacity = 5;
84594c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    const size_t data_capacity = 100;
84694c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
84794c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    int result;
84894c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
84994c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    m = allocate_camera_metadata(entry_capacity, data_capacity);
85094c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
85194c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    // Add several unique entries in non-sorted order
85294c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
85394c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    float colorTransform[9] = {
85494c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala        0.9f, 0.0f, 0.0f,
85594c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala        0.2f, 0.5f, 0.0f,
85694c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala        0.0f, 0.1f, 0.7f
85794c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    };
85894c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    result = add_camera_metadata_entry(m,
85994c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            ANDROID_COLOR_TRANSFORM,
86094c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            colorTransform, 9);
86194c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    EXPECT_EQ(OK, result);
86294c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
86394c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    float focus_distance = 0.5f;
86494c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    result = add_camera_metadata_entry(m,
86594c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            ANDROID_LENS_FOCUS_DISTANCE,
86694c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            &focus_distance, 1);
86794c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    EXPECT_EQ(OK, result);
86894c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
86994c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    int64_t exposure_time = 1000000000;
87094c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    result = add_camera_metadata_entry(m,
87194c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            ANDROID_SENSOR_EXPOSURE_TIME,
87294c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            &exposure_time, 1);
87394c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    EXPECT_EQ(OK, result);
87494c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
87594c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    int32_t sensitivity = 800;
87694c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    result = add_camera_metadata_entry(m,
87794c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            ANDROID_SENSOR_SENSITIVITY,
87894c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            &sensitivity, 1);
87994c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    EXPECT_EQ(OK, result);
88094c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
88194c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    // Test unsorted find
882f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    camera_metadata_entry_t entry;
88394c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    result = find_camera_metadata_entry(m,
88494c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            ANDROID_LENS_FOCUS_DISTANCE,
885f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            &entry);
88694c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    EXPECT_EQ(OK, result);
887f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(ANDROID_LENS_FOCUS_DISTANCE, entry.tag);
888f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)1, entry.index);
889f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(TYPE_FLOAT, entry.type);
890f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)1, entry.count);
891f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(focus_distance, *entry.data.f);
89294c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala
89394c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    result = find_camera_metadata_entry(m,
89494c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala            ANDROID_NOISE_STRENGTH,
895f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala            &entry);
89694c1901a96c268f55012809f8261f2ec89c16deaEino-Ville Talvala    EXPECT_EQ(NOT_FOUND, result);
897f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ((size_t)1, entry.index);
898f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(ANDROID_LENS_FOCUS_DISTANCE, entry.tag);
899f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala    EXPECT_EQ(TYPE_FLOAT, entry.type);
900f5fb8a5516876c5a48cc44b4f1c99504e0b9f245Eino-Ville Talvala