1 /* 2 * Copyright (C) 2019 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 #include <dirent.h> 18 #include <regex> 19 #include <stdlib.h> 20 #include <string.h> 21 #include <sys/stat.h> 22 #include <unistd.h> 23 #include <string> 24 25 #include "utility/ValidateXml.h" 26 27 static void get_files_in_dirs(const char* dir_path, std::vector<std::string>& files) { 28 DIR* d; 29 struct dirent* de; 30 31 d = opendir(dir_path); 32 if (d == nullptr) { 33 return; 34 } 35 36 while ((de = readdir(d))) { 37 if (de->d_type != DT_REG) { 38 continue; 39 } 40 if (std::regex_match(de->d_name, std::regex("(media_codecs)(.*)(.xml)"))) { 41 files.push_back(de->d_name); 42 } 43 } 44 closedir(d); 45 } 46 47 TEST(CheckConfig, mediaCodecsValidation) { 48 RecordProperty("description", 49 "Verify that the media codecs file " 50 "is valid according to the schema"); 51 52 const char* location = "/vendor/etc"; 53 54 std::vector<std::string> files; 55 get_files_in_dirs(location, files); 56 57 for (std::string file_name : files) { 58 EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(file_name.c_str(), {location}, 59 "/data/local/tmp/media_codecs.xsd"); 60 } 61 } 62