Skip to content

Commit 3c5e867

Browse files
feat (datatype): add Stream
Able to use byte Stream. Create Stream datatype to store and process raw bytes. Update basic, memory, make, test files accordingly. Resolves: #132
1 parent 68ceede commit 3c5e867

15 files changed

Lines changed: 605 additions & 4 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LOGDIR = ./log
1515
COVDIR = ./cov
1616
BLDDIR = ./
1717
OPTIMIZATION = -O0
18-
OBJECT_NAMES = basic string data chunk bare_list list iterator node linked_list stack queue tree#graph
18+
OBJECT_NAMES = basic stream string data chunk bare_list list iterator node linked_list stack queue tree#graph
1919
OBJECTS := $(foreach f_name, $(OBJECT_NAMES), $(OBJDIR)/$(f_name).o)
2020
TSTECTS := $(foreach f_name, $(OBJECT_NAMES), $(OBJDIR)/test_$(f_name).o)
2121
EXECUTABLE := $(EXEDIR)/dsa

aft/code_coverage.svg

Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22

33
make again
4+
tabs 4
45
./bin/tst "$@"

cov/stream.c.gcov

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
-: 0:Source:tst/stream.c
2+
-: 0:Graph:./cov/test_stream.gcno
3+
-: 0:Data:./cov/test_stream.gcda
4+
-: 0:Runs:1
5+
-: 1:#include "../inc/test.h"
6+
-: 2:
7+
function test_stream called 0 returned 0% blocks executed 0%
8+
#####: 3:void test_stream (void) {
9+
#####: 4: printf (BOLD_YELLOW "Unit test starts..." BOLD_MAGENTA " [Stream]\n" RESET_STYLE);
10+
%%%%%: 4-block 2
11+
call 0 never executed
12+
-: 5:
13+
#####: 6: char* text = "Hello, World!\n";
14+
#####: 7: size_t length = 14;
15+
-: 8:
16+
#####: 9: Stream* stream = create_stream (length, (BYTE*) text);
17+
call 0 never executed
18+
#####: 10: Stream* ghost_stream = stream;
19+
-: 11:
20+
-: 12: // printf ("%lu %lu\n", length, sizeof (stream -> text));
21+
-: 13:
22+
-: 14: // display_stream_details (stream);
23+
-: 15:
24+
#####: 16: TEST (NULL != stream, "Checked address non-null");
25+
branch 0 never executed (fallthrough)
26+
branch 1 never executed
27+
%%%%%: 16-block 5
28+
call 2 never executed
29+
%%%%%: 16-block 6
30+
call 3 never executed
31+
#####: 17: TEST (length == stream -> length, "Checked block-size allocation");
32+
%%%%%: 17-block 7
33+
branch 0 never executed (fallthrough)
34+
branch 1 never executed
35+
%%%%%: 17-block 8
36+
call 2 never executed
37+
%%%%%: 17-block 9
38+
call 3 never executed
39+
#####: 18: TEST (stream == ghost_stream, "Checked address validation");
40+
%%%%%: 18-block 10
41+
branch 0 never executed (fallthrough)
42+
branch 1 never executed
43+
%%%%%: 18-block 11
44+
call 2 never executed
45+
%%%%%: 18-block 12
46+
call 3 never executed
47+
#####: 19: TEST (compare_raw_byte_stream (length, (BYTE*) text, stream -> base_addr), "Matched expected content");
48+
%%%%%: 19-block 13
49+
call 0 never executed
50+
branch 1 never executed (fallthrough)
51+
branch 2 never executed
52+
%%%%%: 19-block 15
53+
call 3 never executed
54+
%%%%%: 19-block 16
55+
call 4 never executed
56+
-: 20:
57+
-: 21:// void** stream_addresses = capture_stream_addresses (stream);
58+
-: 22:// TEST (!is_stream_memory_erased (stream_addresses), "Stream existance check");
59+
#####: 23: TEST (stream == ghost_stream, "Checked Stream existance");
60+
%%%%%: 23-block 17
61+
branch 0 never executed (fallthrough)
62+
branch 1 never executed
63+
%%%%%: 23-block 18
64+
call 2 never executed
65+
%%%%%: 23-block 19
66+
call 3 never executed
67+
#####: 24: delete_stream (&stream);
68+
%%%%%: 24-block 20
69+
call 0 never executed
70+
#####: 25: TEST (stream != ghost_stream, "Checked Stream deletion");
71+
branch 0 never executed (fallthrough)
72+
branch 1 never executed
73+
%%%%%: 25-block 22
74+
call 2 never executed
75+
%%%%%: 25-block 23
76+
call 3 never executed
77+
-: 26:
78+
-: 27: //TEST (is_stream_memory_erased (stream_addresses), "Stream deletion check");
79+
-: 28:// ERASE (&stream_addresses, 3 * sizeof (void*));
80+
-: 29:/*
81+
-: 30: BYTE* ptr_b = (void*) stream;
82+
-: 31: BYTE* ptr_adr = (void*) (stream -> address);
83+
-: 32: BYTE* ptr_b_f = (void*) stream;
84+
-: 33:
85+
-: 34: for (size_t i = 0; i < sizeof (Stream); i++) {
86+
-: 35: printf("%02x ", *ptr_b);
87+
-: 36: ptr_b = ptr_b + 1;
88+
-: 37: }
89+
-: 38:
90+
-: 39: printf("\n");
91+
-: 40:
92+
-: 41: delete_stream (&stream);
93+
-: 42:
94+
-: 43: for (size_t i = 0; i < sizeof (size_t); i++) {
95+
-: 44: printf("%02x ", *ptr_adr);
96+
-: 45: ptr_adr = ptr_adr + 1;
97+
-: 46: }
98+
-: 47:
99+
-: 48: printf("\n");
100+
-: 49:
101+
-: 50: for (size_t i = 0; i < sizeof (Stream); i++) {
102+
-: 51: printf ("%02x ", *ptr_b_f);
103+
-: 52: ptr_b_f = ptr_b_f + 1;
104+
-: 53: }
105+
-: 54:
106+
-: 55: printf("\n");
107+
-: 56:*/
108+
-: 57:// TEST (NULL == stream, "Address nullified check");
109+
-: 58:// TEST (sizeof (int*) == sizeof (stream), "De-allocated block-size check");
110+
-: 59:// TEST (NULL == stream, "Address nullify check");
111+
-: 60:// TEST (ptr != vptr, "Address validation check");
112+
-: 61:// TEST (n != *((int*) vptr), "Content check");
113+
-: 62:/*
114+
-: 63: Stream* str1 = create_stream (5, "Hello");
115+
-: 64: Stream* str2 = create_stream (5, "World");
116+
-: 65: stream = concatenate_streams (2, str1, str2);
117+
-: 66: TEST (stream -> length == str1 -> length + str2 -> length, "Checked concatenated stream lengths");
118+
-: 67: ghost_stream = create_stream (10, "HelloWorld");
119+
-: 68: TEST (Cmp_Different != compare_streams (stream, ghost_stream), "Matched concatenated streams");
120+
-: 69: delete_stream (&ghost_stream);
121+
-: 70: delete_stream (&stream);
122+
-: 71: delete_stream (&str1);
123+
-: 72: delete_stream (&str2);
124+
-: 73: stream = create_stream (5, "Radar");
125+
-: 74: TEST (1 == get_char_first_index (stream, 'a'), "Matched first index of character in given Stream");
126+
-: 75: TEST (3 == get_char_last_index (stream, 'a'), "Matched last index of character in given Stream");
127+
-: 76: delete_stream (&stream);
128+
-: 77:*/
129+
#####: 78: printf (BOLD_YELLOW "...Unit test ends!" BOLD_MAGENTA " [Stream]\n" RESET_STYLE);
130+
%%%%%: 78-block 24
131+
call 0 never executed
132+
#####: 79:}

inc/basic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ typedef enum COMPARE_STATUS {
2626

2727
typedef enum DATA_STRUCTURE_TYPE {
2828
DS_Raw
29-
, DS_String
3029
, DS_Stream
30+
, DS_String
3131
, DS_Data
3232
, DS_Bare_List
3333
, DS_Chunk

inc/stream.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef STREAM_H
2+
#define STREAM_H
3+
4+
#include "basic.h"
5+
6+
// ---------- x ----------
7+
8+
typedef struct STREAM {
9+
size_t length;
10+
uint8_t* base_addr;
11+
} Stream;
12+
13+
// ---------- x ----------
14+
15+
Stream* create_stream (size_t length, BYTE* data); // pass NULL as for text argument to create empty stream
16+
void delete_stream (Stream** stream_address); // frees stream object from memory
17+
void copy_raw_byte_stream (size_t length, BYTE* src_addr, BYTE* dst_addr);
18+
Stream* duplicate_stream (Stream* stream);
19+
void display_stream (Stream* stream); // prints bytes in hexadecimal
20+
void display_stream_bits (Stream* stream); // prints bytes in hexadecimal
21+
void display_stream_details (Stream* stream);
22+
bool compare_raw_byte_stream (size_t length, BYTE* base_addr_1, BYTE* base_addr_2);
23+
Compare_Status compare_stream (Stream* stream1, Stream* stream2);
24+
25+
#endif // STREAM_H

inc/test.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "./basic.h"
2424
void test_basic (void);
2525

26+
#include "./stream.h"
27+
void test_stream (void);
28+
2629
#include "./string.h"
2730
void test_string (void);
2831

log/all_cov.log

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ Creating 'basic.c.gcov'
1313

1414
Lines executed:100.00% of 16
1515

16+
Function 'test_stream'
17+
Lines executed:0.00% of 15
18+
Branches executed:0.00% of 12
19+
Taken at least once:0.00% of 12
20+
Calls executed:0.00% of 17
21+
22+
File 'tst/stream.c'
23+
Lines executed:0.00% of 15
24+
Branches executed:0.00% of 12
25+
Taken at least once:0.00% of 12
26+
Calls executed:0.00% of 17
27+
Creating 'stream.c.gcov'
28+
29+
Lines executed:0.00% of 15
30+
1631
Function 'test_string'
1732
Lines executed:100.00% of 123
1833
Branches executed:100.00% of 68

log/all_cov_cnt.log

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
50.00
88
60.00
99
100.00
10+
0.00
11+
0.00
12+
0.00
13+
0.00
14+
0.00
15+
0.00
16+
0.00
17+
0.00
18+
0.00
1019
100.00
1120
100.00
1221
50.00

log/coverage.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
83
1+
76

0 commit comments

Comments
 (0)