|
0
|
1 //================================================================= |
|
|
2 // |
|
|
3 // div.c |
|
|
4 // |
|
|
5 // Testcase for C library div() |
|
|
6 // |
|
|
7 //================================================================= |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //================================================================= |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
2
|
32 // Author(s): ctarpy, jlarmour |
|
|
33 // Contributors: jlarmour |
|
|
34 // Date: 1999-03-03 |
|
0
|
35 // Description: Contains testcode for C library div() function |
|
|
36 // |
|
|
37 // |
|
|
38 //####DESCRIPTIONEND#### |
|
|
39 |
|
|
40 // Declarations for test system: |
|
|
41 // |
|
|
42 // TESTCASE_TYPE=CYG_TEST_MODULE |
|
|
43 // COMPOUND_TESTCASE |
|
|
44 |
|
|
45 // INCLUDES |
|
|
46 |
|
|
47 #include <stdlib.h> |
|
|
48 #include <cyg/infra/testcase.h> |
|
|
49 #include <sys/cstartup.h> // C library initialisation |
|
|
50 |
|
|
51 // FUNCTIONS |
|
|
52 |
|
|
53 externC void |
|
|
54 cyg_package_start( void ) |
|
|
55 { |
|
|
56 cyg_iso_c_start(); |
|
|
57 } // cyg_package_start() |
|
|
58 |
|
|
59 |
|
|
60 int |
|
|
61 main( int argc, char *argv[] ) |
|
|
62 { |
|
|
63 int num, denom; |
|
|
64 div_t result; |
|
|
65 |
|
|
66 CYG_TEST_INIT(); |
|
|
67 |
|
|
68 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library " |
|
|
69 "div() function"); |
|
|
70 |
|
|
71 num = 10232; |
|
|
72 denom = 43; |
|
|
73 result = div(num, denom); |
|
|
74 CYG_TEST_PASS_FAIL( (result.quot==237) && (result.rem==41), |
|
|
75 "div( 10232, 43 )"); |
|
|
76 |
|
|
77 num = 4232; |
|
|
78 denom = 2000; |
|
|
79 result = div(num, denom); |
|
|
80 CYG_TEST_PASS_FAIL( (result.quot==2) && (result.rem==232), |
|
|
81 "div( 4232, 2000 )"); |
|
|
82 |
|
|
83 |
|
|
84 num = 20; |
|
|
85 denom = 20; |
|
|
86 result = div(num, denom); |
|
|
87 CYG_TEST_PASS_FAIL( (result.quot==1) && (result.rem==0), |
|
|
88 "div( 20, 20 )"); |
|
|
89 |
|
2
|
90 num = -5; |
|
|
91 denom = 4; |
|
|
92 result = div(num, denom); |
|
|
93 CYG_TEST_PASS_FAIL( (result.quot==-1) && (result.rem==-1), |
|
|
94 "div( -5, 4 )"); |
|
|
95 |
|
|
96 num = 5; |
|
|
97 denom = -4; |
|
|
98 result = div(num, denom); |
|
|
99 CYG_TEST_PASS_FAIL( (result.quot==-1) && (result.rem==1), |
|
|
100 "div( 5, -4 )"); |
|
|
101 |
|
|
102 num = -5; |
|
|
103 denom = -3; |
|
|
104 result = div(num, denom); |
|
|
105 CYG_TEST_PASS_FAIL( (result.quot==1) && (result.rem==-2), |
|
|
106 "div( -5, -3 )"); |
|
|
107 |
|
|
108 num = -7; |
|
|
109 denom = -7; |
|
|
110 result = div(num, denom); |
|
|
111 CYG_TEST_PASS_FAIL( (result.quot==1) && (result.rem==0), |
|
|
112 "div( -7, -7 )"); |
|
|
113 |
|
0
|
114 |
|
|
115 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library " |
|
|
116 "div() function"); |
|
|
117 |
|
|
118 } // main() |
|
|
119 |
|
|
120 // EOF div.c |