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