| // Copyright 2026 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| // |
| |
| #include "formats/jpeg/testing/app_segment_creator.h" |
| |
| #include <string> |
| #include <vector> |
| |
| #include "absl/status/status.h" |
| #include "absl/status/status_matchers.h" |
| #include "gmock/gmock.h" |
| #include "gtest/gtest.h" |
| |
| namespace credentio { |
| namespace { |
| |
| using ::absl_testing::IsOk; |
| using ::absl_testing::StatusIs; |
| |
| TEST(AppSegmentCreatorTest, CreateAppSegmentsSuccess) { |
| AppSegmentParams params; |
| // 4 bytes lbox (10), 4 bytes tbox (0x4a554d42), 2 bytes data |
| params.payload = std::string("\x00\x00\x00\x0a\x4a\x55\x4d\x42\x01\x02", 10); |
| params.max_size = 65535; |
| |
| auto segments_or = CreateAppSegments(params); |
| ASSERT_THAT(segments_or, IsOk()); |
| EXPECT_EQ(segments_or.value().size(), 1); |
| } |
| |
| TEST(AppSegmentCreatorTest, MaxSizeTooSmallReturnsError) { |
| AppSegmentParams params; |
| // 4 bytes lbox (10), 4 bytes tbox (0x4a554d42), 1 byte data |
| params.payload = std::string("\x00\x00\x00\x0a\x4a\x55\x4d\x42\x01", 9); |
| // base_le is 18 when lbox != 1. Setting max_size to 18 should trigger an |
| // error. |
| params.max_size = 18; |
| |
| EXPECT_THAT(CreateAppSegments(params), |
| StatusIs(absl::StatusCode::kInvalidArgument)); |
| } |
| |
| } // namespace |
| } // namespace credentio |