From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../testsuite/27_io/basic_filebuf/close/12790-1.cc | 79 ++++++++ .../testsuite/27_io/basic_filebuf/close/char/1.cc | 87 +++++++++ .../27_io/basic_filebuf/close/char/12790-1.cc | 80 ++++++++ .../27_io/basic_filebuf/close/char/12790-2.cc | 82 +++++++++ .../27_io/basic_filebuf/close/char/12790-3.cc | 81 ++++++++ .../27_io/basic_filebuf/close/char/12790-4.cc | 81 ++++++++ .../testsuite/27_io/basic_filebuf/close/char/2.cc | 80 ++++++++ .../testsuite/27_io/basic_filebuf/close/char/3.cc | 89 +++++++++ .../testsuite/27_io/basic_filebuf/close/char/4.cc | 73 ++++++++ .../27_io/basic_filebuf/close/char/4879.cc | 108 +++++++++++ .../testsuite/27_io/basic_filebuf/close/char/5.cc | 106 +++++++++++ .../27_io/basic_filebuf/close/char/9964.cc | 89 +++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-1.cc | 78 ++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-2.cc | 80 ++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-3.cc | 79 ++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-4.cc | 79 ++++++++ .../testsuite/27_io/basic_filebuf/cons/2020.cc | 52 ++++++ .../testsuite/27_io/basic_filebuf/cons/char/1.cc | 39 ++++ .../27_io/basic_filebuf/cons/wchar_t/1.cc | 39 ++++ .../27_io/basic_filebuf/cons/wchar_t/10132-1.cc | 52 ++++++ .../testsuite/27_io/basic_filebuf/imbue/12206.cc | 125 +++++++++++++ .../testsuite/27_io/basic_filebuf/imbue/char/1.cc | 44 +++++ .../27_io/basic_filebuf/imbue/char/13007.cc | 62 +++++++ .../27_io/basic_filebuf/imbue/char/13171-1.cc | 46 +++++ .../27_io/basic_filebuf/imbue/char/13171-2.cc | 83 +++++++++ .../27_io/basic_filebuf/imbue/char/13171-4.cc | 56 ++++++ .../27_io/basic_filebuf/imbue/char/13582-2.cc | 84 +++++++++ .../27_io/basic_filebuf/imbue/char/14975-1.cc | 68 +++++++ .../testsuite/27_io/basic_filebuf/imbue/char/2.cc | 55 ++++++ .../testsuite/27_io/basic_filebuf/imbue/char/3.cc | 55 ++++++ .../27_io/basic_filebuf/imbue/char/9322.cc | 55 ++++++ .../27_io/basic_filebuf/imbue/wchar_t/1.cc | 44 +++++ .../27_io/basic_filebuf/imbue/wchar_t/12868.cc | 61 ++++++ .../27_io/basic_filebuf/imbue/wchar_t/13007.cc | 62 +++++++ .../27_io/basic_filebuf/imbue/wchar_t/13171-3.cc | 59 ++++++ .../27_io/basic_filebuf/imbue/wchar_t/13582-2.cc | 86 +++++++++ .../27_io/basic_filebuf/imbue/wchar_t/13582-3.cc | 74 ++++++++ .../27_io/basic_filebuf/imbue/wchar_t/14975-2.cc | 95 ++++++++++ .../27_io/basic_filebuf/imbue/wchar_t/2.cc | 55 ++++++ .../27_io/basic_filebuf/imbue/wchar_t/3.cc | 55 ++++++ .../27_io/basic_filebuf/imbue/wchar_t/9322.cc | 55 ++++++ .../27_io/basic_filebuf/in_avail/char/1.cc | 100 ++++++++++ .../27_io/basic_filebuf/in_avail/char/9701-3.cc | 60 ++++++ .../27_io/basic_filebuf/is_open/char/1.cc | 73 ++++++++ .../testsuite/27_io/basic_filebuf/open/12790-1.cc | 61 ++++++ .../testsuite/27_io/basic_filebuf/open/char/1.cc | 74 ++++++++ .../testsuite/27_io/basic_filebuf/open/char/2.cc | 59 ++++++ .../testsuite/27_io/basic_filebuf/open/char/3.cc | 54 ++++++ .../testsuite/27_io/basic_filebuf/open/char/4.cc | 72 ++++++++ .../testsuite/27_io/basic_filebuf/open/char/5.cc | 30 +++ .../27_io/basic_filebuf/open/char/9507.cc | 72 ++++++++ .../27_io/basic_filebuf/overflow/char/1.cc | 70 +++++++ .../27_io/basic_filebuf/overflow/char/13858.cc | 69 +++++++ .../27_io/basic_filebuf/overflow/char/2-unbuf.cc | 55 ++++++ .../27_io/basic_filebuf/overflow/char/2.cc | 54 ++++++ .../27_io/basic_filebuf/overflow/char/3599.cc | 58 ++++++ .../27_io/basic_filebuf/overflow/char/9169.cc | 73 ++++++++ .../27_io/basic_filebuf/overflow/char/9182-2.cc | 80 ++++++++ .../27_io/basic_filebuf/overflow/char/9988.cc | 70 +++++++ .../basic_filebuf/overflow/wchar_t/11305-1.cc | 47 +++++ .../basic_filebuf/overflow/wchar_t/11305-2.cc | 49 +++++ .../basic_filebuf/overflow/wchar_t/11305-3.cc | 46 +++++ .../basic_filebuf/overflow/wchar_t/11305-4.cc | 48 +++++ .../27_io/basic_filebuf/overflow/wchar_t/13858.cc | 70 +++++++ .../27_io/basic_filebuf/pbackfail/char/9761.cc | 56 ++++++ .../basic_filebuf/requirements/base_classes.cc | 43 +++++ .../requirements/explicit_instantiation.cc | 49 +++++ .../27_io/basic_filebuf/requirements/typedefs.cc | 48 +++++ .../27_io/basic_filebuf/sbumpc/char/1-in.cc | 80 ++++++++ .../27_io/basic_filebuf/sbumpc/char/1-io.cc | 93 ++++++++++ .../27_io/basic_filebuf/sbumpc/char/1-out.cc | 62 +++++++ .../27_io/basic_filebuf/sbumpc/char/2-in.cc | 80 ++++++++ .../27_io/basic_filebuf/sbumpc/char/2-io.cc | 92 ++++++++++ .../27_io/basic_filebuf/sbumpc/char/2-out.cc | 63 +++++++ .../27_io/basic_filebuf/sbumpc/char/9825.cc | 56 ++++++ .../27_io/basic_filebuf/seekoff/10132-2.cc | 54 ++++++ .../27_io/basic_filebuf/seekoff/12790-1.cc | 83 +++++++++ .../27_io/basic_filebuf/seekoff/12790-2.cc | 86 +++++++++ .../27_io/basic_filebuf/seekoff/12790-3.cc | 81 ++++++++ .../27_io/basic_filebuf/seekoff/12790-4.cc | 72 ++++++++ .../27_io/basic_filebuf/seekoff/45628-2.cc | 103 +++++++++++ .../27_io/basic_filebuf/seekoff/char/1-in.cc | 124 +++++++++++++ .../27_io/basic_filebuf/seekoff/char/1-io.cc | 124 +++++++++++++ .../27_io/basic_filebuf/seekoff/char/1-out.cc | 124 +++++++++++++ .../27_io/basic_filebuf/seekoff/char/11543.cc | 153 ++++++++++++++++ .../27_io/basic_filebuf/seekoff/char/12232.cc | 71 +++++++ .../27_io/basic_filebuf/seekoff/char/12790-1.cc | 80 ++++++++ .../27_io/basic_filebuf/seekoff/char/12790-2.cc | 81 ++++++++ .../27_io/basic_filebuf/seekoff/char/12790-3.cc | 80 ++++++++ .../27_io/basic_filebuf/seekoff/char/12790-4.cc | 81 ++++++++ .../27_io/basic_filebuf/seekoff/char/2-in.cc | 125 +++++++++++++ .../27_io/basic_filebuf/seekoff/char/2-io.cc | 123 +++++++++++++ .../27_io/basic_filebuf/seekoff/char/2-out.cc | 123 +++++++++++++ .../27_io/basic_filebuf/seekoff/char/26777.cc | 90 +++++++++ .../27_io/basic_filebuf/seekoff/char/3-in.cc | 63 +++++++ .../27_io/basic_filebuf/seekoff/char/3-io.cc | 66 +++++++ .../27_io/basic_filebuf/seekoff/char/3-out.cc | 63 +++++++ .../27_io/basic_filebuf/seekoff/char/4.cc | 93 ++++++++++ .../27_io/basic_filebuf/seekoff/char/45628-1.cc | 79 ++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/1.cc | 137 ++++++++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/11543.cc | 141 ++++++++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc | 78 ++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc | 79 ++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc | 78 ++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc | 79 ++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/2.cc | 90 +++++++++ .../27_io/basic_filebuf/seekoff/wchar_t/3.cc | 51 ++++++ .../27_io/basic_filebuf/seekoff/wchar_t/4.cc | 94 ++++++++++ .../basic_filebuf/seekoff/wchar_t/9875_seekoff.cc | 99 ++++++++++ .../27_io/basic_filebuf/seekpos/10132-3.cc | 54 ++++++ .../27_io/basic_filebuf/seekpos/12790-1.cc | 67 +++++++ .../27_io/basic_filebuf/seekpos/12790-2.cc | 82 +++++++++ .../27_io/basic_filebuf/seekpos/12790-3.cc | 80 ++++++++ .../27_io/basic_filebuf/seekpos/char/1-in.cc | 103 +++++++++++ .../27_io/basic_filebuf/seekpos/char/1-io.cc | 103 +++++++++++ .../27_io/basic_filebuf/seekpos/char/1-out.cc | 105 +++++++++++ .../27_io/basic_filebuf/seekpos/char/12790-1.cc | 81 ++++++++ .../27_io/basic_filebuf/seekpos/char/12790-2.cc | 82 +++++++++ .../27_io/basic_filebuf/seekpos/char/12790-3.cc | 79 ++++++++ .../27_io/basic_filebuf/seekpos/char/12790-4.cc | 82 +++++++++ .../27_io/basic_filebuf/seekpos/char/2-in.cc | 104 +++++++++++ .../27_io/basic_filebuf/seekpos/char/2-io.cc | 102 +++++++++++ .../27_io/basic_filebuf/seekpos/char/2-out.cc | 104 +++++++++++ .../27_io/basic_filebuf/seekpos/char/3-in.cc | 63 +++++++ .../27_io/basic_filebuf/seekpos/char/3-io.cc | 66 +++++++ .../27_io/basic_filebuf/seekpos/char/3-out.cc | 63 +++++++ .../27_io/basic_filebuf/seekpos/wchar_t/1.cc | 51 ++++++ .../27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc | 79 ++++++++ .../27_io/basic_filebuf/seekpos/wchar_t/12790-2.cc | 80 ++++++++ .../27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc | 79 ++++++++ .../27_io/basic_filebuf/seekpos/wchar_t/12790-4.cc | 80 ++++++++ .../27_io/basic_filebuf/seekpos/wchar_t/9874.cc | 139 ++++++++++++++ .../basic_filebuf/seekpos/wchar_t/9875_seekpos.cc | 111 +++++++++++ .../testsuite/27_io/basic_filebuf/setbuf/char/1.cc | 89 +++++++++ .../27_io/basic_filebuf/setbuf/char/12875-1.cc | 58 ++++++ .../27_io/basic_filebuf/setbuf/char/12875-2.cc | 56 ++++++ .../testsuite/27_io/basic_filebuf/setbuf/char/2.cc | 48 +++++ .../testsuite/27_io/basic_filebuf/setbuf/char/3.cc | 51 ++++++ .../27_io/basic_filebuf/sgetc/char/1-in.cc | 72 ++++++++ .../27_io/basic_filebuf/sgetc/char/1-io.cc | 87 +++++++++ .../27_io/basic_filebuf/sgetc/char/1-out.cc | 70 +++++++ .../27_io/basic_filebuf/sgetc/char/2-in.cc | 72 ++++++++ .../27_io/basic_filebuf/sgetc/char/2-io.cc | 86 +++++++++ .../27_io/basic_filebuf/sgetc/char/2-out.cc | 69 +++++++ .../27_io/basic_filebuf/sgetn/char/1-in.cc | 92 ++++++++++ .../27_io/basic_filebuf/sgetn/char/1-io.cc | 105 +++++++++++ .../27_io/basic_filebuf/sgetn/char/1-out.cc | 76 ++++++++ .../27_io/basic_filebuf/sgetn/char/2-in.cc | 88 +++++++++ .../27_io/basic_filebuf/sgetn/char/2-io.cc | 100 ++++++++++ .../27_io/basic_filebuf/sgetn/char/2-out.cc | 76 ++++++++ .../testsuite/27_io/basic_filebuf/sgetn/char/3.cc | 47 +++++ .../27_io/basic_filebuf/showmanyc/char/9533-1.cc | 98 ++++++++++ .../27_io/basic_filebuf/showmanyc/char/9533-2.cc | 58 ++++++ .../27_io/basic_filebuf/snextc/char/1-in.cc | 85 +++++++++ .../27_io/basic_filebuf/snextc/char/1-io.cc | 84 +++++++++ .../27_io/basic_filebuf/snextc/char/1-out.cc | 65 +++++++ .../27_io/basic_filebuf/snextc/char/2-in.cc | 83 +++++++++ .../27_io/basic_filebuf/snextc/char/2-io.cc | 82 +++++++++ .../27_io/basic_filebuf/snextc/char/2-out.cc | 62 +++++++ .../27_io/basic_filebuf/sputbackc/char/1-in.cc | 93 ++++++++++ .../27_io/basic_filebuf/sputbackc/char/1-io.cc | 103 +++++++++++ .../27_io/basic_filebuf/sputbackc/char/1-out.cc | 71 +++++++ .../27_io/basic_filebuf/sputbackc/char/2-in.cc | 93 ++++++++++ .../27_io/basic_filebuf/sputbackc/char/2-io.cc | 102 +++++++++++ .../27_io/basic_filebuf/sputbackc/char/2-out.cc | 72 ++++++++ .../27_io/basic_filebuf/sputbackc/char/9425.cc | 49 +++++ .../27_io/basic_filebuf/sputc/char/1-in.cc | 62 +++++++ .../27_io/basic_filebuf/sputc/char/1-io.cc | 71 +++++++ .../27_io/basic_filebuf/sputc/char/1-out.cc | 70 +++++++ .../27_io/basic_filebuf/sputc/char/1057.cc | 53 ++++++ .../27_io/basic_filebuf/sputc/char/2-in.cc | 63 +++++++ .../27_io/basic_filebuf/sputc/char/2-io.cc | 70 +++++++ .../27_io/basic_filebuf/sputc/char/2-out.cc | 71 +++++++ .../27_io/basic_filebuf/sputc/char/9701-2.cc | 70 +++++++ .../27_io/basic_filebuf/sputn/char/1-in.cc | 62 +++++++ .../27_io/basic_filebuf/sputn/char/1-io.cc | 70 +++++++ .../27_io/basic_filebuf/sputn/char/1-out.cc | 66 +++++++ .../27_io/basic_filebuf/sputn/char/1057.cc | 53 ++++++ .../27_io/basic_filebuf/sputn/char/2-in.cc | 63 +++++++ .../27_io/basic_filebuf/sputn/char/2-io.cc | 69 +++++++ .../27_io/basic_filebuf/sputn/char/2-out.cc | 67 +++++++ .../27_io/basic_filebuf/sputn/char/9339.cc | 49 +++++ .../27_io/basic_filebuf/sputn/char/9701-1.cc | 74 ++++++++ .../27_io/basic_filebuf/sungetc/char/1-in.cc | 72 ++++++++ .../27_io/basic_filebuf/sungetc/char/1-io.cc | 84 +++++++++ .../27_io/basic_filebuf/sungetc/char/1-out.cc | 69 +++++++ .../27_io/basic_filebuf/sungetc/char/2-in.cc | 73 ++++++++ .../27_io/basic_filebuf/sungetc/char/2-io.cc | 83 +++++++++ .../27_io/basic_filebuf/sungetc/char/2-out.cc | 70 +++++++ .../27_io/basic_filebuf/sync/char/1057.cc | 104 +++++++++++ .../27_io/basic_filebuf/sync/char/9182-1.cc | 79 ++++++++ .../27_io/basic_filebuf/underflow/10096.cc | 71 +++++++ .../27_io/basic_filebuf/underflow/char/1.cc | 83 +++++++++ .../27_io/basic_filebuf/underflow/char/10097.cc | 115 ++++++++++++ .../27_io/basic_filebuf/underflow/char/2.cc | 49 +++++ .../27_io/basic_filebuf/underflow/char/3.cc | 84 +++++++++ .../27_io/basic_filebuf/underflow/char/45841.cc | 41 +++++ .../27_io/basic_filebuf/underflow/char/9027.cc | 85 +++++++++ .../27_io/basic_filebuf/underflow/wchar_t/1.cc | 111 +++++++++++ .../basic_filebuf/underflow/wchar_t/11389-1.cc | 50 +++++ .../basic_filebuf/underflow/wchar_t/11389-2.cc | 52 ++++++ .../basic_filebuf/underflow/wchar_t/11389-3.cc | 51 ++++++ .../basic_filebuf/underflow/wchar_t/11389-4.cc | 53 ++++++ .../basic_filebuf/underflow/wchar_t/11544-1.cc | 184 +++++++++++++++++++ .../basic_filebuf/underflow/wchar_t/11544-2.cc | 184 +++++++++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/11603.cc | 201 ++++++++++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/2.cc | 112 +++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/3.cc | 117 ++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/4.cc | 55 ++++++ .../27_io/basic_filebuf/underflow/wchar_t/45841.cc | 41 +++++ .../27_io/basic_filebuf/underflow/wchar_t/5.cc | 74 ++++++++ .../27_io/basic_filebuf/underflow/wchar_t/9178.cc | 204 +++++++++++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/9520.cc | 61 ++++++ 213 files changed, 16622 insertions(+) create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/cons/2020.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/9701-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/is_open/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/13858.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2-unbuf.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/3599.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9169.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9182-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9988.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/13858.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/base_classes.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/explicit_instantiation.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/typedefs.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/9825.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/10132-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/9425.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1057.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1057.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9339.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/1057.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/9182-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc (limited to 'libstdc++-v3/testsuite/27_io/basic_filebuf') diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc new file mode 100644 index 000000000..99d5eda88 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from('b')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + + // Check that close() writes unshift sequence + fb.close(); + + fb.open(name, ios_base::in | ios_base::out | ios_base::ate); + + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + + fb.close(); + + fb.open(name, ios_base::in); + + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc new file mode 100644 index 000000000..0a12e7224 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "filebuf_members-1.tst"; +const char name_02[] = "filebuf_members-1.txt"; + +// Test member functions. +void test_01() +{ + bool test __attribute__((unused)) = true; + const char* name_03 = "filebuf_members-3"; // empty file, need to create + + std::filebuf fb_01; // in + std::filebuf fb_02; // out + std::filebuf fb_03; // in | out + + // bool is_open() + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); + + // filebuf_type* open(const char* __s, ios_base::openmode __mode) + fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); + VERIFY( fb_01.is_open() ); + + // Try to open two different files without closing the first: + // Should keep the old file attached, and disregard attempt to overthrow. + fb_02.open(name_02, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + VERIFY( fb_02.is_open() ); + + fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); + VERIFY( fb_03.is_open() ); + + // filebuf_type* close() + std::filebuf* f; + f = fb_01.close(); + VERIFY( f ); + VERIFY( !fb_01.is_open() ); + + f = fb_02.close(); + VERIFY( f ); + VERIFY( !fb_02.is_open() ); + + f = fb_03.close(); + VERIFY( f ); + VERIFY( !fb_03.is_open() ); + + f = fb_03.close(); + VERIFY( !f ); + VERIFY( !fb_03.is_open() ); +} + +int +main() +{ + test_01(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc new file mode 100644 index 000000000..508261ba2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc new file mode 100644 index 000000000..0a4bdb3c1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + fb.in_avail(); // showmanyc() should have no effect on close(). + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc new file mode 100644 index 000000000..fe0624d10 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return codecvt_base::error; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should fail if codecvt::unshift() fails +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + filebuf* ret = fb.close(); + VERIFY( cvt->unshift_called ); + VERIFY( !ret ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc new file mode 100644 index 000000000..e54c61682 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc new file mode 100644 index 000000000..c1a0f79c8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include +#include +#include + +// Verify that std::filebuf doesn't close files that it didn't open +// when using the following std::filebuf ctor: +// +// std::filebuf(__c_file_type* __f, +// ios_base::openmode __mode, +// int_type __s); +// +// Thanks to "George T. Talbot" for uncovering +// this bug/situation. + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +void test_02() +{ + bool test __attribute__((unused)) = true; + int close_num = 0; + + // read (ext) + FILE* f2 = fopen(name_01, "r"); + VERIFY( f2 ); + if (f2) + { + __gnu_cxx::stdio_filebuf fb(f2, std::ios_base::in, 512); + close_num = fclose(f2); + } + VERIFY( close_num == 0 ); + + // read (standard) + FILE* f = fopen(name_01, "r"); + VERIFY( f ); + if (f) + { + std::ifstream ifstream1(name_01); + VERIFY( ifstream1.is_open() ); + std::ios_base::iostate st01 = ifstream1.rdstate(); + VERIFY( st01 == std::ios_base::goodbit ); + close_num = fclose(f); + } + VERIFY( close_num == 0 ); +} + +int +main() +{ + test_02(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc new file mode 100644 index 000000000..a5db2aed6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc @@ -0,0 +1,89 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +// NB: This test assumes that _M_buf_size == 40, and not the usual +// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be +// simulated a bit more readily. +// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. +const int buffer_size = 8192; +//const int buffer_size = 40; + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create +const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create + +class derived_filebuf: public std::filebuf +{ + public: + void + set_size(int_type __size) { _M_buf_size = __size; } +}; + +derived_filebuf fb_01; // in +derived_filebuf fb_02; // out +derived_filebuf fb_03; // in | out + +// Initialize filebufs to be the same size regardless of platform. +void test03() +{ + fb_01.set_size(buffer_size); + fb_02.set_size(buffer_size); + fb_03.set_size(buffer_size); +} + +// Test overloaded virtual functions. +void test05() +{ + typedef std::filebuf::int_type int_type; + typedef std::filebuf::traits_type traits_type; + typedef std::filebuf::pos_type pos_type; + typedef std::filebuf::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + std::filebuf f_tmp; + + fb_01.open(name_01, std::ios_base::in); + fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); + fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); + + // NB Have to close these suckers. . . + // filebuf_type* close() + fb_01.close(); + fb_02.close(); + fb_03.close(); + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); +} + +int main() +{ + test03(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc new file mode 100644 index 000000000..cd4f5e15b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc @@ -0,0 +1,73 @@ +// 2003-05-19 Paolo Carlini + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// Test that upon filebuf::close() 27.8.1.1,3 is enforced. + +#include +#include + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +void test_04() +{ + typedef std::filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + std::filebuf fb_01, fb_02; + char buffer[] = "xxxxxxxxxx"; + + // 'in' + fb_01.open(name_01, std::ios_base::in); + VERIFY( fb_01.sgetc() != traits_type::eof() ); + VERIFY( fb_01.sbumpc() != traits_type::eof() ); + VERIFY( fb_01.snextc() != traits_type::eof() ); + VERIFY( fb_01.sgetn(buffer, sizeof(buffer)) == sizeof(buffer) ); + + fb_01.close(); + + VERIFY( fb_01.sgetc() == traits_type::eof() ); + VERIFY( fb_01.sbumpc() == traits_type::eof() ); + VERIFY( fb_01.snextc() == traits_type::eof() ); + VERIFY( fb_01.sgetn(buffer, sizeof(buffer)) == 0 ); + + // 'out' + fb_02.open(name_02, std::ios_base::out); + VERIFY( fb_02.sputc('T') != traits_type::eof() ); + VERIFY( fb_02.sputn(buffer, sizeof(buffer)) == sizeof(buffer) ); + + fb_02.close(); + + VERIFY( fb_02.sputc('T') == traits_type::eof() ); + VERIFY( fb_02.sputn(buffer, sizeof(buffer)) == 0 ); +} + +int +main() +{ + test_04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc new file mode 100644 index 000000000..9d2c647ca --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc @@ -0,0 +1,108 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include +#include +#include +#include +#include +#include +#include +#include + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +// libstdc++/2913, libstdc++/4879 +// John Fardo , Brad Garcia +bool +test_04() +{ + using namespace __gnu_test; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_fifo1"; + semaphore s1, s2; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + if (0 != mkfifo(name, S_IRWXU)) + { + std::cerr << "failed to create fifo" << std::endl; + exit(-1); + } + + int fval = fork(); + if (fval == -1) + { + std::cerr << "failed to fork" << std::endl; + unlink(name); + return false; + } + else if (fval == 0) + { + std::ifstream ifs(name); + s1.wait(); + ifs.close(); + s2.signal(); + exit(0); + } + + std::ofstream ofs(name); + s1.signal(); + s2.wait(); + ofs.put('t'); + + /* + * ISO/IED 14882:1998(E) 27.8.1.10.4 + * + * void close(); + * + * Effects: Calls rdbuf()->close() and, if that function fails + * (returns a null pointer), calls setstate(failbit)... + */ + ofs.close(); + if (!(ofs.rdstate() & std::ios::failbit)) + { + test = false; + VERIFY( test ); + } + + unlink(name); + + return test; +} + +int +main() +{ + return !test_04(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc new file mode 100644 index 000000000..25ae66b41 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc @@ -0,0 +1,106 @@ +// 2003-05-20 Paolo Carlini + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// Test that upon filebuf::close() 27.8.1.1,3 is enforced. + +#include +#include + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +bool overflow_called; +bool underflow_called; +bool uflow_called; + +class Close_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + overflow_called = true; + return std::filebuf::overflow(c); + } + + int_type underflow() + { + underflow_called = true; + return std::filebuf::underflow(); + } + + int_type uflow() + { + uflow_called = true; + return std::filebuf::uflow(); + } +}; + +void test_05() +{ + bool test __attribute__((unused)) = true; + + Close_filebuf fb_01, fb_02; + char buffer[] = "xxxxxxxxxx"; + + // 'in' + fb_01.open(name_01, std::ios_base::in); + fb_01.sgetc(); + + fb_01.close(); + + underflow_called = false; + fb_01.sgetc(); + VERIFY( underflow_called == true ); + + uflow_called = false; + fb_01.sbumpc(); + VERIFY( uflow_called == true ); + + uflow_called = false; + fb_01.snextc(); + VERIFY( uflow_called == true ); + + uflow_called = false; + fb_01.sgetn(buffer, sizeof(buffer)); + VERIFY( uflow_called == true ); + + // 'out' + fb_02.open(name_02, std::ios_base::out); + + fb_02.close(); + + overflow_called = false; + fb_02.sputc('T'); + VERIFY( overflow_called == true ); + + overflow_called = false; + fb_02.sputn(buffer, sizeof(buffer)); + VERIFY( overflow_called == true ); +} + +int +main() +{ + test_05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc new file mode 100644 index 000000000..f2c5abc3e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc @@ -0,0 +1,89 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include +#include +#include +#include +#include +#include +#include + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +// libstdc++/9964 +bool test_07() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + semaphore s1, s2; + + const char* name = "tmp_fifo3"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + filebuf fbin; + fbin.open(name, ios_base::in); + s1.wait(); + fbin.close(); + s2.signal(); + exit(0); + } + + filebuf fb; + filebuf* ret = fb.open(name, ios_base::in | ios_base::out); + VERIFY( ret != 0 ); + VERIFY( fb.is_open() ); + s1.signal(); + s2.wait(); + fb.sputc('a'); + + ret = fb.close(); + VERIFY( ret != 0 ); + VERIFY( !fb.is_open() ); + + return test; +} + +int +main() +{ + return !test_07(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc new file mode 100644 index 000000000..85222f596 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc new file mode 100644 index 000000000..eeade5812 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + fb.in_avail(); // showmanyc() should have no effect on close(). + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc new file mode 100644 index 000000000..417fbc2ce --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return codecvt_base::error; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should fail if codecvt::unshift() fails +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + wfilebuf* ret = fb.close(); + VERIFY( cvt->unshift_called ); + VERIFY( !ret ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc new file mode 100644 index 000000000..240417a93 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/2020.cc new file mode 100644 index 000000000..377e519a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/2020.cc @@ -0,0 +1,52 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include +#include +#include + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_filebuf<__gnu_test::pod_ushort> gnu_filebuf; + + try + { gnu_filebuf obj; } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc new file mode 100644 index 000000000..ab2e2c70f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.2 basic_filebuf constructors [lib.filebuf.cons] + +#include +#include +#include + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_filebuf fbuf; + VERIFY( fbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc new file mode 100644 index 000000000..e2081de7c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.2 basic_filebuf constructors [lib.filebuf.cons] + +#include +#include +#include + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_wfilebuf fbuf; + VERIFY( fbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc new file mode 100644 index 000000000..69d2d4517 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc @@ -0,0 +1,52 @@ +// 2003-04-24 Pétur Runólfsson +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +class Cvt : public std::codecvt +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t*, const wchar_t*, const wchar_t*&, + char*, char*, char*&) const + { throw std::runtime_error("codecvt failed"); } +}; + +int main() +{ + bool test __attribute__((unused)) = true; + + std::locale loc = std::locale(std::locale::classic(), new Cvt); + std::wfilebuf* fb = new std::wfilebuf; + fb->pubimbue(loc); + fb->open("tmp_10132", std::ios_base::out); + fb->sputc(L'a'); + + try + { + delete fb; + } + catch(std::exception& obj) + { + VERIFY( false ); + } + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc new file mode 100644 index 000000000..4c6bebf1f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc @@ -0,0 +1,125 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include + +typedef unsigned char Char; + +namespace std +{ + template <> + class codecvt : + public locale::facet, public codecvt_base + { + public: + typedef Char intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + explicit codecvt(size_t refs = 0) + : locale::facet(refs) { } + result out(mbstate_t& state, const Char* from, + const Char* from_end, const Char*& from_next, + char* to, char* to_limit, char*& to_next) const + { + return do_out(state, from, from_end, from_next, + to, to_limit, to_next); + } + result in(mbstate_t& state, const char* from, + const char* from_end, const char*& from_next, + Char* to, Char* to_limit, Char*& to_next) const + { + return do_in(state, from, from_end, from_next, + to, to_limit, to_next); + } + result unshift(mbstate_t& state, char* to, char* to_end, + char*& to_next) const + { return do_unshift(state, to, to_end, to_next); } + int length(mbstate_t& state, const char* from, + const char* from_end, size_t max) const + { return do_length(state, from, from_end, max); } + int encoding() const throw() + { return do_encoding(); } + bool always_noconv() const throw() + { return do_always_noconv(); } + int max_length() const throw() + { return do_max_length(); } + + static locale::id id; + + protected: + virtual result do_out(mbstate_t&, const Char*, + const Char*, + const Char*&, char*, + char*, char*&) const + { return ok; } + virtual result do_in(mbstate_t&, const char*, + const char*, + const char*&, Char*, + Char*, Char*&) const + { return ok; } + virtual result do_unshift(mbstate_t&, char*, char*, + char*&) const + { return noconv; } + virtual int do_length(mbstate_t&, const char*, + const char*, size_t) const + { return 1; } + virtual int do_encoding() const throw() + { return 1; } + virtual bool do_always_noconv() const throw() + { return false; } + virtual int do_max_length() const throw() + { return 1; } + }; + + locale::id codecvt::id; +} + +// libstdc++/12206 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), + new codecvt); + locale::global(loc); + + basic_filebuf > fb; + + loc = locale::classic(); + locale::global(loc); + fb.pubimbue(loc); + + fb.open("tmp_12206", ios_base::out); + try + { + fb.pubseekoff(0, ios_base::cur); + } + catch (std::exception&) + { + } + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc new file mode 100644 index 000000000..37bc1a555 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc @@ -0,0 +1,44 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +std::filebuf fbuf; + +// test the filebuf locale settings +void test02() +{ + std::locale loc_c = std::locale::classic(); + loc_c = fbuf.getloc(); + fbuf.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = fbuf.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc new file mode 100644 index 000000000..326aa1fd8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc @@ -0,0 +1,62 @@ +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Buf : public std::filebuf +{ +public: + std::locale before; + std::locale after; + +protected: + void imbue(const std::locale& loc) + { + before = getloc(); + + std::filebuf::imbue(loc); + + after = getloc(); + } +}; + +// libstdc++/13007 +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::locale loc(std::locale("fr_FR")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); + VERIFY( buf.before == std::locale::classic() ); + VERIFY( buf.after == std::locale::classic() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc new file mode 100644 index 000000000..9fbf67aef --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc @@ -0,0 +1,46 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// libstdc++/13171 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb; + + fb.pubimbue(locale("en_US")); + fb.pubimbue(locale("en_US")); + + fb.open("tmp_13171-1", ios_base::out); + fb.sputc('F'); + fb.pubsync(); + fb.close(); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc new file mode 100644 index 000000000..fa0bf15c0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc @@ -0,0 +1,83 @@ +// { dg-require-namedlocale "fr_FR" } +// { dg-require-namedlocale "en_US" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +#include +#include + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +// libstdc++/13171 +bool test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace __gnu_test; + + locale loc_fr(locale("fr_FR")); + locale loc_en(locale("en_US")); + + const char* name = "tmp_fifo_13171-2"; + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1, s2; + + int child = fork(); + if (child == 0) + { + filebuf fb; + fb.open(name, ios_base::out); + fb.sputc('S'); + fb.pubsync(); + s1.signal(); + s2.wait(); + fb.close(); + exit(0); + } + + filebuf fb; + fb.pubimbue(loc_fr); + fb.open(name, ios_base::in); + s1.wait(); + VERIFY( fb.is_open() ); + fb.pubimbue(loc_en); + filebuf::int_type c = fb.sgetc(); + fb.close(); + VERIFY( c == 'S' ); + s2.signal(); + + return test; +} + +int main() +{ + return !test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc new file mode 100644 index 000000000..1ac9557ce --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc @@ -0,0 +1,56 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +protected: + int do_encoding() const throw() + { return -1; } + + bool do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/13171 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb; + fb.pubimbue(locale(locale("en_US"), new Cvt)); + fb.open("tmp_13171-4", ios_base::out); + fb.pubimbue(locale("fr_FR")); + fb.sputc('N'); + fb.pubsync(); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc new file mode 100644 index 000000000..fdcc03022 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc @@ -0,0 +1,84 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2004-01-11 Petur Runolfsson + +// Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +#include +#include +#include + +#include + +// libstdc++/13582 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace __gnu_test; + + locale loc_en(locale("en_US")); + locale loc_fr(locale("fr_FR")); + + const char* name = "tmp_fifo_13582-2"; + unlink(name); + mkfifo(name, S_IRWXU); + + int child = fork(); + if (child == 0) + { + filebuf fbout; + fbout.open(name, ios_base::out); + fbout.sputn("12345", 5); + fbout.pubsync(); + fbout.close(); + exit(0); + } + + filebuf fbin; + fbin.open(name, ios_base::in); + filebuf::int_type n = fbin.sbumpc(); + VERIFY( n == '1' ); + fbin.pubimbue(loc_en); + n = fbin.sbumpc(); + VERIFY( n == '2' ); + fbin.pubimbue(loc_fr); + n = fbin.sbumpc(); + VERIFY( n == '3' ); + n = fbin.sbumpc(); + VERIFY( n == '4' ); + n = fbin.sbumpc(); + VERIFY( n == '5' ); + n = fbin.sbumpc(); + VERIFY( n == filebuf::traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc new file mode 100644 index 000000000..5007b085e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc @@ -0,0 +1,68 @@ +// { dg-require-namedlocale "en_US" } + +// 2004-04-16 Petur Runolfsson + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Buf : public std::filebuf +{ +protected: + virtual int_type + overflow(int_type c = traits_type::eof()) + { + return traits_type::eq_int_type(c, traits_type::eof()) ? + traits_type::eof() : std::filebuf::overflow(c); + } +}; + +// libstdc++/14975 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + Buf fb; + locale loc_us = locale("en_US"); + fb.pubimbue(loc_us); + fb.open("tmp_14975-1", ios_base::out); + + try + { + fb.sputc('a'); + fb.sputc('b'); + fb.pubimbue(locale::classic()); + fb.sputc('c'); + fb.pubsync(); + fb.close(); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc new file mode 100644 index 000000000..f4d574c21 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "de_DE" } + +// 2003-05-13 Benjamin Kosnik + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + + locale loc; + filebuf ob; + VERIFY( ob.getloc() == loc ); + ob.open(name_01, ios_base::in); + VERIFY( ob.is_open() ); + + typedef streambuf::pos_type pos_type; + pos_type bad = pos_type(streambuf::off_type(-1)); + pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in); + VERIFY( p != bad); + + // According to 27.5.2.2.1, loc == getloc() after pubimbue(loc). + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc new file mode 100644 index 000000000..055573b96 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc @@ -0,0 +1,55 @@ +// 2003-05-13 Benjamin Kosnik + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class state_codecvt : public std::codecvt +{ +protected: + int + do_encoding() const throw() + { return -1; } +}; + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc_s(locale::classic(), new state_codecvt); + filebuf ob; + ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); + + // 2 "if encoding of current locale is state dependent" and + // not at the beginning of the file fails... + locale loc_c = locale::classic(); + locale ret = ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc new file mode 100644 index 000000000..8a611e0dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// libstdc++/9322 +void test07() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc; + std::filebuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc new file mode 100644 index 000000000..f5c6daac3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc @@ -0,0 +1,44 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +std::wfilebuf fbuf; + +// test the filebuf locale settings +void test02() +{ + std::locale loc_c = std::locale::classic(); + loc_c = fbuf.getloc(); + fbuf.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = fbuf.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc new file mode 100644 index 000000000..bc7c3c1bd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc @@ -0,0 +1,61 @@ +// { dg-require-namedlocale "is_IS.UTF-8" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include + +// libstdc++/12868 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc_is(locale("is_IS.UTF-8")); + + { + wofstream out("tmp_12868"); + out << L"\n"; + out.imbue(loc_is); + VERIFY( out.rdbuf()->getloc() == loc_is ); + out << L"Hall\u00f3 heimur\n"; + } + + { + wifstream in("tmp_12868"); + wstring str; + getline(in, str); + if (str.find(L"encoding=\"UTF-8\"") != wstring::npos) + { + in.imbue(loc_is); + VERIFY( in.rdbuf()->getloc() == loc_is ); + } + getline(in, str); + VERIFY( str == L"Hall\u00f3 heimur" ); + } +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc new file mode 100644 index 000000000..9bb1f4035 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc @@ -0,0 +1,62 @@ +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Buf : public std::wfilebuf +{ +public: + std::locale before; + std::locale after; + +protected: + void imbue(const std::locale& loc) + { + before = getloc(); + + std::wfilebuf::imbue(loc); + + after = getloc(); + } +}; + +// libstdc++/13007 +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::locale loc(std::locale("fr_FR")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); + VERIFY( buf.before == std::locale::classic() ); + VERIFY( buf.after == std::locale::classic() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc new file mode 100644 index 000000000..ec11237d0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc @@ -0,0 +1,59 @@ +// { dg-require-namedlocale "fr_FR" } +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// libstdc++/13171 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale::global(locale("fr_FR")); + + ios_base::sync_with_stdio(false); + + locale::global(locale("en_US")); + cin.imbue(locale("en_US")); + cout.imbue(locale("en_US")); + cerr.imbue(locale("en_US")); + clog.imbue(locale("de_DE")); + wcin.imbue(locale("en_US")); + wcout.imbue(locale("en_US")); + wcerr.imbue(locale("en_US")); + wclog.imbue(locale("de_DE")); + + cout << 'f' << endl; + cerr << 'r' << endl; + clog << 'A' << endl; + wcout << L's' << endl; + wcerr << L'i' << endl; + wclog << L'L' << endl; +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc new file mode 100644 index 000000000..7a997739f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc @@ -0,0 +1,86 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2004-01-11 Petur Runolfsson + +// Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +#include +#include +#include + +#include + +// libstdc++/13582 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace __gnu_test; + + locale loc_en(locale("en_US")); + locale loc_fr(locale("fr_FR")); + + const char* name = "tmp_fifo_13582-2"; + unlink(name); + mkfifo(name, S_IRWXU); + + int child = fork(); + if (child == 0) + { + filebuf fbout; + fbout.open(name, ios_base::out); + fbout.sputn("12345", 5); + fbout.pubsync(); + sleep(2); + fbout.close(); + exit(0); + } + + wfilebuf fbin; + fbin.open(name, ios_base::in); + sleep(1); + wfilebuf::int_type n = fbin.sbumpc(); + VERIFY( n == L'1' ); + fbin.pubimbue(loc_en); + n = fbin.sbumpc(); + VERIFY( n == L'2' ); + fbin.pubimbue(loc_fr); + n = fbin.sbumpc(); + VERIFY( n == L'3' ); + n = fbin.sbumpc(); + VERIFY( n == L'4' ); + n = fbin.sbumpc(); + VERIFY( n == L'5' ); + n = fbin.sbumpc(); + VERIFY( n == wfilebuf::traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc new file mode 100644 index 000000000..246ae8c6e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } + +// 2004-01-11 Petur Runolfsson + +// Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// libstdc++/13582 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale loc_en(locale("en_US")); + locale loc_fr(locale("fr_FR")); + + const char* name = "tmp_13582-3.tst"; + + { + filebuf fbout; + fbout.open(name, ios_base::out); + fbout.sputn("AbCdE", 5); + fbout.close(); + } + + { + wfilebuf fbin; + fbin.open(name, ios_base::in); + wfilebuf::int_type n = fbin.sbumpc(); + VERIFY( n == L'A' ); + fbin.pubimbue(loc_en); + fbin.pubseekoff(0, ios_base::cur); + n = fbin.sbumpc(); + VERIFY( n == L'b' ); + fbin.pubimbue(loc_fr); + n = fbin.sbumpc(); + VERIFY( n == L'C' ); + n = fbin.sbumpc(); + VERIFY( n == L'd' ); + fbin.pubseekoff(0, ios_base::cur); + n = fbin.sbumpc(); + VERIFY( n == L'E' ); + n = fbin.sbumpc(); + VERIFY( n == wfilebuf::traits_type::eof() ); + fbin.close(); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc new file mode 100644 index 000000000..dc1314556 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc @@ -0,0 +1,95 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2004-04-16 Petur Runolfsson + +// Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include +#include +#include +#include +#include + +// No asserts, avoid leaking the semaphore if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +// libstdc++/14975 +bool test01() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + + locale loc_us = locale("en_US"); + + const char* name = "tmp_14975-2"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1; + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + { + filebuf fbin; + fbin.open(name, ios_base::in); + } + s1.signal(); + exit(0); + } + + wfilebuf fb; + fb.pubimbue(loc_us); + wfilebuf* ret = fb.open(name, ios_base::out); + VERIFY( ret != 0 ); + VERIFY( fb.is_open() ); + + s1.wait(); + + try + { + fb.sputc(L'a'); + fb.sputc(L'b'); + fb.pubimbue(locale::classic()); + fb.sputc(L'c'); + fb.close(); + } + catch (std::exception&) + { + } + + return test; +} + +int main() +{ + return !test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc new file mode 100644 index 000000000..52941a5fc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "de_DE" } + +// 2003-05-13 Benjamin Kosnik + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + + locale loc; + wfilebuf ob; + VERIFY( ob.getloc() == loc ); + ob.open(name_01, ios_base::in); + VERIFY( ob.is_open() ); + + typedef streambuf::pos_type pos_type; + pos_type bad = pos_type(streambuf::off_type(-1)); + pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in); + VERIFY( p != bad); + + // According to 27.5.2.2.1, p1, loc == getloc() after pubimbue(loc). + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc new file mode 100644 index 000000000..01baec6b5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc @@ -0,0 +1,55 @@ +// 2003-05-13 Benjamin Kosnik + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class state_codecvt : public std::codecvt +{ +protected: + int + do_encoding() const throw() + { return -1; } +}; + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc_s(locale::classic(), new state_codecvt); + wfilebuf ob; + ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); + + // 2 "if encoding of current locale is state dependent" and + // not at the beginning of the file fails... + locale loc_c = locale::classic(); + locale ret = ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc new file mode 100644 index 000000000..f69d9f0d6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// libstdc++/9322 +void test07() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc; + std::wfilebuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc new file mode 100644 index 000000000..94b331867 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc @@ -0,0 +1,100 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +// NB: This test assumes that _M_buf_size == 40, and not the usual +// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be +// simulated a bit more readily. +// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. +const int buffer_size = 8192; +//const int buffer_size = 40; + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create +const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create + +class derived_filebuf: public std::filebuf +{ + public: + void + set_size(int_type __size) { _M_buf_size = __size; } +}; + +derived_filebuf fb_01; // in +derived_filebuf fb_02; // out +derived_filebuf fb_03; // in | out + +// Initialize filebufs to be the same size regardless of platform. +void test03() +{ + fb_01.set_size(buffer_size); + fb_02.set_size(buffer_size); + fb_03.set_size(buffer_size); +} + +// Test overloaded virtual functions. +void test05() +{ + typedef std::filebuf::int_type int_type; + typedef std::filebuf::traits_type traits_type; + typedef std::filebuf::pos_type pos_type; + typedef std::filebuf::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + std::filebuf f_tmp; + std::streamoff strmof_1, strmof_2; + + // GET + // int in_avail() + // if a read position is available, return _M_in_end - _M_in_cur. + // else return showmanyc. + strmof_1 = fb_01.in_avail(); + strmof_2 = fb_02.in_avail(); + VERIFY( strmof_1 == -1 ); + VERIFY( strmof_1 == strmof_2 ); //fail because not open + strmof_1 = fb_03.in_avail(); + VERIFY( strmof_1 == strmof_2 ); + fb_01.open(name_01, std::ios_base::in); + fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); + fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); + strmof_1 = fb_01.in_avail(); + strmof_2 = fb_02.in_avail(); + VERIFY( strmof_1 != strmof_2 ); + VERIFY( strmof_1 >= 0 ); + VERIFY( strmof_2 == -1 ); // empty file + strmof_1 = fb_03.in_avail(); + VERIFY( strmof_1 == 0 ); // empty file +} + +int main() +{ + test03(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/9701-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/9701-3.cc new file mode 100644 index 000000000..b68f65647 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/9701-3.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.5.2.2.3 Get area + +// { dg-require-fileio "" } + +#include +#include + +class Derived_fbuf : public std::filebuf +{ +public: + const char_type* pub_egptr() const + { return egptr(); } + + const char_type* pub_gptr() const + { return gptr(); } +}; + +// libstdc++/9701 (in_avail) +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "tmp_file1"; + + Derived_fbuf df2; + df2.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + df2.sputn("Comomoc", 7); + + df2.pubseekoff(0, ios_base::beg); + df2.sbumpc(); + df2.sputbackc('t'); + + VERIFY( df2.pub_gptr() < df2.pub_egptr() ); + VERIFY( df2.in_avail() == df2.pub_egptr() - df2.pub_gptr() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/is_open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/is_open/char/1.cc new file mode 100644 index 000000000..1b5a66ea8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/is_open/char/1.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "filebuf_members-1.tst"; +const char name_02[] = "filebuf_members-1.txt"; + +// Test member functions. +void test_01() +{ + bool test __attribute__((unused)) = true; + const char* name_03 = "filebuf_members-3"; // empty file, need to create + + std::filebuf fb_01; // in + std::filebuf fb_02; // out + std::filebuf fb_03; // in | out + + // bool is_open() + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); + + // filebuf_type* open(const char* __s, ios_base::openmode __mode) + fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); + fb_02.open(name_02, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); + VERIFY( fb_01.is_open() ); + VERIFY( fb_02.is_open() ); + VERIFY( fb_03.is_open() ); + + // filebuf_type* close() + fb_01.close(); + fb_02.close(); + fb_03.close(); + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); +} + +int +main() +{ + test_01(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc new file mode 100644 index 000000000..fc69cd4eb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_open_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(pod_uchar::from('b')); + fb.close(); + + // Check that reopened basic_filebuf begins in the initial state. + fb.open(name, ios_base::in); + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('b')) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc new file mode 100644 index 000000000..1a40da155 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "filebuf_members-1.tst"; +const char name_02[] = "filebuf_members-1.txt"; + +// Test member functions. +void test_01() +{ + bool test __attribute__((unused)) = true; + const char* name_03 = "filebuf_members-3"; // empty file, need to create + + std::filebuf fb_01; // in + std::filebuf fb_02; // out + std::filebuf fb_03; // in | out + + // bool is_open() + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); + + // filebuf_type* open(const char* __s, ios_base::openmode __mode) + fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); + VERIFY( fb_01.is_open() ); + + // Try to open two different files without closing the first: + // Should keep the old file attached, and disregard attempt to overthrow. + std::filebuf* f = fb_02.open(name_02, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + VERIFY( f ); + VERIFY( fb_02.is_open() ); + + f = fb_02.open(name_03, std::ios_base::in | std::ios_base::out); + VERIFY( !f ); + VERIFY( fb_02.is_open() ); + + fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); + VERIFY( fb_03.is_open() ); +} + +int +main() +{ + test_01(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc new file mode 100644 index 000000000..755784fb9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include +#include +#include +#include +#include +#include +#include +#include + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test_03() +{ + bool test __attribute__((unused)) = true; + int first_fd = ::open(name_01, O_RDONLY); + VERIFY( first_fd != -1 ); + FILE* first_file = ::fdopen(first_fd, "r"); + VERIFY( first_file ); + __gnu_cxx::stdio_filebuf fb(first_file, std::ios_base::in); + + int second_fd = fb.fd(); + + VERIFY( first_fd == second_fd ); +} + +int +main() +{ + test_03(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc new file mode 100644 index 000000000..6b076a699 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include +#include + +// Charles Leggett +void test_05() +{ + bool test __attribute__((unused)) = true; + const char* name = "tmp_file5"; + + std::fstream scratch_file; + + scratch_file.open(name, std::ios::out); + scratch_file.close(); + + scratch_file.open(name, std::ios::in); + if (!scratch_file) + VERIFY( false ); + scratch_file.close(); +} + +int +main() +{ + test_05(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc new file mode 100644 index 000000000..31d25422b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc @@ -0,0 +1,72 @@ +// 2006-10-01 Paolo Carlini + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include + +// DR 596. +void test01() +{ + bool test __attribute__((unused)) = true; + const char* name = "tmp_file4"; + + std::fstream scratch_file; + + scratch_file.open(name, std::ios_base::app); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::out + | std::ios_base::app); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::app); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::app | std::ios_base::binary); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::out + | std::ios_base::app | std::ios_base::binary); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::app + | std::ios_base::binary); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc new file mode 100644 index 000000000..47721e6ad --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc @@ -0,0 +1,30 @@ +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include + +// Test member functions. +void test01() +{ + std::filebuf fb; + + const std::string name = "filebuf_name.txt"; + fb.open(name, std::ios_base::in | std::ios_base::ate); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc new file mode 100644 index 000000000..5b404375e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc @@ -0,0 +1,72 @@ +// { dg-require-mkfifo "" } + +// Copyright (C) 2001, 2002, 2003, 2005, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include +#include +#include +#include +#include +#include +#include + +// libstdc++/9507 +void test_06() +{ + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + const char* name = "tmp_fifo2"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + + std::filebuf fbuf; + // The use of ios_base::ate implies an attempt to seek on the file + // descriptor. The seek will fail. Thus, at the OS level, this + // call to "fbuf.open" will result in a call to "open" (which will + // succeed), a call to "lseek" (which will fail), and, finally, a + // call to "close" (which will succeed). Thus, after this call, the + // file should be closed. + std::filebuf* r = fbuf.open(name, + std::ios_base::in + | std::ios_base::out + | std::ios_base::ate); + if (!r) + VERIFY( !fbuf.is_open() ); + else + VERIFY( fbuf.is_open() ); +} + +int +main() +{ + test_06(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/1.cc new file mode 100644 index 000000000..7c6874313 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/1.cc @@ -0,0 +1,70 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include +#include + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template > + class basic_nullbuf : public std::basic_filebuf + { + protected: + typedef typename + std::basic_filebuf::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf nullbuf; + +template + char + print(const T& x) + { + nullbuf ob; + std::ostream out(&ob); + out << x << std::endl; + return (!out ? '0' : '1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::string control01("11111"); + std::string test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print('x'); + test01 += print("pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/13858.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/13858.cc new file mode 100644 index 000000000..27f7b3664 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/13858.cc @@ -0,0 +1,69 @@ +// 2004-02-14 Petur Runolfsson + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +class Cvt : public std::codecvt +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const char* from, const char*, + const char*& from_next, char* to, char*, char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt_base::error; + } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/13858 +void test01() +{ + using namespace std; + + filebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_13858_char", ios_base::out); + + try + { + fb.sputc('a'); + fb.sputc('b'); + fb.pubimbue(locale::classic()); + fb.sputc('c'); + fb.pubsync(); + fb.close(); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2-unbuf.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2-unbuf.cc new file mode 100644 index 000000000..792b7970a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2-unbuf.cc @@ -0,0 +1,55 @@ +// 2003-06-10 Paolo Carlini + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create + +class OverBuf : public std::filebuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::filebuf::overflow(c); } +}; + +// According to 27.5.2.4.5 filebuf::overflow() returns not_eof(eof()). +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + typedef OverBuf::traits_type traits_type; + + OverBuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_08, ios_base::out | ios_base::trunc); + + VERIFY( fb.pub_overflow() == traits_type::not_eof(traits_type::eof()) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2.cc new file mode 100644 index 000000000..1cb8e503d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2.cc @@ -0,0 +1,54 @@ +// 2003-06-10 Paolo Carlini + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create + +class OverBuf : public std::filebuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::filebuf::overflow(c); } +}; + +// According to 27.5.2.4.5 filebuf::overflow() returns not_eof(eof()). +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + typedef OverBuf::traits_type traits_type; + + OverBuf fb; + fb.open(name_08, ios_base::out | ios_base::trunc); + + VERIFY( fb.pub_overflow() == traits_type::not_eof(traits_type::eof()) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/3599.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/3599.cc new file mode 100644 index 000000000..d02872cc0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/3599.cc @@ -0,0 +1,58 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +#include +#include +#include + +// libstdc++/3599 +class testbuf : public std::filebuf +{ +public: + typedef std::filebuf::traits_type traits_type; + + testbuf() : std::filebuf() { } + +protected: + int_type + overflow(int_type c __attribute__((unused)) = traits_type::eof()) + { return traits_type::not_eof(0); } +}; + +void +test07() +{ + bool test __attribute__((unused)) = true; + testbuf ob; + std::ostream out(&ob); + + out << "gasp"; + VERIFY(out.good()); + + out << std::endl; + VERIFY(out.good()); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9169.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9169.cc new file mode 100644 index 000000000..239c79a65 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9169.cc @@ -0,0 +1,73 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +const char name_04[] = "filebuf_virtuals-4.txt"; // empty file, need to create + +class Cvt_to_upper : public std::codecvt +{ + bool do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9169 +// filebuf output fails if codecvt<>::out returns noconv +void test10() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale c_loc = locale::classic(); + locale loc(c_loc, new Cvt_to_upper); + + string str("abcdefghijklmnopqrstuvwxyz"); + string tmp; + + { + ofstream out; + out.imbue(loc); + out.open(name_04); + copy(str.begin(), str.end(), ostreambuf_iterator(out)); + } + + { + ifstream in; + in.open(name_04); + copy(istreambuf_iterator(in), istreambuf_iterator(), + back_inserter(tmp)); + } + + VERIFY( tmp.size() == str.size() ); + VERIFY( tmp == str ); +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9182-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9182-2.cc new file mode 100644 index 000000000..80d001199 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9182-2.cc @@ -0,0 +1,80 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +const char name_07[] = "filebuf_virtuals-7.txt"; // empty file, need to create + +class errorcvt : public std::codecvt +{ +protected: + std::codecvt_base::result + do_out(mbstate_t&, const char* from, const char*, + const char*& from_next, char* to, char*, + char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt::error; + } + + virtual bool do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9182 +// basic_filebuf<>::sync and overflow do not write out any characters +// if codecvt<>::out returns error +void test14() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc = locale::classic(); + loc = locale(loc, new errorcvt); + + filebuf fbuf1; + fbuf1.pubimbue(loc); + fbuf1.pubsetbuf(0, 0); + fbuf1.open(name_07, ios_base::out | ios_base::trunc); + + try + { + fbuf1.sputn("onne", 4); + fbuf1.close(); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test14(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9988.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9988.cc new file mode 100644 index 000000000..74dd04bb8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9988.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create + +class OverBuf : public std::filebuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::filebuf::overflow(c); } +}; + +// libstdc++/9988 +// filebuf::overflow writes EOF to file +void test15() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + OverBuf fb; + fb.open(name_08, ios_base::out | ios_base::trunc); + + fb.sputc('a'); + fb.pub_overflow('b'); + fb.pub_overflow(); + fb.sputc('c'); + fb.close(); + + filebuf fbin; + fbin.open(name_08, ios_base::in); + filebuf::int_type c; + c = fbin.sbumpc(); + VERIFY( c == 'a' ); + c = fbin.sbumpc(); + VERIFY( c == 'b' ); + c = fbin.sbumpc(); + VERIFY( c == 'c' ); + c = fbin.sbumpc(); + VERIFY( c == filebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1.cc new file mode 100644 index 000000000..7faa0501a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1.cc @@ -0,0 +1,47 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.pubsetbuf(0, 0); + fb.open("tmp_11305-1", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2.cc new file mode 100644 index 000000000..e4a726a0d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2.cc @@ -0,0 +1,49 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.pubsetbuf(0, 0); + fb.open("tmp_11305-2", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf::int_type n2 = fb.sputc(0x40000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( n2 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3.cc new file mode 100644 index 000000000..5d49ed0df --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3.cc @@ -0,0 +1,46 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.open("tmp_11305-3", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4.cc new file mode 100644 index 000000000..3076a1777 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4.cc @@ -0,0 +1,48 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.open("tmp_11405-4", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf::int_type n2 = fb.sputc(0x40000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( n2 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/13858.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/13858.cc new file mode 100644 index 000000000..dd745267a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/13858.cc @@ -0,0 +1,70 @@ +// 2004-02-14 Petur Runolfsson + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +class Cvt : public std::codecvt +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t* from, const wchar_t*, + const wchar_t*& from_next, char* to, char*, + char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt_base::error; + } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/13858 +void test01() +{ + using namespace std; + + wfilebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_13858_wchar_t", ios_base::out); + + try + { + fb.sputc(L'a'); + fb.sputc(L'b'); + fb.pubimbue(locale::classic()); + fb.sputc(L'c'); + fb.pubsync(); + fb.close(); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc new file mode 100644 index 000000000..539460a52 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc @@ -0,0 +1,56 @@ +// 2003-06-02 Paolo Carlini + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +// libstdc++/9761 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf; + filebuf::int_type r1, r2; + + fbuf.open(name_01, ios_base::in); + + fbuf.sbumpc(); + fbuf.sbumpc(); + + r1 = fbuf.sputbackc('a'); + r2 = fbuf.sputbackc('b'); + + fbuf.close(); + + VERIFY( r1 != filebuf::traits_type::eof() ); + VERIFY( r2 == filebuf::traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/base_classes.cc new file mode 100644 index 000000000..b02fa5be3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/base_classes.cc @@ -0,0 +1,43 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.1 - Template class basic_filebuf + +#include + +void test01() +{ + // Check for required base class. + typedef std::filebuf test_type; + typedef std::streambuf base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..dee3b3b35 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/explicit_instantiation.cc @@ -0,0 +1,49 @@ +// { dg-do compile } +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include +#include +#include + +// test05 +// libstdc++/1886 +// should be able to instantiate basic_filebuf for non-standard types. +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_filebuf >; + template class basic_filebuf >; +} // test + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/typedefs.cc new file mode 100644 index 000000000..e3539806f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/typedefs.cc @@ -0,0 +1,48 @@ +// { dg-do compile } +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::filebuf test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc new file mode 100644 index 000000000..9e0814ff3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc @@ -0,0 +1,80 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc new file mode 100644 index 000000000..791a6dddb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc @@ -0,0 +1,93 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sbumpc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + int_type c5 = fb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( !fb_01.write_position() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc new file mode 100644 index 000000000..14235217b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sbumpc_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + int_type c2 = fb_02.sbumpc(); + VERIFY( c2 == traits_type::eof() ); + int_type c4 = fb_02.sbumpc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc new file mode 100644 index 000000000..acb517ebf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc @@ -0,0 +1,80 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc new file mode 100644 index 000000000..576dee3ed --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc @@ -0,0 +1,92 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sbumpc_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + int_type c5 = fb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc new file mode 100644 index 000000000..ccc650e02 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sbumpc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + int_type c2 = fb_02.sbumpc(); + VERIFY( c2 == traits_type::eof() ); + int_type c4 = fb_02.sbumpc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/9825.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/9825.cc new file mode 100644 index 000000000..50ff2e662 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/9825.cc @@ -0,0 +1,56 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +const char name_06[] = "filebuf_virtuals-6.txt"; // empty file, need to create + +// libstdc++/9825 +// filebuf::sputbackc breaks sbumpc +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf; + + fbuf.open(name_06, ios_base::in|ios_base::out|ios_base::trunc); + fbuf.sputn("crazy bees!", 11); + fbuf.pubseekoff(0, ios_base::beg); + fbuf.sbumpc(); + fbuf.sputbackc('x'); + filebuf::int_type c = fbuf.sbumpc(); + VERIFY( c == 'x' ); + c = fbuf.sbumpc(); + VERIFY( c == 'r' ); + c = fbuf.sbumpc(); + VERIFY( c == 'a' ); + fbuf.close(); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc new file mode 100644 index 000000000..008b56d21 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc @@ -0,0 +1,54 @@ +// 2003-04-24 bkoz + +// Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include +#include +#include + +// libstdc++/10132, add on +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_filebuf<__gnu_test::pod_ushort> gnu_filebuf; + + try + { + // Need codecvt facet for width argument in seekoff. + gnu_filebuf obj; + obj.pubseekoff(2, std::ios_base::beg); + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc new file mode 100644 index 000000000..14e0b0a3a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc @@ -0,0 +1,83 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from('a')); + fb.close(); + + fb.open(name, ios_base::in); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff calls codecvt::length with the correct state. + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + VERIFY( pos != traits_type::pos_type(traits_type::off_type(-1)) ); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + fb.sbumpc(); + fb.sbumpc(); + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + c = fb.sbumpc(); + VERIFY( c == traits_type::eof() ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc new file mode 100644 index 000000000..64ada570c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from('a')); + fb.close(); + + fb.open(name, ios_base::in); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff resets the state when seeking to beginning. + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::beg); + VERIFY( pos != traits_type::pos_type(traits_type::off_type(-1)) ); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from(0xff)) ); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + c = fb.sbumpc(); + VERIFY( c == traits_type::eof() ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc new file mode 100644 index 000000000..79cda63fe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from('b')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from(0xfc)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + + fb.close(); + fb.open(name, ios_base::in); + + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff returns the correct state + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + fb.sbumpc(); + + fb.pubseekpos(pos); + + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc new file mode 100644 index 000000000..3bf4353d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2003, 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from('b')); + fb.sputc(pod_uchar::from(0xff)); + + // Check that seekoff sets the current state during output + fb.pubseekoff(0, ios_base::cur); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + + fb.pubseekoff(0, ios_base::beg); + fb.sbumpc(); + fb.sbumpc(); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc new file mode 100644 index 000000000..6e40a89aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc @@ -0,0 +1,103 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include +#include + +const char name_01[] = "tmp_seekoff_45628.tst"; + +unsigned underflows, overflows; + +class my_filebuf +: public std::basic_filebuf<__gnu_test::pod_uchar> +{ + virtual int_type + underflow() + { + ++underflows; + return std::basic_filebuf<__gnu_test::pod_uchar>::underflow(); + } + virtual int_type + overflow(int_type c) + { + ++overflows; + return std::basic_filebuf<__gnu_test::pod_uchar>::overflow(c); + } +}; + +// libstdc++/45628 +void test01() +{ + bool test __attribute__((unused)) = true; + + using __gnu_test::pod_uchar; + std::locale loc(std::locale::classic(), + new std::codecvt); + + my_filebuf::pos_type opos[3], ipos[3]; + my_filebuf q; + q.pubimbue(loc); + + q.open(name_01, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + + q.sputc(pod_uchar::from('a')); + opos[0] = q.pubseekoff(0, std::ios_base::cur); + q.sputc(pod_uchar::from('b')); + opos[1] = q.pubseekoff(0, std::ios_base::cur); + q.sputc(pod_uchar::from('c')); + opos[2] = q.pubseekoff(0, std::ios_base::cur); + + VERIFY( overflows <= 9 ); // pubseekoff calls overflow twice if converting. + // NB: checking opos==ipos is not very rigorous as long as it flushes, since + // all positions will be at initial state. + q.pubseekoff(0, std::ios_base::beg); + + q.sbumpc(); + VERIFY( underflows == 1 ); + + ipos[0] = q.pubseekoff(0, std::ios_base::cur); + VERIFY( ipos[0] == opos[0] ); + q.sbumpc(); + ipos[1] = q.pubseekoff(0, std::ios_base::cur); + VERIFY( ipos[1] == opos[1] ); + q.sbumpc(); + ipos[2] = q.pubseekoff(0, std::ios_base::cur); + VERIFY( ipos[2] == opos[2] ); + + VERIFY( underflows == 1 ); // pubseekoff never flushes get area + + // Bonus test: check automatic mode switches. + q.sputc(pod_uchar::from('d')); + + q.pubseekpos( ipos[1] ); + q.sputc(pod_uchar::from('e')); + + VERIFY( my_filebuf::traits_type::eq( + my_filebuf::traits_type::to_char_type(q.sgetc()), + pod_uchar::from('d')) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc new file mode 100644 index 000000000..248874617 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc @@ -0,0 +1,124 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekoff.txt"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + + // in + { + constraint_filebuf fb; + fb.open(name_01, ios_base::in); + VERIFY( !fb.write_position() ); + + //beg + strmsz_1 = fb.in_avail(); + pt_1 = fb.pubseekoff(2, ios_base::beg); + fb.in_avail(); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '9' ); + fb.pubseekoff(3, ios_base::beg); + c2 = fb.sputc('\n'); //current in pointer +1 + fb.pubseekoff(4, ios_base::beg); + c3 = fb.sgetc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( c3 == '9' ); + fb.pubsync(); + c1 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //cur + pt_2 = fb.pubseekoff(2, ios_base::cur); + off_2 = off_type(pt_2); + VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '1' ); + fb.pubseekoff(0, ios_base::cur); + c2 = fb.sputc('x'); //test current out pointer + c3 = fb.sputc('\n'); + VERIFY( c2 == traits_type::eof() ); + VERIFY( c3 == traits_type::eof() ); + fb.pubseekoff(0, ios_base::cur); + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //end + pt_2 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends + c3 = fb.sputc('\n'); + strmsz_1 = fb.sputn("because because because. . .", 28); + VERIFY( strmsz_1 == 0 ); + fb.pubseekoff(-1, ios_base::end); + fb.sgetc(); + c1 = fb.sungetc(); + // Defect? retval of sungetc is not necessarily the character ungotten. + // So re-get it. + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + VERIFY( !fb.write_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc new file mode 100644 index 000000000..4dc6d8648 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc @@ -0,0 +1,124 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekoff-1io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + + // in | out + { + constraint_filebuf fb; + fb.open(name_01, ios_base::out | ios_base::in); + VERIFY( !fb.write_position() ); + VERIFY( !fb.read_position() ); + + //beg + strmsz_1 = fb.in_avail(); + pt_1 = fb.pubseekoff(2, ios_base::beg); + fb.in_avail(); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '9' ); + fb.pubseekoff(3, ios_base::beg); + c2 = fb.sputc('\n'); //current in pointer +1 + fb.pubseekoff(4, ios_base::beg); + c3 = fb.sgetc(); + VERIFY( c2 != c3 ); + VERIFY( c3 == '9' ); + fb.pubsync(); + c1 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //cur + pt_2 = fb.pubseekoff(2, ios_base::cur); + off_2 = off_type(pt_2); + VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '1' ); + fb.pubseekoff(0, ios_base::cur); + c2 = fb.sputc('x'); //test current out pointer + c3 = fb.sputc('\n'); + fb.pubseekoff(0, ios_base::cur); + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //end + pt_2 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends + c3 = fb.sputc('\n'); + strmsz_1 = fb.sputn("because because because. . .", 28); + VERIFY( strmsz_1 == 28 ); + fb.pubseekoff(-1, ios_base::end); + fb.sgetc(); + c1 = fb.sungetc(); + // Defect? retval of sungetc is not necessarily the character ungotten. + // So re-get it. + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + VERIFY( !fb.write_position() ); + VERIFY( fb.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc new file mode 100644 index 000000000..8d7ab1dfc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc @@ -0,0 +1,124 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekoff-1out.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + + // out + { + constraint_filebuf fb; + fb.open(name_01, ios_base::out); + VERIFY( !fb.write_position() ); + VERIFY( !fb.read_position() ); + + //beg + strmsz_1 = fb.in_avail(); + pt_1 = fb.pubseekoff(2, ios_base::beg); + fb.in_avail(); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + fb.pubseekoff(3, ios_base::beg); + c2 = fb.sputc('\n'); //current in pointer +1 + fb.pubseekoff(4, ios_base::beg); + c3 = fb.sgetc(); + VERIFY( c2 != c3 ); + VERIFY( c3 == traits_type::eof() ); + fb.pubsync(); + c1 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //cur + pt_2 = fb.pubseekoff(2, ios_base::cur); + off_2 = off_type(pt_2); + VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + fb.pubseekoff(0, ios_base::cur); + c2 = fb.sputc('x'); //test current out pointer + c3 = fb.sputc('\n'); + fb.pubseekoff(0, ios_base::cur); + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //end + pt_2 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends + c3 = fb.sputc('\n'); + strmsz_1 = fb.sputn("because because because. . .", 28); + VERIFY( strmsz_1 == 28 ); + fb.pubseekoff(-1, ios_base::end); + fb.sgetc(); + c1 = fb.sungetc(); + // Defect? retval of sungetc is not necessarily the character ungotten. + // So re-get it. + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + VERIFY( !fb.write_position() ); + VERIFY( !fb.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc new file mode 100644 index 000000000..2f6cf2988 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc @@ -0,0 +1,153 @@ +// Copyright (C) 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +struct MyState +{ +}; + +struct MyCharTraits : std::char_traits +{ + typedef std::fpos pos_type; + typedef MyState state_type; +}; + +namespace std +{ + template <> + class codecvt : + public locale::facet, public codecvt_base + { + public: + typedef char intern_type; + typedef char extern_type; + typedef MyState state_type; + + explicit codecvt(size_t refs = 0) + : locale::facet(refs) { } + + result out(state_type& state, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_limit, + extern_type*& to_next) const + { return do_out(state, from, from_end, from_next, + to, to_limit, to_next); } + + result unshift(state_type& state, extern_type* to, extern_type* to_limit, + extern_type*& to_next) const + { return do_unshift(state, to, to_limit, to_next); } + + result in(state_type& state, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_limit, + intern_type*& to_next) const + { return do_in(state, from, from_end, from_next, + to, to_limit, to_next); } + + int encoding() const throw() + { return do_encoding(); } + + bool always_noconv() const throw() + { return do_always_noconv(); } + + int length(state_type& state, const extern_type* from, + const extern_type* end, size_t max) const + { return do_length(state, from, end, max); } + + int max_length() const throw() + { return do_max_length(); } + + static locale::id id; + + protected: + virtual ~codecvt(); + + virtual result do_out(state_type&, const intern_type* from, + const intern_type*, const intern_type*& from_next, + extern_type* to, extern_type*, + extern_type*& to_next) const + { + from_next = from; + to_next = to; + return noconv; + } + + virtual result do_in(state_type&, const extern_type* from, + const extern_type*, const extern_type*& from_next, + intern_type* to, intern_type*, + intern_type*& to_next) const + { + from_next = from; + to_next = to; + return noconv; + } + + virtual result do_unshift(state_type&, extern_type*, extern_type*, + extern_type*&) const + { return noconv; } + + virtual int do_encoding() const throw() + { return 1; } + + virtual bool do_always_noconv() const throw() + { return true; } + + virtual int do_length(state_type&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = end - from; + return std::min(max, len); + } + + virtual int do_max_length() const throw() + { return 1; } + }; + + locale::id codecvt::id; + + codecvt::~codecvt() + { } +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::locale loc(std::locale::classic(), + new std::codecvt); + std::basic_filebuf fb; + fb.pubimbue(loc); + fb.open("tmp_11543", std::ios_base::out); + VERIFY( fb.is_open() ); + MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg); + VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc new file mode 100644 index 000000000..a60293274 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +const char name[] = "tmp_12232"; + +// libstdc++/12232 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name, ios_base::out); + fbout.sputn("abc", 3); + + streampos p1 = fbout.pubseekoff(0, ios_base::cur, ios_base::in); + VERIFY( p1 != streampos(-1) ); + fbout.sputn("de", 2); + + streampos p2 = fbout.pubseekpos(p1, ios_base::openmode()); + VERIFY( p2 != streampos(-1) ); + fbout.sputn("34", 2); + + streampos p3 = fbout.pubseekoff(0, ios_base::beg, ios_base::ate); + VERIFY( p3 != streampos(-1) ); + fbout.sputn("012", 3); + + fbout.close(); + + filebuf fbin; + fbin.open(name, ios_base::in); + + streampos p4 = fbin.pubseekoff(0, ios_base::beg, ios_base::ate); + VERIFY( p4 != streampos(-1) ); + VERIFY( fbin.sgetc() == '0' ); + + streampos p5 = fbin.pubseekoff(-1, ios_base::end, ios_base::out); + VERIFY( p5 != streampos(-1) ); + VERIFY( fbin.sbumpc() == '4' ); + + streampos p6 = fbin.pubseekpos(p4, ios_base::binary); + VERIFY( p6 != streampos(-1) ); + VERIFY( fbin.sbumpc() == '0' ); + + fbin.close(); +} + +int main() +{ + void test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc new file mode 100644 index 000000000..d2860cbf5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc new file mode 100644 index 000000000..f0f1b9938 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc new file mode 100644 index 000000000..026d75029 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift(), +// but only if writing +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( !cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc new file mode 100644 index 000000000..60813c899 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc new file mode 100644 index 000000000..3a8809da2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc @@ -0,0 +1,125 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekoff.txt"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + + // in + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::in); + VERIFY( fb.unbuffered() ); + + //beg + strmsz_1 = fb.in_avail(); + pt_1 = fb.pubseekoff(2, ios_base::beg); + fb.in_avail(); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '9' ); + fb.pubseekoff(3, ios_base::beg); + c2 = fb.sputc('\n'); //current in pointer +1 + fb.pubseekoff(4, ios_base::beg); + c3 = fb.sgetc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( c3 == '9' ); + fb.pubsync(); + c1 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //cur + pt_2 = fb.pubseekoff(2, ios_base::cur); + off_2 = off_type(pt_2); + VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '1' ); + fb.pubseekoff(0, ios_base::cur); + c2 = fb.sputc('x'); //test current out pointer + c3 = fb.sputc('\n'); + VERIFY( c2 == traits_type::eof() ); + VERIFY( c3 == traits_type::eof() ); + fb.pubseekoff(0, ios_base::cur); + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //end + pt_2 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends + c3 = fb.sputc('\n'); + strmsz_1 = fb.sputn("because because because. . .", 28); + VERIFY( strmsz_1 == 0 ); + fb.pubseekoff(-1, ios_base::end); + fb.sgetc(); + c1 = fb.sungetc(); + // Defect? retval of sungetc is not necessarily the character ungotten. + // So re-get it. + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + VERIFY( fb.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc new file mode 100644 index 000000000..89fab2aed --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc @@ -0,0 +1,123 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekoff-2io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + + // in | out + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::out | ios_base::in); + VERIFY( fb.unbuffered() ); + + //beg + strmsz_1 = fb.in_avail(); + pt_1 = fb.pubseekoff(2, ios_base::beg); + fb.in_avail(); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '9' ); + fb.pubseekoff(3, ios_base::beg); + c2 = fb.sputc('\n'); //current in pointer +1 + fb.pubseekoff(4, ios_base::beg); + c3 = fb.sgetc(); + VERIFY( c2 != c3 ); + VERIFY( c3 == '9' ); + fb.pubsync(); + c1 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //cur + pt_2 = fb.pubseekoff(2, ios_base::cur); + off_2 = off_type(pt_2); + VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == '1' ); + fb.pubseekoff(0, ios_base::cur); + c2 = fb.sputc('x'); //test current out pointer + c3 = fb.sputc('\n'); + fb.pubseekoff(0, ios_base::cur); + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //end + pt_2 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends + c3 = fb.sputc('\n'); + strmsz_1 = fb.sputn("because because because. . .", 28); + VERIFY( strmsz_1 == 28 ); + fb.pubseekoff(-1, ios_base::end); + fb.sgetc(); + c1 = fb.sungetc(); + // Defect? retval of sungetc is not necessarily the character ungotten. + // So re-get it. + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + VERIFY( fb.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc new file mode 100644 index 000000000..b1ad66e89 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc @@ -0,0 +1,123 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekoff-2out.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + + // out + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::out); + VERIFY( fb.unbuffered() ); + + //beg + strmsz_1 = fb.in_avail(); + pt_1 = fb.pubseekoff(2, ios_base::beg); + fb.in_avail(); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + fb.pubseekoff(3, ios_base::beg); + c2 = fb.sputc('\n'); //current in pointer +1 + fb.pubseekoff(4, ios_base::beg); + c3 = fb.sgetc(); + VERIFY( c2 != c3 ); + VERIFY( c3 == traits_type::eof() ); + fb.pubsync(); + c1 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //cur + pt_2 = fb.pubseekoff(2, ios_base::cur); + off_2 = off_type(pt_2); + VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + fb.pubseekoff(0, ios_base::cur); + c2 = fb.sputc('x'); //test current out pointer + c3 = fb.sputc('\n'); + fb.pubseekoff(0, ios_base::cur); + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + + //end + pt_2 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends + c3 = fb.sputc('\n'); + strmsz_1 = fb.sputn("because because because. . .", 28); + VERIFY( strmsz_1 == 28 ); + fb.pubseekoff(-1, ios_base::end); + fb.sgetc(); + c1 = fb.sungetc(); + // Defect? retval of sungetc is not necessarily the character ungotten. + // So re-get it. + c1 = fb.sgetc(); + fb.pubsync(); + c3 = fb.sgetc(); + VERIFY( c1 == c3 ); + VERIFY( fb.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc new file mode 100644 index 000000000..d98234bab --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc @@ -0,0 +1,90 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2006-03-22 Paolo Carlini + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// libstdc++/26777 +bool test01() +{ + using namespace std; + using namespace __gnu_test; + + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo6"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1, s2; + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + filebuf fbout; + fbout.open(name, ios_base::in | ios_base::out); + VERIFY( fbout.is_open() ); + fbout.sputn("Whatever", 8); + fbout.pubsync(); + s1.signal(); + s2.wait(); + fbout.close(); + s1.signal(); + exit(0); + } + + filebuf fbin; + fbin.open(name, ios::in); + s1.wait(); + + fbin.sgetc(); + fbin.pubseekoff(0, ios::cur, ios::in); + s2.signal(); + s1.wait(); + + ostringstream oss; + oss << &fbin; + fbin.close(); + + VERIFY( oss.str() == "Whatever" ); + + return test; +} + +int main() +{ + return !test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc new file mode 100644 index 000000000..a0c4d5a86 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.1.3 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test02(std::filebuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekoff + p = in.pubseekoff(0, ios_base::beg, ios_base::in); + VERIFY( pass == (p != bad) ); + + p = in.pubseekoff(0, ios_base::beg, ios_base::out); + VERIFY( pass == (p != bad) ); // See libstdc++/12232 + + p = in.pubseekoff(0, ios_base::beg); + VERIFY( pass == (p != bad) ); +} + +const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it +const char name_03[] = "filebuf_members-1.tst"; // empty file + +int main() +{ + using namespace std; + + filebuf in1; + in1.open(name_01, ios_base::in); + filebuf in2; + filebuf in3; + in3.open(name_03, ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, true); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc new file mode 100644 index 000000000..803a81f27 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.1.3 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test02(std::filebuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekoff + p = in.pubseekoff(0, ios_base::beg, ios_base::in); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekoff(0, ios_base::beg, ios_base::out); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekoff(0, ios_base::beg); + if (pass) + VERIFY( p != bad ); +} + +const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it +const char name_03[] = "filebuf_members-1.tst"; // empty file + +int main() +{ + using namespace std; + + filebuf in1; + in1.open(name_01, ios_base::in | ios_base::out); + filebuf in2; + filebuf in3; + in3.open(name_03, ios_base::in | ios_base::out); + test02(in1, true); + test02(in2, false); + test02(in3, true); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc new file mode 100644 index 000000000..08eac2933 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.1.3 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test02(std::filebuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekoff + p = in.pubseekoff(0, ios_base::beg, ios_base::in); + VERIFY( pass == (p != bad) ); // See libstdc++/12232 + + p = in.pubseekoff(0, ios_base::beg, ios_base::out); + VERIFY( pass == (p != bad) ); + + p = in.pubseekoff(0, ios_base::beg); + VERIFY( pass == (p != bad) ); +} + +const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it +const char name_03[] = "filebuf_members-1.tst"; // empty file + +int main() +{ + using namespace std; + + filebuf out1; + out1.open(name_01, ios_base::out); + filebuf out2; + filebuf out3; + out3.open(name_03, ios_base::out); + test02(out1, true); + test02(out2, false); + test02(out3, true); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc new file mode 100644 index 000000000..fe21b3a88 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc @@ -0,0 +1,93 @@ +// { dg-require-fileio "" } + +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef filebuf::pos_type pos_type; + const char name[] = "tmp_seekoff-4.tst"; + + const size_t size = 12; + char buf[size]; + streamsize n; + + filebuf fb; + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + n = fb.sputn("abcd", 4); + VERIFY( n == 4 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 3); + VERIFY( n == 3 ); + VERIFY( !memcmp(buf, "abc", 3) ); + + // Check read => write without pubseekoff(0, ios_base::cur) + + n = fb.sputn("ef", 2); + VERIFY( n == 2 ); + + fb.pubseekoff(0, ios_base::beg); + + n = fb.sgetn(buf, size); + VERIFY( n == 5 ); + VERIFY( !memcmp(buf, "abcef", 5) ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sputn("gh", 2); + VERIFY( n == 2 ); + + // Check write => read without pubseekoff(0, ios_base::cur) + + n = fb.sgetn( buf, 3 ); + VERIFY( !memcmp(buf, "cef", 3) ); + + n = fb.sputn("ijkl", 4); + VERIFY( n == 4 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 2); + VERIFY( n == 2 ); + VERIFY( !memcmp(buf, "gh", 2) ); + + fb.pubseekoff(0, ios_base::end); + n = fb.sputn("mno", 3); + VERIFY( n == 3 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, size); + VERIFY( n == 12 ); + VERIFY( !memcmp(buf, "ghcefijklmno", 12) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc new file mode 100644 index 000000000..a80a33876 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "tmp_seekoff_45628.tst"; + +unsigned underflows, overflows; + +class my_filebuf +: public std::filebuf +{ + virtual int_type + underflow() + { + ++underflows; + return std::filebuf::underflow(); + } + virtual int_type + overflow(int_type c) + { + ++overflows; + return std::filebuf::overflow(c); + } +}; + +// libstdc++/45628 +void test01() +{ + bool test __attribute__((unused)) = true; + + my_filebuf q; + q.open(name_01, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + + q.sputc('a'); + q.pubseekoff(0, std::ios_base::cur); + q.sputc('b'); + q.pubseekoff(0, std::ios_base::cur); + q.sputc('c'); + q.pubseekoff(0, std::ios_base::cur); + + VERIFY( overflows <= 1 ); // only initial sputc allowed to overflow + q.pubseekoff(0, std::ios_base::beg); + + q.sbumpc(); + VERIFY( underflows == 1 ); + + q.pubseekoff(0, std::ios_base::cur); + q.sbumpc(); + q.pubseekoff(0, std::ios_base::cur); + q.sbumpc(); + q.pubseekoff(0, std::ios_base::cur); + + VERIFY( underflows == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc new file mode 100644 index 000000000..c6f13dcd0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc @@ -0,0 +1,137 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-08 Petur Runolfsson + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Check that basic_filebuf::seekoff handles UTF-8 when open for input. +void test01() +{ + using namespace std; + typedef wfilebuf::pos_type pos_type; + typedef wfilebuf::int_type int_type; + + bool test __attribute__((unused)) = true; + const char name[] = "tmp_seekoff-1.tst"; + const int_type eof = wfilebuf::traits_type::eof(); + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + const int loops = 2 * BUFSIZ / wlen; + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + for (int i = 0; i < loops; ++i) + fwrite(cstr, 1, clen, file); + fclose(file); + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + + pos_type p1 = fb.pubseekoff(0, ios_base::cur); + pos_type end = fb.pubseekoff(0, ios_base::end); + pos_type beg = fb.pubseekoff(0, ios_base::beg); + VERIFY( p1 == beg ); + + const size_t limit = wlen * loops; + for (size_t index = 0; index < limit; ++index) + { + // Call seekoff at pseudo-random intervals. + if (index % 5 == 0 || index % 7 == 0) + { + pos_type p2 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p2 != pos_type(-1) ); + } + int_type c1 = fb.sbumpc(); + VERIFY( c1 != eof ); + VERIFY( static_cast(c1) == wstr[index % wlen] ); + } + + pos_type p3 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p3 == end ); + + int_type c2 = fb.sbumpc(); + VERIFY( c2 == eof ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc new file mode 100644 index 000000000..fd0c19ea3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc @@ -0,0 +1,141 @@ +// Copyright (C) 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +struct MyState +{ +}; + +struct MyCharTraits : std::char_traits +{ + typedef std::fpos pos_type; + typedef MyState state_type; +}; + +namespace std +{ + template <> + class codecvt : + public locale::facet, public codecvt_base + { + public: + typedef wchar_t intern_type; + typedef char extern_type; + typedef MyState state_type; + + explicit codecvt(size_t refs = 0) + : locale::facet(refs) { } + + result out(state_type& state, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_limit, + extern_type*& to_next) const + { return do_out(state, from, from_end, from_next, + to, to_limit, to_next); } + + result unshift(state_type& state, extern_type* to, extern_type* to_limit, + extern_type*& to_next) const + { return do_unshift(state, to, to_limit, to_next); } + + result in(state_type& state, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_limit, + intern_type*& to_next) const + { return do_in(state, from, from_end, from_next, + to, to_limit, to_next); } + + int encoding() const throw() + { return do_encoding(); } + + bool always_noconv() const throw() + { return do_always_noconv(); } + + int length(state_type& state, const extern_type* from, + const extern_type* end, size_t max) const + { return do_length(state, from, end, max); } + + int max_length() const throw() + { return do_max_length(); } + + static locale::id id; + + protected: + virtual ~codecvt(); + + virtual result do_out(state_type&, const intern_type*, + const intern_type*, const intern_type*&, + extern_type*, extern_type*, extern_type*&) const + { return error; } + + virtual result do_in(state_type&, const extern_type*, const extern_type*, + const extern_type*&, intern_type*, intern_type*, + intern_type*&) const + { return error; } + + virtual result do_unshift(state_type&, extern_type*, extern_type*, + extern_type*&) const + { return noconv; } + + virtual int do_encoding() const throw() + { return 1; } + + virtual bool do_always_noconv() const throw() + { return false; } + + virtual int do_length(state_type&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = end - from; + return std::min(max, len); + } + + virtual int do_max_length() const throw() + { return 1; } + }; + + locale::id codecvt::id; + + codecvt::~codecvt() + { } +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::locale loc(std::locale::classic(), + new std::codecvt); + std::basic_filebuf fb; + fb.pubimbue(loc); + fb.open("tmp_11543", std::ios_base::out); + VERIFY( fb.is_open() ); + MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg); + VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc new file mode 100644 index 000000000..b889f1bf5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc new file mode 100644 index 000000000..d38952586 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc new file mode 100644 index 000000000..4057cd418 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift(), +// but only if writing +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( !cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc new file mode 100644 index 000000000..c04b4e79b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekoff() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.pubseekoff(0, ios_base::cur); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc new file mode 100644 index 000000000..cc9c4e22a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc @@ -0,0 +1,90 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-08 Petur Runolfsson + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Check that basic_filebuf::seekoff handles UTF-8 when open for input and +// output. +void test02() +{ + using namespace std; + typedef wfilebuf::int_type int_type; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_seekoff-2.tst"; + + locale loc = locale("se_NO.UTF-8"); + + const size_t size = 10; + wchar_t buf[size]; + streamsize n; + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + n = fb.sputn(L"\xa0st", 3); + VERIFY( n == 3 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 2); + VERIFY( n == 2 ); + VERIFY( !wmemcmp(buf, L"\xa0s", 2) ); + + fb.pubseekoff(0, ios_base::cur); + n = fb.sputn(L"\xb2R", 2); + VERIFY( n == 2 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, size); + VERIFY( n == 4 ); + VERIFY( !wmemcmp(buf, L"\xa0s\xb2R", 4) ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sputn(L"\x90m\x92n\x94", 5); + VERIFY( n == 5 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 2); + VERIFY( n == 2 ); + VERIFY( !wmemcmp(buf, L"\x90m", 2) ); + + fb.pubseekoff(0, ios_base::end); + n = fb.sputn(L"I\xbfJ", 3); + VERIFY( n == 3 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, size); + VERIFY( n == 8 ); + VERIFY( !wmemcmp(buf, L"\x90m\x92n\x94I\xbfJ", 8) ); + + fb.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc new file mode 100644 index 000000000..435ebcc3e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_seekoff_3"; + + wfilebuf fb; + + fb.open(name, ios_base::out); + fb.sputc(0xf001); + + try + { + // seekoff should flush the output sequence, which will fail + // if the output buffer contains illegal characters. + fb.pubseekoff(0, ios_base::cur); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc new file mode 100644 index 000000000..245f18f48 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc @@ -0,0 +1,94 @@ +// { dg-require-fileio "" } + +// Copyright (C) 2010, 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef wfilebuf::pos_type pos_type; + const char name[] = "tmp_seekoff-4.tst"; + + const size_t size = 12; + wchar_t buf[size]; + streamsize n; + + wfilebuf fb; + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + n = fb.sputn(L"abcd", 4); + VERIFY( n == 4 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 3); + VERIFY( n == 3 ); + VERIFY( !wmemcmp(buf, L"abc", 3) ); + + // Check read => write without pubseekoff(0, ios_base::cur) + + n = fb.sputn(L"ef", 2); + VERIFY( n == 2 ); + + fb.pubseekoff(0, ios_base::beg); + + n = fb.sgetn(buf, size); + VERIFY( n == 5 ); + VERIFY( !wmemcmp(buf, L"abcef", 5) ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sputn(L"gh", 2); + VERIFY( n == 2 ); + + // Check write => read without pubseekoff(0, ios_base::cur) + + n = fb.sgetn( buf, 3 ); + VERIFY( !memcmp(buf, L"cef", 3) ); + + n = fb.sputn(L"ijkl", 4); + VERIFY( n == 4 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 2); + VERIFY( n == 2 ); + VERIFY( !wmemcmp(buf, L"gh", 2) ); + + fb.pubseekoff(0, ios_base::end); + n = fb.sputn(L"mno", 3); + VERIFY( n == 3 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, size); + VERIFY( n == 12 ); + VERIFY( !wmemcmp(buf, L"ghcefijklmno", 12) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc new file mode 100644 index 000000000..312386a24 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include + +class Cvt : public std::codecvt +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, + const wchar_t*& from_next, char* to, char* to_end, + char*& to_next) const + { + std::size_t from_len = from_end - from; + std::size_t to_len = (to_end - to) / sizeof(wchar_t); + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len; + to_next = to + len * sizeof(wchar_t); + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_in(std::mbstate_t&, const char* from, const char* from_end, + const char*& from_next, wchar_t* to, wchar_t* to_end, + wchar_t*& to_next) const + { + std::size_t from_len = + (from_end - from) / sizeof(wchar_t); + std::size_t to_len = to_end - to; + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len * sizeof(wchar_t); + to_next = to + len; + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_unshift(std::mbstate_t&, char*, char*, char*&) const + { return std::codecvt_base::noconv; } + + virtual int do_encoding() const throw() { return sizeof(wchar_t); } + virtual bool do_always_noconv() const throw() { return false; } + + virtual int + do_length(std::mbstate_t&, const char* from, const char* end, + std::size_t max) + { + std::size_t len = (end - from) / sizeof(wchar_t); + return std::min(len, max) * sizeof(wchar_t); + } + + virtual int do_max_length() const throw() { return sizeof(wchar_t); } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // seekoff + wfilebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_9875_seekoff", ios_base::out | ios_base::in | ios_base::trunc); + fb.sputn(L"0123456789", 10); + fb.pubseekoff(-3, ios_base::cur); + VERIFY( fb.sgetc() == L'7' ); + fb.pubseekoff(-3, ios_base::cur); + VERIFY( fb.sgetc() == L'4' ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/10132-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/10132-3.cc new file mode 100644 index 000000000..34d437925 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/10132-3.cc @@ -0,0 +1,54 @@ +// 2003-04-24 bkoz + +// Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include +#include +#include + +// libstdc++/10132, add on +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_filebuf<__gnu_test::pod_ushort> gnu_filebuf; + + try + { + // Need codecvt facet for width argument in seekpos. + gnu_filebuf obj; + obj.pubseekpos(0); + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-1.cc new file mode 100644 index 000000000..ffe5aa726 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-1.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + + // Check that seekpos restores the state correctly + fb.pubseekpos(pos); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-2.cc new file mode 100644 index 000000000..8b7050965 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-2.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from('b')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from(0xfc)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + + fb.close(); + fb.open(name, ios_base::in); + + fb.sbumpc(); + fb.sbumpc(); + traits_type::pos_type pos1 = fb.pubseekoff(0, ios_base::cur); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekpos returns the correct state + traits_type::pos_type pos2 = fb.pubseekpos(pos1); + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + fb.sbumpc(); + + fb.pubseekpos(pos2); + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-3.cc new file mode 100644 index 000000000..79337d381 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-3.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from('b')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from('c')); + fb.sputc(pod_uchar::from(0xff)); + + fb.pubseekoff(0, ios_base::beg); + fb.sbumpc(); + fb.sbumpc(); + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff sets the current state for output + fb.pubseekpos(pos); + + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + fb.sputc(pod_uchar::from(0)); + + fb.pubseekpos(pos); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc new file mode 100644 index 000000000..da5a80b4b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc @@ -0,0 +1,103 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in + { + constraint_filebuf fb; + fb.open(name_01, ios_base::in); + VERIFY( !fb.write_position() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == traits_type::eof() ); + VERIFY( c2 != c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( !fb.write_position() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc new file mode 100644 index 000000000..c90de5e31 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc @@ -0,0 +1,103 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-1io.tst"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + + bool test __attribute__((unused)) = true; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in | out + { + constraint_filebuf fb; + fb.open(name_01, ios_base::out | ios_base::in); + VERIFY( !fb.write_position() ); + VERIFY( !fb.read_position() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.write_position() ); + VERIFY( !fb.read_position() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc new file mode 100644 index 000000000..0b596a451 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc @@ -0,0 +1,105 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-1out.tst"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // out + { + constraint_filebuf fb; + fb.open(name_01, ios_base::out); + VERIFY( !fb.write_position() ); + VERIFY( !fb.read_position() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 != c3 ); + VERIFY( c3 == traits_type::eof() ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.write_position() ); + VERIFY( !fb.read_position() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-1.cc new file mode 100644 index 000000000..1a024941f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-1.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-2.cc new file mode 100644 index 000000000..b0085e29e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-2.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-3.cc new file mode 100644 index 000000000..0eb3ecf80 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-3.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift(), +// but only if writing +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( !cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-4.cc new file mode 100644 index 000000000..506482bd6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-4.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc('a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc new file mode 100644 index 000000000..782fb6bb8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc @@ -0,0 +1,104 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::in); + VERIFY( fb.unbuffered() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == traits_type::eof() ); + VERIFY( c2 != c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.unbuffered() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc new file mode 100644 index 000000000..4916d6059 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc @@ -0,0 +1,102 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-2io.tst"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + + bool test __attribute__((unused)) = true; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in | out + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::out | ios_base::in); + VERIFY( fb.unbuffered() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.unbuffered() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc new file mode 100644 index 000000000..9031bca6c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc @@ -0,0 +1,104 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-2out.tst"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // out + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::out); + VERIFY( fb.unbuffered() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 != c3 ); + VERIFY( c3 == traits_type::eof() ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.unbuffered() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc new file mode 100644 index 000000000..278d39e72 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.1.3 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test02(std::filebuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + VERIFY( pass == (p != bad) ); + + p = in.pubseekpos(0, ios_base::out); + VERIFY( pass == (p != bad) ); // See libstdc++/12232 + + p = in.pubseekpos(0); + VERIFY( pass == (p != bad) ); +} + +const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it +const char name_03[] = "filebuf_members-1.tst"; // empty file + +int main() +{ + using namespace std; + + filebuf in1; + in1.open(name_01, ios_base::in); + filebuf in2; + filebuf in3; + in3.open(name_03, ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, true); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc new file mode 100644 index 000000000..3f37a266a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.1.3 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test02(std::filebuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekpos(0, ios_base::out); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekpos(0); + if (pass) + VERIFY( p != bad ); +} + +const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it +const char name_03[] = "filebuf_members-1.tst"; // empty file + +int main() +{ + using namespace std; + + filebuf in1; + in1.open(name_01, ios_base::in | ios_base::out); + filebuf in2; + filebuf in3; + in3.open(name_03, ios_base::in | ios_base::out); + test02(in1, true); + test02(in2, false); + test02(in3, true); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-out.cc new file mode 100644 index 000000000..07bdc0cae --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-out.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.7.1.3 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test02(std::filebuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + VERIFY( pass == (p != bad) ); // See libstdc++/12232 + + p = in.pubseekpos(0, ios_base::out); + VERIFY( pass == (p != bad) ); + + p = in.pubseekpos(0); + VERIFY( pass == (p != bad) ); +} + +const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it +const char name_03[] = "filebuf_members-1.tst"; // empty file + +int main() +{ + using namespace std; + + filebuf out1; + out1.open(name_01, ios_base::out); + filebuf out2; + filebuf out3; + out3.open(name_03, ios_base::out); + test02(out1, true); + test02(out2, false); + test02(out3, true); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/1.cc new file mode 100644 index 000000000..320938319 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/1.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_seekpos_1"; + + wfilebuf fb; + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(0xf001); + + try + { + fb.pubseekpos(pos); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc new file mode 100644 index 000000000..55325875a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-2.cc new file mode 100644 index 000000000..e939050a4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-2.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc new file mode 100644 index 000000000..a1afdcad2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift(), +// but only if writing +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( !cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-4.cc new file mode 100644 index 000000000..57a9a3c02 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-4.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(L'a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc new file mode 100644 index 000000000..e011f875d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc @@ -0,0 +1,139 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-10-07 Petur Runolfsson +// +// Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include + +// libstdc++/9874 +void test01() +{ + using namespace std; + typedef wfilebuf::pos_type pos_type; + typedef wfilebuf::int_type int_type; + typedef vector > vec_type; + + bool test __attribute__((unused)) = true; + const char name[] = "tmp_seekpos-9874.tst"; + const int_type eof = wfilebuf::traits_type::eof(); + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + const int loops = 2 * BUFSIZ / wlen; + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + for (int i = 0; i < loops; ++i) + fwrite(cstr, 1, clen, file); + fclose(file); + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + + vec_type vec; + + const size_t limit = wlen * loops; + for (size_t index = 0; index < limit; ++index) + { + // Call seekoff at pseudo-random intervals. + if (index % 5 == 0 || index % 7 == 0) + { + pos_type p1 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p1 != pos_type(-1) ); + vec.push_back(make_pair(p1, index)); + } + int_type c1 = fb.sbumpc(); + VERIFY( c1 != eof ); + } + + for (vec_type::iterator it = vec.begin(); it != vec.end(); ++it) + { + pos_type p2 = fb.pubseekpos(it->first); + VERIFY( p2 == it->first ); + int_type c2 = fb.sbumpc(); + VERIFY( c2 != eof ); + VERIFY( static_cast(c2) == wstr[it->second % wlen] ); + } + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc new file mode 100644 index 000000000..501ce1fda --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc @@ -0,0 +1,111 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include + +class Cvt : public std::codecvt +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, + const wchar_t*& from_next, char* to, char* to_end, + char*& to_next) const + { + std::size_t from_len = from_end - from; + std::size_t to_len = (to_end - to) / sizeof(wchar_t); + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len; + to_next = to + len * sizeof(wchar_t); + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_in(std::mbstate_t&, const char* from, const char* from_end, + const char*& from_next, wchar_t* to, wchar_t* to_end, + wchar_t*& to_next) const + { + std::size_t from_len = + (from_end - from) / sizeof(wchar_t); + std::size_t to_len = to_end - to; + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len * sizeof(wchar_t); + to_next = to + len; + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_unshift(std::mbstate_t&, char*, char*, char*&) const + { return std::codecvt_base::noconv; } + + virtual int do_encoding() const throw() { return sizeof(wchar_t); } + virtual bool do_always_noconv() const throw() { return false; } + + virtual int + do_length(std::mbstate_t&, const char* from, const char* end, + std::size_t max) + { + std::size_t len = (end - from) / sizeof(wchar_t); + return std::min(len, max) * sizeof(wchar_t); + } + + virtual int do_max_length() const throw() { return sizeof(wchar_t); } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // seekpos + wfilebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_9875_seekpos", ios_base::out | ios_base::in | ios_base::trunc); + fb.sputn(L"0123456789", 10); + + streampos p1 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p1 != streampos(-1) ); + fb.sputc(L'a'); + + streampos p2 = fb.pubseekpos(p1); + VERIFY( p2 != streampos(-1) ); + VERIFY( p2 == p1 ); + VERIFY( fb.sgetc() == L'a' ); + + fb.pubseekoff(0, ios_base::beg); + wchar_t buf[11]; + streamsize s1 = fb.sgetn(buf, 11); + VERIFY( s1 == 11 ); + VERIFY( !wmemcmp(buf, L"0123456789a", 11) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc new file mode 100644 index 000000000..42688e825 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc @@ -0,0 +1,89 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +class testbuf : public std::filebuf +{ +public: + + // Typedefs: + typedef std::filebuf base_type; + typedef base_type::traits_type traits_type; + typedef base_type::char_type char_type; + + testbuf(): base_type() + { _M_mode = (std::ios_base::in | std::ios_base::out); } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + test = (!this->pbase()); + test &= (!this->pptr()); + return test; + } +}; + +const char name_01[] = "filebuf_virtuals-1.txt"; + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + typedef std::filebuf::int_type int_type; + typedef std::filebuf::traits_type traits_type; + typedef std::filebuf::pos_type pos_type; + typedef std::filebuf::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + + { + testbuf f_tmp; + + // setbuf + // pubsetbuf(char_type* s, streamsize n) + f_tmp.pubsetbuf(0,0); + VERIFY( f_tmp.check_pointers() ); + } + + { + testbuf f_tmp; + + f_tmp.open(name_01, ios_base::out | ios_base::in); + f_tmp.sbumpc(); + + // setbuf + // pubsetbuf(char_type* s, streamsize n) + f_tmp.pubsetbuf(0, 0); + VERIFY( f_tmp.check_pointers() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-1.cc new file mode 100644 index 000000000..ed567de1b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-1.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12875 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_setbuf4"; + static char buf[1024]; + + FILE* out = fopen(name, "w"); + fputs("Hello, world", out); + fclose(out); + + filebuf in; + in.open(name, ios_base::in); + char str[256]; + streamsize r = in.sgetn(str, 6); + VERIFY( r == 6 ); + VERIFY( !memcmp(str, "Hello,", 6) ); + in.pubsetbuf(buf, 1024); + r = in.sgetn(str, 6); + VERIFY( r == 6 ); + VERIFY( !memcmp(str, " world", 6) ); + in.close(); +} + +// libstdc++/12875 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc new file mode 100644 index 000000000..b736b1460 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12875 +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_setbuf5"; + static char buf[1024]; + + filebuf out; + out.open(name, ios_base::out); + streamsize r = out.sputn("Hello,", 6); + VERIFY( r == 6 ); + out.pubsetbuf(buf, 1024); + r = out.sputn(" world", 6); + VERIFY( r == 6 ); + VERIFY( out.close() ); + + FILE* in = fopen(name, "r"); + char str[256]; + VERIFY( fgets(str, 256, in) ); + VERIFY( !strcmp(str, "Hello, world") ); + fclose(in); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/2.cc new file mode 100644 index 000000000..768285d75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/2.cc @@ -0,0 +1,48 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + filebuf fbuf; + fbuf.pubsetbuf(buf, 512); + fbuf.open("tmp_setbuf2", ios_base::out); + fbuf.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/3.cc new file mode 100644 index 000000000..bdb3989c3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/3.cc @@ -0,0 +1,51 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +void test03() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + filebuf fbuf01; + // NB: +2 otherwise sputn is optimized to a direct write, + // bypassing the buffer. + fbuf01.pubsetbuf(buf, strlitsize + 2); + fbuf01.open("tmp_setbuf3", ios_base::out); + + fbuf01.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc new file mode 100644 index 000000000..3defffccf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc new file mode 100644 index 000000000..306f93af7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc @@ -0,0 +1,87 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sgetc_1io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in | out 1 + { + constraint_filebuf fb_03; // in | out + fb_03.open(name_03, ios::out | ios::in | ios::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c1 = fb_03.sgetc(); + c2 = fb_03.sbumpc(); + VERIFY( c1 == traits_type::eof() ); + VERIFY( c1 == c2 ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in | ios::out); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc new file mode 100644 index 000000000..32bc8092d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetc_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // out + { + constraint_filebuf fb_02; // out + fb_02.open(name_02, ios::out | ios::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + fb_02.sbumpc(); + c1 = fb_02.sbumpc(); + c2 = fb_02.sgetc(); + VERIFY( c1 == c2 ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc new file mode 100644 index 000000000..d3c179786 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in + { + constraint_filebuf fb_01; // in + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc new file mode 100644 index 000000000..6f162c9f8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc @@ -0,0 +1,86 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_sgetc_2io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in | out 1 + { + constraint_filebuf fb_03; // in | out + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios::out | ios::in | ios::trunc); + VERIFY( fb_03.unbuffered() ); + c1 = fb_03.sgetc(); + c2 = fb_03.sbumpc(); + VERIFY( c1 == traits_type::eof() ); + VERIFY( c1 == c2 ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; // in + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in | ios::out); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc new file mode 100644 index 000000000..04ea095dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetc_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // out + { + constraint_filebuf fb_02; // out + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios::out | ios::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + fb_02.sbumpc(); + c1 = fb_02.sbumpc(); + c2 = fb_02.sgetc(); + VERIFY( c1 == c2 ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc new file mode 100644 index 000000000..47c0597cb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc @@ -0,0 +1,92 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + char buffer[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in + { + constraint_filebuf fb_01; + // Need this since BUFSIZ is only guaranteed >= 255 and we want + // to trigger the same underflow situation everywhere. + fb_01.pubsetbuf(buffer, 8192); + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.in_avail(); // 8261 + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc new file mode 100644 index 000000000..ffcdc2c14 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc @@ -0,0 +1,105 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it +const char name_03[] = "tmp_sgetn_1io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + char buffer[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + strmsz_1 = fb_03.sgetn(carray1, 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + // Need this since BUFSIZ is only guaranteed >= 255 and we want + // to trigger the same underflow situation everywhere. + fb_01.pubsetbuf(buffer, 8192); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc new file mode 100644 index 000000000..c9da66539 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc @@ -0,0 +1,76 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetn_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray2[8192] = ""; + int_type c2, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + strmsz_2 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, 10); + VERIFY( strmsz_2 == 0 ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + strmsz_1 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == -1 ); + VERIFY( strmsz_2 == 0 ); + c4 = fb_02.sgetc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc new file mode 100644 index 000000000..dda7c67e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc @@ -0,0 +1,88 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); // 8181 or 8250 depending on buffer + strmsz_2 = fb_01.sgetn(carray2, 8181 + 5); + VERIFY( 8181 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, 65 + 5); + VERIFY( 70 == strmsz_2 ); // at the end of the actual file + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc new file mode 100644 index 000000000..d401f8732 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc @@ -0,0 +1,100 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetn.txt"; // file with data in it +const char name_03[] = "tmp_sgetn_2io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + strmsz_1 = fb_03.sgetn(carray1, 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, 8181 + 5); + VERIFY( 8181 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, 65 + 5); + VERIFY( 70 == strmsz_2 ); //at the end of the actual file + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc new file mode 100644 index 000000000..fd332b683 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc @@ -0,0 +1,76 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetn_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray2[8192] = ""; + int_type c2; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + strmsz_2 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, 10); + VERIFY( strmsz_2 == 0 ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + strmsz_1 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == -1 ); + VERIFY( strmsz_2 == 0 ); + fb_02.sgetc(); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc new file mode 100644 index 000000000..146a23ea7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc @@ -0,0 +1,47 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "sgetn.txt"; + +void test06() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buffer[] = "xxxxxxxxxx"; + typedef filebuf::int_type int_type; + filebuf fbuf01; + fbuf01.open(name_01, ios_base::in); + int_type len1 = fbuf01.sgetn(buffer, sizeof(buffer)); + VERIFY( len1 == sizeof(buffer) ); + VERIFY( buffer[0] == '/' ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-1.cc new file mode 100644 index 000000000..5aa31d78f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-1.cc @@ -0,0 +1,98 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include +#include +#include +#include + +// libstdc++/9533 +void test_01() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + const char* name = "tmp_fifo1"; + + const int count = 10000; + + signal(SIGPIPE, SIG_IGN); + unlink(name); + + if (0 != mkfifo(name, S_IRWXU)) + { + VERIFY( false ); + } + + int fval = fork(); + if (fval == -1) + { + unlink(name); + VERIFY( false ); + } + else if (fval == 0) + { + filebuf ofbuf; + ofbuf.open(name, ios_base::in|ios_base::out); + VERIFY( ofbuf.is_open() ); + sleep(1); + + for (int i = 0; i < count; ++i) + ofbuf.sputc(i % 100); + + ofbuf.pubsync(); + sleep(1); + ofbuf.close(); + exit(0); + } + + filebuf ifbuf; + ifbuf.open(name, ios_base::in); + VERIFY( ifbuf.is_open() ); + + for (int j = 0; j < count; ++j) + { + filebuf::int_type c1 = ifbuf.sbumpc(); + VERIFY( c1 == j % 100 ); + } + + filebuf::int_type c6 = ifbuf.sbumpc(); + VERIFY( c6 == filebuf::traits_type::eof() ); + + sleep(2); + ifbuf.close(); + + unlink(name); +} + +int +main() +{ + test_01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-2.cc new file mode 100644 index 000000000..0cba3a8f6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-2.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +// libstdc++/9533 +void test_02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "tmp_file1"; + const char* strlit = "0123456789"; + + filebuf fb; + + int written = 0; + fb.open(name, ios_base::out | ios_base::trunc); + for (int i = 0; i < BUFSIZ; ++i) + written += fb.sputn(strlit, 10); + fb.close(); + + int read = 0; + int n = 0; + char buf[10]; + fb.open(name, ios_base::in); + do + { + n = fb.sgetn(buf, sizeof(buf)); + read += n; + } + while (n); + + VERIFY( read == written ); +} + +int +main() +{ + test_02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc new file mode 100644 index 000000000..93a3771fc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc @@ -0,0 +1,85 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.snextc(); + VERIFY( c1 == '/' ); + c1 = fb_01.snextc(); + VERIFY( c1 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc new file mode 100644 index 000000000..7d51c0c98 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc @@ -0,0 +1,84 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c3 = fb_03.snextc(); + VERIFY( c3 == traits_type::eof() ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( !fb_01.write_position() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc new file mode 100644 index 000000000..e993fc7fe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc @@ -0,0 +1,65 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c2; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc new file mode 100644 index 000000000..77b40d4c4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc @@ -0,0 +1,83 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.snextc(); + VERIFY( c1 == '/' ); // overflow + c1 = fb_01.snextc(); + VERIFY( c1 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc new file mode 100644 index 000000000..e0c6f71db --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc @@ -0,0 +1,82 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it +const char name_03[] = "tmp_snextc_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + c3 = fb_03.snextc(); + VERIFY( c3 == traits_type::eof() ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc new file mode 100644 index 000000000..728b2867e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_snextc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c2; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( fb_02.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc new file mode 100644 index 000000000..f8190a9cd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc @@ -0,0 +1,93 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sputbackc('/'); + VERIFY( c1 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == ' ' ); + c1 = fb_01.sgetc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == 'a' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c1 == c3 ); + fb_01.pubseekoff(5, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == '0' ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '1' ); + c2 = fb_01.sputbackc('b'); + VERIFY( c2 == 'b' ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '1' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '7' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc new file mode 100644 index 000000000..726947379 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc @@ -0,0 +1,103 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_1io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in | out + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + strmsz_1 = fb_01.sputn("racadabras", 10);//"abracadabras or what?" + strmsz_2 = fb_01.sputn(", i wanna reach out and", 10); + fb_01.pubseekoff(0, std::ios_base::cur); + c1 = fb_01.sgetc(); // -1 + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( 1 == strmsz_2 ); + //test for _in_cur == _in_beg + // fb_01._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc + fb_01.pubseekoff(10, std::ios_base::beg); + fb_01.sputc('m'); + fb_01.pubseekoff(0, std::ios_base::cur); + strmsz_1 = fb_01.in_avail(); + c1 = fb_01.sgetc(); + fb_01.snextc(); + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 == 'z' ); + // test for replacing char with identical one + fb_01.snextc(); + fb_01.pubseekoff(0, std::ios_base::cur); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.sputc('a'); + fb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sputbackc('a'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( strmsz_1 + 1 == strmsz_2 ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc new file mode 100644 index 000000000..2cd1fdfef --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // out + { + constraint_filebuf fb_01; // out + fb_01.open(name_01, ios::out | ios::trunc); + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c1 == c2 ); + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc new file mode 100644 index 000000000..a2aa792e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc @@ -0,0 +1,93 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in + { + constraint_filebuf fb_01; // in + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sputbackc('/'); + VERIFY( c1 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == ' ' ); + c1 = fb_01.sgetc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == 'a' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c1 == c3 ); + fb_01.pubseekoff(5, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == '0' ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '1' ); + c2 = fb_01.sputbackc('b'); + VERIFY( c2 == 'b' ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '1' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '7' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc new file mode 100644 index 000000000..588c6b9b7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc @@ -0,0 +1,102 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_2io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in | out + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.sputn("racadabras", 10);//"abracadabras or what?" + strmsz_2 = fb_01.sputn(", i wanna reach out and", 10); + fb_01.pubseekoff(0, std::ios_base::cur); + c1 = fb_01.sgetc(); // -1 + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( 1 == strmsz_2 ); + //test for _in_cur == _in_beg + // fb_01._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc + fb_01.pubseekoff(10, std::ios_base::beg); + fb_01.sputc('m'); + fb_01.pubseekoff(0, std::ios_base::cur); + strmsz_1 = fb_01.in_avail(); + c1 = fb_01.sgetc(); + fb_01.snextc(); + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 == 'z' ); + // test for replacing char with identical one + fb_01.snextc(); + fb_01.pubseekoff(0, std::ios_base::cur); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.sputc('a'); + fb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sputbackc('a'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( strmsz_1 + 1 == strmsz_2 ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc new file mode 100644 index 000000000..f72ef3b67 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // out + { + constraint_filebuf fb_01; // out + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::out | ios::trunc); + VERIFY( fb_01.unbuffered() ); + VERIFY( !fb_01.read_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c1 == c2 ); + VERIFY( fb_01.unbuffered() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/9425.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/9425.cc new file mode 100644 index 000000000..608f13260 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/9425.cc @@ -0,0 +1,49 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +// libstdc++/9439, libstdc++/9425 +// basic_filebuf<>::pbackfail calls basic_filebuf<>::seekoff, but +// fails to check the return value +void test09() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf; + fbuf.open(name_01, ios_base::in); + filebuf::int_type r = fbuf.sputbackc('a'); + fbuf.close(); + + VERIFY( r == filebuf::traits_type::eof() ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc new file mode 100644 index 000000000..53d8734e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + c3 = fb_01.sputc('a'); + VERIFY( c3 == traits_type::eof() ); + VERIFY( !fb_01.write_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc new file mode 100644 index 000000000..f0e446c70 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputc_1io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c1 = fb_03.sputc('b'); + VERIFY( c1 == 'b' ); + c2 = fb_03.sputc('d'); + VERIFY( c2 == 'd' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_03.sputc(char(i)); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc new file mode 100644 index 000000000..1c7ee8237 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputc_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sputc('a'); + VERIFY( c1 == 'a' ); + c2 = fb_02.sputc('c'); + VERIFY( c2 == 'c' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_02.sputc(char(i)); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1057.cc new file mode 100644 index 000000000..a2368f932 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class nullsetpbuf : public std::filebuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc('a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc new file mode 100644 index 000000000..e6a7f069f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + c3 = fb_01.sputc('a'); + VERIFY( c3 == traits_type::eof() ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc new file mode 100644 index 000000000..16645f8db --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputc_2io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + c1 = fb_03.sputc('b'); + VERIFY( c1 == 'b' ); + c2 = fb_03.sputc('d'); + VERIFY( c2 == 'd' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_03.sputc(char(i)); + VERIFY( fb_03.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc new file mode 100644 index 000000000..9572be161 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sputc('a'); + VERIFY( c1 == 'a' ); + c2 = fb_02.sputc('c'); + VERIFY( c2 == 'c' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_02.sputc(char(i)); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc new file mode 100644 index 000000000..1fdf45955 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +const char name_05[] = "filebuf_virtuals-5.txt"; // empty file, need to create + +bool over_called; + +class Derived_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::filebuf::overflow(c); + } + + const char_type* pub_epptr() const + { return epptr(); } + + const char_type* pub_pptr() const + { return pptr(); } +}; + +// libstdc++/9701 (partial) +void test11() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputc + Derived_filebuf dfbuf_01; + dfbuf_01.open(name_05, std::ios_base::out); + over_called = false; + dfbuf_01.sputc('i'); + VERIFY( over_called ); + over_expected = dfbuf_01.pub_epptr() == dfbuf_01.pub_pptr(); + over_called = false; + dfbuf_01.sputc('v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dfbuf_01.close(); +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc new file mode 100644 index 000000000..537ebe2ca --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.sputn("racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( !fb_01.write_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc new file mode 100644 index 000000000..39f4fed71 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputn_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in | out + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" + VERIFY( strmsz_1 == 10 ); + strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); + VERIFY( strmsz_2 == 10 ); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc new file mode 100644 index 000000000..7abd18be1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputn_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + strmsz_1 = fb_02.sputn("racadabras", 10); + VERIFY( strmsz_1 == 10 ); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1057.cc new file mode 100644 index 000000000..c84a079d2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +// 27.5.2 template class basic_streambuf + +#include +#include +#include + +class nullsetpbuf : public std::filebuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as xsputn writes to null pointer + nsp.sputn(text1.c_str(), text1.length()); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc new file mode 100644 index 000000000..7c2a92151 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc @@ -0,0 +1,63 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.sputn("racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc new file mode 100644 index 000000000..d5a5fdae1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputn_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in | out + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" + VERIFY( strmsz_1 == 10 ); + strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); + VERIFY( strmsz_2 == 10 ); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( fb_03.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc new file mode 100644 index 000000000..ab70def6c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc @@ -0,0 +1,67 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputn_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + strmsz_1 = fb_02.sputn("racadabras", 10); + VERIFY( strmsz_1 == 10 ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9339.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9339.cc new file mode 100644 index 000000000..154fdba9a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9339.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include + +// libstdc++/9339 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf01; + int len = 35; + fbuf01.pubsetbuf(0, 0); + fbuf01.open("tmp_9339", ios_base::out | ios_base::trunc); + streamsize s1 = fbuf01.sputn("Pete Goldlust @ Carl Hammer Gallery", len); + VERIFY( s1 == len ); + fbuf01.close(); + + filebuf fbuf02; + char buf[256]; + fbuf02.open("tmp_9339", ios_base::in); + streamsize s2 = fbuf02.sgetn(buf, 256); + VERIFY( s2 == len ); + fbuf02.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc new file mode 100644 index 000000000..1379fe004 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc @@ -0,0 +1,74 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +const char name_05[] = "filebuf_virtuals-5.txt"; // empty file, need to create + +bool over_called; + +class Derived_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::filebuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9701 (partial) +void test11() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputn + Derived_filebuf dfbuf_02; + dfbuf_02.open(name_05, std::ios_base::out); + over_called = false; + dfbuf_02.sputn("sonne's", 7); + VERIFY( over_called ); + over_expected = dfbuf_02.pub_epptr() == dfbuf_02.pub_pptr(); + over_called = false; + dfbuf_02.sputn(" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dfbuf_02.close(); +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc new file mode 100644 index 000000000..e4e17733b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sungetc(); + VERIFY( c2 == c1 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + fb_01.pubseekoff(2, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + c2 = fb_01.sungetc(); + VERIFY( c2 == traits_type::not_eof(traits_type::eof()) ); + VERIFY( !fb_01.write_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc new file mode 100644 index 000000000..54a1372b4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc @@ -0,0 +1,84 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sungetc_1io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // in | out + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.pubseekoff(-1, std::ios_base::end); + fb_01.sbumpc(); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); + VERIFY( c2 == 'v' ); // VERIFY( c2 != traits_type::eof() ); + VERIFY( strmsz_1 + 1 == strmsz_2 ); + //test for _in_cur == _in_end + fb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = fb_01.in_avail(); // -1 cuz at the end + c1 = fb_01.sgetc(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); // 1 + fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( strmsz_2 != strmsz_1 ); + VERIFY( strmsz_2 == 1 ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc new file mode 100644 index 000000000..759cb0039 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sungetc_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // out + { + constraint_filebuf fb_01; // out + fb_01.open(name_01, ios::out | ios::trunc); + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_01.sungetc(); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sungetc(); + VERIFY( c1 == c2 ); + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc new file mode 100644 index 000000000..94e176a6a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc @@ -0,0 +1,73 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sungetc(); + VERIFY( c2 == c1 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + fb_01.pubseekoff(2, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + c2 = fb_01.sungetc(); + VERIFY( c2 == traits_type::not_eof(traits_type::eof()) ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc new file mode 100644 index 000000000..782a83db9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc @@ -0,0 +1,83 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sungetc_2io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // in | out + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_01.unbuffered() ); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.pubseekoff(-1, std::ios_base::end); + fb_01.sbumpc(); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); + VERIFY( c2 == 'v' ); // VERIFY( c2 != traits_type::eof() ); + VERIFY( strmsz_1 + 1 == strmsz_2 ); + //test for _in_cur == _in_end + fb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = fb_01.in_avail(); // -1 cuz at the end + c1 = fb_01.sgetc(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); // 1 + fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( strmsz_2 != strmsz_1 ); + VERIFY( strmsz_2 == 1 ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc new file mode 100644 index 000000000..dbdd9ab45 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sungetc_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // out + { + constraint_filebuf fb_01; // out + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::out | ios::trunc); + VERIFY( fb_01.unbuffered() ); + VERIFY( !fb_01.read_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_01.sungetc(); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sungetc(); + VERIFY( c1 == c2 ); + VERIFY( fb_01.unbuffered() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/1057.cc new file mode 100644 index 000000000..832e29558 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/1057.cc @@ -0,0 +1,104 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + + +// 27.5.2 template class basic_streambuf + +#include +#include + +class setpbuf : public std::filebuf +{ + char buffer[4]; + std::string result; + +public: + + std::string& + get_result() + { return result; } + + setpbuf() + { + this->open("tmp_1057", std::ios_base::out | std::ios_base::trunc); + char foo [32]; + setp(foo, foo + 32); + setp(buffer, buffer + 4); + } + + ~setpbuf() + { + sync(); + close(); + } + + virtual int_type + overflow(int_type n) + { + if (sync() != 0) + return traits_type::eof(); + + result += traits_type::to_char_type(n); + + return n; + } + + virtual int + sync() + { + result.append(pbase(), pptr()); + setp(buffer, buffer + 4); + return 0; + } +}; + +// libstdc++/1057 +void test04() +{ + bool test __attribute__((unused)) = true; + std::string text = "abcdefghijklmn"; + + // 01 + setpbuf sp1; + // Here xsputn writes over sp1.result + sp1.sputn(text.c_str(), text.length()); + + // This crashes when result is accessed + sp1.pubsync(); + VERIFY( sp1.get_result() == text ); + + // 02 + setpbuf sp2; + for (std::string::size_type i = 0; i < text.length(); ++i) + { + // sputc also writes over result + sp2.sputc(text[i]); + } + + // Crash here + sp2.pubsync(); + VERIFY( sp2.get_result() == text ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/9182-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/9182-1.cc new file mode 100644 index 000000000..a2a262a0d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/9182-1.cc @@ -0,0 +1,79 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +const char name_07[] = "filebuf_virtuals-7.txt"; // empty file, need to create + +class errorcvt : public std::codecvt +{ +protected: + std::codecvt_base::result + do_out(mbstate_t&, const char* from, const char*, + const char*& from_next, char* to, char*, + char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt::error; + } + + virtual bool do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9182 +// basic_filebuf<>::sync and overflow do not write out any characters +// if codecvt<>::out returns error +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc = locale::classic(); + loc = locale(loc, new errorcvt); + + filebuf fbuf1; + fbuf1.pubimbue(loc); + fbuf1.open(name_07, ios_base::out | ios_base::trunc); + + try + { + fbuf1.sputn("ison", 4); + fbuf1.pubsync(); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc new file mode 100644 index 000000000..fb8d2f615 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc @@ -0,0 +1,71 @@ +// 2003-05-03 Petur Runolfsson + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class MyTraits : public std::char_traits +{ +}; + +// libstdc++/10096 +void test01() +{ + using namespace std; + + const char* name = "filebuf_virtuals-1.txt"; + + string str; + filebuf fb1; + fb1.open(name, ios_base::in); + + filebuf::int_type c1; + while ((c1 = fb1.sbumpc()) != filebuf::traits_type::eof()) + str.push_back(filebuf::traits_type::to_char_type(c1)); + fb1.close(); + + basic_filebuf fb; + VERIFY( fb.sgetc() == MyTraits::eof() ); + + fb.open(name, ios_base::in); + VERIFY( fb.is_open() ); + + for (string::iterator i = str.begin(); i != str.end(); ++i) + { + MyTraits::int_type c2 = fb.sbumpc(); + VERIFY( c2 != MyTraits::eof() ); + VERIFY( c2 == MyTraits::to_int_type(*i) ); + } + + VERIFY( fb.sgetc() == MyTraits::eof() ); + fb.close(); + VERIFY( !fb.is_open() ); + VERIFY( fb.sgetc() == MyTraits::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc new file mode 100644 index 000000000..03fcd7d9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc @@ -0,0 +1,83 @@ +// 2003-05-03 Petur Runolfsson + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Check that basic_filebuf::underflow() handles +// codecvt::always_noconv() == false and codecvt::in() == noconv. +class NoconvCvt : public std::codecvt +{ +protected: + virtual bool + do_always_noconv() const throw() + { return false; } + + virtual result + do_in(state_type&, const char* from, const char*, const char*& from_next, + char* to, char*, char*& to_next) + { + from_next = from; + to_next = to; + return noconv; + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "filebuf_virtuals-1.txt"; + + string str; + filebuf fb; + filebuf::int_type c1; + + if (fb.open(name, ios_base::in)) + { + while ((c1 = fb.sbumpc()) != EOF) + str.push_back(filebuf::traits_type::to_char_type(c1)); + fb.close(); + } + + locale loc(locale::classic(), new NoconvCvt); + fb.pubimbue(loc); + + if (fb.open(name, ios_base::in)) + { + for (string::iterator i = str.begin(); i != str.end(); ++i) + { + c1 = fb.sbumpc(); + VERIFY( c1 != filebuf::traits_type::eof() ); + VERIFY( c1 == filebuf::traits_type::to_int_type(*i) ); + } + VERIFY( fb.sgetc() == filebuf::traits_type::eof() ); + fb.close(); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc new file mode 100644 index 000000000..af0e9141c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc @@ -0,0 +1,115 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include +#include +#include + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +class UnderBuf : public std::filebuf +{ +public: + int_type + pub_underflow() + { return underflow(); } + + std::streamsize + pub_showmanyc() + { return showmanyc(); } +}; + +// libstdc++/10097 +// filebuf::underflow drops characters. +bool test16() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo1"; + + signal(SIGPIPE, SIG_IGN); + unlink(name); + + if (0 != mkfifo(name, S_IRWXU)) + { + VERIFY( false ); + } + + semaphore s1, s2; + int fval = fork(); + if (fval == -1) + { + unlink(name); + VERIFY( false ); + } + else if (fval == 0) + { + filebuf fbout; + fbout.open(name, ios_base::in|ios_base::out); + VERIFY( fbout.is_open() ); + fbout.sputn("0123456789", 10); + fbout.pubsync(); + s1.wait(); + fbout.close(); + s2.signal(); + exit(0); + } + + UnderBuf fb; + fb.open(name, ios_base::in); + + fb.sgetc(); + streamsize n = fb.pub_showmanyc(); + + while (n > 0) + { + --n; + + UnderBuf::int_type c = fb.pub_underflow(); + VERIFY( c != UnderBuf::traits_type::eof() ); + + fb.sbumpc(); + } + + fb.close(); + s1.signal(); + s2.wait(); + + return test; +} + +int main() +{ + return !test16(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc new file mode 100644 index 000000000..0d36be046 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc @@ -0,0 +1,49 @@ +// 2003-06-25 Paolo Carlini + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb_out, fb_in_out; + + fb_out.open("tmp_underflow.tst", ios::out); + fb_out.sputc('S'); + fb_out.sputc('T'); + fb_out.close(); + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out); + while (fb_in_out.sbumpc() != filebuf::traits_type::eof()); + + VERIFY( fb_in_out.sputc('x') == 'x' ); + fb_in_out.close(); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc new file mode 100644 index 000000000..4de8a4d46 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +class Mycvtcc +: public std::codecvt +{ +protected: + virtual result + do_in(state_type&, + const extern_type* from, const extern_type* from_end, + const extern_type*& from_next, + intern_type* to, intern_type* to_limit, + intern_type*& to_next) const + { + from_next = from, to_next = to; + + if (from_next == from_end || to_next == to_limit) + return partial; + + if (std::islower(*from_next)) + *to_next = std::toupper(*from_next); + else + *to_next = *from_next; + ++from_next, ++to_next; + return ok; + } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// See Novell Bug 255122 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + const char* name = "tmp_underflow_3.tst"; + filebuf fbuf, fbufx; + + fbuf.open(name, ios_base::out | ios_base::trunc); + VERIFY( fbuf.sputc('a') == 'a' ); + VERIFY( fbuf.sputc('b') == 'b' ); + VERIFY( fbuf.sputc('\n') == '\n' ); + fbuf.close(); + + fbufx.pubimbue(locale(locale::classic(), new Mycvtcc)); + fbufx.open(name, ios_base::in); + VERIFY( fbufx.sbumpc() == 'A' ); + VERIFY( fbufx.sbumpc() == 'B' ); + VERIFY( fbufx.sbumpc() == '\n' ); + VERIFY( fbufx.sbumpc() == filebuf::traits_type::eof() ); + fbufx.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc new file mode 100644 index 000000000..a356d626e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb_in_out; + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc); + + VERIFY( fb_in_out.sputc('x') == 'x' ); + VERIFY( fb_in_out.sgetc() == filebuf::traits_type::eof() ); + fb_in_out.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc new file mode 100644 index 000000000..25f55493d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc @@ -0,0 +1,85 @@ +// 2003-05-03 Petur Runolfsson + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +class Cvt_to_upper : public std::codecvt +{ + typedef std::codecvt Base; + +public: + explicit Cvt_to_upper(std::size_t refs = 0) + : Base(refs) + { } + +protected: + virtual result + do_in(state_type&, + const extern_type* from, const extern_type* from_end, + const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + while (from < from_end && to < to_end) + *to++ = std::toupper(*from++); + + to_next = to; + from_next = from; + return from == from_end ? ok : partial; + } + + virtual bool + do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9027 +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "filebuf_virtuals-1.txt"; + locale loc (locale::classic(), new Cvt_to_upper); + + filebuf fbin; + fbin.pubimbue(loc); + fbin.open(name, ios_base::in); + + int c; + while ((c = fbin.sbumpc()) != EOF) + { + VERIFY( !islower(c) ); + } + + fbin.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc new file mode 100644 index 000000000..72c3ecb0a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc @@ -0,0 +1,111 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Test handing of UTF-8 in basic_filebuf::underflow +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_underflow-1.tst"; + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + fwrite(cstr, 1, clen, file); + fclose(file); + + wchar_t wbuf[wlen + 1]; + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + streamsize n = fb.sgetn(wbuf, wlen + 1); + fb.close(); + + VERIFY( n == static_cast(wlen) ); + VERIFY( !wmemcmp(wbuf, wstr, wlen) ); +} + +int main () +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc new file mode 100644 index 000000000..55e226705 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc @@ -0,0 +1,50 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +const char name_01[] = "tmp_11389-1"; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_01, ios_base::out); + fbout.sputc('a'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.open(name_01, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc new file mode 100644 index 000000000..e4527ee69 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc @@ -0,0 +1,52 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +const char name_02[] = "tmp_11389-2"; + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_02, ios_base::out); + fbout.sputc('a'); + fbout.sputc('b'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.open(name_02, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sbumpc() == L'b' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc new file mode 100644 index 000000000..45bb4bdf5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc @@ -0,0 +1,51 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +const char name_03[] = "tmp_11389-3"; + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_03, ios_base::out); + fbout.sputc('a'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.pubsetbuf(0, 0); + fbin.open(name_03, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc new file mode 100644 index 000000000..637f89806 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc @@ -0,0 +1,53 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +const char name_04[] = "tmp_11389-4"; + +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_04, ios_base::out); + fbout.sputc('a'); + fbout.sputc('b'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.pubsetbuf(0, 0); + fbin.open(name_04, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sbumpc() == L'b' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc new file mode 100644 index 000000000..7a27acd6f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc @@ -0,0 +1,184 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt Base; + static const size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(size_t refs = 0) + : Base(refs) + { } + +protected: + virtual typename std::codecvt::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt::ok + : std::codecvt::partial; + } + + virtual typename std::codecvt::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt::ok; + } + + virtual typename std::codecvt::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt::error : + (from_next == from_end ? std::codecvt::ok + : std::codecvt::partial); + } + + virtual int + do_encoding() const throw() + { return width; } + + virtual int + do_length(StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, static_cast(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { return width; } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/11544 (incomplete character in file) +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new checksumcvt); + + const char* name = "tmp_11544-1"; + + FILE* f = fopen(name, "w"); + putc('a', f); + fclose(f); + + wifstream in; + in.imbue(loc); + in.open(name); + + VERIFY( in.good() ); + in.get(); + VERIFY( !in.good() ); + VERIFY( in.bad() ); + VERIFY( !in.eof() ); + + in.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc new file mode 100644 index 000000000..f6a2eaca9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc @@ -0,0 +1,184 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt Base; + static const size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(size_t refs = 0) + : Base(refs) + { } + +protected: + virtual typename std::codecvt::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt::ok + : std::codecvt::partial; + } + + virtual typename std::codecvt::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt::ok; + } + + virtual typename std::codecvt::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt::error : + (from_next == from_end ? std::codecvt::ok + : std::codecvt::partial); + } + + virtual int + do_encoding() const throw() + { return width; } + + virtual int + do_length(StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, static_cast(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { return width; } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/11544 (invalid byte sequence in file) +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new checksumcvt); + + const char* name = "tmp_11544-2"; + + FILE* f = fopen(name, "w"); + VERIFY( fwrite("aaaab", 1, 5, f) == 5 ); + fclose(f); + + wifstream in; + in.imbue(loc); + in.open(name); + + VERIFY( in.good() ); + in.get(); + VERIFY( !in.good() ); + VERIFY( in.bad() ); + VERIFY( !in.eof() ); + + in.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc new file mode 100644 index 000000000..116c404a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc @@ -0,0 +1,201 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-binary-io "" } + +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt Base; + static const std::size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(std::size_t refs = 0) + : Base(refs) + { } + +protected: + virtual std::codecvt_base::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = + reinterpret_cast(from); + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt_base::ok + : std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt_base::ok; + } + + virtual std::codecvt_base::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt_base::error : + (from_next == from_end ? std::codecvt_base::ok + : std::codecvt_base::partial); + } + + virtual int + do_encoding() const throw() + { return width; } + + virtual int + do_length(const StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, + static_cast(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { return width; } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +class Buf : public std::wfilebuf +{ +public: + std::streamsize pub_showmanyc() + { return showmanyc(); } + std::wfilebuf::int_type pub_underflow() + { return underflow(); } +}; + +// libstdc++/11603 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open("tmp_11603", ios_base::out); + fbout.sputn("aaaab", 5); + fbout.close(); + + locale loc(locale::classic(), new checksumcvt); + + Buf fb; + fb.pubimbue(loc); + fb.open("tmp_11603", ios_base::in); + VERIFY( fb.pub_showmanyc() == 1 ); + + try + { + wfilebuf::int_type ret = fb.pub_underflow(); + VERIFY( ret != wfilebuf::traits_type::eof() ); + fb.sbumpc(); + ret = fb.pub_underflow(); + VERIFY( ret == wfilebuf::traits_type::eof() ); + } + catch (...) + { } + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc new file mode 100644 index 000000000..c6f30442c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc @@ -0,0 +1,112 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Test handing of UTF-8 in unbuffered basic_filebuf::underflow +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_underflow-2.tst"; + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + fwrite(cstr, 1, clen, file); + fclose(file); + + wchar_t wbuf[wlen + 1]; + + wfilebuf fb; + fb.pubimbue(loc); + fb.pubsetbuf(0, 0); + fb.open(name, ios_base::in); + streamsize n = fb.sgetn(wbuf, wlen + 1); + fb.close(); + + VERIFY( n == static_cast(wlen) ); + VERIFY( !wmemcmp(wbuf, wstr, wlen) ); +} + +int main () +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc new file mode 100644 index 000000000..42892e4ac --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc @@ -0,0 +1,117 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Test handing of UTF-8 in basic_filebuf::underflow +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_underflow-3.tst"; + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + const int loops = 2 * BUFSIZ / wlen; + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + for (int i = 0; i < loops; ++i) + fwrite(cstr, 1, clen, file); + fclose(file); + + wchar_t wbuf[wlen]; + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + for (int i = 0; i < loops; ++i) + { + streamsize n = fb.sgetn(wbuf, wlen); + VERIFY( n == static_cast(wlen) ); + VERIFY( !wmemcmp(wbuf, wstr, wlen) ); + } + + VERIFY( fb.sgetc() == wfilebuf::traits_type::eof() ); + fb.close(); +} + +int main () +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc new file mode 100644 index 000000000..6e63db09d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson +// Adapted from 27_io/basic_filebuf/underflow/char/2.cc + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale loc (locale("se_NO.UTF-8")); + wfilebuf fb_out, fb_in_out; + fb_out.pubimbue(loc); + fb_in_out.pubimbue(loc); + + fb_out.open("tmp_underflow.tst", ios::out); + fb_out.sputc(L'S'); + fb_out.sputc(L'T'); + fb_out.close(); + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out); + while (fb_in_out.sbumpc() != wfilebuf::traits_type::eof()); + + VERIFY( fb_in_out.sputc(L'x') == L'x' ); + fb_in_out.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc new file mode 100644 index 000000000..2d7cb7af2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + wfilebuf fb_in_out; + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc); + + VERIFY( fb_in_out.sputc(L'x') == L'x' ); + VERIFY( fb_in_out.sgetc() == wfilebuf::traits_type::eof() ); + fb_in_out.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc new file mode 100644 index 000000000..4c4b8d3b4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Test that unbuffered really means unbuffered for UTF-8 +void test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "tmp_underflow-5"; + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(locale("se_NO.UTF-8")); + + FILE* file = fopen(name, "w"); + setvbuf(file, 0, _IONBF, 0); + fputs("abcde", file); + + fb.open(name, ios_base::in); + VERIFY( fb.sbumpc() == L'a' ); + + fseek(file, 1, SEEK_SET); + fputc('0', file); + + VERIFY( fb.sbumpc() == L'0' ); + VERIFY( fb.sbumpc() == L'c' ); + + fputc('1', file); + fputc('2', file); + + VERIFY( fb.sbumpc() == L'2' ); + VERIFY( fb.sbumpc() == L'e' ); + VERIFY( fb.sbumpc() == WEOF ); + + fputc('3', file); + fputc('4', file); + + VERIFY( fb.sbumpc() == L'4' ); + VERIFY( fb.sbumpc() == WEOF ); + + fb.close(); + fclose(file); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc new file mode 100644 index 000000000..344db32d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc @@ -0,0 +1,204 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt Base; + static const size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(size_t refs = 0) + : Base(refs) + { } + +protected: + virtual typename std::codecvt::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt::ok + : std::codecvt::partial; + } + + virtual typename std::codecvt::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt::ok; + } + + virtual typename std::codecvt::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt::error : + (from_next == from_end ? std::codecvt::ok + : std::codecvt::partial); + } + + virtual int + do_encoding() const throw() + { + return width; + } + + virtual int + do_length(StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, static_cast(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { + return width; + } + + virtual bool + do_always_noconv() const throw() + { + return false; + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc; + loc = locale(loc, new checksumcvt); + + wfilebuf fbuf1; + fbuf1.pubimbue(loc); + fbuf1.open("tmp_9178", ios_base::out | ios_base::trunc); + + string tmpstr = "abcdefghijklmnopqrstuvwxyz0123456789 \t\n"; + + wifstream stream; + wstring str1; + + while (str1.length() < 20000) + { + transform(tmpstr.begin(), tmpstr.end(), + back_inserter(str1), + bind1st(std::mem_fun(&std::wios::widen), &stream)); + } + + fbuf1.sputn(str1.data(), str1.size()); + fbuf1.close(); + + wfilebuf fbuf2; + fbuf2.pubimbue(loc); + fbuf2.open("tmp_9178", std::ios_base::in); + + wstring str2; + copy(istreambuf_iterator(&fbuf2), + istreambuf_iterator(), + back_inserter(str2)); + + VERIFY( str1 == str2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc new file mode 100644 index 000000000..f791b86aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc @@ -0,0 +1,61 @@ +// { dg-require-namedlocale "de_DE.ISO-8859-15@euro" } + +// 2003-05-03 Petur Runolfsson + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +// libstdc++/9520 +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_9520"; + + FILE* file = fopen(name, "w"); + for (int i = 1; i < 256; ++i) + putc(static_cast(i), file); + fclose(file); + + locale loc (locale("de_DE.ISO-8859-15@euro")); + wchar_t buf[1]; + wfilebuf fb; + fb.pubimbue(loc); + fb.pubsetbuf(buf, 1); + fb.open(name, ios_base::in); + + for (int j = 1; j < 256; ++j) + { + wfilebuf::int_type c1 = fb.sgetc(); + VERIFY( c1 != wfilebuf::traits_type::eof() ); + wfilebuf::int_type c2 = fb.sbumpc(); + VERIFY( c1 == c2 ); + } + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} -- cgit v1.2.3