@@ -128,15 +128,41 @@ TEST_CASE("urlencoding is correct") {
128128 // CHECK(Countly::encodeURL("测试") == "%E6%B5%8B%E8%AF%95"); // UTF-8 TODO: Needs to be fixed. This is throwing an exception.
129129}
130130
131+ #ifdef COUNTLY_USE_CUSTOM_SHA256
132+ std::string customChecksumCalculator (const std::string& data) {
133+ std::string result = data.c_str ();
134+ result.append (" -custom_sha" );
135+ return result;
136+ }
137+
138+ TEST_CASE (" custom sha256 function validation" ) {
139+ Countly& countly = Countly::getInstance ();
140+
141+ std::string salt = " test-salt" ;
142+ std::string checksum = countly.calculateChecksum (salt, " hello world:" );
143+ CHECK (checksum == " " ); // when customSha256 isn't set.
144+
145+ countly.setSha256 (customChecksumCalculator);
146+ salt = " test-salt" ;
147+ checksum = countly.calculateChecksum (salt, " hello world:" );
148+ CHECK (checksum == " hello world:test-salt-custom_sha" );
149+
150+ salt = " š ūļ ķ" ;
151+ checksum = countly.calculateChecksum (salt, " 测试:" );
152+ CHECK (checksum == " 测试:š ūļ ķ-custom_sha" );
153+ }
154+ #else
131155TEST_CASE (" checksum function validation" ) {
156+ Countly& countly = Countly::getInstance ();
132157 std::string salt = " test-salt" ;
133- std::string checksum = Countly:: calculateChecksum (salt, " hello world" );
158+ std::string checksum = countly. calculateChecksum (salt, " hello world" );
134159 CHECK (checksum == " aaf992c81357b0ed1bb404826e01825568126ebeb004c3bc690d3d8e0766a3cc" );
135160
136161 salt = " š ūļ ķ" ;
137- checksum = Countly:: calculateChecksum (salt, " 测试" );
162+ checksum = countly. calculateChecksum (salt, " 测试" );
138163 CHECK (checksum == " f51d24b0cb938e2f40b1f8609c62bf2508e24bcaa3b6b1a7fbf108d3c7f2f073" );
139164}
165+ #endif
140166
141167TEST_CASE (" forms are serialized correctly" ) {
142168 CHECK (Countly::serializeForm (std::map<std::string, std::string>({{" key1" , " value1" }, {" key2" , " value2" }})) == " key1=value1&key2=value2" );
0 commit comments