| // 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/bmff/xpath.h" | |
| #include "gmock/gmock.h" | |
| #include "gtest/gtest.h" | |
| namespace credentio { | |
| namespace { | |
| using ::testing::Eq; | |
| class XPathTest : public ::testing::Test { | |
| protected: | |
| XPath a1_ = XPath(nullptr, "A", 1); | |
| XPath a1_b1_ = XPath(&a1_, "B", 1); | |
| XPath a1_b1_c1_ = XPath(&a1_b1_, "C", 1); | |
| XPath a1_b1_c2_ = XPath(&a1_b1_, "C", 2); | |
| XPath a_ = XPath(nullptr, "A"); | |
| XPath a_b1_ = XPath(&a_, "B", 1); | |
| }; | |
| TEST_F(XPathTest, ToString) { | |
| EXPECT_THAT(a1_.ToString(), Eq("/A[1]")); | |
| EXPECT_THAT(a1_b1_.ToString(), Eq("/A[1]/B[1]")); | |
| EXPECT_THAT(a1_b1_c1_.ToString(), Eq("/A[1]/B[1]/C[1]")); | |
| EXPECT_THAT(a1_b1_c2_.ToString(), Eq("/A[1]/B[1]/C[2]")); | |
| EXPECT_THAT(a_.ToString(), Eq("/A")); | |
| EXPECT_THAT(a_b1_.ToString(), Eq("/A/B[1]")); | |
| } | |
| TEST_F(XPathTest, XPathMatcherMatches) { | |
| XPathMatcher matcher("/moov/meta"); | |
| EXPECT_TRUE(matcher.Matches("/moov[1]/meta[1]")); | |
| EXPECT_FALSE(matcher.Matches("/[moo[1]/[met[1]")); | |
| } | |
| } // namespace | |
| } // namespace credentio |