source: tests/io/eofType.cfa @ a9e327a

Last change on this file since a9e327a was a9e327a, checked in by Peter A. Buhr <pabuhr@…>, 7 weeks ago

formatting

  • 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 : Wed Jan 22 08:45:51 2025
13// Update Count     : 8
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 "eofBool.1.txt", INDIR "eofBool.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 "eofChar.1.txt", INDIR "eofChar.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 "eofInt.1.txt", INDIR "eofInt.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 "eofDouble.1.txt", INDIR "eofDouble.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 "eofComplex.1.txt", INDIR "eofComplex.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.