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. # Run the unit tests.
test : all test_functional test_unit 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. # Run the functional tests.
test_functional : all test_functional : all
$(Q)$(MAKE) -C test/functional/src $(Q)$(MAKE) -C test/functional/src

View file

@ -34,6 +34,33 @@ function check_test_status {
fi 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 check_test_status
clear clear
check_test_const
clear
check_spellcheck check_spellcheck
clear clear
check_docs 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. * For more information see @ref chart_labels.
*/ */
void chart_series_set_labels_num_format(lxw_chart_series *series, 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 * @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. * 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. * @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. * **Axis types**: This function is applicable to to all axes types.
* See @ref ww_charts_axes. * 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. * @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. * Set an data labels number format.
*/ */
void 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) if (!num_format)
return; return;
@ -5531,7 +5531,7 @@ chart_series_set_trendline_intercept(lxw_chart_series *series,
* Set a line type for a series trendline. * Set a line type for a series trendline.
*/ */
void 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) if (!name)
return; return;
@ -5687,7 +5687,7 @@ chart_axis_set_num_font(lxw_chart_axis *axis, lxw_chart_font *font)
* Set an axis number format. * Set an axis number format.
*/ */
void 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) if (!num_format)
return; return;