-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
142 lines (114 loc) · 4.4 KB
/
test.cpp
File metadata and controls
142 lines (114 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "headers.h"
#include <doctest/doctest.h>
void create_test_file(const std::string &path, const std::string &content)
{
std::ofstream file(path, std::ios::binary);
file << content;
}
void create_test_image(const std::string &path, int width, int height, int channels)
{
std::vector<unsigned char> pixels(width * height * channels, 128);
stbi_write_png(path.c_str(), width, height, channels, pixels.data(), width * channels);
}
TEST_CASE("Testing read_file_to_string")
{
SUBCASE("Reading existing file")
{
const std::string test_file = "test_file.txt";
const std::string content = "Hello World!";
create_test_file(test_file, content);
CHECK(read_file_to_string(test_file) == content);
std::filesystem::remove(test_file);
}
SUBCASE("Reading non-existent file")
{
CHECK_THROWS_AS(read_file_to_string("non_existent_file.txt"), std::runtime_error);
}
}
TEST_CASE("Testing QIM steganography")
{
const std::string original_img = "test_qim.png";
const std::string stego_img = "stego_qim.png";
const std::string msg_file = "test_qim_msg.txt";
const std::string output_file = "output_qim_msg.txt";
const std::string q_value = "4";
create_test_file(msg_file, "Message");
create_test_image(original_img, 32, 32, 3);
SUBCASE("QIM embedding and extraction")
{
REQUIRE_NOTHROW(qim_embed(original_img, stego_img, msg_file, q_value));
REQUIRE_NOTHROW(qim_extract(stego_img, q_value, output_file));
std::string extracted = read_file_to_string(output_file);
CHECK(extracted == "Message");
}
SUBCASE("QIM embedding with invalid image")
{
CHECK_THROWS_AS(qim_embed("non_existent.png", stego_img, msg_file, q_value), std::runtime_error);
}
SUBCASE("QIM extraction with invalid image")
{
CHECK_THROWS_AS(qim_extract("non_existent.png", q_value, output_file), std::runtime_error);
}
std::filesystem::remove(original_img);
std::filesystem::remove(stego_img);
std::filesystem::remove(msg_file);
std::filesystem::remove(output_file);
}
TEST_CASE("Testing LSB steganography")
{
const std::string original_img = "test_lsb.png";
const std::string stego_img = "stego_lsb.png";
const std::string msg_file = "test_lsb_msg.txt";
const std::string output_file = "output_lsb_msg.txt";
create_test_file(msg_file, "Message");
create_test_image(original_img, 32, 32, 3);
SUBCASE("LSB embedding and extraction")
{
REQUIRE_NOTHROW(lsb_embed(original_img, stego_img, msg_file));
REQUIRE_NOTHROW(lsb_extract(stego_img, output_file));
std::string extracted = read_file_to_string(output_file);
CHECK(extracted == "Message");
}
SUBCASE("LSB embedding with invalid image")
{
CHECK_THROWS_AS(lsb_embed("non_existent.png", stego_img, msg_file), std::runtime_error);
}
SUBCASE("LSB extraction with invalid image")
{
CHECK_THROWS_AS(lsb_extract("non_existent.png", output_file), std::runtime_error);
}
std::filesystem::remove(original_img);
std::filesystem::remove(stego_img);
std::filesystem::remove(msg_file);
std::filesystem::remove(output_file);
}
TEST_CASE("Testing CD steganography")
{
const std::string original_img = "test_cd.png";
const std::string stego_img = "stego_cd.png";
const std::string msg_file = "test_cd_msg.txt";
const std::string output_file = "output_cd_msg.txt";
create_test_file(msg_file, "Message");
std::vector<unsigned char> pixels(32 * 32 * 3);
stbi_write_png(original_img.c_str(), 32, 32, 3, pixels.data(), 32 * 3);
SUBCASE("CD embedding and extraction")
{
REQUIRE_NOTHROW(cd_embed(original_img, stego_img, msg_file));
REQUIRE_NOTHROW(cd_extract(stego_img, output_file));
std::string extracted = read_file_to_string(output_file);
CHECK(extracted == "Message");
}
SUBCASE("CD embedding with invalid image")
{
CHECK_THROWS_AS(cd_embed("non_existent.png", stego_img, msg_file), std::runtime_error);
}
SUBCASE("CD extraction with invalid image")
{
CHECK_THROWS_AS(cd_extract("non_existent.png", output_file), std::runtime_error);
}
std::filesystem::remove(original_img);
std::filesystem::remove(stego_img);
std::filesystem::remove(msg_file);
std::filesystem::remove(output_file);
}