Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/coding
diff options
context:
space:
mode:
authorAlex Zolotarev <deathbaba@gmail.com>2012-12-14 17:13:02 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:47:58 +0300
commit98372ba583ca4a01bab65f8a0c63c55a9085cba9 (patch)
treec7e7b2d35ea4b768ec3f432648a70cc62bb3f861 /coding
parentfc00349a4de4d6199c0028067bf157617a5221dd (diff)
Moved invalid base64 implementation to another namespace
Diffstat (limited to 'coding')
-rw-r--r--coding/base64.cpp4
-rw-r--r--coding/base64.hpp10
-rw-r--r--coding/coding_tests/base64_for_user_id_test.cpp52
-rw-r--r--coding/coding_tests/coding_tests.pro2
4 files changed, 63 insertions, 5 deletions
diff --git a/coding/base64.cpp b/coding/base64.cpp
index d5d886c909..f80c483139 100644
--- a/coding/base64.cpp
+++ b/coding/base64.cpp
@@ -8,7 +8,9 @@ using namespace boost::archive::iterators;
typedef base64_from_binary<transform_width<string::const_iterator, 6, 8> > base64_t;
typedef transform_width<binary_from_base64<string::const_iterator>, 8, 6 > binary_t;
-namespace base64
+/// This namespace contains historically invalid implementation of base64,
+/// but it's still needed for production code
+namespace base64_for_user_ids
{
string encode(string rawBytes)
{
diff --git a/coding/base64.hpp b/coding/base64.hpp
index f30afc9708..e9a4081a8e 100644
--- a/coding/base64.hpp
+++ b/coding/base64.hpp
@@ -2,8 +2,12 @@
#include "../std/string.hpp"
-namespace base64
+/// This namespace contains historically invalid implementation of base64,
+/// but it's still needed for production code
+namespace base64_for_user_ids
{
- string encode(string rawBytes);
- string decode(string const & base64Chars);
+
+string encode(string rawBytes);
+string decode(string const & base64Chars);
+
}
diff --git a/coding/coding_tests/base64_for_user_id_test.cpp b/coding/coding_tests/base64_for_user_id_test.cpp
new file mode 100644
index 0000000000..c1e80d249b
--- /dev/null
+++ b/coding/coding_tests/base64_for_user_id_test.cpp
@@ -0,0 +1,52 @@
+#include "../../testing/testing.hpp"
+
+#include "../../base/logging.hpp"
+#include "../../base/pseudo_random.hpp"
+
+#include "../base64.hpp"
+
+using namespace base64_for_user_ids;
+
+UNIT_TEST(Base64_Encode_User_Ids)
+{
+ TEST_EQUAL(encode("Hello, world!"), "SGVsbG8sIHdvcmxkITAw", ());
+ TEST_EQUAL(encode(""), "", ());
+ TEST_EQUAL(encode("$"), "JDAw", ());
+ TEST_EQUAL(encode("MapsWithMe is an offline maps application for any device in the world."),
+ "TWFwc1dpdGhNZSBpcyBhbiBvZmZsaW5lIG1hcHMgYXBwbGljYXRpb24gZm9yIGFueSBkZXZpY2Ug"
+ "aW4gdGhlIHdvcmxkLjAw", ());
+}
+
+UNIT_TEST(Base64_Decode_User_Ids)
+{
+ TEST_EQUAL(decode("SGVsbG8sIHdvcmxkIQ"), "Hello, world!", ());
+ TEST_EQUAL(decode(""), "", ());
+ TEST_EQUAL(decode("JA"), "$", ());
+ TEST_EQUAL(decode("TWFwc1dpdGhNZSBpcyBhbiBvZmZsaW5lIG1hcHMgYXBwbGljYXRpb24gZm9yIGFueSBkZXZpY2Ug"
+ "aW4gdGhlIHdvcmxkLg"),
+ "MapsWithMe is an offline maps application for any device in the world.", ());
+}
+
+UNIT_TEST(Base64_QualityTest_User_Ids)
+{
+ size_t const NUMBER_OF_TESTS = 10000;
+ LCG32 generator(NUMBER_OF_TESTS);
+ for (size_t i = 0; i < NUMBER_OF_TESTS; ++i)
+ {
+ string randomBytes;
+ for (size_t j = 0 ; j < 8; ++j)
+ {
+ if (j == 4)
+ {
+ randomBytes.push_back('\0');
+ continue;
+ }
+ randomBytes.push_back(static_cast<char>(generator.Generate()));
+ }
+ string const result = encode(randomBytes);
+ TEST_GREATER_OR_EQUAL(result.size(), randomBytes.size(),
+ (randomBytes, result));
+ for (size_t i = 0; i < result.size(); ++i)
+ TEST_NOT_EQUAL(result[i], 0, ());
+ }
+}
diff --git a/coding/coding_tests/coding_tests.pro b/coding/coding_tests/coding_tests.pro
index b4c46de468..226fb3ece2 100644
--- a/coding/coding_tests/coding_tests.pro
+++ b/coding/coding_tests/coding_tests.pro
@@ -32,7 +32,7 @@ SOURCES += ../../testing/testingmain.cpp \
gzip_test.cpp \
coder_util_test.cpp \
bit_shift_test.cpp \
- base64_test.cpp \
+ base64_for_user_id_test.cpp \
sha2_test.cpp \
value_opt_string_test.cpp \
multilang_utf8_string_test.cpp \