55
66
77int
8- test__create_horizontal_line__is_console_width ()
8+ test__append_horizontal_line ()
99{
1010 /* Arrange */
11- CONSOLE_SCREEN_BUFFER_INFO csbi = {
12- 80 , 40 , /* buffer columns, rows */
13- 0 , 0 , /* cursor column, row */
14- 14 , /* color attributes */
15- 0 , 0 , 79 , 39 , /* coords left, top, right, bottom */
16- 0 , 0 /* max window size */
17- };
18- size_t console_width = (size_t ) csbi .srWindow .Right + 1 ;
19- char line [8192 ] = { 0 };
20- size_t length = 0 ;
11+ char result [4096 ] = { 0 };
12+ unsigned int length = 0 ;
13+ unsigned int console_width = 80 ;
2114
2215 /* Act */
23- create_horizontal_line ( line , csbi );
24- length = strlen (line );
16+ append_horizontal_line ( result , console_width );
17+ length = strlen (result );
2518
2619 /* Assert */
2720 if (length != console_width ) {
28- printf ("LINE %d: LENGTH OF LINE SHOULD MATCH CONSOLE WIDTH " , __LINE__ );
21+ printf ("\nLINE %d: RESULT: %u\nEXPECTED: %u\n " , __LINE__ , length , console_width );
2922 return 1 ;
3023 }
3124
@@ -34,21 +27,19 @@ test__create_horizontal_line__is_console_width()
3427
3528
3629int
37- test__get_console_info__sets_attributes ()
30+ test__compact_size_with_suffix__is_bytes ()
3831{
3932 /* Arrange */
40- struct console_info console = { -1 , -1 , -1 };
33+ int size = 1023 ;
34+ char result [16 ] = { 0 };
35+ const char * expected = "1023 B" ;
4136
4237 /* Act */
43- get_console_info ( & console );
38+ compact_size_with_suffix ( size , result );
4439
4540 /* Assert */
46- if (console .colors < 0 || console .width < 1 || console .height < 0 ) {
47- printf ("RESULT: %d, %d, %d\n" ,
48- console .colors ,
49- console .width ,
50- console .height );
51- printf ("LINE %d: CONSOLE ATTRIBUTES SHOULD BE SET" , __LINE__ );
41+ if (strcmp (result , expected ) != 0 ) {
42+ printf ("\nLINE %d: RESULT: %s\nEXPECTED: %s\n" , __LINE__ , result , expected );
5243 return 1 ;
5344 }
5445
@@ -57,37 +48,12 @@ test__get_console_info__sets_attributes()
5748
5849
5950int
60- test__create_footer ()
61- {
62- // /* Arrange */
63- // char footer_string[1024] = { 0 };
64- // int console_width = 80;
65- // char * root_path = "x:\\";
66- // char search_drive = 'C';
67- //
68- // /* Act */
69- // create_footer(footer_string, console_width, root_path, search_drive);
70-
71- /* Assert */
72- // if (strcmp(footer_string,
73- // " 0 files, totaling , consuming 0 bytes of disk space.\n"
74- // " 0 bytes available on Drive C: Volume label: C_DRIVE\n"
75- // ) != 0) {
76- // puts("STRING SHOULD MATCH");
77- // return 1;
78- // }
79- //
80- return 0 ;
81- }
82-
83-
84- int
85- test__compact_size_with_suffix__is_bytes ()
51+ test__compact_size_with_suffix__is_gigabytes ()
8652{
8753 /* Arrange */
88- int size = 1023 ;
54+ long long size = 1073741824 ;
8955 char result [16 ] = { 0 };
90- const char * expected = "1023 B " ;
56+ const char * expected = "1 GB " ;
9157
9258 /* Act */
9359 compact_size_with_suffix (size , result );
@@ -145,12 +111,12 @@ test__compact_size_with_suffix__is_megabytes()
145111
146112
147113int
148- test__compact_size_with_suffix__is_not_megabytes ()
114+ test__compact_size_with_suffix__is_not_gigabytes ()
149115{
150116 /* Arrange */
151- int size = 1048575 ;
117+ long long size = 1073741823 ;
152118 char result [16 ] = { 0 };
153- const char * expected = "1023 KB " ;
119+ const char * expected = "1023 MB " ;
154120
155121 /* Act */
156122 compact_size_with_suffix (size , result );
@@ -166,12 +132,12 @@ test__compact_size_with_suffix__is_not_megabytes()
166132
167133
168134int
169- test__compact_size_with_suffix__is_gigabytes ()
135+ test__compact_size_with_suffix__is_not_megabytes ()
170136{
171137 /* Arrange */
172- long long size = 1073741824 ;
138+ int size = 1048575 ;
173139 char result [16 ] = { 0 };
174- const char * expected = "1 GB " ;
140+ const char * expected = "1023 KB " ;
175141
176142 /* Act */
177143 compact_size_with_suffix (size , result );
@@ -187,12 +153,12 @@ test__compact_size_with_suffix__is_gigabytes()
187153
188154
189155int
190- test__compact_size_with_suffix__is_not_gigabytes ()
156+ test__compact_size_with_suffix__is_terabytes ()
191157{
192158 /* Arrange */
193- long long size = 1073741823 ;
159+ long long size = 1099511627776 ;
194160 char result [16 ] = { 0 };
195- const char * expected = "1023 MB " ;
161+ const char * expected = "1 TB " ;
196162
197163 /* Act */
198164 compact_size_with_suffix (size , result );
@@ -208,12 +174,12 @@ test__compact_size_with_suffix__is_not_gigabytes()
208174
209175
210176int
211- test__compact_size_with_suffix__is_terabytes ()
177+ test__compact_size_with_suffix__works_with_ntfs_volume_limit ()
212178{
213179 /* Arrange */
214- long long size = 1099511627776 ;
180+ long long size = 281474976710656 ;
215181 char result [16 ] = { 0 };
216- const char * expected = "1 TB" ;
182+ const char * expected = "256 TB" ;
217183
218184 /* Act */
219185 compact_size_with_suffix (size , result );
@@ -229,19 +195,52 @@ test__compact_size_with_suffix__is_terabytes()
229195
230196
231197int
232- test__compact_size_with_suffix__works_with_ntfs_volume_limit ()
198+ test__create_footer ()
199+ {
200+ // /* Arrange */
201+ // char footer_string[1024] = { 0 };
202+ // int console_width = 80;
203+ // char * root_path = "x:\\";
204+ // char search_drive = 'C';
205+ //
206+ // /* Act */
207+ // create_footer(footer_string, console_width, root_path, search_drive);
208+
209+ /* Assert */
210+ // if (strcmp(footer_string,
211+ // " 0 files, totaling , consuming 0 bytes of disk space.\n"
212+ // " 0 bytes available on Drive C: Volume label: C_DRIVE\n"
213+ // ) != 0) {
214+ // puts("STRING SHOULD MATCH");
215+ // return 1;
216+ // }
217+ //
218+ return 0 ;
219+ }
220+
221+
222+ int
223+ test__create_horizontal_line__is_console_width ()
233224{
234225 /* Arrange */
235- long long size = 281474976710656 ;
236- char result [16 ] = { 0 };
237- const char * expected = "256 TB" ;
226+ CONSOLE_SCREEN_BUFFER_INFO csbi = {
227+ 80 , 40 , /* buffer columns, rows */
228+ 0 , 0 , /* cursor column, row */
229+ 14 , /* color attributes */
230+ 0 , 0 , 79 , 39 , /* coords left, top, right, bottom */
231+ 0 , 0 /* max window size */
232+ };
233+ size_t console_width = (size_t ) csbi .srWindow .Right + 1 ;
234+ char line [8192 ] = { 0 };
235+ size_t length = 0 ;
238236
239237 /* Act */
240- compact_size_with_suffix (size , result );
238+ create_horizontal_line (line , csbi );
239+ length = strlen (line );
241240
242241 /* Assert */
243- if (strcmp ( result , expected ) != 0 ) {
244- printf ("\nLINE %d: RESULT: %s\nEXPECTED: %s\n" , __LINE__ , result , expected );
242+ if (length != console_width ) {
243+ printf ("LINE %d: LENGTH OF LINE SHOULD MATCH CONSOLE WIDTH" , __LINE__ );
245244 return 1 ;
246245 }
247246
@@ -250,20 +249,21 @@ test__compact_size_with_suffix__works_with_ntfs_volume_limit()
250249
251250
252251int
253- test__append_horizontal_line ()
252+ test__get_console_info__sets_attributes ()
254253{
255254 /* Arrange */
256- char result [4096 ] = { 0 };
257- unsigned int length = 0 ;
258- unsigned int console_width = 80 ;
255+ struct console_info console = { -1 , -1 , -1 };
259256
260257 /* Act */
261- append_horizontal_line (result , console_width );
262- length = strlen (result );
258+ get_console_info (& console );
263259
264260 /* Assert */
265- if (length != console_width ) {
266- printf ("\nLINE %d: RESULT: %u\nEXPECTED: %u\n" , __LINE__ , length , console_width );
261+ if (console .colors < 0 || console .width < 1 || console .height < 0 ) {
262+ printf ("RESULT: %d, %d, %d\n" ,
263+ console .colors ,
264+ console .width ,
265+ console .height );
266+ printf ("LINE %d: CONSOLE ATTRIBUTES SHOULD BE SET" , __LINE__ );
267267 return 1 ;
268268 }
269269
@@ -295,19 +295,19 @@ main()
295295{
296296 int failed_count = 0 ;
297297
298+ //failed_count += test__append_horizontal_line();
298299 failed_count += test__compact_size_with_suffix__is_bytes ();
300+ failed_count += test__compact_size_with_suffix__is_gigabytes ();
299301 failed_count += test__compact_size_with_suffix__is_kilobytes ();
300302 failed_count += test__compact_size_with_suffix__is_megabytes ();
301- failed_count += test__compact_size_with_suffix__is_not_megabytes ();
302- failed_count += test__compact_size_with_suffix__is_gigabytes ();
303303 failed_count += test__compact_size_with_suffix__is_not_gigabytes ();
304+ failed_count += test__compact_size_with_suffix__is_not_megabytes ();
304305 failed_count += test__compact_size_with_suffix__is_terabytes ();
305306 failed_count += test__compact_size_with_suffix__works_with_ntfs_volume_limit ();
306- failed_count += test__create_horizontal_line__is_console_width ();
307- failed_count += test__get_console_width__greater_than_zero ();
308- //failed_count += test__append_horizontal_line();
309307 //failed_count += test__create_footer();
308+ failed_count += test__create_horizontal_line__is_console_width ();
310309 failed_count += test__get_console_info__sets_attributes ();
310+ failed_count += test__get_console_width__greater_than_zero ();
311311
312312 printf ("\n%d failing test%c\n" , failed_count , failed_count != 1 ? 's' : '\0' );
313313
0 commit comments