2 * Copyright (c) 2019 The Regents of the University of California
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <gtest/gtest.h>
30 #include <sys/types.h>
35 #include "base/loader/image_file_data.hh"
36 #include "base/loader/small_image_file.test.hh"
38 using namespace Loader
;
40 TEST(ImageFileDataTest
, SimpleImage
)
43 * Create a temporary file from our data blob.
45 char filename
[] = "image-XXXXXX";
46 int fd
= mkstemp(filename
);
48 ssize_t size
= write(fd
, image_file
, sizeof(image_file
));
51 * In this basic test, the image file is simply loaded to the
52 * ImageFileData object (i.e., no decompression).
54 ImageFileData
idf(filename
);
56 EXPECT_EQ(idf
.filename(), filename
);
57 EXPECT_EQ(size
, idf
.len());
59 for (size_t i
= 0; i
< sizeof(image_file
); i
++) {
60 EXPECT_EQ(image_file
[i
], idf
.data()[i
]);
64 * Close and delete the temporary file.
71 TEST(ImageFileDataTest
, GZipImage
)
74 * Create temporary files from our data blobs.
76 char filename_gz
[] = "image-XXXXXX";
77 int fd_gz
= mkstemp(filename_gz
);
79 ssize_t size_gz
= write(fd_gz
, image_file_gzipped
,
80 sizeof(image_file_gzipped
));
82 char filename
[] = "image-XXXXXX";
83 int fd
= mkstemp(filename
);
85 ssize_t size
= write(fd
, image_file
, sizeof(image_file
));
88 * ImageFileData decompresses a gzipped file. image_file_gzipped is just
89 * image_file gzipped. Therefore ifd_gz.len() should equal ifd.len() and
90 * ifd.data() should equal ifd_gz.data().
92 ImageFileData
ifd_gz(filename_gz
);
93 ImageFileData
ifd(filename
);
95 EXPECT_EQ(ifd
.len(), ifd_gz
.len());
96 EXPECT_EQ(size
, ifd
.len());
97 EXPECT_NE(size_gz
, ifd_gz
.len());
99 for (size_t index
= 0; index
< ifd
.len(); index
++) {
100 EXPECT_EQ(ifd
.data()[index
], ifd_gz
.data()[index
]);
104 * Close and delete the temporary files.