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 #ifndef CTSAUDIO_REPORT_H
18 #define CTSAUDIO_REPORT_H
19 
20 #include <list>
21 #include <map>
22 
23 #include <utils/String8.h>
24 #include "FileUtil.h"
25 
26 class TaskCase;
27 /**
28  * Class to generate report
29  */
30 class Report: public FileUtil {
31 public:
32     /**
33      * returns static instance of Report
34      * report without dir name, for the 1st call, will only print to stdout.
35      * This mode is necessary to prevent creating tons of reports during unit testing
36      */
37     static Report* Instance(const char* dirName = NULL);
38     // should be called before finishing to flush the report to file system
39     static void Finalize();
40 
41     void addCasePassed(const TaskCase* task);
42     void addCaseFailed(const TaskCase* task);
43 
44 
45 private:
46     Report();
47     ~Report();
48     bool init(const char* dirName);
49     void writeReport();
50     void printf(const char* fmt, ...);
51     typedef std::pair<android::String8, android::String8> StringPair;
52     void writeResult(std::list<StringPair>::const_iterator begin,
53             std::list<StringPair>::const_iterator end, bool passed);
54 
55 private:
56     static Report* mInstance;
57     std::list<StringPair> mPassedCases;
58     std::list<StringPair> mFailedCases;
59 };
60 
61 
62 #endif // CTSAUDIO_REPORT_H
63