comparison UnitTestsSources/UnitTestsMain.cpp @ 3326:b21d4cc8e5d1

speed up base64 decoding + added tests
author Alain Mazy <alain@mazy.be>
date Thu, 21 Mar 2019 11:41:03 +0100
parents b32b7c44a223
children c0aa5f1cf2f5
comparison
equal deleted inserted replaced
3325:2e7c5c15ba25 3326:b21d4cc8e5d1
372 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); 372 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
373 Toolbox::ComputeSHA1(s, ""); 373 Toolbox::ComputeSHA1(s, "");
374 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); 374 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s);
375 } 375 }
376 376
377
378 static std::string EncodeBase64Bis(const std::string& s)
379 {
380 std::string result;
381 Toolbox::EncodeBase64(result, s);
382 return result;
383 }
384
385
386 TEST(Toolbox, Base64)
387 {
388 ASSERT_EQ("", EncodeBase64Bis(""));
389 ASSERT_EQ("YQ==", EncodeBase64Bis("a"));
390
391 const std::string hello = "SGVsbG8gd29ybGQ=";
392 ASSERT_EQ(hello, EncodeBase64Bis("Hello world"));
393
394 std::string decoded;
395 Toolbox::DecodeBase64(decoded, hello);
396 ASSERT_EQ("Hello world", decoded);
397
398 // Invalid character
399 ASSERT_THROW(Toolbox::DecodeBase64(decoded, "?"), OrthancException);
400
401 // All the allowed characters
402 Toolbox::DecodeBase64(decoded, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=");
403 }
404
405 TEST(Toolbox, PathToExecutable) 377 TEST(Toolbox, PathToExecutable)
406 { 378 {
407 printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str()); 379 printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str());
408 printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str()); 380 printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str());
409 } 381 }