blob: 1b1690d84b30e079ea14961ca3b79dffb99bcdd7 [file] [log] [blame]
Neelkamal Semwal3d2b2572020-03-31 15:11:57 +05301/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of 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,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __SONIVOX_TEST_ENVIRONMENT_H__
18#define __SONIVOX_TEST_ENVIRONMENT_H__
19
20#include <gtest/gtest.h>
21
22#include <getopt.h>
23
24using namespace std;
25
26class SonivoxTestEnvironment : public::testing::Environment {
27 public:
28 SonivoxTestEnvironment() : res("/data/local/tmp/"), deleteOutput(true){}
29
30 // Parses the command line arguments
31 int initFromOptions(int argc, char **argv);
32
33 void setRes(const char *_res) { res = _res; }
34
35 const string getRes() const { return res; }
36
37 bool cleanUp() const { return deleteOutput; }
38
39 private:
40 string res;
41 bool deleteOutput;
42};
43
44int SonivoxTestEnvironment::initFromOptions(int argc, char **argv) {
45 static struct option options[] = {{"res", required_argument, 0, 'P'},
46 {"cleanUp", optional_argument, 0, 'C'},
47 {0, 0, 0, 0}};
48
49 while (true) {
50 int index = 0;
51 int c = getopt_long(argc, argv, "P:C:", options, &index);
52 if (c == -1) {
53 break;
54 }
55
56 switch (c) {
57 case 'P': {
58 setRes(optarg);
59 break;
60 }
61 case 'C':
62 if (!strcmp(optarg, "false")) {
63 deleteOutput = false;
64 }
65 break;
66 default:
67 break;
68 }
69 }
70
71 if (optind < argc) {
72 fprintf(stderr,
73 "unrecognized option: %s\n\n"
74 "usage: %s <gtest options> <test options>\n\n"
75 "test options are:\n\n"
76 "-P, --path: Resource files directory location\n"
77 "-C, default:true. Delete output file after test completes\n",
78 argv[optind ?: 1], argv[0]);
79 return 2;
80 }
81 return 0;
82}
83
84#endif // __SONIVOX_TEST_ENVIRONMENT_H__