1;
2; Maxime Lenoir (contact also: Alain Coulais)
3; Distributed version 2010/06/14
4; Under GNU GPL V2 or later
5;
6; Purpose:
7;
8; -- Checking if we can go back in lines ...
9;
10; -- Check READF procedure with different end-of-line characters (CR, LF, CRLF)
11; @2010/06/14 : issue with lines ended with CR character
12;
13;
14; see also "TEST_BUG_3244840" in "TEST_FORMAT", using
15; unwritten temporary file and POINT_LUN
16;
17; --------------------------------------------
18;
19; due to changes by Alain, no more useful
20;
21; pro TESTREADF_ERR, type
22; ;
23; MESSAGE, /continue, '% TEST_READF: failed with '+type+' char'
24; SPAWN, 'rm -f testreadf.txt'
25; EXIT, status=1
26; ;
27; end
28;
29; --------------------------------------------------------
30; http://sourceforge.net/p/gnudatalanguage/bugs/573/
31; playing with lines skipping
32;
33pro TEST_BUG_573, verbose=verbose, errors=errors, test=test
34;
35MESSAGE, /continue, 'running TEST_BUG_573'
36;
37if N_ELEMENTS(errors) EQ 0 then errors=0
38;
39filename='test_bug_573.tmp'
40;
41OPENW, nlun, filename, /get_lun;, /delete
42PRINTF, nlun, '234.123 231.2 54.3'
43PRINTF, nlun, '5432.4 543.'
44PRINTF, nlun, '33.4 444.22 3321.'
45CLOSE, nlun
46FREE_LUN, nlun
47
48;
49OPENR, unit, filename, /get_lun
50foo=DBLARR(5)
51READF,unit, foo
52READF,unit, foo2, foo3, foo4
53CLOSE, unit
54CLOSE, unit
55;
56; expected values
57exp2=33.4000
58exp3=444.220
59exp4=3321.00
60;
61if ((foo2 NE exp2) OR (foo3 NE exp3) OR (foo4 NE exp4)) then begin
62   errors++
63   MESSAGE, /continue, 'Failure in TEST_BUG_573'
64   if KEYWORD_SET(verbose) then begin
65      print, 'Expected: ', foo2, foo3, foo4
66      print, 'result  : ', exp2, exp3, exp4
67   endif
68endif else begin
69   MESSAGE, /continue, 'passing with success TEST_BUG_573'
70endelse
71;
72if KEYWORD_SET(test) then STOP
73;
74end
75;
76; --------------------------------------------------------
77;
78pro MINIREREADF, filename
79;
80if N_PARAMS() EQ 0 then begin
81    MESSAGE, /continue, 'You mus provide a Filename !'
82    return
83endif
84;
85resu=FILE_INFO(filename)
86if (resu.exists NE 1) then begin
87    MESSAGE, /continue, 'File : '+filename+' not available'
88    return
89endif
90;
91line=''
92;
93OPENR, lun, /get_lun, filename
94WHILE ~EOF(lun) do begin
95    READF, lun, line
96    print, line
97endwhile
98;
99end
100;
101; --------------------------------------------
102;
103pro TESTREADF, verbose=verbose, type=type, no_erase=no_erase, errors=errors
104;
105if KEYWORD_SET(verbose) then begin
106    print, '====='
107    print, 'test'+type+':'
108endif
109case type of
110    'CR': begin
111        char='\r'
112        suffixe='CR.txt'
113    end
114    'LF': begin
115        char='\n'
116        suffixe='LF.txt'
117    end
118    'CRLF': begin
119        char='\r\n'
120        suffixe='CRLF.txt'
121    end
122    else: begin
123        MESSAGE, /continue, 'type={CR, LF, CRLF}'
124        EXIT, status=1
125    end
126endcase
127;
128DEFSYSV, '!gdl', exists=is_it_gdl
129if (is_it_gdl EQ 1) then soft='GDL' else soft='IDL'
130;
131filename='TestReadF_'+soft+'_'+suffixe
132;
133; generating the ASCII file
134;
135;SPAWN, 'echo -e "testl1'+char+'testl2" > '+filename
136SPAWN, 'printf "testl1'+char+'testl2" > '+filename
137;
138; reading back the generated ASCII file
139;
140OPENR, fd, filename, /get_lun
141str=''
142;
143; reading first line
144;
145READF, fd, str
146if (str NE 'testl1') then begin
147    MESSAGE, /continue, '% TEST_READF: failed with '+type+' char'
148    errors=errors+1
149endif
150if KEYWORD_SET(verbose) then print, str
151if EOF(fd) then begin
152    MESSAGE, /continue, '% TEST_READF: failed with '+type+' char'
153    errors=errors+1
154endif else begin
155    ;;
156    ;; reading second line
157    ;;
158    READF, fd, str
159    if (str NE 'testl2') then begin
160        MESSAGE, /continue, '% TEST_READF: failed with '+type+' char'
161        errors=errors+1
162    endif
163    if KEYWORD_SET(verbose) then print, str
164endelse
165;
166CLOSE, fd
167FREE_LUN, fd
168;
169if NOT(KEYWORD_SET(no_erase)) then SPAWN, 'rm -f '+filename
170;
171end
172;
173; --------------------------------------------
174;
175pro TEST_READF, verbose=verbose, no_erase=no_erase, help=help, $
176                no_exit=no_exit, test=test
177;
178if KEYWORD_SET(help) then begin
179    print, 'pro TEST_READF, verbose=verbose, no_erase=no_erase, help=help, $'
180    print, '                no_exit=no_exit, test=test'
181    return
182endif
183;
184if KEYWORD_SET(verbose) then begin
185    print, 'Should print (for each pro):'
186    print, 'testl1'
187    print, 'testl2'
188endif
189;
190errors=0
191;
192TESTREADF, verbose=verbose, no_erase=no_erase, errors=errors, type='LF'
193TESTREADF, verbose=verbose, no_erase=no_erase, errors=errors, type='CRLF'
194TESTREADF, verbose=verbose, no_erase=no_erase, errors=errors, type='CR'
195;
196TEST_BUG_573, verbose=verbose, errors=errors
197;
198if ~KEYWORD_SET(no_exit) then begin
199   if (errors GT 0) then EXIT, status=1
200endif
201;
202if KEYWORD_SET(test) then STOP
203;
204end
205