5f776b87954eb6397df13948a096158e98c8c095
[uffi.git] / examples / c-test-fns.c
1 /***************************************************************************
2  * FILE IDENTIFICATION
3  *
4  *  Name:         c-test-fns.c
5  *  Purpose:      Test functions in C for UFFI library
6  *  Programer:    Kevin M. Rosenberg
7  *  Date Started: Mar 2002
8  *
9  *  CVS Id:   $Id$
10  *
11  * This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg
12  *
13  * These variables are correct for GCC
14  * you'll need to modify these for other compilers
15  ***************************************************************************/
16
17 #if defined(WIN32)||defined(WIN64)
18 #include <windows.h>
19
20 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll,
21                           DWORD fdwReason,
22                           LPVOID lpvReserved)
23 {
24         return 1;
25 }
26
27 #define DLLEXPORT __declspec(dllexport)
28
29 #else
30 #define DLLEXPORT
31 #endif
32
33 #include <ctype.h>
34 #include <stdlib.h>
35 #include <math.h>
36
37
38 /* Test of constant input string */
39 DLLEXPORT
40 int
41 cs_count_upper (char* psz)
42 {
43   int count = 0;
44
45   if (psz) {
46     while (*psz) {
47       if (isupper (*psz))
48         ++count;
49       ++psz;
50     }
51     return count;
52   } else
53     return -1;
54 }
55
56 /* Test of input and output of a string */
57 DLLEXPORT
58 void
59 cs_to_upper (char* psz)
60 {
61   if (psz) {
62     while (*psz) {
63       *psz = toupper (*psz);
64       ++psz;
65     }
66   }
67 }
68
69 /* Test of an output only string */
70 DLLEXPORT
71 void
72 cs_make_random (int size, char* buffer)
73 {
74   int i;
75   for (i = 0; i < size; i++)
76     buffer[i] = 'A' + (rand() % 26);
77 }
78
79
80 /* Test of input/output vector */
81 DLLEXPORT
82 void
83 half_double_vector (int size, double* vec)
84 {
85   int i;
86   for (i = 0; i < size; i++)
87     vec[i] /= 2.;
88 }
89
90
91