Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions integration-tests/c-example/lib/algorithm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdlib.h>

int abs_val(int x) {
if (x < 0 && abs(x) > 0) {
return -1;
} else if (x > 0) {
return 1;
}
return abs(x);
}

int sign(char const *str) {
int x = atoi(str);
if (x == 5) {
return 7;
}
if (x > 0) {
return 1;
} else if (x < 0) {
return -1;
}
return 0;
}
4 changes: 3 additions & 1 deletion integration-tests/c-example/lib/assertion_failures.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include "assert.h"

int buggy_function1(int a, int b);

int buggy_function2(int a);

int buggy_function3(int a, int b);

#endif //UNITTESTBOT_SRC_ASSERT_FAIL_H
#endif //SIMPLE_TEST_PROJECT_SRC_ASSERT_FAIL_H
3 changes: 3 additions & 0 deletions integration-tests/c-example/lib/basic_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
#define SIMPLE_TEST_PROJECT_BASIC_FUNCTIONS_H

int max_(int a, int b);

int min(int a, int b);

int sqr_positive(int a);

int simple_loop(unsigned int n);

#endif //SIMPLE_TEST_PROJECT_BASIC_FUNCTIONS_H
10 changes: 10 additions & 0 deletions integration-tests/c-example/lib/compound_literals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int f() {
struct s {
int i;
} *p = 0, *q;
int j = 0;
again:
q = p, p = &((struct s) { j++ });
if (j < 2) goto again;
return p == q && q->i == 1; // always returns 1
}
21 changes: 21 additions & 0 deletions integration-tests/c-example/lib/generic_selection.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#define typeid(x) _Generic((x), \
_Bool: 0, \
char: 1, \
int: 2, \
float: 3, \
default: 4)

int get_typeid(unsigned short int casen) {
switch (casen) {
case 0:
return typeid((_Bool const) 0);
case 1:
return typeid((char) 'c');
case 2:
return typeid(24);
case 3:
return typeid(42.f);
default:
return typeid("char const *");
}
}
16 changes: 15 additions & 1 deletion integration-tests/c-example/lib/halt.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "halt.h"

#include "signal.h"
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

int raise_by_num(int num) {
return raise(num);
Expand All @@ -9,3 +11,15 @@ int raise_by_num(int num) {
int raise_stop(int _) {
return raise(SIGSTOP);
}

void cleanup() {
fprintf(stderr, "Normal program termination with cleaning up\n");
}

int call_abort() {
if (atexit(cleanup)) {
return EXIT_FAILURE;
}
fprintf(stderr, "Going to abort the program\n");
abort();
}
4 changes: 4 additions & 0 deletions integration-tests/c-example/lib/halt.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ int raise_by_num(int num);

int raise_stop(int _);

void cleanup();

int call_abort();

#endif
56 changes: 56 additions & 0 deletions integration-tests/c-example/lib/loops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "loops.h"
#include <stdbool.h>

unsigned int while_loop(unsigned int n) {
unsigned int i = 0;
while (i < n) {
i = i + 1;
if (n % i == 37U)
return 1;
else if (i == 50U)
return 2U;
}
return 0U;
}

int do_while_loop(int n) {
int i = 0;
do {
i = i + 1;
if (n % i == 37)
return 1;
else if (i == 50)
return 2;
} while (i < n);
return 0;
}

int continue_break(int n) {
int i = n, res = 0;
do {
res += i;
if (res > 100) {
break;
}
if (i < 20) {
continue;
}
} while (false);
return res;
}

int goto_keyword(unsigned int a) {
unsigned int sum = 0;
do {
if (a == 15) {
goto RET;
}
sum += a;
a++;
} while (a < 22);
if (sum > 1000) {
return 1;
}
return 2;
RET: return -1;
}
12 changes: 12 additions & 0 deletions integration-tests/c-example/lib/loops.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef C_EXAMPLE_LOOPS_H
#define C_EXAMPLE_LOOPS_H

unsigned int while_loop(unsigned int n);

int do_while_loop(int n);

int continue_break(int n);

int goto_keyword(unsigned int a);

#endif //C_EXAMPLE_LOOPS_H
4 changes: 2 additions & 2 deletions integration-tests/c-example/lib/memory.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "stdlib.h"
#include "string.h"
#include <stdlib.h>
#include <string.h>

int out_of_bound_access_to_heap(int num) {
int *p = calloc(5, sizeof(int));
Expand Down
83 changes: 42 additions & 41 deletions integration-tests/c-example/lib/multi_arrays.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
#include "multi_arrays.h"

#include <string.h>

struct MyStructMult {
int a[2][3][2];
};

struct IntArray {
int ints[2][5];
};

struct PointStruct {
int x;
int y;
};


int kek(int a[1][2]) {
return 1;
int get_elem(int a[1][2]) {
return a[0][0];
}


int sumSign(int a[2][2]) {
int sum_sign(int a[2][2]) {
int sum = 0;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
Expand All @@ -37,6 +20,25 @@ int sumSign(int a[2][2]) {
}
}

int sum_sign_1d_small(const int a[9]) {
int sum = 0;
for (int i = 0; i < 9; i++) {
sum += a[i];
if (i % 2 == 0) {
sum++;
} else {
sum--;
}
}
if (sum == 0) {
return 0;
} else if (sum > 0) {
return 1;
} else {
return -1;
}
}

int value(int a[2][3]) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
Expand All @@ -48,7 +50,7 @@ int value(int a[2][3]) {
return -1;
}

int value2(int (* a)[3]) {
int value2(int (*a)[3]) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
if (a[i][j] > 0) {
Expand All @@ -60,8 +62,7 @@ int value2(int (* a)[3]) {
}


int some_method(int ** pointer2d) {
int x = 2;
int some_method(int **pointer2d) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
if (pointer2d[i][j] > 0) {
Expand All @@ -75,13 +76,13 @@ int some_method(int ** pointer2d) {
int return_sign_sum(struct MyStructMult st) {
int res = 0;
for (int i = 0; i < 2; i++) {
for(int j = 0; j < 3; j++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 2; k++) {
res += st.a[i][j][k];
}
}
}
}

if (res > 0) {
return 1;
} else if (res == 0) {
Expand All @@ -98,7 +99,7 @@ long long return_sign_sum_of_struct_array(struct PointStruct arr[2][2]) {
if (arr[i][j].x > 0) {
sumDiffs += arr[i][j].x;
} else {
sumDiffs += -arr[i][j].x;
sumDiffs += -arr[i][j].x;
}

if (arr[i][j].y > 0) {
Expand All @@ -111,31 +112,31 @@ long long return_sign_sum_of_struct_array(struct PointStruct arr[2][2]) {
return sumDiffs;
}

int point_quart(struct PointStruct ** point) {
int point_quart(struct PointStruct **point) {
if ((**point).x > 0) {
if ((**point).y > 0) {
return 1;
} else {
return 4;
}
if ((**point).y > 0) {
return 1;
} else {
return 4;
}
} else {
if ((**point).y > 0) {
return 2;
} else {
return 3;
}
if ((**point).y > 0) {
return 2;
} else {
return 3;
}
}
}

struct IntArray return_struct_with_2d_array(int a) {
if (a > 0) {
struct IntArray st = {{{1,2,3,4,5}, {1,2,3,4,5}}};
struct IntArray st = {{{ 1, 2, 3, 4, 5 }, { 1, 2, 3, 4, 5 }}};
return st;
} else if (a < 0) {
struct IntArray st = {{{-1,-2,-3,-4,-5}, {-1,-2,-3,-4,-5}}};
struct IntArray st = {{{ -1, -2, -3, -4, -5 }, { -1, -2, -3, -4, -5 }}};
return st;
} else {
struct IntArray st = {{{0,0,0,0,0}, {0,0,0,0,0}}};
struct IntArray st = {{{ 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }}};
return st;
}
}
Expand Down
44 changes: 40 additions & 4 deletions integration-tests/c-example/lib/multi_arrays.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
int kek(int a[1][2]);
#ifndef C_EXAMPLE_MULTI_ARRAYS_H
#define C_EXAMPLE_MULTI_ARRAYS_H

int sumSign(int a[2][2]);
#include <stddef.h>

struct MyStructMult {
int a[2][3][2];
};

struct IntArray {
int ints[2][5];
};

struct PointStruct {
int x;
int y;
};

int get_elem(int a[1][2]);

int sum_sign(int a[2][2]);

int sum_sign_1d_small(const int a[9]);

int value(int a[2][3]);
int value2(int (* a)[3]);
int some_method(int ** pointer2d);

int value2(int (*a)[3]);

int value3(int a[]);

int some_method(int **pointer2d);

int return_sign_sum(struct MyStructMult st);

long long return_sign_sum_of_struct_array(struct PointStruct arr[2][2]);

int point_quart(struct PointStruct **point);

struct IntArray return_struct_with_2d_array(int a);

int count_dashes();

#endif //C_EXAMPLE_MULTI_ARRAYS_H
Loading