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 class TiXmlElement;
     25 
     26 
     27 class GenericFactory;
     28 
     29 /**
     30  * Class to parse Test description XML and generate test model with TestCase in top
     31  */
     32 
     33 class ModelBuilder {
     34 public:
     35     ModelBuilder();
     36     ModelBuilder(GenericFactory* factory);
     37     virtual ~ModelBuilder();
     38 
     39     /**
     40      * parse given xml with test case or batch. When caseOnly is true, only test case can be in.
     41      */
     42     virtual TaskGeneric* parseTestDescriptionXml(const android::String8& xmlFileName,
     43             bool caseOnly = false);
     44 
     45     struct ChildInfo {
     46         TaskGeneric::TaskType type;
     47         bool mandatory; // whether the child is mandatory or not
     48     };
     49 
     50 private:
     51     virtual bool parseAttributes(const TiXmlElement& elem, TaskGeneric& task);
     52     virtual TaskGeneric* parseGeneric(const TiXmlElement& elem, int tableIndex);
     53     virtual TaskCase* parseCase(const TiXmlElement& root);
     54     virtual TaskBatch* parseBatch(const TiXmlElement& root, const android::String8& xmlFileName);
     55     virtual TaskCase* parseInclude(const TiXmlElement& elem, const android::String8& path);
     56 
     57     struct ParsingInfo {
     58         const char* name; // XML element name
     59         TaskGeneric::TaskType type;
     60         const ChildInfo* allowedChildren;
     61         int Nchildren;
     62     };
     63     // no table for batch, and ETaskInvalidLast is not in either (-2)
     64     static const int PARSING_TABLE_SIZE = TaskGeneric::ETaskInvalidLast - 2;
     65     static ParsingInfo mParsingTable[PARSING_TABLE_SIZE];
     66 
     67     GenericFactory* mFactory;
     68 
     69 };
     70 
     71 
     72 #endif // CTSAUDIO_MODELBUILDER_H
     73