1 /*
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 __MPEG4_H263_DECODER_TEST_ENVIRONMENT_H__
18 #define __MPEG4_H263_DECODER_TEST_ENVIRONMENT_H__
19
20 #include <gtest/gtest.h>
21
22 #include <getopt.h>
23
24 using namespace std;
25
26 class Mpeg4H263DecoderTestEnvironment : public ::testing::Environment {
27 public:
Mpeg4H263DecoderTestEnvironment()28 Mpeg4H263DecoderTestEnvironment() : res("/data/local/tmp/") {}
29
30 // Parses the command line arguments
31 int initFromOptions(int argc, char **argv);
32
setRes(const char * _res)33 void setRes(const char *_res) { res = _res; }
34
getRes()35 const string getRes() const { return res; }
36
37 private:
38 string res;
39 };
40
initFromOptions(int argc,char ** argv)41 int Mpeg4H263DecoderTestEnvironment::initFromOptions(int argc, char **argv) {
42 static struct option options[] = {{"path", required_argument, 0, 'P'}, {0, 0, 0, 0}};
43
44 while (true) {
45 int index = 0;
46 int c = getopt_long(argc, argv, "P:", options, &index);
47 if (c == -1) {
48 break;
49 }
50
51 switch (c) {
52 case 'P': {
53 setRes(optarg);
54 break;
55 }
56 default:
57 break;
58 }
59 }
60
61 if (optind < argc) {
62 fprintf(stderr,
63 "unrecognized option: %s\n\n"
64 "usage: %s <gtest options> <test options>\n\n"
65 "test options are:\n\n"
66 "-P, --path: Resource files directory location\n",
67 argv[optind ?: 1], argv[0]);
68 return 2;
69 }
70 return 0;
71 }
72
73 #endif // __MPEG4_H263_DECODER_TEST_ENVIRONMENT_H__
74