Skip to content

Commit f4776da

Browse files
committed
Refactoring of the example
1 parent b58458d commit f4776da

File tree

11 files changed

+110
-107
lines changed

11 files changed

+110
-107
lines changed

.github/workflows/cppcheck.yml

-24
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Debug/*
1212
Release/*
1313
.vs/*
1414
build/*
15+
.vscode/*

Lab1C/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
add_executable(Lab1C lab1.c)
22
target_include_directories(Lab1C PUBLIC ../LibraryC)
33
target_link_libraries(Lab1C LibraryC)
4+
5+
add_test(NAME TestLab1C COMMAND Lab1C ${CMAKE_CURRENT_SOURCE_DIR}/input.txt)

Lab1C/input.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
10
2+
1 2 3 4 5 6 7 8 9 0
3+
4
4+
1 2 3 4

Lab1C/lab1.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
#include <stdio.h>
22
#include "array.h"
33

4+
Array *array_create_and_read(FILE *input)
5+
{
6+
int n;
7+
fscanf(input, "%d", &n);
8+
/* Create array */
9+
Array *arr = array_create(n, NULL);
10+
/* Read array data */
11+
for (int i = 0 ; i < n ; ++i)
12+
{
13+
int x;
14+
fscanf(input, "%d", &x);
15+
array_set(arr, i, x);
16+
}
17+
return arr;
18+
}
19+
420
void task1(Array *arr)
521
{
622
}
@@ -9,13 +25,16 @@ void task2(Array *arr)
925
{
1026
}
1127

12-
int main()
28+
int main(int argc, char **argv)
1329
{
1430
Array *arr = NULL;
15-
/* Create array here */
31+
FILE *input = fopen(argv[1], "r");
32+
arr = array_create_and_read(input);
1633
task1(arr);
1734
array_delete(arr);
1835
/* Create another array here */
36+
arr = array_create_and_read(input);
1937
task2(arr);
2038
array_delete(arr);
39+
fclose(input);
2140
}

LibraryC/Tests/CMakeLists.txt

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ target_include_directories(TestArrayC PUBLIC ..)
33
target_link_libraries(TestArrayC LibraryC)
44
add_test(TestArrayC TestArrayC)
55

6-
add_executable(TestListC list.cpp)
7-
target_include_directories(TestListC PUBLIC ..)
8-
target_link_libraries(TestListC LibraryC)
9-
add_test(TestListC TestListC)
6+
# add_executable(TestListC list.cpp)
7+
# target_include_directories(TestListC PUBLIC ..)
8+
# target_link_libraries(TestListC LibraryC)
9+
# add_test(TestListC TestListC)
1010

11-
add_executable(TestQueueC queue.cpp)
12-
target_include_directories(TestQueueC PUBLIC ..)
13-
target_link_libraries(TestQueueC LibraryC)
14-
add_test(TestQueueC TestQueueC)
15-
set_tests_properties(TestQueueC PROPERTIES TIMEOUT 10)
11+
# add_executable(TestQueueC queue.cpp)
12+
# target_include_directories(TestQueueC PUBLIC ..)
13+
# target_link_libraries(TestQueueC LibraryC)
14+
# add_test(TestQueueC TestQueueC)
15+
# set_tests_properties(TestQueueC PROPERTIES TIMEOUT 10)
1616

17-
add_executable(TestStackC stack.cpp)
18-
target_include_directories(TestStackC PUBLIC ..)
19-
target_link_libraries(TestStackC LibraryC)
20-
add_test(TestStackC TestStackC)
17+
# add_executable(TestStackC stack.cpp)
18+
# target_include_directories(TestStackC PUBLIC ..)
19+
# target_link_libraries(TestStackC LibraryC)
20+
# add_test(TestStackC TestStackC)
2121

22-
add_executable(TestVectorC vector.cpp)
23-
target_include_directories(TestVectorC PUBLIC ..)
24-
target_link_libraries(TestVectorC LibraryC)
25-
add_test(TestVectorC TestVectorC)
26-
set_tests_properties(TestVectorC PROPERTIES TIMEOUT 10)
22+
# add_executable(TestVectorC vector.cpp)
23+
# target_include_directories(TestVectorC PUBLIC ..)
24+
# target_link_libraries(TestVectorC LibraryC)
25+
# add_test(TestVectorC TestVectorC)
26+
# set_tests_properties(TestVectorC PROPERTIES TIMEOUT 10)

LibraryC/Tests/array.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main()
1616
{
1717
int *d = new int;
1818
*d = i * 2;
19-
array_set(arr, i, d);
19+
array_set(arr, i, (Data)d);
2020
}
2121

2222
for (int i = 0 ; i < 10 ; ++i)

LibraryC/array.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#define ARRAY_H
33

44
#include <stddef.h>
5+
#include <stdint.h>
56

67
// Non-resizeable array
78
// Stores pointer to custom user data
8-
typedef void* Data;
9+
typedef uintptr_t Data;
910
// Custom function to free user pointers on delete
1011
typedef void (FFree)(void*);
1112

LibraryCPP/Tests/CMakeLists.txt

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
add_executable(TestArrayCPP array.cpp)
2-
target_include_directories(TestArrayCPP PUBLIC ..)
3-
target_link_libraries(TestArrayCPP LibraryCPP)
4-
add_test(TestArrayCPP TestArrayCPP)
1+
# add_executable(TestArrayCPP array.cpp)
2+
# target_include_directories(TestArrayCPP PUBLIC ..)
3+
# target_link_libraries(TestArrayCPP LibraryCPP)
4+
# add_test(TestArrayCPP TestArrayCPP)
55

6-
add_executable(TestListCPP list.cpp)
7-
target_include_directories(TestListCPP PUBLIC ..)
8-
target_link_libraries(TestListCPP LibraryCPP)
9-
add_test(TestListCPP TestListCPP)
6+
# add_executable(TestListCPP list.cpp)
7+
# target_include_directories(TestListCPP PUBLIC ..)
8+
# target_link_libraries(TestListCPP LibraryCPP)
9+
# add_test(TestListCPP TestListCPP)
1010

11-
add_executable(TestQueueCPP queue.cpp)
12-
target_include_directories(TestQueueCPP PUBLIC ..)
13-
target_link_libraries(TestQueueCPP LibraryCPP)
14-
add_test(TestQueueCPP TestQueueCPP)
15-
set_tests_properties(TestQueueCPP PROPERTIES TIMEOUT 10)
11+
# add_executable(TestQueueCPP queue.cpp)
12+
# target_include_directories(TestQueueCPP PUBLIC ..)
13+
# target_link_libraries(TestQueueCPP LibraryCPP)
14+
# add_test(TestQueueCPP TestQueueCPP)
15+
# set_tests_properties(TestQueueCPP PROPERTIES TIMEOUT 10)
1616

17-
add_executable(TestStackCPP stack.cpp)
18-
target_include_directories(TestStackCPP PUBLIC ..)
19-
target_link_libraries(TestStackCPP LibraryCPP)
20-
add_test(TestStackCPP TestStackCPP)
17+
# add_executable(TestStackCPP stack.cpp)
18+
# target_include_directories(TestStackCPP PUBLIC ..)
19+
# target_link_libraries(TestStackCPP LibraryCPP)
20+
# add_test(TestStackCPP TestStackCPP)
2121

22-
add_executable(TestVectorCPP vector.cpp)
23-
target_include_directories(TestVectorCPP PUBLIC ..)
24-
target_link_libraries(TestVectorCPP LibraryCPP)
25-
add_test(TestVectorCPP TestVectorCPP)
26-
set_tests_properties(TestVectorCPP PROPERTIES TIMEOUT 10)
22+
# add_executable(TestVectorCPP vector.cpp)
23+
# target_include_directories(TestVectorCPP PUBLIC ..)
24+
# target_link_libraries(TestVectorCPP LibraryCPP)
25+
# add_test(TestVectorCPP TestVectorCPP)
26+
# set_tests_properties(TestVectorCPP PROPERTIES TIMEOUT 10)

LibraryCPPClass/Tests/CMakeLists.txt

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
add_executable(TestArrayCPPClass array.cpp)
2-
target_include_directories(TestArrayCPPClass PUBLIC ..)
3-
target_link_libraries(TestArrayCPPClass LibraryCPPClass)
4-
add_test(TestArrayCPPClass TestArrayCPPClass)
1+
# add_executable(TestArrayCPPClass array.cpp)
2+
# target_include_directories(TestArrayCPPClass PUBLIC ..)
3+
# target_link_libraries(TestArrayCPPClass LibraryCPPClass)
4+
# add_test(TestArrayCPPClass TestArrayCPPClass)
55

6-
add_executable(TestListCPPClass list.cpp)
7-
target_include_directories(TestListCPPClass PUBLIC ..)
8-
target_link_libraries(TestListCPPClass LibraryCPPClass)
9-
add_test(TestListCPPClass TestListCPPClass)
6+
# add_executable(TestListCPPClass list.cpp)
7+
# target_include_directories(TestListCPPClass PUBLIC ..)
8+
# target_link_libraries(TestListCPPClass LibraryCPPClass)
9+
# add_test(TestListCPPClass TestListCPPClass)
1010

11-
add_executable(TestQueueCPPClass queue.cpp)
12-
target_include_directories(TestQueueCPPClass PUBLIC ..)
13-
target_link_libraries(TestQueueCPPClass LibraryCPPClass)
14-
add_test(TestQueueCPPClass TestQueueCPPClass)
15-
set_tests_properties(TestQueueCPPClass PROPERTIES TIMEOUT 10)
11+
# add_executable(TestQueueCPPClass queue.cpp)
12+
# target_include_directories(TestQueueCPPClass PUBLIC ..)
13+
# target_link_libraries(TestQueueCPPClass LibraryCPPClass)
14+
# add_test(TestQueueCPPClass TestQueueCPPClass)
15+
# set_tests_properties(TestQueueCPPClass PROPERTIES TIMEOUT 10)
1616

17-
add_executable(TestStackCPPClass stack.cpp)
18-
target_include_directories(TestStackCPPClass PUBLIC ..)
19-
target_link_libraries(TestStackCPPClass LibraryCPPClass)
20-
add_test(TestStackCPPClass TestStackCPPClass)
17+
# add_executable(TestStackCPPClass stack.cpp)
18+
# target_include_directories(TestStackCPPClass PUBLIC ..)
19+
# target_link_libraries(TestStackCPPClass LibraryCPPClass)
20+
# add_test(TestStackCPPClass TestStackCPPClass)
2121

22-
add_executable(TestVectorCPPClass vector.cpp)
23-
target_include_directories(TestVectorCPPClass PUBLIC ..)
24-
target_link_libraries(TestVectorCPPClass LibraryCPPClass)
25-
add_test(TestVectorCPPClass TestVectorCPPClass)
26-
set_tests_properties(TestVectorCPPClass PROPERTIES TIMEOUT 10)
22+
# add_executable(TestVectorCPPClass vector.cpp)
23+
# target_include_directories(TestVectorCPPClass PUBLIC ..)
24+
# target_link_libraries(TestVectorCPPClass LibraryCPPClass)
25+
# add_test(TestVectorCPPClass TestVectorCPPClass)
26+
# set_tests_properties(TestVectorCPPClass PROPERTIES TIMEOUT 10)
+17-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
add_executable(TestArrayCPPTemplate array.cpp)
2-
target_include_directories(TestArrayCPPTemplate PUBLIC ..)
3-
add_test(TestArrayCPPTemplate TestArrayCPPTemplate)
1+
# add_executable(TestArrayCPPTemplate array.cpp)
2+
# target_include_directories(TestArrayCPPTemplate PUBLIC ..)
3+
# add_test(TestArrayCPPTemplate TestArrayCPPTemplate)
44

5-
add_executable(TestListCPPTemplate list.cpp)
6-
target_include_directories(TestListCPPTemplate PUBLIC ..)
7-
add_test(TestListCPPTemplate TestListCPPTemplate)
5+
# add_executable(TestListCPPTemplate list.cpp)
6+
# target_include_directories(TestListCPPTemplate PUBLIC ..)
7+
# add_test(TestListCPPTemplate TestListCPPTemplate)
88

9-
add_executable(TestQueueCPPTemplate queue.cpp)
10-
target_include_directories(TestQueueCPPTemplate PUBLIC ..)
11-
add_test(TestQueueCPPTemplate TestQueueCPPTemplate)
12-
set_tests_properties(TestQueueCPPTemplate PROPERTIES TIMEOUT 10)
9+
# add_executable(TestQueueCPPTemplate queue.cpp)
10+
# target_include_directories(TestQueueCPPTemplate PUBLIC ..)
11+
# add_test(TestQueueCPPTemplate TestQueueCPPTemplate)
12+
# set_tests_properties(TestQueueCPPTemplate PROPERTIES TIMEOUT 10)
1313

14-
add_executable(TestStackCPPTemplate stack.cpp)
15-
target_include_directories(TestStackCPPTemplate PUBLIC ..)
16-
add_test(TestStackCPPTemplate TestStackCPPTemplate)
14+
# add_executable(TestStackCPPTemplate stack.cpp)
15+
# target_include_directories(TestStackCPPTemplate PUBLIC ..)
16+
# add_test(TestStackCPPTemplate TestStackCPPTemplate)
1717

18-
add_executable(TestVectorCPPTemplate vector.cpp)
19-
target_include_directories(TestVectorCPPTemplate PUBLIC ..)
20-
add_test(TestVectorCPPTemplate TestVectorCPPTemplate)
21-
set_tests_properties(TestVectorCPPTemplate PROPERTIES TIMEOUT 10)
18+
# add_executable(TestVectorCPPTemplate vector.cpp)
19+
# target_include_directories(TestVectorCPPTemplate PUBLIC ..)
20+
# add_test(TestVectorCPPTemplate TestVectorCPPTemplate)
21+
# set_tests_properties(TestVectorCPPTemplate PROPERTIES TIMEOUT 10)

0 commit comments

Comments
 (0)