xref: /aosp_15_r20/external/gflags/test/gflags_strip_flags_test.cc (revision 08ab5237c114d5c0eac1090c56f941d3f639d7d3)
1*08ab5237SOystein Eftevaag // Copyright (c) 2011, Google Inc.
2*08ab5237SOystein Eftevaag // All rights reserved.
3*08ab5237SOystein Eftevaag //
4*08ab5237SOystein Eftevaag // Redistribution and use in source and binary forms, with or without
5*08ab5237SOystein Eftevaag // modification, are permitted provided that the following conditions are
6*08ab5237SOystein Eftevaag // met:
7*08ab5237SOystein Eftevaag //
8*08ab5237SOystein Eftevaag //     * Redistributions of source code must retain the above copyright
9*08ab5237SOystein Eftevaag // notice, this list of conditions and the following disclaimer.
10*08ab5237SOystein Eftevaag //     * Redistributions in binary form must reproduce the above
11*08ab5237SOystein Eftevaag // copyright notice, this list of conditions and the following disclaimer
12*08ab5237SOystein Eftevaag // in the documentation and/or other materials provided with the
13*08ab5237SOystein Eftevaag // distribution.
14*08ab5237SOystein Eftevaag //     * Neither the name of Google Inc. nor the names of its
15*08ab5237SOystein Eftevaag // contributors may be used to endorse or promote products derived from
16*08ab5237SOystein Eftevaag // this software without specific prior written permission.
17*08ab5237SOystein Eftevaag //
18*08ab5237SOystein Eftevaag // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*08ab5237SOystein Eftevaag // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*08ab5237SOystein Eftevaag // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21*08ab5237SOystein Eftevaag // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22*08ab5237SOystein Eftevaag // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23*08ab5237SOystein Eftevaag // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24*08ab5237SOystein Eftevaag // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*08ab5237SOystein Eftevaag // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*08ab5237SOystein Eftevaag // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*08ab5237SOystein Eftevaag // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*08ab5237SOystein Eftevaag // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*08ab5237SOystein Eftevaag //
30*08ab5237SOystein Eftevaag // ---
31*08ab5237SOystein Eftevaag // Author: [email protected] (Craig Silverstein)
32*08ab5237SOystein Eftevaag //
33*08ab5237SOystein Eftevaag // A simple program that uses STRIP_FLAG_HELP.  We'll have a shell
34*08ab5237SOystein Eftevaag // script that runs 'strings' over this program and makes sure
35*08ab5237SOystein Eftevaag // that the help string is not in there.
36*08ab5237SOystein Eftevaag 
37*08ab5237SOystein Eftevaag #define STRIP_FLAG_HELP 1
38*08ab5237SOystein Eftevaag #include <gflags/gflags.h>
39*08ab5237SOystein Eftevaag 
40*08ab5237SOystein Eftevaag #include <stdio.h>
41*08ab5237SOystein Eftevaag 
42*08ab5237SOystein Eftevaag using GFLAGS_NAMESPACE::SetUsageMessage;
43*08ab5237SOystein Eftevaag using GFLAGS_NAMESPACE::ParseCommandLineFlags;
44*08ab5237SOystein Eftevaag 
45*08ab5237SOystein Eftevaag 
46*08ab5237SOystein Eftevaag DEFINE_bool(test, true, "This text should be stripped out");
47*08ab5237SOystein Eftevaag 
main(int argc,char ** argv)48*08ab5237SOystein Eftevaag int main(int argc, char** argv) {
49*08ab5237SOystein Eftevaag   SetUsageMessage("Usage message");
50*08ab5237SOystein Eftevaag   ParseCommandLineFlags(&argc, &argv, false);
51*08ab5237SOystein Eftevaag 
52*08ab5237SOystein Eftevaag   // Unfortunately, for us, libtool can replace executables with a shell
53*08ab5237SOystein Eftevaag   // script that does some work before calling the 'real' executable
54*08ab5237SOystein Eftevaag   // under a different name.  We need the 'real' executable name to run
55*08ab5237SOystein Eftevaag   // 'strings' on it, so we construct this binary to print the real
56*08ab5237SOystein Eftevaag   // name (argv[0]) on stdout when run.
57*08ab5237SOystein Eftevaag   puts(argv[0]);
58*08ab5237SOystein Eftevaag 
59*08ab5237SOystein Eftevaag   return 0;
60*08ab5237SOystein Eftevaag }
61