Home | History | Annotate | Download | only in vts
      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 "android-base/logging.h"
     26 #include "utility/ValidateXml.h"
     27 
     28 static void get_files_in_dirs(const char* dir_path, std::vector<std::string>& files) {
     29     DIR* d;
     30     struct dirent* de;
     31 
     32     d = opendir(dir_path);
     33     if (d == nullptr) {
     34         return;
     35     }
     36 
     37     while ((de = readdir(d))) {
     38         if (de->d_type != DT_REG) {
     39             continue;
     40         }
     41         if (std::regex_match(de->d_name, std::regex("(.*)(.xml)"))) {
     42             files.push_back(de->d_name);
     43         }
     44     }
     45     closedir(d);
     46 }
     47 
     48 TEST(CheckConfig, permission) {
     49     RecordProperty("description",
     50                    "Verify that the permission file "
     51                    "is valid according to the schema");
     52 
     53     const char* location = "/vendor/etc/permissions";
     54 
     55     std::vector<std::string> files;
     56     get_files_in_dirs(location, files);
     57 
     58     for (std::string file_name : files) {
     59         EXPECT_ONE_VALID_XML_MULTIPLE_LOCATIONS(file_name.c_str(), {location},
     60                                                 "/data/local/tmp/permission.xsd");
     61     }
     62 }
     63