comparison packages/language/c/libc/current/tests/stdlib/qsort.c @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 //=================================================================
2 //
3 // qsort.c
4 //
5 // Testcase for C library qsort()
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
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved.
26 // -------------------------------------------
27 //
28 //####COPYRIGHTEND####
29 //=================================================================
30 //#####DESCRIPTIONBEGIN####
31 //
32 // Author(s): jlarmour@cygnus.co.uk
33 // Contributors: jlarmour@cygnus.co.uk
34 // Date: 1998/6/3
35 // Description: Contains testcode for C library qsort() function
36 //
37 //
38 //####DESCRIPTIONEND####
39
40 // Declarations for test system:
41 //
42 // TESTCASE_TYPE=CYG_TEST_MODULE
43 // COMPOUND_TESTCASE
44
45 // CONFIGURATION
46
47 #include <pkgconf/libc.h> // Configuration header
48
49 // INCLUDES
50
51 #include <stdlib.h>
52 #include <cyg/infra/testcase.h>
53 #include <sys/cstartup.h> // C library initialisation
54
55
56 // FUNCTIONS
57
58
59 externC void
60 cyg_package_start( void )
61 {
62 #ifdef CYGPKG_LIBC
63 cyg_iso_c_start();
64 #else
65 (void)main(0, NULL);
66 #endif
67 } // cyg_package_start()
68
69
70 #ifdef CYGPKG_LIBC
71 static int
72 Compar( const void *int1, const void *int2 )
73 {
74 if ( *(int*)int1 < *(int*)int2 )
75 return -1;
76 else if ( *(int*)int1 == *(int*)int2 )
77 return 0;
78 else
79 return 1;
80 } // Compar()
81 #endif
82
83
84 int
85 main( int argc, char *argv[] )
86 {
87 #ifdef CYGPKG_LIBC
88 unsigned int ctr;
89 int fail=0;
90 int i_array_sorted[] = {1, 5, 8, 35, 84, 258, 1022, 5300, 7372, 9029};
91 int i_array_unsorted[] = {258, 8, 7372, 1, 5, 9029, 1022, 35, 5300, 84};
92 #endif
93
94 CYG_TEST_INIT();
95
96 CYG_TEST_INFO("Starting tests from testcase " __FILE__ " for C library "
97 "qsort() function");
98
99 #ifdef CYGPKG_LIBC
100 qsort(i_array_unsorted,
101 sizeof(i_array_unsorted) / sizeof(i_array_unsorted[0]),
102 sizeof(int), &Compar);
103
104 for (ctr = 0;
105 ctr < (sizeof(i_array_unsorted) / sizeof(i_array_unsorted[0]));
106 ++ctr)
107 {
108 if (i_array_sorted[ctr] != i_array_unsorted[ctr])
109 ++fail;
110 } // for
111
112 CYG_TEST_PASS_FAIL( fail == 0, "qsort() sorts correctly" );
113
114 #else // ifndef CYGPKG_LIBC
115 CYG_TEST_PASS("Testing is not applicable to this configuration");
116 #endif // ifndef CYGPKG_LIBC
117
118 CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library "
119 "qsort() function");
120
121 } // main()
122
123 // EOF qsort.c