Révision 301
approxBasisSollya/test/test-read-lines/test-read-lines-suite-1.c (revision 301) | ||
---|---|---|
1 |
/** @file test-read-lines-suite-1.c |
|
2 |
* Test the basic features of the read-lines library. |
|
3 |
* |
|
4 |
* @author ST |
|
5 |
* @date 2018-03-14 |
|
6 |
* |
|
7 |
*/ |
|
8 |
/******************************************************************************/ |
|
9 |
|
|
10 |
/* includes of system headers */ |
|
11 |
#include <stdlib.h> |
|
12 |
#include <stdio.h> |
|
13 |
|
|
14 |
/* includes of project (CUnit) headers */ |
|
15 |
#include <CUnit.h> |
|
16 |
#include <Basic.h> |
|
17 |
|
|
18 |
/* includes of local (functions to test) headers */ |
|
19 |
#include<read-lines-from-file.h> |
|
20 |
|
|
21 |
/* Exportable prototypes (cleanup, init, setup, teardown and test functions),*/ |
|
22 |
|
|
23 |
/* The suite cleanup, init, setup, teardown functions (name used in |
|
24 |
the driver program to build the suite). */ |
|
25 |
int |
|
26 |
test_read_lines_suite_1_cleanup(void); |
|
27 |
|
|
28 |
int |
|
29 |
test_read_lines_suite_1_init(void); |
|
30 |
|
|
31 |
void |
|
32 |
test_read_lines_suite_1_setup(void); |
|
33 |
|
|
34 |
void |
|
35 |
test_read_lines_suite_1_teardown(void); |
|
36 |
|
|
37 |
/* Test functions of the suite (one function per test in the suite, |
|
38 |
names are used in the driver program to build the suite).*/ |
|
39 |
void |
|
40 |
test_read_lines_suite_1_test_1(); |
|
41 |
|
|
42 |
void |
|
43 |
test_read_lines_suite_1_test_2(); |
|
44 |
|
|
45 |
void |
|
46 |
test_read_lines_suite_1_test_3(); |
|
47 |
|
|
48 |
void |
|
49 |
test_read_lines_suite_1_test_4(); |
|
50 |
|
|
51 |
void |
|
52 |
test_read_lines_suite_1_test_5(); |
|
53 |
|
|
54 |
/* The topmost part of the file is included by main program to initialize |
|
55 |
data structures. The lower part is kept her to avoid double definitions.*/ |
|
56 |
#ifndef TEST_DRIVER |
|
57 |
/* Internal prototypes */ |
|
58 |
|
|
59 |
/* Types, constants and macros definitions */ |
|
60 |
|
|
61 |
/* Global variables */ |
|
62 |
|
|
63 |
/* Function definitions */ |
|
64 |
|
|
65 |
/** Suite management functions. **/ |
|
66 |
int |
|
67 |
test_read_lines_suite_1_cleanup() |
|
68 |
{ |
|
69 |
return(0); |
|
70 |
} /* End test_read_lines_suite_1_cleanp() */ |
|
71 |
|
|
72 |
int |
|
73 |
test_read_lines_suite_1_init(void) |
|
74 |
{ |
|
75 |
return(0); |
|
76 |
} /* End test_read_lines_suite_1_init. */ |
|
77 |
|
|
78 |
void |
|
79 |
test_read_lines_suite_1_setup(void) |
|
80 |
{ |
|
81 |
} /* End test_read_lines_suite_1_setup. */ |
|
82 |
|
|
83 |
void |
|
84 |
test_read_lines_suite_1_teardown(void) |
|
85 |
{ |
|
86 |
} /* End test_read_lines_suite_1_teardown. */ |
|
87 |
|
|
88 |
void |
|
89 |
test_read_lines_suite_1_test_1() |
|
90 |
{ |
|
91 |
rlff_readLines_t* linesRead = NULL; |
|
92 |
|
|
93 |
linesRead = rlff_read_lines_from_file_name("non-existant-file.txt"); |
|
94 |
CU_ASSERT_PTR_NULL_FATAL(linesRead); |
|
95 |
} /* End test_read_lines_suite_1_test_1. */ |
|
96 |
|
|
97 |
void |
|
98 |
test_read_lines_suite_1_test_2() |
|
99 |
{ |
|
100 |
rlff_readLines_t* linesRead = NULL; |
|
101 |
|
|
102 |
linesRead = rlff_read_lines_from_file_name("basis-01.txt"); |
|
103 |
CU_ASSERT_PTR_NOT_NULL_FATAL(linesRead); |
|
104 |
CU_ASSERT_EQUAL(linesRead->linesNum, 8); |
|
105 |
CU_ASSERT_EQUAL(linesRead->linesLength, 9); |
|
106 |
rlff_free_lines(linesRead); |
|
107 |
} /* End test_read_lines_suite_1_test_2. */ |
|
108 |
|
|
109 |
void |
|
110 |
test_read_lines_suite_1_test_3() |
|
111 |
{ |
|
112 |
rlff_readLines_t* linesRead = NULL; |
|
113 |
|
|
114 |
linesRead = rlff_read_lines_from_file_name("basis-02.txt"); |
|
115 |
CU_ASSERT_PTR_NOT_NULL_FATAL(linesRead); |
|
116 |
CU_ASSERT_EQUAL(linesRead->linesNum, 8); |
|
117 |
CU_ASSERT_EQUAL(linesRead->linesLength, 11); |
|
118 |
rlff_free_lines(linesRead); |
|
119 |
} /* End test_read_lines_suite_1_test_3. */ |
|
120 |
|
|
121 |
void |
|
122 |
test_read_lines_suite_1_test_4() |
|
123 |
{ |
|
124 |
rlff_readLines_t* linesRead = NULL; |
|
125 |
|
|
126 |
/* basis-03.txt is a zero-length file. */ |
|
127 |
linesRead = rlff_read_lines_from_file_name("basis-03.txt"); |
|
128 |
CU_ASSERT_PTR_NOT_NULL_FATAL(linesRead); |
|
129 |
CU_ASSERT_EQUAL(linesRead->linesNum, 0); |
|
130 |
CU_ASSERT_EQUAL(linesRead->linesLength, 0); |
|
131 |
rlff_free_lines(linesRead); |
|
132 |
} /* End test_read_lines_suite_1_test_4. */ |
|
133 |
|
|
134 |
void |
|
135 |
test_read_lines_suite_1_test_5() |
|
136 |
{ |
|
137 |
rlff_readLines_t* linesRead = NULL; |
|
138 |
|
|
139 |
/* basis-04.txt is only made of a comment line starting with spaces. */ |
|
140 |
linesRead = rlff_read_lines_from_file_name("basis-04.txt"); |
|
141 |
CU_ASSERT_PTR_NOT_NULL_FATAL(linesRead); |
|
142 |
CU_ASSERT_EQUAL(linesRead->linesNum, 0); |
|
143 |
CU_ASSERT_EQUAL(linesRead->linesLength, 0); |
|
144 |
rlff_free_lines(linesRead); |
|
145 |
} /* End test_read_lines_suite_1_test_5. */ |
|
146 |
|
|
147 |
#endif |
|
0 | 148 |
approxBasisSollya/test/test-read-lines/test-read-lines-basic-driver.c (revision 301) | ||
---|---|---|
1 |
/** @file test-read-lines-basic-driver.c |
|
2 |
* Name and purpose |
|
3 |
* Driver program to run test suites |
|
4 |
* using the CUnit Basic interface. |
|
5 |
* |
|
6 |
* @author ST |
|
7 |
* @date 2018-03-14 |
|
8 |
*/ |
|
9 |
/******************************************************************************/ |
|
10 |
|
|
11 |
/* Includes of system headers */ |
|
12 |
#include <stdlib.h> |
|
13 |
#include <stdio.h> |
|
14 |
|
|
15 |
/* Includes of project headers */ |
|
16 |
#include <Basic.h> |
|
17 |
|
|
18 |
|
|
19 |
/* Includes of local (suite) headers */ |
|
20 |
|
|
21 |
/* Includes of test suite prototypes */ |
|
22 |
/* This definition is to limit inclusion to local headers (and |
|
23 |
not include functions definition). */ |
|
24 |
#define TEST_DRIVER 1 |
|
25 |
#include "test-read-lines-suite-1.c" |
|
26 |
|
|
27 |
/* Internal prototypes */ |
|
28 |
|
|
29 |
|
|
30 |
/* Register the test suites.*/ |
|
31 |
CU_ErrorCode |
|
32 |
register_suites_and_display_error(CU_SuiteInfo* suites); |
|
33 |
|
|
34 |
/* Types, constants and macros definitions */ |
|
35 |
|
|
36 |
/* Global variables */ |
|
37 |
|
|
38 |
/* Tests. */ |
|
39 |
/* Individual suite definitions : each suite is defined by: |
|
40 |
- a CU_TestInfo array (e.g. suite1); |
|
41 |
- a list of individual tests (each element has two fields): |
|
42 |
- a name string (e.g. "suite1test1"), |
|
43 |
- a function name (e.g. suite1_test1); |
|
44 |
- the list ends with a CU_TEST_INFO_NULL element. */ |
|
45 |
CU_TestInfo test_read_lines_suite_1[] = |
|
46 |
{ |
|
47 |
{"test_read_lines_suite_1_test_1", |
|
48 |
test_read_lines_suite_1_test_1}, |
|
49 |
{"test_read_lines_suite_1_test_2", |
|
50 |
test_read_lines_suite_1_test_2}, |
|
51 |
{"test_read_lines_suite_1_test_3", |
|
52 |
test_read_lines_suite_1_test_3}, |
|
53 |
{"test_read_lines_suite_1_test_4", |
|
54 |
test_read_lines_suite_1_test_4}, |
|
55 |
{"test_read_lines_suite_1_test_5", |
|
56 |
test_read_lines_suite_1_test_5}, |
|
57 |
CU_TEST_INFO_NULL, |
|
58 |
}; /* End test_read_lines_suite_1. */ |
|
59 |
|
|
60 |
/* Suites definition list defined by: |
|
61 |
- a CU_SuiteInfo array (e.g. suites) ; |
|
62 |
- a list of suites (each individual element has four fields): |
|
63 |
- a name string (e.g. "suite1"), |
|
64 |
- a suite initializing function (e.g. suite1_init), |
|
65 |
- a suite cleanup function (e.g. suite1_cleanup), |
|
66 |
- a suite setup function (e.g. suite_setup), |
|
67 |
- a suite teardown function (e.g. suite_teardown), |
|
68 |
- the name of the suite tests array (see above); |
|
69 |
- the list ends with a CU_SUITE_INFO_NULL element. */ |
|
70 |
CU_SuiteInfo test_read_lines_suites[] = |
|
71 |
{ |
|
72 |
{"test_read_lines_suite_1", |
|
73 |
test_read_lines_suite_1_init, |
|
74 |
test_read_lines_suite_1_cleanup, |
|
75 |
test_read_lines_suite_1_setup, |
|
76 |
test_read_lines_suite_1_teardown, |
|
77 |
test_read_lines_suite_1}, |
|
78 |
CU_SUITE_INFO_NULL, |
|
79 |
}; /* End test_read_lines_suites. */ |
|
80 |
|
|
81 |
/* Functions */ |
|
82 |
|
|
83 |
int main(int argc, char** argv) |
|
84 |
{ |
|
85 |
CU_ErrorCode last_error; |
|
86 |
unsigned int tests_failed_count = 0; |
|
87 |
|
|
88 |
/**************************************/ |
|
89 |
/* Initialize the CUnit test registry */ |
|
90 |
/**************************************/ |
|
91 |
if (CUE_SUCCESS != CU_initialize_registry()) |
|
92 |
return CU_get_error(); |
|
93 |
|
|
94 |
/*****************************************/ |
|
95 |
/* Add register the suites. */ |
|
96 |
/*****************************************/ |
|
97 |
/* The argument is the name of the name of the suites definition list |
|
98 |
(e.g. suites)*/ |
|
99 |
last_error = register_suites_and_display_error(test_read_lines_suites); |
|
100 |
if (last_error != CUE_SUCCESS) |
|
101 |
{ |
|
102 |
CU_cleanup_registry(); |
|
103 |
return(last_error); |
|
104 |
} |
|
105 |
CU_basic_set_mode(CU_BRM_VERBOSE); |
|
106 |
last_error = CU_basic_run_tests(); |
|
107 |
if (last_error != CUE_SUCCESS) |
|
108 |
{ |
|
109 |
fprintf(stderr, "Tests execution failed for some internal reason: %s.\n", |
|
110 |
CU_get_error_msg()); |
|
111 |
CU_cleanup_registry(); |
|
112 |
return(last_error); |
|
113 |
} |
|
114 |
//CU_console_run_tests(); |
|
115 |
tests_failed_count = CU_get_number_of_tests_failed(); |
|
116 |
CU_cleanup_registry(); |
|
117 |
return tests_failed_count; |
|
118 |
} /* End main */ |
|
119 |
|
|
120 |
/* Helper functions. */ |
|
121 |
|
|
122 |
CU_ErrorCode |
|
123 |
register_suites_and_display_error(CU_SuiteInfo* suites) |
|
124 |
{ |
|
125 |
CU_ErrorCode register_suites_error; |
|
126 |
register_suites_error = CU_register_suites(suites); |
|
127 |
if (register_suites_error != CUE_SUCCESS) |
|
128 |
{ |
|
129 |
fprintf(stderr, "%s\n", CU_get_error_msg()); |
|
130 |
return(register_suites_error); |
|
131 |
} /* End if pTest == NULL. */ |
|
132 |
return CUE_SUCCESS; |
|
133 |
} /* End register_suites_and_display_error */ |
|
0 | 134 |
approxBasisSollya/test/test-read-lines/Makefile (revision 301) | ||
---|---|---|
1 |
CC = gcc |
|
2 |
CFLAGS = -Wall -g -I CUnit-include -I ../.. |
|
3 |
LDLIB = #-Wl,--verbose |
|
4 |
|
|
5 |
OBJS = test-read-lines-suite-1.o \ |
|
6 |
../../read-lines-from-file.o |
|
7 |
INCS = |
|
8 |
SOURCES = $(INCS) |
|
9 |
|
|
10 |
TEST_DRIVER = test-read-lines-basic-driver |
|
11 |
|
|
12 |
ALL_TARGETS = $(TEST_DRIVER) |
|
13 |
|
|
14 |
SCRATCH_PRG := $(patsubst %.c,%,$(wildcard *.c)) |
|
15 |
SCRATCH_ALL := $(SCRATCH_PRG) |
|
16 |
|
|
17 |
LAST_ARCH_FILE = lastArch.txt |
|
18 |
|
|
19 |
ARCH := $(shell uname -m) |
|
20 |
|
|
21 |
DUMMY := $(shell touch $(LAST_ARCH_FILE)) |
|
22 |
|
|
23 |
LAST_ARCH := $(shell cat $(LAST_ARCH_FILE)) |
|
24 |
|
|
25 |
ifneq ($(LAST_ARCH), $(ARCH)) |
|
26 |
DUMMY := $(shell echo $(ARCH) > $(LAST_ARCH_FILE)) |
|
27 |
DUMMY := $(shell $(MAKE) clean) |
|
28 |
endif |
|
29 |
|
|
30 |
ifeq (x86_64, $(ARCH)) |
|
31 |
CFLAGS := -m64 $(CFLAGS) |
|
32 |
LDLIB := -L CUnit-lib-$(ARCH) -Wl,-Bstatic -lcunit -Wl,-Bdynamic |
|
33 |
endif |
|
34 |
|
|
35 |
ifeq (ppc64, $(ARCH)) |
|
36 |
CFLAGS := -m64 $(CFLAGS) |
|
37 |
# LDLIB := |
|
38 |
endif |
|
39 |
|
|
40 |
ifeq (i686, $(ARCH)) |
|
41 |
CFLAGS := $(CFLAGS) |
|
42 |
LDLIB := -L CUnit-lib-$(ARCH) -Wl,-Bstatic -lcunit -Wl,-Bdynamic |
|
43 |
endif |
|
44 |
|
|
45 |
# ------------------------------------------------------------------------- |
|
46 |
|
|
47 |
default: all |
|
48 |
# Remove all implicit (suffix) rules. No need to remove pattern rules. |
|
49 |
# Just redefine them. |
|
50 |
.SUFFIXES: |
|
51 |
# Keep the OBJS we want to link with user code. |
|
52 |
.PRECIOUS: $(OBJS) |
|
53 |
|
|
54 |
all: $(ALL_TARGETS) |
|
55 |
test: $(TEST_DRIVER) |
|
56 |
@$(TEST_DRIVER) |
|
57 |
|
|
58 |
% : %.o $(OBJS) |
|
59 |
$(CC) $(CFLAGS) -o $@ $< $(OBJS) $(LDLIB) |
|
60 |
|
|
61 |
%.o : %.c $(INCS) |
|
62 |
$(CC) $(CFLAGS) -c -o $@ $< |
|
63 |
|
|
64 |
# ------------------------------------------------------------------------- |
|
65 |
|
|
66 |
.PHONY: clean scratch |
|
67 |
|
|
68 |
clean: |
|
69 |
@rm -f $(ALL_TARGETS) $(TEST_DRIVER) |
|
70 |
@rm -f *.o a.out $(OBJS) |
|
71 |
@rm -f *~ *% #*# |
|
72 |
|
|
73 |
|
approxBasisSollya/test/test-read-lines/basis-01.txt (revision 301) | ||
---|---|---|
1 |
# Regular file for tests (has spaces and tabs at end of lines). |
|
2 |
# Should yield 8 lines with a maximum length of 9 characters. |
|
3 |
# (one extra slot for the '\0' terminal character). |
|
4 |
aaaaaaaa |
|
5 |
# |
|
6 |
bcdefgh |
|
7 |
# |
|
8 |
kl # 123 |
|
9 |
# mn |
|
10 |
op |
|
11 |
q r |
|
12 |
s t |
|
13 |
uv |
|
14 |
|
|
15 |
w x y. |
|
16 |
|
|
0 | 17 |
approxBasisSollya/test/test-read-lines/basis-02.txt (revision 301) | ||
---|---|---|
1 |
# Regular file for tests (has comments, spaces and tabs at end of lines). |
|
2 |
# Should yield 8 lines with a maximum length of 8 characters |
|
3 |
# (one slot more for the final '\0' terminal character). |
|
4 |
aaaaaaaa |
|
5 |
# |
|
6 |
bcdefghi |
|
7 |
# |
|
8 |
kl # 123 |
|
9 |
#mn |
|
10 |
op |
|
11 |
qr |
|
12 |
st |
|
13 |
uv |
|
14 |
|
|
15 |
w x y z.. |
|
16 |
|
|
0 | 17 |
approxBasisSollya/test/test-read-lines/basis-04.txt (revision 301) | ||
---|---|---|
1 |
# This file has only a comment line. |
|
0 | 2 |
Formats disponibles : Unified diff