• 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 #include "jsvmtest.h"
16 
17 #ifdef OHOS_JSVMTEST_XTS
18 bool TestRunner::globalInited = true;
19 #else
20 bool TestRunner::globalInited = false;
21 #endif
22 
23 JSVM_Env jsvm_env = nullptr;
24 
25 // return number of passed cases
RunAllTests()26 int RunAllTests()
27 {
28     int passed = 0;
29     auto &testVec = TestRunner::GetTestVec();
30     for (size_t i = 0; i < testVec.size(); ++i) {
31         testVec[i]->Run(i);
32         ++passed;
33     }
34     return passed;
35 }
36 
37 // return number of passed cases
RunTestsWithPrefix(const char * prefix)38 int RunTestsWithPrefix(const char *prefix)
39 {
40     int passed = 0;
41     auto &testVec = TestRunner::GetTestVec();
42     for (size_t i = 0; i < testVec.size(); ++i) {
43         const std::string name = testVec[i]->GetName();
44         if (name.find(prefix) != 0) {
45             continue;
46         }
47         testVec[i]->Run(i);
48         ++passed;
49     }
50     return passed;
51 }
52 
53 // return number of passed cases
RunTest(const char * name)54 int RunTest(const char *name)
55 {
56     auto &testMap = TestRunner::GetTestMap();
57     auto it = testMap.find(name);
58     if (it == testMap.end()) {
59         std::cout << "There is no test named " << name << std::endl;
60         return 0;
61     }
62     return 1;
63 }
64 
65 #if !defined(OHOS_JSVM_HAP) && !defined(OHOS_JSVMTEST_XTS)
main(int argc,char ** argv)66 int main(int argc, char **argv)
67 {
68     constexpr int kMinArgc = 2;
69     if (argc >= kMinArgc) {
70         std::string name = argv[1];
71         if (name.find("/") != std::string::npos) {
72             RunTest(name.c_str());
73         } else {
74             RunTestsWithPrefix(name.c_str());
75         }
76         return 0;
77     }
78     RunAllTests();
79 }
80 #endif  // OHOS_JSVM_HAP
81