Mercurial > pub > dyncall > dyncall
annotate test/callback_suite/main.c @ 410:7608e34098b0
- cleanups, simplifications, some api clarification, ...
- test cases consistency:
* return status code depending on test results (for actual conformance tests, not stuff that is not an example or hack to check something, ..)
* platform init helper added for some
author | Tassilo Philipp |
---|---|
date | Tue, 05 Oct 2021 21:53:04 +0200 |
parents | f5577f6bf97a |
children | d8f0e6cecdab |
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 | |
26 #include <assert.h> | |
27 #include <stdlib.h> | |
28 #include "_auto_config.h" | |
29 #include "env.h" | |
30 #include "../common/platformInit.h" | |
31 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
32 | |
33 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
34 void PrintUsage(const char* appName) |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
35 { |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
36 printf("usage:\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
37 %s [ -v ] [ from [to] ]\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
38 where\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
39 from, to: test range\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
40 options\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
41 -v verbose reports\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
42 -h help on usage\n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
43 \n\ |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
44 ", appName); |
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 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
47 |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
48 |
0 | 49 const char* appname = "unknown"; |
50 | |
51 /* test one case, returns error code */ | |
52 int DoTest(int id); | |
53 | |
54 /* capture total results for failure (0) and success (1) */ | |
55 int totalErrorCodes[2] = { 0, 0 }; | |
56 | |
57 void TestRange(int from, int to) | |
58 { | |
59 int i; | |
60 for(i = from ; i <= to ; ++i ) | |
61 { | |
62 int status = DoTest(i); | |
63 totalErrorCodes[status]++; | |
64 } | |
65 } | |
66 | |
67 void InitEnv(); | |
68 | |
69 void ExitWithUsage() | |
70 { | |
71 PrintUsage(appname); | |
72 exit(0); | |
73 } | |
74 | |
75 #define Error(X, Y) fprintf(stderr, X, Y); ExitWithUsage() | |
76 | |
77 int main(int argc, char* argv[] ) | |
78 { | |
79 int from = 1; | |
80 int to = CONFIG_NSIGS; | |
81 int ncases; | |
82 | |
83 int i; | |
84 int pos; | |
85 int number; | |
86 int totalResult; | |
87 | |
88 dcTest_initPlatform(); | |
89 | |
90 InitEnv(); | |
91 appname = argv[0]; | |
92 | |
93 pos = 0; | |
94 for(i = 1 ; i < argc ; ++i ) { | |
95 | |
96 if ( argv[i][0] == '-' ) { | |
97 switch(argv[i][1]) { | |
98 case 'v': OptionVerbose = 1; continue; | |
99 case 'h': PrintUsage(appname); return 0; | |
100 default: Error("invalid option: %s", argv[i]); | |
101 } | |
102 } | |
103 | |
104 number = atoi(argv[i]); | |
105 switch(pos) { | |
106 case 0: to = from = number; ++pos; break; | |
107 case 1: to = number; break; | |
108 default: Error("too many arguments%s", ""); | |
109 } | |
110 } | |
111 | |
112 assert(from > 0); | |
113 assert(to <= CONFIG_NSIGS); | |
114 assert(from <= to); | |
115 | |
116 ncases = (to - from) + 1; | |
117 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
118 printf("case\tsignat.\tresult\n"); |
0 | 119 TestRange(from, to); |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
120 totalResult = (totalErrorCodes[1] == ncases); |
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
121 printf("result: callback_suite: %d\n", totalResult); |
0 | 122 |
123 dcTest_deInitPlatform(); | |
124 | |
410
7608e34098b0
- cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents:
281
diff
changeset
|
125 return !totalResult; |
0 | 126 } |
127 |