[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: maint: update the mbsalign module
From: |
Jim Meyering |
Subject: |
Re: maint: update the mbsalign module |
Date: |
Wed, 17 Mar 2010 16:09:40 +0100 |
Pádraig Brady wrote:
> On 16/03/10 07:28, Jim Meyering wrote:
>> These look like fine improvements.
>> Have you considered dividing it into two or more change sets?
>> Mixing "fix" and "clean-up" changes in one change-set is
>> best avoided, if only to ease review and bisection.
>
> Sure. I'll split out the fix which is triggered when
> one has \t characters in combination with multi byte chars
> in an oversized field:
>
>> In addition, it would ease long-term maintenance if you would
>> at least outline how to exercise the bug(s?) you're fixing.
>> Then I'll try to make time to write a test for it.
>
> char* str = ambsalign("t\tést", 4, MBS_ALIGN_LEFT, 0);
> puts(str);
> free(str);
Thanks!
I prepared the following (not yet pushed).
Without your patch, it fails -- as expected.
However, this use of mbsalign still returns n=4,
even *with* your patch. So maybe I did something wrong...
FWIW, I tested it using gnulib-tool via
cd coreutils
/gnulib/gnulib-tool --local-dir=gl --create-testdir --with-tests \
--test mbsalign
or more directly:
cd gl/tests
gcc -g -I../../gnulib/tests -I../../lib test-mbsalign.c
../../lib/libcoreutils.a
./a.out
I'll pursue this later, in case you have a newer version
of your patch. Then I'll add a few more tests, too, of course.
>From 107ffee5164c58f942dfe13ec72fefa926b15bc3 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 17 Mar 2010 15:57:49 +0100
Subject: [PATCH] mbsalign: add unit tests
* gl/modules/mbsalign-tests: New file.
* gl/tests/test-mbsalign.c (main): New test program.
---
gl/modules/mbsalign-tests | 11 +++++++++++
gl/tests/test-mbsalign.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)
create mode 100644 gl/modules/mbsalign-tests
create mode 100644 gl/tests/test-mbsalign.c
diff --git a/gl/modules/mbsalign-tests b/gl/modules/mbsalign-tests
new file mode 100644
index 0000000..8e0d138
--- /dev/null
+++ b/gl/modules/mbsalign-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-mbsalign.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-mbsalign
+check_PROGRAMS += test-mbsalign
diff --git a/gl/tests/test-mbsalign.c b/gl/tests/test-mbsalign.c
new file mode 100644
index 0000000..bf8b572
--- /dev/null
+++ b/gl/tests/test-mbsalign.c
@@ -0,0 +1,35 @@
+/* Test that mbsalign works as advertised.
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Jim Meyering, based on an example from Pádraig Brady. */
+
+#include <config.h>
+
+#include "mbsalign.h"
+#include "macros.h"
+#include <stdlib.h>
+
+int
+main (void)
+{
+ char dest[4];
+ size_t width = sizeof dest;
+ size_t n = mbsalign ("t\tést", dest, sizeof dest, &width, MBS_ALIGN_LEFT, 0);
+
+ ASSERT (n == 7);
+
+ return 0;
+}
--
1.7.0.2.451.g960ec