Mercurial > pub > dyncall > dyncall
comparison test/callback_suite/main.c @ 0:3e629dc19168
initial from svn dyncall-1745
author | Daniel Adler |
---|---|
date | Thu, 19 Mar 2015 22:24:28 +0100 |
parents | |
children | f5577f6bf97a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3e629dc19168 |
---|---|
1 /* | |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/callback_suite/main.c | |
6 Description: | |
7 License: | |
8 | |
9 Copyright (c) 2011-2015 Daniel Adler <dadler@uni-goettingen.de>, | |
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 "print.h" | |
31 #include "../common/platformInit.h" | |
32 #include "../common/platformInit.c" /* Impl. for functions only used in this translation unit */ | |
33 | |
34 | |
35 const char* appname = "unknown"; | |
36 | |
37 /* test one case, returns error code */ | |
38 int DoTest(int id); | |
39 | |
40 /* capture total results for failure (0) and success (1) */ | |
41 int totalErrorCodes[2] = { 0, 0 }; | |
42 | |
43 void TestRange(int from, int to) | |
44 { | |
45 int i; | |
46 for(i = from ; i <= to ; ++i ) | |
47 { | |
48 int status = DoTest(i); | |
49 totalErrorCodes[status]++; | |
50 } | |
51 } | |
52 | |
53 void InitEnv(); | |
54 | |
55 void ExitWithUsage() | |
56 { | |
57 PrintUsage(appname); | |
58 exit(0); | |
59 } | |
60 | |
61 #define Error(X, Y) fprintf(stderr, X, Y); ExitWithUsage() | |
62 | |
63 int main(int argc, char* argv[] ) | |
64 { | |
65 int from = 1; | |
66 int to = CONFIG_NSIGS; | |
67 int ncases; | |
68 | |
69 int i; | |
70 int pos; | |
71 int number; | |
72 int totalResult; | |
73 | |
74 dcTest_initPlatform(); | |
75 | |
76 InitEnv(); | |
77 appname = argv[0]; | |
78 | |
79 pos = 0; | |
80 for(i = 1 ; i < argc ; ++i ) { | |
81 | |
82 if ( argv[i][0] == '-' ) { | |
83 switch(argv[i][1]) { | |
84 case 'v': OptionVerbose = 1; continue; | |
85 case 'h': PrintUsage(appname); return 0; | |
86 default: Error("invalid option: %s", argv[i]); | |
87 } | |
88 } | |
89 | |
90 number = atoi(argv[i]); | |
91 switch(pos) { | |
92 case 0: to = from = number; ++pos; break; | |
93 case 1: to = number; break; | |
94 default: Error("too many arguments%s", ""); | |
95 } | |
96 } | |
97 | |
98 assert(from > 0); | |
99 assert(to <= CONFIG_NSIGS); | |
100 assert(from <= to); | |
101 | |
102 ncases = (to - from) + 1; | |
103 | |
104 PrintHeader(); | |
105 TestRange(from, to); | |
106 totalResult = (totalErrorCodes[1] == ncases) ? 1 : 0; | |
107 PrintTotalResult(totalResult); | |
108 | |
109 dcTest_deInitPlatform(); | |
110 | |
111 return 0; | |
112 } | |
113 |