2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #define LOG_TAG "VolumeManager_test"
20 #include <utils/Log.h>
21 #include <openssl/md5.h>
22 #include "../VolumeManager.h"
24 #include <gtest/gtest.h>
28 class VolumeManagerTest : public testing::Test {
30 virtual void SetUp() {
33 virtual void TearDown() {
37 TEST_F(VolumeManagerTest, AsecHashTests) {
38 char buffer[MD5_ASCII_LENGTH_PLUS_NULL];
39 char* dst = reinterpret_cast<char*>(&buffer);
41 const char* src1 = "";
42 const char* exp1 = "d41d8cd98f00b204e9800998ecf8427e";
44 EXPECT_TRUE(VolumeManager::asecHash(exp1, (char*)NULL, sizeof(buffer)) == NULL && errno == ESPIPE)
45 << "Should return NULL and set errno to ESPIPE when destination buffer is NULL";
46 EXPECT_TRUE(VolumeManager::asecHash(exp1, dst, 0) == NULL && errno == ESPIPE)
47 << "Should return NULL and set errno to ESPIPE when destination buffer length is 0";
48 EXPECT_TRUE(VolumeManager::asecHash((const char*)NULL, dst, sizeof(buffer)) == NULL && errno == ESPIPE)
49 << "Should return NULL and set errno to ESPIPE when source buffer is NULL";
51 EXPECT_FALSE(VolumeManager::asecHash(src1, dst, sizeof(buffer)) == NULL)
52 << "Should not return NULL on valid source, destination, and destination size";
53 EXPECT_STREQ(exp1, dst)
54 << "MD5 summed output should match";
56 const char* src2 = "android";
57 const char* exp2 = "c31b32364ce19ca8fcd150a417ecce58";
58 EXPECT_FALSE(VolumeManager::asecHash(src2, dst, sizeof(buffer)) == NULL)
59 << "Should not return NULL on valid source, destination, and destination size";
60 EXPECT_STREQ(exp2, dst)
61 << "MD5 summed output should match";