1*495ae853SAndroid Build Coastguard Worker /*
2*495ae853SAndroid Build Coastguard Worker * Copyright (C) 2021 The Android Open Source Project
3*495ae853SAndroid Build Coastguard Worker *
4*495ae853SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*495ae853SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*495ae853SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*495ae853SAndroid Build Coastguard Worker *
8*495ae853SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*495ae853SAndroid Build Coastguard Worker *
10*495ae853SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*495ae853SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*495ae853SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*495ae853SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*495ae853SAndroid Build Coastguard Worker * limitations under the License.
15*495ae853SAndroid Build Coastguard Worker */
16*495ae853SAndroid Build Coastguard Worker
17*495ae853SAndroid Build Coastguard Worker #ifndef __AVC_ENCODER_TEST_ENVIRONMENT_H__
18*495ae853SAndroid Build Coastguard Worker #define __AVC_ENCODER_TEST_ENVIRONMENT_H__
19*495ae853SAndroid Build Coastguard Worker
20*495ae853SAndroid Build Coastguard Worker #include <gtest/gtest.h>
21*495ae853SAndroid Build Coastguard Worker #include <getopt.h>
22*495ae853SAndroid Build Coastguard Worker
23*495ae853SAndroid Build Coastguard Worker using namespace std;
24*495ae853SAndroid Build Coastguard Worker
25*495ae853SAndroid Build Coastguard Worker class TestArgs : public::testing::Environment {
26*495ae853SAndroid Build Coastguard Worker public:
TestArgs()27*495ae853SAndroid Build Coastguard Worker TestArgs() : res("/data/local/tmp/AvcEncTestRes/") {}
28*495ae853SAndroid Build Coastguard Worker
29*495ae853SAndroid Build Coastguard Worker // Parses the command line arguments
30*495ae853SAndroid Build Coastguard Worker int initFromOptions(int argc, char **argv);
31*495ae853SAndroid Build Coastguard Worker
setRes(const char * _res)32*495ae853SAndroid Build Coastguard Worker void setRes(const char *_res) { res = _res; }
33*495ae853SAndroid Build Coastguard Worker
getRes()34*495ae853SAndroid Build Coastguard Worker const string getRes() const { return res; }
35*495ae853SAndroid Build Coastguard Worker
36*495ae853SAndroid Build Coastguard Worker private:
37*495ae853SAndroid Build Coastguard Worker string res;
38*495ae853SAndroid Build Coastguard Worker };
39*495ae853SAndroid Build Coastguard Worker
initFromOptions(int argc,char ** argv)40*495ae853SAndroid Build Coastguard Worker int TestArgs::initFromOptions(int argc, char **argv) {
41*495ae853SAndroid Build Coastguard Worker static struct option options[] = {{"path", required_argument, 0, 'P'}, {0, 0, 0, 0}};
42*495ae853SAndroid Build Coastguard Worker
43*495ae853SAndroid Build Coastguard Worker while (true) {
44*495ae853SAndroid Build Coastguard Worker int index = 0;
45*495ae853SAndroid Build Coastguard Worker int c = getopt_long(argc, argv, "P:", options, &index);
46*495ae853SAndroid Build Coastguard Worker if (c == -1) {
47*495ae853SAndroid Build Coastguard Worker break;
48*495ae853SAndroid Build Coastguard Worker }
49*495ae853SAndroid Build Coastguard Worker
50*495ae853SAndroid Build Coastguard Worker switch (c) {
51*495ae853SAndroid Build Coastguard Worker case 'P': {
52*495ae853SAndroid Build Coastguard Worker setRes(optarg);
53*495ae853SAndroid Build Coastguard Worker break;
54*495ae853SAndroid Build Coastguard Worker }
55*495ae853SAndroid Build Coastguard Worker default:
56*495ae853SAndroid Build Coastguard Worker break;
57*495ae853SAndroid Build Coastguard Worker }
58*495ae853SAndroid Build Coastguard Worker }
59*495ae853SAndroid Build Coastguard Worker
60*495ae853SAndroid Build Coastguard Worker if (optind < argc) {
61*495ae853SAndroid Build Coastguard Worker fprintf(stderr,
62*495ae853SAndroid Build Coastguard Worker "unrecognized option: %s\n\n"
63*495ae853SAndroid Build Coastguard Worker "usage: %s <gtest options> <test options>\n\n"
64*495ae853SAndroid Build Coastguard Worker "test options are:\n\n"
65*495ae853SAndroid Build Coastguard Worker "-P, --path: Resource files directory location\n",
66*495ae853SAndroid Build Coastguard Worker argv[optind ?: 1], argv[0]);
67*495ae853SAndroid Build Coastguard Worker return 2;
68*495ae853SAndroid Build Coastguard Worker }
69*495ae853SAndroid Build Coastguard Worker return 0;
70*495ae853SAndroid Build Coastguard Worker }
71*495ae853SAndroid Build Coastguard Worker
72*495ae853SAndroid Build Coastguard Worker #endif // __AVC_ENCODER_TEST_ENVIRONMENT_H__
73