Home | History | Annotate | Download | only in task
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * 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, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 
     18 #ifndef CTSAUDIO_MODELBUILDER_H
     19 #define CTSAUDIO_MODELBUILDER_H
     20 
     21 #include <utils/String8.h>
     22 #include "TaskAll.h"
     23 
     24 namespace tinyxml2 {
     25 class XMLElement;
     26 };
     27 
     28 class GenericFactory;
     29 
     30 /**
     31  * Class to parse Test description XML and generate test model with TestCase in top
     32  */
     33 
     34 class ModelBuilder {
     35 public:
     36     ModelBuilder();
     37     explicit ModelBuilder(GenericFactory* factory);
     38     virtual ~ModelBuilder();
     39 
     40     /**
     41      * parse given xml with test case or batch. When caseOnly is true, only test case can be in.
     42      */
     43     virtual TaskGeneric* parseTestDescriptionXml(const android::String8& xmlFileName,
     44             bool caseOnly = false);
     45 
     46     struct ChildInfo {
     47         TaskGeneric::TaskType type;
     48         bool mandatory; // whether the child is mandatory or not
     49     };
     50 
     51 private:
     52     virtual bool parseAttributes(const tinyxml2::XMLElement& elem, TaskGeneric& task);
     53     virtual TaskGeneric* parseGeneric(const tinyxml2::XMLElement& elem, int tableIndex);
     54     virtual TaskCase* parseCase(const tinyxml2::XMLElement& root);
     55     virtual TaskBatch* parseBatch(const tinyxml2::XMLElement& root, const android::String8& xmlFileName);
     56     virtual TaskCase* parseInclude(const tinyxml2::XMLElement& elem, const android::String8& path);
     57 
     58     struct ParsingInfo {
     59         const char* name; // XML element name
     60         TaskGeneric::TaskType type;
     61         const ChildInfo* allowedChildren;
     62         int Nchildren;
     63     };
     64     // no table for batch, and ETaskInvalidLast is not in either (-2)
     65     static const int PARSING_TABLE_SIZE = TaskGeneric::ETaskInvalidLast - 2;
     66     static ParsingInfo mParsingTable[PARSING_TABLE_SIZE];
     67 
     68     GenericFactory* mFactory;
     69 
     70 };
     71 
     72 
     73 #endif // CTSAUDIO_MODELBUILDER_H
     74