• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 Google LLC
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 //     https://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 "check_tag.h"  // NOLINT(build/include)
16 
17 using ::sapi::IsOk;
18 using ::testing::Eq;
19 using ::testing::IsFalse;
20 using ::testing::IsTrue;
21 
22 // sapi functions:
23 // TIFFGetField
24 
CheckShortField(TiffApi & api,sapi::v::RemotePtr & tif,const ttag_t field,const uint16_t value)25 void CheckShortField(TiffApi& api, sapi::v::RemotePtr& tif, const ttag_t field,
26                      const uint16_t value) {
27   sapi::v::UShort tmp(123);
28   absl::StatusOr<int> status_or_int;
29 
30   status_or_int = api.TIFFGetField1(&tif, field, tmp.PtrBoth());
31   ASSERT_THAT(status_or_int, IsOk()) << "TIFFGetField1 fatal error";
32   EXPECT_THAT(status_or_int.value(), IsTrue())
33       << "Problem fetching tag " << field;
34   EXPECT_THAT(tmp.GetValue(), Eq(value))
35       << "Wrong SHORT value fetched for tag " << field;
36 }
37 
CheckShortPairedField(TiffApi & api,sapi::v::RemotePtr & tif,const ttag_t field,const std::array<uint16_t,2> & values)38 void CheckShortPairedField(TiffApi& api, sapi::v::RemotePtr& tif,
39                            const ttag_t field,
40                            const std::array<uint16_t, 2>& values) {
41   sapi::v::UShort tmp0(123);
42   sapi::v::UShort tmp1(456);
43   absl::StatusOr<int> status_or_int;
44 
45   status_or_int =
46       api.TIFFGetField2(&tif, field, tmp0.PtrBoth(), tmp1.PtrBoth());
47   ASSERT_THAT(status_or_int, IsOk()) << "TIFFGetField2 fatal error";
48   EXPECT_THAT(status_or_int.value(), IsTrue())
49       << "Problem fetching tag " << field;
50   EXPECT_THAT(tmp0.GetValue(), Eq(values[0]))
51       << "Wrong SHORT PAIR[0] fetched for tag " << field;
52   EXPECT_THAT(tmp1.GetValue(), Eq(values[1]))
53       << "Wrong SHORT PAIR[1] fetched for tag " << field;
54 }
55 
CheckLongField(TiffApi & api,sapi::v::RemotePtr & tif,const ttag_t field,const uint32_t value)56 void CheckLongField(TiffApi& api, sapi::v::RemotePtr& tif, const ttag_t field,
57                     const uint32_t value) {
58   sapi::v::UInt tmp(123);
59   absl::StatusOr<int> status_or_int;
60 
61   status_or_int = api.TIFFGetField1(&tif, field, tmp.PtrBoth());
62   ASSERT_THAT(status_or_int, IsOk()) << "TIFFGetField1 fatal error";
63   EXPECT_THAT(status_or_int.value(), IsTrue())
64       << "Problem fetching tag " << field;
65   EXPECT_THAT(tmp.GetValue(), Eq(value))
66       << "Wrong LONG value fetched for tag " << field;
67 }
68