@@ -74,4 +74,98 @@ BOOST_AUTO_TEST_CASE(hint_encoding_decoding_roundtrip_bytewise)
74
74
reinterpret_cast <const unsigned char *>(&decoded)));
75
75
}
76
76
77
+ BOOST_AUTO_TEST_CASE (long_string_encoding)
78
+ {
79
+ using namespace osrm ::engine;
80
+ std::string long_string (1000 , ' A' ); // String of 1000 'A's
81
+ std::string encoded = encodeBase64 (long_string);
82
+ BOOST_CHECK_EQUAL (decodeBase64 (encoded), long_string);
83
+ }
84
+
85
+ BOOST_AUTO_TEST_CASE (invalid_base64_decoding)
86
+ {
87
+ using namespace osrm ::engine;
88
+ BOOST_CHECK_THROW (decodeBase64 (" Invalid!" ), std::exception);
89
+ }
90
+
91
+ BOOST_AUTO_TEST_CASE (hint_serialization_size)
92
+ {
93
+ using namespace osrm ::engine;
94
+ using namespace osrm ::util;
95
+
96
+ const Coordinate coordinate;
97
+ const PhantomNode phantom;
98
+ const osrm::test::MockDataFacade<osrm::engine::routing_algorithms::ch::Algorithm> facade{};
99
+
100
+ const SegmentHint hint{phantom, facade.GetCheckSum ()};
101
+ const auto base64 = hint.ToBase64 ();
102
+
103
+ BOOST_CHECK_EQUAL (base64.size (), 112 );
104
+ }
105
+
106
+ BOOST_AUTO_TEST_CASE (extended_roundtrip_tests)
107
+ {
108
+ using namespace osrm ::engine;
109
+
110
+ std::vector<std::string> test_strings = {
111
+ " Hello, World!" , // Simple ASCII string
112
+ " 1234567890" , // Numeric string
113
+ " !@#$%^&*()_+" , // Special characters
114
+ std::string (1000 , ' A' ), // Long repeating string
115
+ " ¡Hola, mundo!" , // Non-ASCII characters
116
+ " こんにちは、世界!" , // Unicode characters
117
+ std::string (" \x00\x01\x02\x03 " , 4 ), // Binary data
118
+ " a" , // Single character
119
+ " ab" , // Two characters
120
+ " abc" , // Three characters (no padding in Base64)
121
+ std::string (190 , ' x' ) // String that doesn't align with Base64 padding
122
+ };
123
+
124
+ for (const auto &test_str : test_strings)
125
+ {
126
+ std::string encoded = encodeBase64 (test_str);
127
+ std::string decoded = decodeBase64 (encoded);
128
+ BOOST_CHECK_EQUAL (decoded, test_str);
129
+
130
+ // Additional checks
131
+ BOOST_CHECK (encoded.find_first_not_of (
132
+ " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" ) ==
133
+ std::string::npos);
134
+ if (test_str.length () % 3 != 0 )
135
+ {
136
+ BOOST_CHECK (encoded.back () == ' =' );
137
+ }
138
+ }
139
+ }
140
+
141
+ BOOST_AUTO_TEST_CASE (roundtrip_with_url_safe_chars)
142
+ {
143
+ using namespace osrm ::engine;
144
+
145
+ std::string original = " Hello+World/Nothing?Is:Impossible" ;
146
+ std::string encoded = encodeBase64 (original);
147
+
148
+ // Replace '+' with '-' and '/' with '_'
149
+ std::replace (encoded.begin (), encoded.end (), ' +' , ' -' );
150
+ std::replace (encoded.begin (), encoded.end (), ' /' , ' _' );
151
+
152
+ std::string decoded = decodeBase64 (encoded);
153
+ BOOST_CHECK_EQUAL (decoded, original);
154
+ }
155
+
156
+ BOOST_AUTO_TEST_CASE (roundtrip_stress_test)
157
+ {
158
+ using namespace osrm ::engine;
159
+
160
+ std::string test_str;
161
+ for (int i = 0 ; i < 1000 ; ++i)
162
+ {
163
+ test_str += static_cast <char >(i % 256 );
164
+ }
165
+
166
+ std::string encoded = encodeBase64 (test_str);
167
+ std::string decoded = decodeBase64 (encoded);
168
+ BOOST_CHECK_EQUAL (decoded, test_str);
169
+ }
170
+
77
171
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments