Skip to content

Commit 0f9e13f

Browse files
committed
Make tests C++
They use macros extensively. Future commits need to extend one of them quite a lot, but compilation would fail, because the macros in order to be reusable is going to compare some constants resulting sometimes into expressions like uint >= 0. The compiler doesn't allow such things, while in C++ it would be ok (worst case it would need a constexpr attribute). Part of tarantool/tarantool#9965.
1 parent af9cf22 commit 0f9e13f

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project(msgpuck C)
1+
project(msgpuck C CXX)
22
cmake_minimum_required(VERSION 2.8.5)
33

44
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")

Diff for: test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif()
1313

1414
set(alltests)
1515
foreach (test msgpuck)
16-
add_executable(${test}.test ${test}.c test.c)
16+
add_executable(${test}.test ${test}.cc test.c)
1717
target_link_libraries(${test}.test msgpuck)
1818

1919
list(APPEND alltests ${test}.test_run)

Diff for: test/msgpuck.c renamed to test/msgpuck.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3030
* SUCH DAMAGE.
3131
*/
32-
3332
#include <assert.h>
3433
#include <string.h>
3534
#include <stdlib.h>
@@ -1155,9 +1154,9 @@ test_mp_print()
11551154
int mp_buff_sz = (MP_PRINT_MAX_DEPTH + 1) * mp_sizeof_array(1) +
11561155
mp_sizeof_uint(1);
11571156
int exp_str_sz = 2 * (MP_PRINT_MAX_DEPTH + 1) + 3 + 1;
1158-
char *mp_buff = malloc(mp_buff_sz);
1159-
char *exp_str = malloc(exp_str_sz);
1160-
char *decoded = malloc(exp_str_sz);
1157+
char *mp_buff = (char *)malloc(mp_buff_sz);
1158+
char *exp_str = (char *)malloc(exp_str_sz);
1159+
char *decoded = (char *)malloc(exp_str_sz);
11611160
char *buff_wptr = mp_buff;
11621161
char *exp_str_wptr = exp_str;
11631162
for (int i = 0; i <= 2 * (MP_PRINT_MAX_DEPTH + 1); i++) {

Diff for: test/test.h

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535

3636
#include <stdio.h>
3737

38+
#if defined(__cplusplus)
39+
extern "C" {
40+
#endif /* defined(__cplusplus) */
41+
3842
/**
3943
@brief example
4044
@@ -125,4 +129,8 @@ int check_plan(void);
125129
} \
126130
}
127131

132+
#if defined(__cplusplus)
133+
}
134+
#endif /* defined(__cplusplus) */
135+
128136
#endif /* TEST_H_INCLUDED */

0 commit comments

Comments
 (0)