diff options
author | Kenny Root <kroot@google.com> | 2010-06-18 19:06:50 -0700 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2010-06-20 22:03:10 -0700 |
commit | acc9e7dcca8978fc809fa5b4d9b819c515a980ff (patch) | |
tree | e87097a4721ae08f01f153a86800d90ff4003de9 /tests | |
parent | f69b3b9af78c94b5ce56a73e086b22b585ea5c85 (diff) | |
download | system_vold-acc9e7dcca8978fc809fa5b4d9b819c515a980ff.zip system_vold-acc9e7dcca8978fc809fa5b4d9b819c515a980ff.tar.gz system_vold-acc9e7dcca8978fc809fa5b4d9b819c515a980ff.tar.bz2 |
Change ASCII conversion for hash and add tests
Hash was printed using snprintf(), but we can just write yet another hex
conversion utility!
Change-Id: I04f1992deaf5bf1b3e2751c8f07072f8ed6660e9
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Android.mk | 36 | ||||
-rw-r--r-- | tests/VolumeManager_test.cpp | 64 |
2 files changed, 100 insertions, 0 deletions
diff --git a/tests/Android.mk b/tests/Android.mk new file mode 100644 index 0000000..8ae4b5d --- /dev/null +++ b/tests/Android.mk @@ -0,0 +1,36 @@ +# Build the unit tests. +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +test_src_files := \ + VolumeManager_test.cpp + +shared_libraries := \ + liblog \ + libstlport \ + libcrypto + +static_libraries := \ + libvold \ + libgtest \ + libgtest_main + +c_includes := \ + external/openssl/include \ + bionic \ + bionic/libstdc++/include \ + external/gtest/include \ + external/stlport/stlport + +module_tags := eng tests + +$(foreach file,$(test_src_files), \ + $(eval include $(CLEAR_VARS)) \ + $(eval LOCAL_SHARED_LIBRARIES := $(shared_libraries)) \ + $(eval LOCAL_STATIC_LIBRARIES := $(static_libraries)) \ + $(eval LOCAL_C_INCLUDES := $(c_includes)) \ + $(eval LOCAL_SRC_FILES := $(file)) \ + $(eval LOCAL_MODULE := $(notdir $(file:%.cpp=%))) \ + $(eval LOCAL_MODULE_TAGS := $(module_tags)) \ + $(eval include $(BUILD_EXECUTABLE)) \ +) diff --git a/tests/VolumeManager_test.cpp b/tests/VolumeManager_test.cpp new file mode 100644 index 0000000..c0c1fa5 --- /dev/null +++ b/tests/VolumeManager_test.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <errno.h> + +#define LOG_TAG "VolumeManager_test" +#include <utils/Log.h> +#include <openssl/md5.h> +#include "../VolumeManager.h" + +#include <gtest/gtest.h> + +namespace android { + +class VolumeManagerTest : public testing::Test { +protected: + virtual void SetUp() { + } + + virtual void TearDown() { + } +}; + +TEST_F(VolumeManagerTest, AsecHashTests) { + char buffer[MD5_ASCII_LENGTH_PLUS_NULL]; + char* dst = reinterpret_cast<char*>(&buffer); + + const char* src1 = ""; + const char* exp1 = "d41d8cd98f00b204e9800998ecf8427e"; + + EXPECT_TRUE(VolumeManager::asecHash(exp1, (char*)NULL, sizeof(buffer)) == NULL && errno == ESPIPE) + << "Should return NULL and set errno to ESPIPE when destination buffer is NULL"; + EXPECT_TRUE(VolumeManager::asecHash(exp1, dst, 0) == NULL && errno == ESPIPE) + << "Should return NULL and set errno to ESPIPE when destination buffer length is 0"; + EXPECT_TRUE(VolumeManager::asecHash((const char*)NULL, dst, sizeof(buffer)) == NULL && errno == ESPIPE) + << "Should return NULL and set errno to ESPIPE when source buffer is NULL"; + + EXPECT_FALSE(VolumeManager::asecHash(src1, dst, sizeof(buffer)) == NULL) + << "Should not return NULL on valid source, destination, and destination size"; + EXPECT_STREQ(exp1, dst) + << "MD5 summed output should match"; + + const char* src2 = "android"; + const char* exp2 = "c31b32364ce19ca8fcd150a417ecce58"; + EXPECT_FALSE(VolumeManager::asecHash(src2, dst, sizeof(buffer)) == NULL) + << "Should not return NULL on valid source, destination, and destination size"; + EXPECT_STREQ(exp2, dst) + << "MD5 summed output should match"; +} + +} |