• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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  * All file named xmlFileName in each xmlFileLocations folder must be valid if present.
49  * @tparam atLeastOneRequired If true, at least one file has to be found.
50  *                           If false, no found file is a success.
51  */
52 template <bool atLeastOneRequired = true>
53 ::testing::AssertionResult validateXmlMultipleLocations(
54     const char* xmlFileNameExpr, const char* xmlFileLocationsExpr, const char* xsdFilePathExpr,
55     const char* xmlFileName, std::vector<const char*> xmlFileLocations, const char* xsdFilePath);
56 
57 /** ASSERT that all found XML are valid according to an xsd. */
58 #define ASSERT_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath)         \
59     ASSERT_PRED_FORMAT3(                                                                        \
60         ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations<false>, \
61         xmlFileName, xmlFileLocations, xsdFilePath)
62 
63 /** EXPECT that all found XML are valid according to an xsd. */
64 #define EXPECT_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath)         \
65     EXPECT_PRED_FORMAT3(                                                                        \
66         ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations<false>, \
67         xmlFileName, xmlFileLocations, xsdFilePath)
68 
69 /** ASSERT that all found XML are valid according to an xsd. At least one must be found. */
70 #define ASSERT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath)    \
71     ASSERT_PRED_FORMAT3(                                                                       \
72         ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations<true>, \
73         xmlFileName, xmlFileLocations, xsdFilePath)
74 
75 /** EXPECT that all found XML are valid according to an xsd. At least one must be found. */
76 #define EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(xmlFileName, xmlFileLocations, xsdFilePath)    \
77     EXPECT_PRED_FORMAT3(                                                                       \
78         ::android::hardware::audio::common::test::utility::validateXmlMultipleLocations<true>, \
79         xmlFileName, xmlFileLocations, xsdFilePath)
80 
81 }  // namespace utility
82 }  // namespace test
83 }  // namespace common
84 }  // namespace audio
85 }  // namespace hardware
86 }  // namespace android
87 
88 #endif  // ANDROID_HARDWARE_AUDIO_COMMON_TEST_UTILITY_VALIDATE_XML_H
89