Path: blob/master/test/functional/Panama/panamatest.c
6000 views
/*******************************************************************************1* Copyright (c) 2017, 2018 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/212223#include "stdio.h"24#include "stdbool.h"25#include "stdlib.h"2627typedef struct {28int x;29int y;30} Point;3132typedef struct {33Point st;34Point en;35} Line;3637typedef struct {38Point v;39int n;40} ScalarVector;4142typedef struct {43char *n;44Point v;45} PointerVector;4647typedef struct {48char *m;49char *n;50} PointerPointer;5152typedef struct {53int64_t a;54double b;55} Complex;5657typedef struct {58int64_t x;59int32_t y;60/* there will be 32bits of padding here */61int64_t z;62} Padding;6364typedef struct {65char *pc;66Point *pp;67char **ppc;68Point **ppp;69} PointerStruct;7071typedef struct {72Line triangle[3];73int arr[4];74} ArrayStruct;7576typedef struct {77int8_t n;78} SmallStruct;7980typedef struct {81char **pp;82char *p;83int n;84void *x;85Line *ln;86Point pt;87int arr[3];88double d;89} LargeStruct;9091char addTwoByte(char val1, char val2) {92return val1 + val2;93}9495char addTwoChar(char val1, char val2) {96return val1 + val2 - 'a' + 1;97}9899double addTwoDouble(double val1, double val2) {100return val1 + val2;101}102103float addTwoFloat(float val1, float val2) {104return val1 + val2;105}106107int addTwoInt(int val1, int val2) {108return val1 + val2;109}110111long addTwoLong(long val1, long val2) {112return val1 + val2;113}114115short addTwoShort(short val1, short val2) {116return val1 + val2;117}118119bool testBoolean(bool val1) {120return !val1;121}122123int returnFour(void) {124return 4;125}126127void voidWithArgs(int val1) {128printf("voidWithArgs(%d) success\n", val1);129}130131void voidNoArgs(void) {132printf("voidNoArgs success\n");133}134135double manyArgs(int val1, float val2, long val3, double val4) {136return val3 + val1 * 10 + val2 * 0.1 + val4 * 0.001;137}138139int* getIntPtr(void) {140int *arr = (int*) malloc(sizeof(int) * 4);141arr[0] = 4;142arr[1] = 3;143arr[2] = 2;144arr[3] = 1;145return arr;146}147148bool checkIntPtr(int *arr) {149return (4 == arr[0] && 3 == arr[1] && 2 == arr[2] && 1 == arr[3]);150}151152void freeIntPtr(int *arr) {153free(arr);154}155156Point getPoint(int x, int y) {157Point* p = (Point*) malloc(sizeof(Point));158p->x = x;159p->y = y;160return *p;161}162163bool checkPoint(Point p, int x, int y) {164return (p.x == x && p.y == y);165}166167Point* getPointPtr(int x, int y) {168Point* p = (Point*) malloc(sizeof(Point));169p->x = x;170p->y = y;171return p;172}173174bool checkPointPtr(Point *p, int x, int y) {175return (p->x == x && p->y == y);176}177178void freePointPtr(Point *p) {179free(p);180}181182Line getLine(Point st, Point en) {183Line* ln = (Line*) malloc(sizeof(Line));184ln->st = st;185ln->en = en;186return *ln;187}188189bool checkLine(Line ln, Point st, Point en) {190return (ln.st.x == st.x && ln.st.y == st.y && ln.en.x == en.x && ln.en.y == en.y);191}192193ScalarVector getScalarVector(int n, Point pt) {194ScalarVector* s = (ScalarVector*) malloc(sizeof(ScalarVector));195s->n = n;196s->v = pt;197return *s;198}199200bool checkScalarVector(ScalarVector s, int n, Point pt) {201return (s.n == n && s.v.x == pt.x && s.v.y == pt.y);202}203204PointerVector getPointerVector(char *n, Point pt) {205PointerVector* s = (PointerVector*) malloc(sizeof(PointerVector));206s->n = n;207s->v = pt;208return *s;209}210211bool checkPointerVector(PointerVector s, char *n, Point pt) {212return (0 == strcmp(s.n, n) && s.v.x == pt.x && s.v.y == pt.y);213}214215PointerPointer getPointerPointer(char *m, char *n) {216PointerPointer* s = (PointerPointer*) malloc(sizeof(PointerPointer));217s->m = m;218s->n = n;219return *s;220}221222bool checkPointerPointer(PointerPointer s, char *m, char *n) {223return (0 == strcmp(s.m, m) && 0 == strcmp(s.n, n));224}225226Complex getComplex(int64_t n, double f) {227Complex* s = (Complex*) malloc(sizeof(Complex));228s->a = n;229s->b = f;230return *s;231}232233bool checkComplex(Complex s, int64_t n, double f) {234return (s.a == n && s.b == f);235}236237Padding getPadding(int64_t a, int32_t b, int64_t c) {238Padding* s = (Padding*) malloc(sizeof(Padding));239s->x = a;240s->y = b;241s->z = c;242return *s;243}244245bool checkPadding(Padding s, int64_t a, int32_t b, int64_t c) {246return (s.x == a && s.y == b && s.z == c);247}248249PointerStruct getPointerStruct(char *pc, Point *pp, char **ppc, Point **ppp) {250PointerStruct* s = (PointerStruct*) malloc(sizeof(PointerStruct));251s->pc = pc;252s->pp = pp;253s->ppc = ppc;254s->ppp = ppp;255return *s;256}257258bool checkPointerStruct(PointerStruct s, char *pc, Point pp, char *ppc, Point ppp) {259return (0 == strcmp(s.pc, pc) && 0 == strcmp(*(s.ppc), ppc) && s.pp->x == pp.x && s.pp->y == pp.y && (*s.ppp)->x == ppp.x && (*s.ppp)->y == ppp.y);260}261262ArrayStruct getArrayStruct(Line ln0, Line ln1, Line ln2, int a0, int a1, int a2, int a3) {263ArrayStruct* s = (ArrayStruct*) malloc(sizeof(ArrayStruct));264s->triangle[0] = ln0;265s->triangle[1] = ln1;266s->triangle[2] = ln2;267268s->arr[0] = a0;269s->arr[1] = a1;270s->arr[2] = a2;271s->arr[3] = a3;272return *s;273}274275bool checkArrayStruct(ArrayStruct s, Line ln0, Line ln1, Line ln2, int a0, int a1, int a2, int a3) {276return (s.triangle[0].st.x == ln0.st.x && s.triangle[0].st.y == ln0.st.y && s.triangle[0].en.x == ln0.en.x && s.triangle[0].en.y == ln0.en.y277&& s.triangle[1].st.x == ln1.st.x && s.triangle[1].st.y == ln1.st.y && s.triangle[1].en.x == ln1.en.x && s.triangle[1].en.y == ln1.en.y278&& s.triangle[2].st.x == ln2.st.x && s.triangle[2].st.y == ln2.st.y && s.triangle[2].en.x == ln2.en.x && s.triangle[2].en.y == ln2.en.y279&& s.arr[0] == a0 && s.arr[1] == a1 && s.arr[2] == a2 && s.arr[3] == a3 );280}281282SmallStruct getSmallStruct(int8_t n) {283SmallStruct* s = (SmallStruct*) malloc(sizeof(SmallStruct));284s->n = n;285return *s;286}287288bool checkSmallStruct(SmallStruct s, int8_t n) {289return (s.n == n);290}291292LargeStruct getLargeStruct(char *p, int n, Line *ln, Point pt, int a0, int a1, int a2, double d) {293LargeStruct* s = (LargeStruct*) malloc(sizeof(LargeStruct));294s->pp = (char**) malloc(sizeof(char*));295*(s->pp) = p;296s->p = p;297s->n = n;298s->x = (void *) p;299s->ln = ln;300s->pt = pt;301s->arr[0] = a0;302s->arr[1] = a1;303s->arr[2] = a2;304s->d = d;305return *s;306}307308bool checkLargeStruct(LargeStruct s, char *p, int n, Line ln, Point pt, int a0, int a1, int a2, double d) {309return (0 == strcmp(*(s.pp), p) && 0 == strcmp(s.p, p) && s.n == n && s.x == p310&& s.ln->st.x == ln.st.x && s.ln->st.y == ln.st.y && s.ln->en.x == ln.en.x && s.ln->en.y == ln.en.y311&& s.pt.x == pt.x && s.pt.y == pt.y && s.arr[0] == a0 && s.arr[1] == a1 && s.arr[2] == a2 && s.d == d);312}313314Point* getStructArray(void) {315Point* p1 = (Point*) malloc(sizeof(Point));316Point* p2 = (Point*) malloc(sizeof(Point));317p1->x = 2;318p1->y = 3;319p2->x = 4;320p2->y = 6;321322Point* arr = (Point*) malloc(sizeof(Point) * 2);323arr[0] = *p1;324arr[1] = *p2;325return arr;326}327328bool checkStructArray(Point *arr) {329return (2 == arr[0].x && 3 == arr[0].y && 4 == arr[1].x && 6 == arr[1].y);330}331332void freeStructArray(Point *arr) {333free(arr);334}335336337