• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "rs_graphic_test.h"
17 #include "rs_graphic_test_director.h"
18 #include "rs_parameter_parse.h"
19 #include "rs_graphic_test_ext.h"
20 
21 #include <iostream>
22 #include <string>
23 
24 using namespace OHOS;
25 using namespace OHOS::Rosen;
26 using namespace std;
27 
28 constexpr size_t ARGS_ONE = 1;
29 constexpr size_t ARGS_TWO = 2;
30 constexpr size_t ARGS_THREE = 3;
31 constexpr size_t ARGS_FOUR = 4;
32 
33 typedef int (*ProcFunc)(int argc, char **argv);
34 typedef struct {
35     string oid;
36     ProcFunc procFunc;
37 } GraphicTestCommandTb;
38 
SplitString(const string & str,vector<string> & vec,const string & pattern)39 static void SplitString(const string& str, vector<string>& vec, const string& pattern)
40 {
41     string::size_type pos1 = 0;
42     string::size_type pos2 = str.find(pattern);
43     while (pos2 != string::npos) {
44         vec.push_back(str.substr(pos1, pos2 - pos1));
45         pos1 = pos2 + pattern.size();
46         pos2 = str.find(pattern, pos1);
47     }
48 
49     if (pos1 != str.length()) {
50         vec.push_back(str.substr(pos1));
51     }
52 }
53 
DisplayCaseLayer(vector<string> & curlayerInfo,vector<string> & layerInfo)54 static void DisplayCaseLayer(vector<string>& curlayerInfo, vector<string>& layerInfo)
55 {
56     for (uint32_t loop = 0; loop < curlayerInfo.size(); loop++) {
57         if (loop >= layerInfo.size()) {
58             layerInfo.push_back(curlayerInfo[loop]);
59         } else if (curlayerInfo[loop] == layerInfo[loop]) {
60             continue;
61         } else {
62             layerInfo[loop] = curlayerInfo[loop];
63         }
64 
65         string out {};
66         for (uint32_t idx = 0; idx < loop; idx++) {
67             out.append("|  ");
68         }
69         out.append("|--").append(curlayerInfo[loop]);
70         cout << out << endl;
71     }
72 }
73 
DisplayAllCaseInfo(int argc,char ** argv)74 static int DisplayAllCaseInfo(int argc, char **argv)
75 {
76     vector<const TestDefInfo*> info = ::OHOS::Rosen::TestDefManager::Instance().GetAllTestInfos();
77     vector<string> layerInfo {};
78     vector<string> curlayerInfo {};
79     string findPath = "graphic_test";
80     if (argc == ARGS_THREE) {
81         findPath = string(argv[ARGS_TWO]);
82     }
83     cout << findPath << endl;
84     findPath.append("/");
85 
86     for (uint32_t loop = 0; loop < info.size(); loop++) {
87         string filePath = info[loop]->filePath;
88         if (filePath.find(findPath) == string::npos) {
89             continue;
90         }
91 
92         size_t startPos = filePath.find(findPath) + findPath.length();
93         if (filePath.rfind("/") > startPos) {
94             string subPath = filePath.substr(startPos, filePath.rfind("/") - startPos);
95             SplitString(subPath, curlayerInfo, "/");
96         }
97 
98         curlayerInfo.push_back(info[loop]->testCaseName);
99         DisplayCaseLayer(curlayerInfo, layerInfo);
100 
101         string out {};
102         for (uint32_t idx = 0; idx < curlayerInfo.size() - 1; idx++) {
103             out.append("|  ");
104         }
105 
106         out.append("   |--").append(info[loop]->testName);
107         cout << out << endl;
108         curlayerInfo.clear();
109     }
110     return 0;
111 }
112 
FilterTestUnit(int argc,char ** argv)113 static int FilterTestUnit(int argc, char **argv)
114 {
115     string unitName;
116     string caseName = "*";
117     switch (argc) {
118         case ARGS_THREE:
119             unitName = argv[ARGS_TWO];
120             break;
121         case ARGS_FOUR:
122             unitName = argv[ARGS_TWO];
123             caseName = argv[ARGS_THREE];
124             RSGraphicTestDirector::Instance().SetSingleTest(true);
125             break;
126         default:
127             cout << "format fail [-unit unitName [caseName]]" << endl;
128             return 0;
129     }
130 
131     int argcTemp = ARGS_TWO;
132     string filter = "--gtest_filter=";
133     filter.append(unitName).append(".").append(caseName);
134     argv[ARGS_ONE] = filter.data();
135     RSGraphicTestDirector::Instance().Run();
136     testing::InitGoogleTest(&argcTemp, argv);
137     return RUN_ALL_TESTS();
138 }
139 
main(int argc,char ** argv)140 int main(int argc, char **argv)
141 {
142     GraphicTestCommandTb funcTbl[] = {
143         { "-list", DisplayAllCaseInfo },
144         { "-unit", FilterTestUnit }
145     };
146 
147     if (argc >= ARGS_TWO) {
148         size_t tblCnt = sizeof(funcTbl) / sizeof(funcTbl[0]);
149         for (uint32_t paraNo = 0; paraNo < tblCnt; paraNo++) {
150             if (funcTbl[paraNo].oid == string(argv[ARGS_ONE])) {
151                 return funcTbl[paraNo].procFunc(argc, argv);
152             }
153         }
154     }
155 
156     RSGraphicTestDirector::Instance().Run();
157     testing::GTEST_FLAG(output) = "xml:./";
158     testing::InitGoogleTest(&argc, argv);
159     return RUN_ALL_TESTS();
160 }
161