Kenny Root | acc9e7d | 2010-06-18 19:06:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 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 |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include <errno.h> |
| 18 | |
| 19 | #define LOG_TAG "VolumeManager_test" |
| 20 | #include <utils/Log.h> |
| 21 | #include <openssl/md5.h> |
| 22 | #include "../VolumeManager.h" |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | class VolumeManagerTest : public testing::Test { |
| 29 | protected: |
| 30 | virtual void SetUp() { |
| 31 | } |
| 32 | |
| 33 | virtual void TearDown() { |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | TEST_F(VolumeManagerTest, AsecHashTests) { |
| 38 | char buffer[MD5_ASCII_LENGTH_PLUS_NULL]; |
| 39 | char* dst = reinterpret_cast<char*>(&buffer); |
| 40 | |
| 41 | const char* src1 = ""; |
| 42 | const char* exp1 = "d41d8cd98f00b204e9800998ecf8427e"; |
| 43 | |
| 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"; |
| 50 | |
| 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"; |
| 55 | |
| 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"; |
| 62 | } |
| 63 | |
| 64 | } |