• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #include "tensorflow/lite/experimental/acceleration/mini_benchmark/jpeg_decompress_buffered_struct.h"
16 
17 #include <cstddef>
18 
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 
22 namespace tflite {
23 namespace acceleration {
24 namespace decode_jpeg_kernel {
25 namespace {
26 
27 const int kSizeOfJpegDecompressStruct = sizeof(jpeg_decompress_struct);
28 
TEST(JpegDecompressBufferedStructTest,ExpectInitializationSizeMatchesStructSize)29 TEST(JpegDecompressBufferedStructTest,
30      ExpectInitializationSizeMatchesStructSize) {
31   JpegDecompressBufferedStruct buffered_struct(kSizeOfJpegDecompressStruct);
32   EXPECT_EQ(buffered_struct.size(), kSizeOfJpegDecompressStruct);
33 }
34 
TEST(JpegDecompressBufferedStructTest,StructWithSizeGreaterThanCompiledStruct)35 TEST(JpegDecompressBufferedStructTest,
36      StructWithSizeGreaterThanCompiledStruct) {
37   int excess_bytes = 16;
38   JpegDecompressBufferedStruct buffered_struct(kSizeOfJpegDecompressStruct +
39                                                excess_bytes);
40   EXPECT_EQ(buffered_struct.size(), kSizeOfJpegDecompressStruct + excess_bytes);
41   const char* buffer = buffered_struct.buffer();
42   ASSERT_NE(buffer, nullptr);
43   while (excess_bytes--) {
44     EXPECT_EQ(
45         (unsigned char)(buffer[kSizeOfJpegDecompressStruct + excess_bytes]),
46         '\0');
47   }
48 }
49 
TEST(JpegDecompressBufferedStructTest,StructWithSizeLessThanCompiledStruct)50 TEST(JpegDecompressBufferedStructTest, StructWithSizeLessThanCompiledStruct) {
51   JpegDecompressBufferedStruct buffered_struct(kSizeOfJpegDecompressStruct -
52                                                16);
53   EXPECT_EQ(buffered_struct.size(), kSizeOfJpegDecompressStruct);
54 }
55 
56 }  // namespace
57 }  // namespace decode_jpeg_kernel
58 }  // namespace acceleration
59 }  // namespace tflite
60