source: tests/io/eofType.cfa@ 8705a11

Last change on this file since 8705a11 was a750c71b, checked in by Peter A. Buhr <pabuhr@…>, 8 months ago

update input file names for eofType test

  • Property mode set to 100644
File size: 2.6 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2025 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// eofType.cfa -- Test for end-of-file with and without a terminating newline across multiple types.
8//
9// Author : Peter A. Buhr
10// Created On : Wed Jan 22 07:41:41 2025
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Jan 23 14:33:08 2025
13// Update Count : 9
14//
15
16#include <fstream.hfa> // sin/sout
17
18void openfile( ifstream & testfile, const char * filename ) { // helper
19 try {
20 open( testfile, filename );
21 } catch( open_failure * ex; ex->istream == &testfile ) { // input file errors
22 exit | "Unable to open input file \"" | filename | "\"";
23 } // try
24}
25
26// test.py provides macro IN_DIR, which is the absolute path to the current .in directory
27#define xstr(s) str(s)
28#define str(s) #s
29// Add quotes around directory name.
30#define INDIR xstr(IN_DIR)
31
32int main() {
33 ifstream testfile;
34 {
35 char * filenames[] = { INDIR "eofType.bool.1.txt", INDIR "eofType.bool.2.txt" };
36 bool value;
37
38 for ( i; 2 ) {
39 openfile( testfile, filenames[i] );
40 try {
41 for () {
42 testfile | value;
43 sout | value;
44 } // for
45 } catch( end_of_file * ) {
46 sout | "eof";
47 } // try
48 close( testfile );
49 }
50 }
51 {
52 char * filenames[] = { INDIR "eofType.char.1.txt", INDIR "eofType.char.2.txt" };
53 char value;
54
55 for ( i; 2 ) {
56 openfile( testfile, filenames[i] );
57 try {
58 for () {
59 testfile | value;
60 sout | value;
61 } // for
62 } catch( end_of_file * ) {
63 sout | "eof";
64 } // try
65 close( testfile );
66 }
67 }
68 {
69 char * filenames[] = { INDIR "eofType.int.1.txt", INDIR "eofType.int.2.txt" };
70 int value;
71
72 for ( i; 2 ) {
73 openfile( testfile, filenames[i] );
74 try {
75 for () {
76 testfile | value;
77 sout | value;
78 } // for
79 } catch( end_of_file * ) {
80 sout | "eof";
81 } // try
82 close( testfile );
83 }
84 }
85 {
86 char * filenames[] = { INDIR "eofType.double.1.txt", INDIR "eofType.double.2.txt" };
87 double value;
88
89 for ( i; 2 ) {
90 openfile( testfile, filenames[i] );
91 try {
92 for () {
93 testfile | value;
94 sout | value;
95 } // for
96 } catch( end_of_file * ) {
97 sout | "eof";
98 } // try
99 close( testfile );
100 }
101 }
102 {
103 char * filenames[] = { INDIR "eofType.complex.1.txt", INDIR "eofType.complex.2.txt" };
104 _Complex value;
105
106 for ( i; 2 ) {
107 openfile( testfile, filenames[i] );
108 try {
109 for () {
110 testfile | value;
111 sout | value;
112 } // for
113 } catch( end_of_file * ) {
114 sout | "eof";
115 } // try
116 close( testfile );
117 }
118 }
119} // main
Note: See TracBrowser for help on using the repository browser.