Merge "Move utils unit tests to a utils specific test dir"
This commit is contained in:
@@ -9,7 +9,7 @@ LOCAL_PATH := $(call my-dir)
|
|||||||
# routine.
|
# routine.
|
||||||
|
|
||||||
test_name := base64_test
|
test_name := base64_test
|
||||||
test_src_dir := ../core/test
|
test_src_dir := ../util/test
|
||||||
include $(LOCAL_PATH)/unit-test.mk
|
include $(LOCAL_PATH)/unit-test.mk
|
||||||
|
|
||||||
test_name := buffer_reader_test
|
test_name := buffer_reader_test
|
||||||
@@ -67,11 +67,11 @@ test_src_dir := ../metrics/test
|
|||||||
include $(LOCAL_PATH)/unit-test.mk
|
include $(LOCAL_PATH)/unit-test.mk
|
||||||
|
|
||||||
test_name := file_store_unittest
|
test_name := file_store_unittest
|
||||||
test_src_dir := ../core/test
|
test_src_dir := ../util/test
|
||||||
include $(LOCAL_PATH)/unit-test.mk
|
include $(LOCAL_PATH)/unit-test.mk
|
||||||
|
|
||||||
test_name := file_utils_unittest
|
test_name := file_utils_unittest
|
||||||
test_src_dir := .
|
test_src_dir := ../util/test
|
||||||
include $(LOCAL_PATH)/unit-test.mk
|
include $(LOCAL_PATH)/unit-test.mk
|
||||||
|
|
||||||
test_name := generic_crypto_unittest
|
test_name := generic_crypto_unittest
|
||||||
|
|||||||
@@ -42,23 +42,23 @@ const std::string kOneByteOverB64Data("SGVsbG8gRnJpZW5kIQ==");
|
|||||||
const std::string kTwoBytesOverB64Data("SGVsbG8gRnJpZW5kISE=");
|
const std::string kTwoBytesOverB64Data("SGVsbG8gRnJpZW5kISE=");
|
||||||
const std::string kB64TestData = "GPFc9rc+INmI8FwtyTrUrv6xnKHWZNZ/5uaT21nFjNg=";
|
const std::string kB64TestData = "GPFc9rc+INmI8FwtyTrUrv6xnKHWZNZ/5uaT21nFjNg=";
|
||||||
|
|
||||||
const std::pair<const std::string *, const std::string *> kBase64TestVectors[] =
|
const std::pair<const std::string*, const std::string*> kBase64TestVectors[] = {
|
||||||
{make_pair(&kNullString, &kNullString),
|
make_pair(&kNullString, &kNullString),
|
||||||
make_pair(&kf, &kfB64),
|
make_pair(&kf, &kfB64),
|
||||||
make_pair(&kfo, &kfoB64),
|
make_pair(&kfo, &kfoB64),
|
||||||
make_pair(&kfoo, &kfooB64),
|
make_pair(&kfoo, &kfooB64),
|
||||||
make_pair(&kfoob, &kfoobB64),
|
make_pair(&kfoob, &kfoobB64),
|
||||||
make_pair(&kfooba, &kfoobaB64),
|
make_pair(&kfooba, &kfoobaB64),
|
||||||
make_pair(&kfoobar, &kfoobarB64),
|
make_pair(&kfoobar, &kfoobarB64),
|
||||||
make_pair(&kMultipleOf24BitsData, &kMultipleOf24BitsB64Data),
|
make_pair(&kMultipleOf24BitsData, &kMultipleOf24BitsB64Data),
|
||||||
make_pair(&kOneByteOverData, &kOneByteOverB64Data),
|
make_pair(&kOneByteOverData, &kOneByteOverB64Data),
|
||||||
make_pair(&kTwoBytesOverData, &kTwoBytesOverB64Data),
|
make_pair(&kTwoBytesOverData, &kTwoBytesOverB64Data),
|
||||||
make_pair(&kTestData, &kB64TestData)};
|
make_pair(&kTestData, &kB64TestData)};
|
||||||
|
|
||||||
const std::string kBase64ErrorVectors[] = {"Foo$sa", "Foo\x99\x23\xfa\02",
|
const std::string kBase64ErrorVectors[] = {"Foo$sa", "Foo\x99\x23\xfa\02",
|
||||||
"Foo==Foo", "FooBa"};
|
"Foo==Foo", "FooBa"};
|
||||||
|
|
||||||
std::string ConvertToBase64WebSafe(const std::string &std_base64_string) {
|
std::string ConvertToBase64WebSafe(const std::string& std_base64_string) {
|
||||||
std::string str(std_base64_string);
|
std::string str(std_base64_string);
|
||||||
for (size_t i = 0; i < str.size(); ++i) {
|
for (size_t i = 0; i < str.size(); ++i) {
|
||||||
if (str[i] == '+')
|
if (str[i] == '+')
|
||||||
@@ -73,10 +73,10 @@ std::string ConvertToBase64WebSafe(const std::string &std_base64_string) {
|
|||||||
|
|
||||||
class Base64EncodeDecodeTest
|
class Base64EncodeDecodeTest
|
||||||
: public ::testing::TestWithParam<
|
: public ::testing::TestWithParam<
|
||||||
std::pair<const std::string *, const std::string *> > {};
|
std::pair<const std::string*, const std::string*> > {};
|
||||||
|
|
||||||
TEST_P(Base64EncodeDecodeTest, EncodeDecodeTest) {
|
TEST_P(Base64EncodeDecodeTest, EncodeDecodeTest) {
|
||||||
std::pair<const std::string *, const std::string *> values = GetParam();
|
std::pair<const std::string*, const std::string*> values = GetParam();
|
||||||
std::vector<uint8_t> decoded_vector = Base64Decode(values.second->data());
|
std::vector<uint8_t> decoded_vector = Base64Decode(values.second->data());
|
||||||
std::string decoded_string(decoded_vector.begin(), decoded_vector.end());
|
std::string decoded_string(decoded_vector.begin(), decoded_vector.end());
|
||||||
EXPECT_STREQ(values.first->data(), decoded_string.data());
|
EXPECT_STREQ(values.first->data(), decoded_string.data());
|
||||||
@@ -85,7 +85,7 @@ TEST_P(Base64EncodeDecodeTest, EncodeDecodeTest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(Base64EncodeDecodeTest, WebSafeEncodeDecodeTest) {
|
TEST_P(Base64EncodeDecodeTest, WebSafeEncodeDecodeTest) {
|
||||||
std::pair<const std::string *, const std::string *> values = GetParam();
|
std::pair<const std::string*, const std::string*> values = GetParam();
|
||||||
std::string encoded_string = ConvertToBase64WebSafe(*(values.second));
|
std::string encoded_string = ConvertToBase64WebSafe(*(values.second));
|
||||||
std::vector<uint8_t> decoded_vector = Base64SafeDecode(encoded_string);
|
std::vector<uint8_t> decoded_vector = Base64SafeDecode(encoded_string);
|
||||||
std::string decoded_string(decoded_vector.begin(), decoded_vector.end());
|
std::string decoded_string(decoded_vector.begin(), decoded_vector.end());
|
||||||
@@ -111,13 +111,13 @@ class HtoNLL64Test : public ::testing::Test {};
|
|||||||
|
|
||||||
TEST_F(HtoNLL64Test, PositiveNumber) {
|
TEST_F(HtoNLL64Test, PositiveNumber) {
|
||||||
uint8_t data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
uint8_t data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||||
int64_t *network_byte_order = reinterpret_cast<int64_t *>(data);
|
int64_t* network_byte_order = reinterpret_cast<int64_t*>(data);
|
||||||
int64_t host_byte_order = htonll64(*network_byte_order);
|
int64_t host_byte_order = htonll64(*network_byte_order);
|
||||||
EXPECT_EQ(0x0102030405060708, host_byte_order);
|
EXPECT_EQ(0x0102030405060708, host_byte_order);
|
||||||
}
|
}
|
||||||
TEST_F(HtoNLL64Test, NegativeNumber) {
|
TEST_F(HtoNLL64Test, NegativeNumber) {
|
||||||
uint8_t data[8] = {0xfe, 2, 3, 4, 5, 6, 7, 8};
|
uint8_t data[8] = {0xfe, 2, 3, 4, 5, 6, 7, 8};
|
||||||
int64_t *network_byte_order = reinterpret_cast<int64_t *>(data);
|
int64_t* network_byte_order = reinterpret_cast<int64_t*>(data);
|
||||||
int64_t host_byte_order = htonll64(*network_byte_order);
|
int64_t host_byte_order = htonll64(*network_byte_order);
|
||||||
EXPECT_EQ(-0x01FdFcFbFaF9F8F8, host_byte_order);
|
EXPECT_EQ(-0x01FdFcFbFaF9F8F8, host_byte_order);
|
||||||
}
|
}
|
||||||
@@ -104,8 +104,7 @@ TEST_F(FileTest, FileSize) {
|
|||||||
EXPECT_EQ(file->Write(write_data.data(), write_data_size), write_data_size);
|
EXPECT_EQ(file->Write(write_data.data(), write_data_size), write_data_size);
|
||||||
EXPECT_TRUE(file_system.Exists(path));
|
EXPECT_TRUE(file_system.Exists(path));
|
||||||
|
|
||||||
EXPECT_EQ(static_cast<ssize_t>(write_data_size),
|
EXPECT_EQ(static_cast<ssize_t>(write_data_size), file_system.FileSize(path));
|
||||||
file_system.FileSize(path));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FileTest, WriteReadBinaryFile) {
|
TEST_F(FileTest, WriteReadBinaryFile) {
|
||||||
@@ -116,7 +115,7 @@ TEST_F(FileTest, WriteReadBinaryFile) {
|
|||||||
size_t write_data_size = write_data.size();
|
size_t write_data_size = write_data.size();
|
||||||
std::unique_ptr<File> file = file_system.Open(path, FileSystem::kCreate);
|
std::unique_ptr<File> file = file_system.Open(path, FileSystem::kCreate);
|
||||||
ASSERT_TRUE(file);
|
ASSERT_TRUE(file);
|
||||||
EXPECT_EQ(file->Write(write_data.data(),write_data_size), write_data_size);
|
EXPECT_EQ(file->Write(write_data.data(), write_data_size), write_data_size);
|
||||||
EXPECT_TRUE(file_system.Exists(path));
|
EXPECT_TRUE(file_system.Exists(path));
|
||||||
|
|
||||||
std::string read_data;
|
std::string read_data;
|
||||||
@@ -159,9 +158,8 @@ TEST_F(FileTest, ListFiles) {
|
|||||||
|
|
||||||
// Should find three files. Order not important.
|
// Should find three files. Order not important.
|
||||||
EXPECT_EQ(3u, names.size());
|
EXPECT_EQ(3u, names.size());
|
||||||
EXPECT_THAT(names, ::testing::UnorderedElementsAre(kTestFileName,
|
EXPECT_THAT(names, ::testing::UnorderedElementsAre(
|
||||||
kTestFileName2,
|
kTestFileName, kTestFileName2, kTestFileName3));
|
||||||
kTestFileName3));
|
|
||||||
|
|
||||||
std::string wild_card_path = path_dir + kWildcard + kTestFileNameExt;
|
std::string wild_card_path = path_dir + kWildcard + kTestFileNameExt;
|
||||||
EXPECT_TRUE(file_system.Remove(wild_card_path));
|
EXPECT_TRUE(file_system.Remove(wild_card_path));
|
||||||
Reference in New Issue
Block a user