+
+ /* testfile7 - append, seek, write, close, read. */
+ g_print("Test append-seek-write-close-read... ");
+
+ ref = glk_fileref_create_by_name(fileusage_Data | fileusage_BinaryMode, "testfile7", 0);
+ delete_if_exists(ref);
+ strid_t str = glk_stream_open_file(ref, filemode_WriteAppend, 0);
+ glk_put_string_stream(str, "Purple monkey chef.\n");
+ glk_stream_set_position(str, 14, seekmode_Start);
+ g_assert_cmpuint(glk_stream_get_position(str), ==, 14);
+ glk_put_string_stream(str, "dishwasher.\n");
+ glk_stream_close(str, &counts);
+ g_assert_cmpuint(counts.readcount, ==, 0);
+ g_assert_cmpuint(counts.writecount, ==, 32);
+
+ str = glk_stream_open_file(ref, filemode_Read, 0);
+ readcount = glk_get_buffer_stream(str, buffer, BUFLEN);
+ buffer[readcount] = '\0';
+ g_assert_cmpstr(buffer, ==, "Purple monkey dishwasher.\n");
+
+ glk_stream_close(str, &counts);
+ g_assert_cmpuint(counts.readcount, ==, 26);
+ g_assert_cmpuint(counts.writecount, ==, 0);
+
+ g_print("PASS\n");
+
+ /* testfile10 - Write, close, read, write, close, read. */
+ g_print("Test write-close-read-write-close-read... ");
+
+ ref = glk_fileref_create_by_name(fileusage_Data | fileusage_BinaryMode, "testfile10", 0);
+ delete_if_exists(ref);
+ str = glk_stream_open_file(ref, filemode_ReadWrite, 0);
+ glk_put_string_stream(str, "Purple synchroscopes.\n");
+ glk_stream_close(str, &counts);
+ g_assert_cmpuint(counts.readcount, ==, 0);
+ g_assert_cmpuint(counts.writecount, ==, 22);
+
+ str = glk_stream_open_file(ref, filemode_ReadWrite, 0);
+ readcount = glk_get_buffer_stream(str, buffer, 7);
+ buffer[readcount] = '\0';
+ g_assert_cmpstr(buffer, ==, "Purple ");
+ g_assert_cmpuint(glk_stream_get_position(str), ==, 7);
+ glk_put_string_stream(str, "monkey dishwasher.\n");
+ glk_stream_set_position(str, 0, seekmode_Start);
+ g_assert_cmpuint(glk_stream_get_position(str), ==, 0);
+ readcount = glk_get_buffer_stream(str, buffer, BUFLEN);
+ buffer[readcount] = '\0';
+ g_assert_cmpstr(buffer, ==, "Purple monkey dishwasher.\n");
+ glk_stream_close(str, &counts);
+ g_assert_cmpuint(counts.readcount, ==, 33);
+ g_assert_cmpuint(counts.writecount, ==, 19);
+
+ g_print("PASS\n");