1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_VALIDATE_XML_H 18 #define ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_VALIDATE_XML_H 19 20 #include <gtest/gtest.h> 21 22 namespace android { 23 namespace hardware { 24 namespace audio { 25 namespace common { 26 namespace test { 27 namespace utility { 28 29 /** Validate the provided XmlFile with the provided xsdFile. 30 * Intended to use with ASSERT_PRED_FORMAT2 as such: 31 * ASSERT_PRED_FORMAT2(validateXml, pathToXml, pathToXsd); 32 * See ASSERT_VALID_XML for a helper macro. 33 */ 34 ::testing::AssertionResult validateXml(const char* xmlFilePathExpr, const char* xsdFilePathExpr, 35 const char* xmlFilePath, const char* xsdFilePath); 36 37 /** Helper gtest ASSERT to test XML validity against an XSD. */ 38 #define ASSERT_VALID_XML(xmlFilePath, xsdFilePath) \ 39 ASSERT_PRED_FORMAT2(::android::hardware::audio::common::test::utility::validateXml, \ 40 xmlFilePath, xsdFilePath) 41 42 /** Helper gtest EXPECT to test XML validity against an XSD. */ 43 #define EXPECT_VALID_XML(xmlFilePath, xsdFilePath) \ 44 EXPECT_PRED_FORMAT2(::android::hardware::audio::common::test::utility::validateXml, \ 45 xmlFilePath, xsdFilePath) 46 47 /** Validate an XML according to an xsd. 48 * The XML file must be in at least one of the provided locations. 49 * If multiple are found, all are validated. 50 */ 51 ::testing::AssertionResult validateXmlMultipleLocations( 52 const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr, 53 const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath); 54 55 /** ASSERT that an XML is valid according to an xsd. 56 * The XML file must be in at least one of the provided locations. 57 * If multiple are found, all are validated. 58 */ 59 #define ASSERT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \ 60 ASSERT_PRED_FORMAT3( \ 61 ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations, \ 62 xmlFileName, xmlFileLocations, xsdFilePath) 63 64 /** EXPECT an XML to be valid according to an xsd. 65 * The XML file must be in at least one of the provided locations. 66 * If multiple are found, all are validated. 67 */ 68 #define EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath) \ 69 EXPECT_PRED_FORMAT3( \ 70 ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations, \ 71 xmlFileName, xmlFileLocations, xsdFilePath) 72 73 } // namespace utility 74 } // namespace test 75 } // namespace common 76 } // namespace audio 77 } // namespace hardware 78 } // namespace android 79 80 #endif // ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_VALIDATE_XML_H 81