xref: /aosp_15_r20/external/bazel-skylib/tests/native_binary/assertarg.cc (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1*bcb5dc79SHONG Yifan // Copyright 2019 The Bazel Authors. All rights reserved.
2*bcb5dc79SHONG Yifan //
3*bcb5dc79SHONG Yifan // Licensed under the Apache License, Version 2.0 (the "License");
4*bcb5dc79SHONG Yifan // you may not use this file except in compliance with the License.
5*bcb5dc79SHONG Yifan // You may obtain a copy of the License at
6*bcb5dc79SHONG Yifan //
7*bcb5dc79SHONG Yifan //    http://www.apache.org/licenses/LICENSE-2.0
8*bcb5dc79SHONG Yifan //
9*bcb5dc79SHONG Yifan // Unless required by applicable law or agreed to in writing, software
10*bcb5dc79SHONG Yifan // distributed under the License is distributed on an "AS IS" BASIS,
11*bcb5dc79SHONG Yifan // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*bcb5dc79SHONG Yifan // See the License for the specific language governing permissions and
13*bcb5dc79SHONG Yifan // limitations under the License.
14*bcb5dc79SHONG Yifan 
15*bcb5dc79SHONG Yifan #include <stdio.h>
16*bcb5dc79SHONG Yifan #include <string.h>
17*bcb5dc79SHONG Yifan 
main(int argc,char ** argv)18*bcb5dc79SHONG Yifan int main(int argc, char** argv) {
19*bcb5dc79SHONG Yifan   static const char* kExpected[] = {
20*bcb5dc79SHONG Yifan     "a b",
21*bcb5dc79SHONG Yifan     "c d",
22*bcb5dc79SHONG Yifan     "tests/native_binary/testdata.txt",
23*bcb5dc79SHONG Yifan     "$(location",
24*bcb5dc79SHONG Yifan     "testdata.txt)",
25*bcb5dc79SHONG Yifan     "tests/native_binary/testdata.txt",
26*bcb5dc79SHONG Yifan     "tests/native_binary/testdata.txt $(location testdata.txt) tests/native_binary/testdata.txt",
27*bcb5dc79SHONG Yifan     "$TEST_SRCDIR",
28*bcb5dc79SHONG Yifan     "${TEST_SRCDIR}",
29*bcb5dc79SHONG Yifan     "",
30*bcb5dc79SHONG Yifan   };
31*bcb5dc79SHONG Yifan 
32*bcb5dc79SHONG Yifan   for (int i = 1; i < argc; ++i) {
33*bcb5dc79SHONG Yifan     if (!kExpected[i - 1][0]) {
34*bcb5dc79SHONG Yifan       fprintf(stderr, "too many arguments, expected only %d\n", i);
35*bcb5dc79SHONG Yifan       return 1;
36*bcb5dc79SHONG Yifan     }
37*bcb5dc79SHONG Yifan     if (argc < i) {
38*bcb5dc79SHONG Yifan       fprintf(stderr, "expected more than %d arguments\n", i);
39*bcb5dc79SHONG Yifan       return 1;
40*bcb5dc79SHONG Yifan     }
41*bcb5dc79SHONG Yifan     if (strcmp(argv[i], kExpected[i - 1]) != 0) {
42*bcb5dc79SHONG Yifan       fprintf(stderr, "argv[%d]=(%s), expected (%s)\n", i, argv[i],
43*bcb5dc79SHONG Yifan               kExpected[i - 1]);
44*bcb5dc79SHONG Yifan       return 1;
45*bcb5dc79SHONG Yifan     }
46*bcb5dc79SHONG Yifan   }
47*bcb5dc79SHONG Yifan   return 0;
48*bcb5dc79SHONG Yifan }
49