Skip to content

Commit 7211d7f

Browse files
committed
fix baddata test for perl wrapper
fix a few issues withlibxdifile make windows icon for xdi fles
1 parent 918a988 commit 7211d7f

File tree

13 files changed

+209
-12
lines changed

13 files changed

+209
-12
lines changed

c/xdifile.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ _EXPORT(char*) XDI_errorstring(int errcode) {
4343
} else if (errcode == ERR_NCOLS_CHANGE) {
4444
return "number of columns changes in file";
4545
} else if (errcode == ERR_NONNUMERIC) {
46-
return "non-numeric value in data table";
46+
return "non-numeric value in data table or for d-spacing";
4747
} else if (errcode == ERR_IGNOREDMETA) {
4848
return "contains unrecognized header lines";
4949
}
@@ -170,8 +170,9 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
170170
nheader= index of first line that does not start with '#'
171171
*/
172172
for (i = 1; i < ilen ; i++) {
173-
if ((strlen(textlines[i]) > 3) &&
174-
(strncmp(textlines[i], TOK_COMM, 1) != 0)) {
173+
regex_status = slre_match(1, DATALINE, textlines[i], strlen(textlines[i]));
174+
if ((strlen(textlines[i]) > 3) && (regex_status == NULL)) {
175+
/* (strncmp(textlines[i], TOK_COMM, 1) != 0)) { */
175176
break;
176177
}
177178
}
@@ -282,8 +283,8 @@ XDI_readfile(char *filename, XDIFile *xdifile) {
282283
}
283284
}
284285
}
285-
if (has_minusline == 0) { iret = ERR_NOMINUSLINE; }
286286
if (ignored_headerline > 0) { iret = ERR_IGNOREDMETA; }
287+
if (has_minusline == 0) { iret = ERR_NOMINUSLINE; }
287288

288289
/* check edge, element, return error code if invalid */
289290
valid = 0;

c/xdifile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ _EXPORT(int) XDI_get_array_name(XDIFile *xdifile, char *name, double *out);
6262
#define FAMILYNAME "^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_][ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789]+$"
6363
#define KEYNAME "^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789]+$"
6464

65+
#define DATALINE "^[ \t]*[0123456789.]"
6566

6667
/* Notes:
6768
1. The absorption edge must be one of those listed in ValidEdges below
File renamed without changes.
File renamed without changes.

filemagic/xdi.ico

11.9 KB
Binary file not shown.

filemagic/xdi.reg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Windows Registry Editor Version 5.00
2+
3+
[HKEY_CLASSES_ROOT\.xdi]
4+
5+
[HKEY_CLASSES_ROOT\.tj\DefaultIcon]
6+
@="C:\\path\\to\\xdi.ico"

perl/t/baddata/07_columns.t

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/perl -I../../blib/lib -I../../blib/arch
2+
3+
## test the non numeric values in columns bad data examples
4+
5+
use Test::More tests => 9;
6+
7+
use strict;
8+
use warnings;
9+
use File::Basename;
10+
use File::Spec;
11+
12+
BEGIN { use_ok('Xray::XDI') };
13+
14+
my $here = dirname($0);
15+
my $file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_07.xdi');
16+
my $xdi = Xray::XDI->new(file=>$file);
17+
18+
ok(($xdi->ok), 'bad_07.xdi flagged as ok');
19+
ok((not $xdi->error), 'no column labels');
20+
21+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_08.xdi');
22+
$xdi = Xray::XDI->new(file=>$file);
23+
24+
ok(($xdi->ok), 'bad_08.xdi flagged as ok');
25+
ok((not $xdi->error), 'to few column labels');
26+
27+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_09.xdi');
28+
$xdi = Xray::XDI->new(file=>$file);
29+
30+
ok(($xdi->ok), 'bad_09.xdi flagged as ok');
31+
ok((not $xdi->error), 'to many column labels');
32+
33+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_10.xdi');
34+
$xdi = Xray::XDI->new(file=>$file);
35+
36+
ok(($xdi->ok), 'bad_10.xdi flagged as ok');
37+
ok((not $xdi->error), 'column indeces not continuous');
38+
39+
40+
open(my $COV, '>>', 'coverage.txt');
41+
print $COV 7, $/;
42+
print $COV 8, $/;
43+
print $COV 9, $/;
44+
print $COV 10, $/;
45+
close $COV;

perl/t/baddata/11_bad_comment_char.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ my $here = dirname($0);
1717
my $file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_11.xdi');
1818
my $xdi = Xray::XDI->new(file=>$file);
1919

20-
print $xdi->error, $/;
21-
22-
ok((not $xdi->ok), 'bad_11.xdi flagged as failing to import');
23-
ok(($xdi->error =~ m{contains unrecognized header lines}), 'correctly identified bad comment character');
20+
ok(($xdi->warning and $xdi->ok), 'bad_11.xdi flagged as failing to import');
21+
ok(($xdi->error =~ m{contains unrecognized header lines}), 'correctly identified bad comment character in metadata line');
2422

2523

2624
open(my $COV, '>>', 'coverage.txt');

perl/t/baddata/12_no_dspacing.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ my $here = dirname($0);
1717
my $file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_12.xdi');
1818
my $xdi = Xray::XDI->new(file=>$file);
1919

20-
ok((not $xdi->ok), 'bad_12.xdi flagged as failing to import');
20+
ok(($xdi->warning and $xdi->ok), 'bad_12.xdi flagged as ok');
2121
ok(($xdi->error =~ m{no mono.d_spacing}), 'correctly identified missing d-spacing');
2222

2323

perl/t/baddata/18_headers.t

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/perl -I../../blib/lib -I../../blib/arch
2+
3+
## test the bad headers examples
4+
5+
use Test::More tests => 15;
6+
7+
use strict;
8+
use warnings;
9+
use File::Basename;
10+
use File::Spec;
11+
12+
BEGIN { use_ok('Xray::XDI') };
13+
14+
my $here = dirname($0);
15+
my $file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_18.xdi');
16+
my $xdi = Xray::XDI->new(file=>$file);
17+
18+
ok((not $xdi->ok), 'bad_18.xdi flagged as failing to import');
19+
ok(($xdi->error =~ m{metadata not formatted as}), 'correctly identified Family.Key -- no value');
20+
21+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_19.xdi');
22+
$xdi = Xray::XDI->new(file=>$file);
23+
24+
ok((not $xdi->ok), 'bad_19.xdi flagged as failing to import');
25+
ok(($xdi->error =~ m{metadata not formatted as}), 'correctly identified Family.Key -- no colon');
26+
27+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_20.xdi');
28+
$xdi = Xray::XDI->new(file=>$file);
29+
30+
ok((not $xdi->ok), 'bad_20.xdi flagged as failing to import');
31+
ok(($xdi->error =~ m{metadata not formatted as}), 'correctly identified Family.Key -- two colons');
32+
33+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_21.xdi');
34+
$xdi = Xray::XDI->new(file=>$file);
35+
36+
ok((not $xdi->ok), 'bad_21.xdi flagged as failing to import');
37+
ok(($xdi->error =~ m{metadata not formatted as}), 'correctly identified Family.Key -- no dot');
38+
39+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_22.xdi');
40+
$xdi = Xray::XDI->new(file=>$file);
41+
42+
ok((not $xdi->ok), 'bad_22.xdi flagged as failing to import');
43+
ok(($xdi->error =~ m{invalid keyword name}), 'correctly identified Family.Key -- two dots');
44+
45+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_23.xdi');
46+
$xdi = Xray::XDI->new(file=>$file);
47+
48+
ok(($xdi->ok), 'bad_23.xdi flagged as ok');
49+
ok((not $xdi->error), 'correctly identified Family.Key -- key starts with number');
50+
51+
$file = File::Spec->catfile($here, '..', '..', '..', 'baddata', 'bad_24.xdi');
52+
$xdi = Xray::XDI->new(file=>$file);
53+
54+
ok((not $xdi->ok), 'bad_24.xdi flagged as failing to import');
55+
ok(($xdi->error =~ m{invalid family name}), 'correctly identified Family.Key -- family starts with number');
56+
57+
open(my $COV, '>>', 'coverage.txt');
58+
print $COV 18, $/;
59+
print $COV 19, $/;
60+
print $COV 20, $/;
61+
print $COV 21, $/;
62+
print $COV 22, $/;
63+
print $COV 23, $/;
64+
print $COV 24, $/;
65+
close $COV;

0 commit comments

Comments
 (0)