X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=tests%2Fuffi-c-test.c;fp=tests%2Fuffi-c-test.c;h=ee1ab3a3f6fd6ddd542c3b65a823223285dc2a54;hb=7c6a7667f14741d85625f4091e931f1d5ed42159;hp=0000000000000000000000000000000000000000;hpb=9b65ff8b72e258dc50b3acb41328bd31f0d68880;p=uffi.git diff --git a/tests/uffi-c-test.c b/tests/uffi-c-test.c new file mode 100644 index 0000000..ee1ab3a --- /dev/null +++ b/tests/uffi-c-test.c @@ -0,0 +1,141 @@ +/*************************************************************************** + * FILE IDENTIFICATION + * + * Name: c-test-fns.c + * Purpose: Test functions in C for UFFI library + * Programer: Kevin M. Rosenberg + * Date Started: Mar 2002 + * + * CVS Id: $Id$ + * + * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg + * + * UFFI users are granted the rights to distribute and use this software + * as governed by the terms of the Lisp Lesser GNU Public License + * (http://opensource.franz.com/preamble.html), also known as the LLGPL. + + * These variables are correct for GCC + * you'll need to modify these for other compilers + ***************************************************************************/ + +#ifdef WIN32 +#include + +BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, + DWORD fdwReason, + LPVOID lpvReserved) +{ + return 1; +} + +#define DLLEXPORT __declspec(dllexport) + +#else +#define DLLEXPORT +#endif + +#include +#include +#include + + +DLLEXPORT unsigned char uchar_13 = 13; +DLLEXPORT signed char schar_neg_120 = -120; +DLLEXPORT unsigned short uword_257 = 257; +DLLEXPORT signed short sword_neg_321 = -321; +DLLEXPORT unsigned int uint_1234567 = 1234567; +DLLEXPORT signed int sint_neg_123456 = -123456; +DLLEXPORT double double_3_1 = 3.1; +DLLEXPORT float float_neg_4_5 = -4.5; + +/* Test of constant input string */ +DLLEXPORT +int +cs_count_upper (char* psz) +{ + int count = 0; + + if (psz) { + while (*psz) { + if (isupper (*psz)) + ++count; + ++psz; + } + return count; + } else + return -1; +} + +/* Test of input and output of a string */ +DLLEXPORT +void +cs_to_upper (char* psz) +{ + if (psz) { + while (*psz) { + *psz = toupper (*psz); + ++psz; + } + } +} + +/* Test of an output only string */ +DLLEXPORT +void +cs_make_random (int size, char* buffer) +{ + int i; + for (i = 0; i < size; i++) + buffer[i] = 'A' + (rand() % 26); +} + + +/* Test of input/output vector */ +DLLEXPORT +void +half_double_vector (int size, double* vec) +{ + int i; + for (i = 0; i < size; i++) + vec[i] /= 2.; +} + + + +DLLEXPORT +void * +cast_test_int () { + int *x = (int *) malloc(sizeof(int)); + *x = 23; + return x; +} + +DLLEXPORT +void * +cast_test_float () +{ + double *y = (double *) malloc(sizeof(double)); + *y = 3.21; + return y; +} + +DLLEXPORT int fvar_addend = 3; + +typedef struct { + int i; + double d; +} fvar_struct_type; + +fvar_struct_type fvar_struct = {42, 3.2}; + +DLLEXPORT +int fvar_struct_int () { + return (fvar_addend + fvar_struct.i); +} + +DLLEXPORT +double fvar_struct_double () { + return fvar_struct.d; +} + +