11#include < xtd/io/memory_stream>
22#include < xtd/not_implemented_exception>
33#include < xtd/tunit/assert>
4+ #include < xtd/tunit/collection_assert>
45#include < xtd/tunit/test_class_attribute>
56#include < xtd/tunit/test_method_attribute>
67
@@ -10,10 +11,6 @@ using namespace xtd::tunit;
1011
1112namespace xtd ::io::tests {
1213 class test_class_ (memory_stream_tests) {
13- void test_method_ (memory_buffer) {
14- assert::are_equal (typeof_<std::stringbuf>(), typeof_<memory_stream::memory_buffer>());
15- }
16-
1714 void test_method_ (create_memory_stream) {
1815 auto stream = memory_stream {};
1916 assert::are_equal (" xtd::io::memory_stream" , stream.to_string ());
@@ -23,7 +20,11 @@ namespace xtd::io::tests {
2320 }
2421
2522 void test_method_ (create_memory_stream_with_capacity) {
26- assert ::throws<not_implemented_exception>([] {auto stream = memory_stream {42_z};});
23+ auto stream = memory_stream {42_z};
24+ assert::are_equal (" xtd::io::memory_stream" , stream.to_string ());
25+ assert::are_equal (42_z, stream.capacity ());
26+ assert::is_zero (stream.length ());
27+ assert::is_zero (stream.position ());
2728 }
2829
2930 void test_method_ (can_read) {
@@ -49,14 +50,21 @@ namespace xtd::io::tests {
4950 }
5051
5152 void test_method_ (set_capacity) {
52- assert ::throws<not_implemented_exception>([] {memory_stream {}.capacity (42_z);});
53+ auto stream = memory_stream {};
54+ assert::is_zero (stream.capacity ());
55+ stream.capacity (42_z);
56+ assert::are_equal (42_z, stream.capacity ());
57+ assert::is_zero (stream.length ());
58+ assert::is_zero (stream.position ());
5359 }
5460
5561 void test_method_ (length) {
5662 auto stream = memory_stream {};
5763 assert::is_zero (stream.length ());
5864 stream.write_byte (42 );
5965 assert::are_equal (1_z, stream.length ());
66+ stream.position (0 );
67+ assert::are_equal (42 , stream.read_byte ());
6068 }
6169
6270 void test_method_ (position) {
@@ -88,16 +96,38 @@ namespace xtd::io::tests {
8896 void test_method_ (copy_to) {
8997 auto stream1 = memory_stream {};
9098 stream1.write ({10 , 20 , 30 , 40 , 50 });
91-
99+
92100 auto stream2 = memory_stream {};
93- stream1.copy_to (stream2, stream1. length () );
94- assert::are_equal ( stream1.length (), stream2. length () );
101+ stream1.position ( 0 );
102+ stream1.copy_to ( stream2);
95103 stream2.position (0 );
96104 assert::are_equal (10 , stream2.read_byte ());
97105 assert::are_equal (20 , stream2.read_byte ());
98106 assert::are_equal (30 , stream2.read_byte ());
99107 assert::are_equal (40 , stream2.read_byte ());
100108 assert::are_equal (50 , stream2.read_byte ());
109+ assert::are_equal (stream::eof, stream2.read_byte ());
110+
111+ }
112+ void test_method_ (copy_to_with_buffer_size) {
113+ auto stream1 = memory_stream {};
114+ stream1.write ({10 , 20 , 30 , 40 , 50 });
115+
116+ auto stream2 = memory_stream {};
117+ stream1.position (1 );
118+ stream1.copy_to (stream2, 3 );
119+ stream2.position (0 );
120+ assert::are_equal (20 , stream2.read_byte ());
121+ assert::are_equal (30 , stream2.read_byte ());
122+ assert::are_equal (40 , stream2.read_byte ());
123+ assert::are_equal (stream::eof, stream2.read_byte ());
124+ }
125+
126+ void test_method_ (to_array) {
127+ auto stream1 = memory_stream {};
128+ stream1.write ({10 , 20 , 30 , 40 , 50 });
129+ stream1.position (0 );
130+ collection_assert::are_equal ({10 , 20 , 30 , 40 , 50 }, stream1.to_array ());
101131 }
102132 };
103133}
0 commit comments