blob: d4f551d5c1312419c5609c084f3a26fbccf67e28 [file] [log] [blame]
Wyatt Hepler421a8102020-01-13 11:30:58 -08001// Copyright 2020 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
Wyatt Hepler421a8102020-01-13 11:30:58 -080015#include <string.h>
16
Michael Spanga99220e2020-06-11 20:07:16 -040017#include "pw_status/status.h"
18
Wyatt Hepler421a8102020-01-13 11:30:58 -080019pw_Status PassStatusFromC(pw_Status status) { return status; }
20
21pw_Status PassStatusFromCpp(pw_Status status);
22
23#define CHECK_STATUS_FROM_CPP(status) \
24 (PW_STATUS_##status != PassStatusFromCpp(PW_STATUS_##status))
25
26int TestStatusFromC() {
27 int errors = 0;
28
29 errors += CHECK_STATUS_FROM_CPP(OK);
30 errors += CHECK_STATUS_FROM_CPP(CANCELLED);
31 errors += CHECK_STATUS_FROM_CPP(UNKNOWN);
32 errors += CHECK_STATUS_FROM_CPP(INVALID_ARGUMENT);
33 errors += CHECK_STATUS_FROM_CPP(DEADLINE_EXCEEDED);
34 errors += CHECK_STATUS_FROM_CPP(NOT_FOUND);
35 errors += CHECK_STATUS_FROM_CPP(ALREADY_EXISTS);
36 errors += CHECK_STATUS_FROM_CPP(PERMISSION_DENIED);
37 errors += CHECK_STATUS_FROM_CPP(UNAUTHENTICATED);
38 errors += CHECK_STATUS_FROM_CPP(RESOURCE_EXHAUSTED);
39 errors += CHECK_STATUS_FROM_CPP(FAILED_PRECONDITION);
40 errors += CHECK_STATUS_FROM_CPP(ABORTED);
41 errors += CHECK_STATUS_FROM_CPP(OUT_OF_RANGE);
42 errors += CHECK_STATUS_FROM_CPP(UNIMPLEMENTED);
43 errors += CHECK_STATUS_FROM_CPP(INTERNAL);
44 errors += CHECK_STATUS_FROM_CPP(UNAVAILABLE);
45 errors += CHECK_STATUS_FROM_CPP(DATA_LOSS);
46
47 return errors;
48}
49
50#undef CHECK_STATUS_FROM_CPP
51
52#define CHECK_STATUS_STRING(status) \
53 (strcmp(#status, pw_StatusString(PW_STATUS_##status)) != 0)
54
55int TestStatusStringsFromC() {
56 int errors = 0;
57
58 errors += CHECK_STATUS_STRING(OK);
59 errors += CHECK_STATUS_STRING(CANCELLED);
60 errors += CHECK_STATUS_STRING(DEADLINE_EXCEEDED);
61 errors += CHECK_STATUS_STRING(NOT_FOUND);
62 errors += CHECK_STATUS_STRING(ALREADY_EXISTS);
63 errors += CHECK_STATUS_STRING(PERMISSION_DENIED);
64 errors += CHECK_STATUS_STRING(UNAUTHENTICATED);
65 errors += CHECK_STATUS_STRING(RESOURCE_EXHAUSTED);
66 errors += CHECK_STATUS_STRING(FAILED_PRECONDITION);
67 errors += CHECK_STATUS_STRING(ABORTED);
68 errors += CHECK_STATUS_STRING(OUT_OF_RANGE);
69 errors += CHECK_STATUS_STRING(UNIMPLEMENTED);
70 errors += CHECK_STATUS_STRING(INTERNAL);
71 errors += CHECK_STATUS_STRING(UNAVAILABLE);
72 errors += CHECK_STATUS_STRING(DATA_LOSS);
73
74 return errors;
75}
76
77#undef CHECK_STATUS_STRING