-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow .cdl files to have a leading utf-8 BOM. Also add test.
- Loading branch information
dmh
committed
Mar 8, 2014
1 parent
deeca5f
commit baade3e
Showing
6 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/********************************************************************* | ||
* Copyright 1993, UCAR/Unidata | ||
* See netcdf/COPYRIGHT file for copying and redistribution conditions. | ||
*********************************************************************/ | ||
|
||
#include <config.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
/* BOM Sequences */ | ||
static char* U8 = "\xEF\xBB\xBF"; /* UTF-8 */ | ||
static char* BE32 = "\x00\x00\xFE\xFF"; /* UTF-32; big-endian */ | ||
static char* LE32 = "\xFF\xFE"; /* UTF-32; little-endian */ | ||
static char* BE16 = "\xFE\xFF"; /* UTF-16; big-endian */ | ||
static char* LE16 = "\xFF\xFE"; /* UTF-16; little-endian */ | ||
|
||
int | ||
main(int argc, char** argv) | ||
{ | ||
char* bom = U8; | ||
int bomlen = 3; | ||
if(argc > 1 && strlen(argv[1]) > 0) { | ||
char* which = argv[1]; | ||
switch (which[0]) { | ||
case '1': bom = BE16; bomlen = 2; break; | ||
case '3': bom = BE32; bomlen = 2; break; | ||
default: break; | ||
} | ||
} | ||
fwrite(bom,1,bomlen,stdout); | ||
exit(0); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
# This shell script tests BOM support in ncgen | ||
|
||
set -e | ||
|
||
if test "x$srcdir" = "x"; then | ||
srcdir=`dirname $0`; | ||
fi | ||
# add hack for sunos | ||
export srcdir; | ||
|
||
echo "" | ||
|
||
rm -f tst_bom.cdl tmp.cdl tst_bom8.* tst_bom16.* | ||
|
||
cat <<EOF >>tst_bom.cdl | ||
netcdf tst_bom { | ||
variables: | ||
float f; | ||
data: | ||
f = 1; | ||
} | ||
EOF | ||
|
||
echo "*** Generate a cdl file with leading UTF-8 BOM." | ||
./bom 8 >tst_bom8.cdl | ||
cat tst_bom.cdl >> tst_bom8.cdl | ||
|
||
echo "*** Verify .nc file" | ||
../ncgen/ncgen -k1 -o tst_bom8.nc tst_bom8.cdl | ||
../ncdump/ncdump -n tst_bom tst_bom8.nc > tmp.cdl | ||
diff -w tst_bom.cdl tmp.cdl | ||
|
||
# Do it again but with Big-Endian 16; should fail | ||
|
||
rm -f tmp.cdl tst_bom8.* tst_bom16.* | ||
|
||
echo "*** Generate a cdl file with leading UTF-16 BOM." | ||
./bom 16 >tst_bom16.cdl | ||
cat tst_bom.cdl >> tst_bom16.cdl | ||
|
||
echo "*** Verify UTF-16 file fails" | ||
if ../ncgen/ncgen -k1 -o tst_bom16.nc tst_bom16.cdl ; then | ||
echo 'BOM Big Endian 16 succeeded, but should not' | ||
exit 1 | ||
else | ||
echo '***XFAIL: BOM Big Endian 16' | ||
fi | ||
|
||
# Cleanup | ||
rm -f tst_bom.cdl tmp.cdl tst_bom8.* tst_bom16.* | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
baade3e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit breaks tests,
(How about setting up a travis-ci instance and hooking it up with Github? http://docs.travis-ci.com/user/getting-started/)
baade3e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baade3e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
Setting up a travis-ci file would have the additional benefit of being tightly integrated with Github by, e.g., showing green or red lights for pull requests. Also, since you already maintain a rather concise testing framework, adding a
.travis.yaml
file would be rather trivial. In fact I think I might start playing around with it now. :)