Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1 | // Copyright (C) 2019 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include <gmock/gmock.h> |
| 16 | #include <gtest/gtest.h> |
| 17 | #include <stdio.h> |
| 18 | #include "src/storage/StorageManager.h" |
| 19 | |
| 20 | #ifdef __ANDROID__ |
| 21 | |
| 22 | namespace android { |
| 23 | namespace os { |
| 24 | namespace statsd { |
| 25 | |
| 26 | using namespace testing; |
| 27 | using std::make_shared; |
| 28 | using std::shared_ptr; |
| 29 | using std::vector; |
| 30 | using testing::Contains; |
| 31 | |
| 32 | TEST(StorageManagerTest, TrainInfoReadWriteTest) { |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 33 | InstallTrainInfo trainInfo; |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 34 | trainInfo.trainVersionCode = 12345; |
| 35 | const char* expIds = "test_ids"; |
| 36 | trainInfo.experimentIds.assign(expIds, expIds + strlen(expIds)); |
| 37 | |
| 38 | StorageManager::writeTrainInfo(trainInfo.trainVersionCode, trainInfo.experimentIds); |
| 39 | |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 40 | InstallTrainInfo result; |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 41 | StorageManager::readTrainInfo(result); |
| 42 | EXPECT_EQ(trainInfo.trainVersionCode, result.trainVersionCode); |
| 43 | EXPECT_EQ(trainInfo.experimentIds.size(), result.experimentIds.size()); |
| 44 | EXPECT_EQ(trainInfo.experimentIds, result.experimentIds); |
| 45 | } |
| 46 | |
| 47 | } // namespace statsd |
| 48 | } // namespace os |
| 49 | } // namespace android |
| 50 | #else |
| 51 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 52 | #endif |