Mercurial > pub > dyncall > dyncall
annotate test/callback_suite/main.c @ 495:45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
author | Tassilo Philipp |
---|---|
date | Mon, 21 Mar 2022 16:50:44 +0100 |
parents | d8f0e6cecdab |
children | 049e04af13c8 |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/callback_suite/main.c | |
6 Description: | |
7 License: | |
8 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
9 Copyright (c) 2011-2021 Daniel Adler <dadler@uni-goettingen.de>, |
0 | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
487 | 26 #include <stdio.h> |
0 | 27 #include <stdlib.h> |
28 #include "env.h" | |
29 #include "../common/platformInit.h" | |
30 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
31 | |
32 | |
487 | 33 static void PrintUsage(const char* appName) |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
34 { |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
35 printf("usage:\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
36 %s [ -v ] [ from [to] ]\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
37 where\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
38 from, to: test range\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
39 options\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
40 -v verbose reports\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
41 -h help on usage\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
42 \n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
43 ", appName); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
44 } |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
45 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
46 |
0 | 47 /* test one case, returns error code */ |
48 int DoTest(int id); | |
49 | |
50 void InitEnv(); | |
51 | |
52 | |
487 | 53 #define Error(X, Y, N) { fprintf(stderr, X, Y); PrintUsage(N); exit(1); } |
0 | 54 |
487 | 55 int main(int argc, char* argv[]) |
0 | 56 { |
57 int from = 1; | |
58 int to = CONFIG_NSIGS; | |
59 int ncases; | |
60 | |
61 int i; | |
62 int pos; | |
63 int totalResult; | |
64 | |
487 | 65 /* capture total results for failure (0) and success (1) */ |
66 int totalErrorCodes[2] = { 0, 0 }; | |
67 | |
0 | 68 dcTest_initPlatform(); |
69 | |
70 InitEnv(); | |
71 | |
72 pos = 0; | |
487 | 73 for(i = 1 ; i < argc ; ++i) |
74 { | |
75 int number; | |
0 | 76 |
487 | 77 if(argv[i][0] == '-') |
495
45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents:
487
diff
changeset
|
78 { |
0 | 79 switch(argv[i][1]) { |
487 | 80 case 'v': |
495
45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents:
487
diff
changeset
|
81 OptionVerbose = 1; |
45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents:
487
diff
changeset
|
82 continue; |
487 | 83 case 'h': |
84 case '?': | |
495
45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents:
487
diff
changeset
|
85 PrintUsage(argv[0]); |
45ac093ca822
- test/callback_suite: make it use shared random sig generator from call_suite and call_suite_aggrs
Tassilo Philipp
parents:
487
diff
changeset
|
86 return 0; |
487 | 87 default: Error("invalid option: %s\n\n", argv[i], argv[0]); |
0 | 88 } |
89 } | |
90 | |
91 number = atoi(argv[i]); | |
487 | 92 switch(pos++) { |
93 case 0: to = from = number; break; | |
94 case 1: to = number; break; | |
95 default: Error("too many arguments (%d given, 2 allowed)\n\n", pos, argv[0]); | |
0 | 96 } |
97 } | |
98 | |
487 | 99 if(from <= 0 || to > CONFIG_NSIGS || from > to) |
100 Error("invalid arguments (provided from or to not in order or outside of range [1,%d])\n\n", CONFIG_NSIGS, argv[0]); | |
0 | 101 |
102 ncases = (to - from) + 1; | |
103 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
104 printf("case\tsignat.\tresult\n"); |
487 | 105 |
106 for(i = from ; i <= to ; ++i ) | |
107 ++totalErrorCodes[!!DoTest(i)]; | |
108 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
109 totalResult = (totalErrorCodes[1] == ncases); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
110 printf("result: callback_suite: %d\n", totalResult); |
0 | 111 |
112 dcTest_deInitPlatform(); | |
113 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
114 return !totalResult; |
0 | 115 } |
116 |