Fix const char* for C++ and added tests.

Fixed const char* in several APIs and added test to ensure that
any others are caught in future.

Issue #102.
This commit is contained in:
John McNamara 2017-06-25 20:16:36 +01:00
parent ccb53c9750
commit b5c42463bc
4 changed files with 41 additions and 6 deletions

View File

@ -43,6 +43,12 @@ endif
# Run the unit tests.
test : all test_functional test_unit
# Test for C++ const correctness on APIs.
test_const : all
$(Q)$(MAKE) clean -C test/functional/src
$(Q)! $(MAKE) -C test/functional/src CFLAGS=-Wwrite-strings 2>&1 | grep -A 1 "note:"
# Run the functional tests.
test_functional : all
$(Q)$(MAKE) -C test/functional/src

View File

@ -34,6 +34,33 @@ function check_test_status {
fi
}
#############################################################
#
# Run test for C++ const correctness.
#
function check_test_const {
echo
echo -n "Is the const test passing? [y/N]: "
read RESPONSE
if [ "$RESPONSE" != "y" ]; then
echo -n " Run test now? [y/N]: "
read RESPONSE
if [ "$RESPONSE" != "y" ]; then
echo
echo -e "Please run: make test_const\n";
exit 1
else
echo " Running test...";
make test_const
check_test_const
fi
fi
}
#############################################################
#
@ -269,6 +296,8 @@ function check_git_status {
check_test_status
clear
check_test_const
clear
check_spellcheck
clear
check_docs

View File

@ -1768,7 +1768,7 @@ void chart_series_set_labels_percentage(lxw_chart_series *series);
* For more information see @ref chart_labels.
*/
void chart_series_set_labels_num_format(lxw_chart_series *series,
char *num_format);
const char *num_format);
/**
* @brief Set the font properties for chart data labels in a series
@ -1983,7 +1983,7 @@ void chart_series_set_trendline_intercept(lxw_chart_series *series,
*
* For more information see @ref chart_trendlines.
*/
void chart_series_set_trendline_name(lxw_chart_series *series, char *name);
void chart_series_set_trendline_name(lxw_chart_series *series, const char *name);
/**
* @brief Set the trendline line properties for a chart data series.
@ -2279,7 +2279,7 @@ void chart_axis_set_num_font(lxw_chart_axis *axis, lxw_chart_font *font);
* **Axis types**: This function is applicable to to all axes types.
* See @ref ww_charts_axes.
*/
void chart_axis_set_num_format(lxw_chart_axis *axis, char *num_format);
void chart_axis_set_num_format(lxw_chart_axis *axis, const char *num_format);
/**
* @brief Set the line properties for a chart axis.

View File

@ -5384,7 +5384,7 @@ chart_series_set_labels_percentage(lxw_chart_series *series)
* Set an data labels number format.
*/
void
chart_series_set_labels_num_format(lxw_chart_series *series, char *num_format)
chart_series_set_labels_num_format(lxw_chart_series *series, const char *num_format)
{
if (!num_format)
return;
@ -5531,7 +5531,7 @@ chart_series_set_trendline_intercept(lxw_chart_series *series,
* Set a line type for a series trendline.
*/
void
chart_series_set_trendline_name(lxw_chart_series *series, char *name)
chart_series_set_trendline_name(lxw_chart_series *series, const char *name)
{
if (!name)
return;
@ -5687,7 +5687,7 @@ chart_axis_set_num_font(lxw_chart_axis *axis, lxw_chart_font *font)
* Set an axis number format.
*/
void
chart_axis_set_num_format(lxw_chart_axis *axis, char *num_format)
chart_axis_set_num_format(lxw_chart_axis *axis, const char *num_format)
{
if (!num_format)
return;