1c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
2c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Copyright (C) 2013 The Android Open Source Project
3c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
4c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Licensed under the Apache License, Version 2.0 (the "License");
5c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// you may not use this file except in compliance with the License.
6c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// You may obtain a copy of the License at
7c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
8c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//      http://www.apache.org/licenses/LICENSE-2.0
9c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
10c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// Unless required by applicable law or agreed to in writing, software
11c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// distributed under the License is distributed on an "AS IS" BASIS,
12c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// See the License for the specific language governing permissions and
14c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu// limitations under the License.
15c0beca55d290fe0b1c96d78cbbcf94b05c23f5a5Peter Qiu//
1641cc634bcf55c46e9ada7447403c01553152205fArman Uguray
1741cc634bcf55c46e9ada7447403c01553152205fArman Uguray#include "shill/pending_activation_store.h"
1841cc634bcf55c46e9ada7447403c01553152205fArman Uguray
1941cc634bcf55c46e9ada7447403c01553152205fArman Uguray#include <base/files/scoped_temp_dir.h>
2041cc634bcf55c46e9ada7447403c01553152205fArman Uguray#include <gmock/gmock.h>
2141cc634bcf55c46e9ada7447403c01553152205fArman Uguray#include <gtest/gtest.h>
2241cc634bcf55c46e9ada7447403c01553152205fArman Uguray
2341cc634bcf55c46e9ada7447403c01553152205fArman Uguray#include "shill/mock_store.h"
2404147470fdeaaf9ab7588bd3a7988d74aa990068mukesh agrawal#include "shill/store_factory.h"
2541cc634bcf55c46e9ada7447403c01553152205fArman Uguray
2641cc634bcf55c46e9ada7447403c01553152205fArman Ugurayusing ::testing::_;
2741cc634bcf55c46e9ada7447403c01553152205fArman Ugurayusing ::testing::DoAll;
2841cc634bcf55c46e9ada7447403c01553152205fArman Ugurayusing ::testing::Mock;
2941cc634bcf55c46e9ada7447403c01553152205fArman Ugurayusing ::testing::Return;
3041cc634bcf55c46e9ada7447403c01553152205fArman Ugurayusing ::testing::SetArgumentPointee;
3141cc634bcf55c46e9ada7447403c01553152205fArman Uguray
3241cc634bcf55c46e9ada7447403c01553152205fArman Uguraynamespace shill {
3341cc634bcf55c46e9ada7447403c01553152205fArman Uguray
3441cc634bcf55c46e9ada7447403c01553152205fArman Ugurayclass PendingActivationStoreTest : public ::testing::Test {
3541cc634bcf55c46e9ada7447403c01553152205fArman Uguray public:
3604147470fdeaaf9ab7588bd3a7988d74aa990068mukesh agrawal  PendingActivationStoreTest() : mock_store_(new MockStore()) {
3704147470fdeaaf9ab7588bd3a7988d74aa990068mukesh agrawal  }
3841cc634bcf55c46e9ada7447403c01553152205fArman Uguray
3941cc634bcf55c46e9ada7447403c01553152205fArman Uguray protected:
4041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  void SetMockStore() {
4141cc634bcf55c46e9ada7447403c01553152205fArman Uguray    store_.storage_.reset(mock_store_.release());
4241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  }
4341cc634bcf55c46e9ada7447403c01553152205fArman Uguray
44c20ed13f5c0e87e7a5164d1b5330ccd99cced58fBen Chan  std::unique_ptr<MockStore> mock_store_;
4541cc634bcf55c46e9ada7447403c01553152205fArman Uguray  PendingActivationStore store_;
4641cc634bcf55c46e9ada7447403c01553152205fArman Uguray};
4741cc634bcf55c46e9ada7447403c01553152205fArman Uguray
4841cc634bcf55c46e9ada7447403c01553152205fArman UgurayTEST_F(PendingActivationStoreTest, FileInteractions) {
4941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  const char kEntry1[] = "1234";
5041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  const char kEntry2[] = "4321";
5141cc634bcf55c46e9ada7447403c01553152205fArman Uguray
5241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  base::ScopedTempDir temp_dir;
5341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
5441cc634bcf55c46e9ada7447403c01553152205fArman Uguray
55eca9dd6a1895177cc81b75f38d4e006c49488b23mukesh agrawal  EXPECT_TRUE(store_.InitStorage(temp_dir.path()));
5641cc634bcf55c46e9ada7447403c01553152205fArman Uguray
5741cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
5841cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
5941cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry1));
6041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
6141cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
6241cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry2));
6341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
6441cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
6541cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry1));
6641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
6741cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
6841cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry2));
6941cc634bcf55c46e9ada7447403c01553152205fArman Uguray
7041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.SetActivationState(
7141cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
7241cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry1,
7341cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStatePending));
7441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.SetActivationState(
7541cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
7641cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry2,
7741cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStateActivated));
7841cc634bcf55c46e9ada7447403c01553152205fArman Uguray
7941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStatePending,
8041cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
8141cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry1));
8241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
8341cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
8441cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry2));
8541cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
8641cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
8741cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry1));
8841cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
8941cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
9041cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry2));
9141cc634bcf55c46e9ada7447403c01553152205fArman Uguray
9241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.SetActivationState(
9341cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierMEID,
9441cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry1,
9541cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStateActivated));
9641cc634bcf55c46e9ada7447403c01553152205fArman Uguray
9741cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStatePending,
9841cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
9941cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry1));
10041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
10141cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
10241cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry2));
10341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
10441cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
10541cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry1));
10641cc634bcf55c46e9ada7447403c01553152205fArman Uguray
10741cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.SetActivationState(
10841cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
10941cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry1,
11041cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStateActivated));
11141cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.SetActivationState(
11241cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
11341cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry2,
11441cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStatePending));
11541cc634bcf55c46e9ada7447403c01553152205fArman Uguray
11641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
11741cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierICCID,
11841cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry1));
11941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStatePending,
12041cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierICCID,
12141cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry2));
12241cc634bcf55c46e9ada7447403c01553152205fArman Uguray
12341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  // Close and reopen the file to verify that the entries persisted.
124eca9dd6a1895177cc81b75f38d4e006c49488b23mukesh agrawal  EXPECT_TRUE(store_.InitStorage(temp_dir.path()));
12541cc634bcf55c46e9ada7447403c01553152205fArman Uguray
12641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
12741cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierICCID,
12841cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry1));
12941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStatePending,
13041cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierICCID,
13141cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry2));
13241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
13341cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
13441cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry1));
13541cc634bcf55c46e9ada7447403c01553152205fArman Uguray
13641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.RemoveEntry(
13741cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierMEID, kEntry1));
13841cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.RemoveEntry(
13941cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID, kEntry2));
14041cc634bcf55c46e9ada7447403c01553152205fArman Uguray
14141cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
14241cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
14341cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry1));
14441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
14541cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
14641cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry2));
14741cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
14841cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
14941cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry1));
15041cc634bcf55c46e9ada7447403c01553152205fArman Uguray
15141cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.RemoveEntry(
15241cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID, kEntry1));
15341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.RemoveEntry(
15441cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierMEID, kEntry2));
15541cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
15641cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
15741cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry1));
15841cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
15941cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
16041cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry2));
16141cc634bcf55c46e9ada7447403c01553152205fArman Uguray
162eca9dd6a1895177cc81b75f38d4e006c49488b23mukesh agrawal  EXPECT_TRUE(store_.InitStorage(temp_dir.path()));
16341cc634bcf55c46e9ada7447403c01553152205fArman Uguray
16441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
16541cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
16641cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry1));
16741cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
16841cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
16941cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry2));
17041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
17141cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
17241cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierICCID, kEntry1));
17341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
17441cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(
17541cc634bcf55c46e9ada7447403c01553152205fArman Uguray                PendingActivationStore::kIdentifierMEID, kEntry2));
17641cc634bcf55c46e9ada7447403c01553152205fArman Uguray}
17741cc634bcf55c46e9ada7447403c01553152205fArman Uguray
17841cc634bcf55c46e9ada7447403c01553152205fArman UgurayTEST_F(PendingActivationStoreTest, GetActivationState) {
1793b30ca58d13cf66b75ba0729b222ddc42ae68b33Paul Stewart  MockStore* mock_store = mock_store_.get();
18041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  SetMockStore();
18141cc634bcf55c46e9ada7447403c01553152205fArman Uguray
18241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  const char kEntry[] = "12345689";
18341cc634bcf55c46e9ada7447403c01553152205fArman Uguray
18441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  // Value not found
18541cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store, GetInt(PendingActivationStore::kIccidGroupId,
18641cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                  kEntry,
18741cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                  _))
18841cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillOnce(Return(false));
18941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
19041cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierICCID,
19141cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry));
19241cc634bcf55c46e9ada7447403c01553152205fArman Uguray
19341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  // File contains invalid entry
19441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store,
19541cc634bcf55c46e9ada7447403c01553152205fArman Uguray              GetInt(PendingActivationStore::kMeidGroupId, kEntry, _))
1960a3e27994a45a9723f3867fe7f297e089bd2254bArman Uguray      .WillOnce(DoAll(
1970a3e27994a45a9723f3867fe7f297e089bd2254bArman Uguray          SetArgumentPointee<2>(
1980a3e27994a45a9723f3867fe7f297e089bd2254bArman Uguray              static_cast<int>(PendingActivationStore::kStateMax)),
1990a3e27994a45a9723f3867fe7f297e089bd2254bArman Uguray          Return(true)));
20041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
20141cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierMEID,
20241cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry));
20341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store,
20441cc634bcf55c46e9ada7447403c01553152205fArman Uguray              GetInt(PendingActivationStore::kMeidGroupId, kEntry, _))
20541cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillOnce(DoAll(SetArgumentPointee<2>(0), Return(true)));
20641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateUnknown,
20741cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierMEID,
20841cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry));
20941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  Mock::VerifyAndClearExpectations(mock_store);
21041cc634bcf55c46e9ada7447403c01553152205fArman Uguray
21141cc634bcf55c46e9ada7447403c01553152205fArman Uguray  // All enum values
21241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store,
21341cc634bcf55c46e9ada7447403c01553152205fArman Uguray              GetInt(PendingActivationStore::kIccidGroupId, kEntry, _))
21441cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillOnce(DoAll(SetArgumentPointee<2>(1), Return(true)));
21541cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStatePending,
21641cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierICCID,
21741cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry));
21841cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store,
21941cc634bcf55c46e9ada7447403c01553152205fArman Uguray              GetInt(PendingActivationStore::kIccidGroupId, kEntry, _))
22041cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillOnce(DoAll(SetArgumentPointee<2>(2), Return(true)));
22141cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_EQ(PendingActivationStore::kStateActivated,
22241cc634bcf55c46e9ada7447403c01553152205fArman Uguray            store_.GetActivationState(PendingActivationStore::kIdentifierICCID,
22341cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                      kEntry));
22441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  Mock::VerifyAndClearExpectations(mock_store);
22541cc634bcf55c46e9ada7447403c01553152205fArman Uguray}
22641cc634bcf55c46e9ada7447403c01553152205fArman Uguray
22741cc634bcf55c46e9ada7447403c01553152205fArman UgurayTEST_F(PendingActivationStoreTest, SetActivationState) {
2283b30ca58d13cf66b75ba0729b222ddc42ae68b33Paul Stewart  MockStore* mock_store = mock_store_.get();
22941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  SetMockStore();
23041cc634bcf55c46e9ada7447403c01553152205fArman Uguray
23141cc634bcf55c46e9ada7447403c01553152205fArman Uguray  const char kEntry[] = "12345689";
23241cc634bcf55c46e9ada7447403c01553152205fArman Uguray
23341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store, Flush()).WillRepeatedly(Return(true));
23441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store,
23541cc634bcf55c46e9ada7447403c01553152205fArman Uguray              SetInt(PendingActivationStore::kIccidGroupId, kEntry, _))
23641cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillOnce(Return(false));
23741cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_FALSE(store_.SetActivationState(
23841cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
23941cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry,
24041cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStateUnknown));
24141cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_FALSE(store_.SetActivationState(
24241cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
24341cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry,
24441cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStateUnknown));
24541cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_FALSE(store_.SetActivationState(
24641cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
24741cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry,
24841cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStatePending));
24941cc634bcf55c46e9ada7447403c01553152205fArman Uguray
25041cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store,
25141cc634bcf55c46e9ada7447403c01553152205fArman Uguray              SetInt(PendingActivationStore::kIccidGroupId, kEntry, _))
25241cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillRepeatedly(Return(true));
25341cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_FALSE(store_.SetActivationState(
25441cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
25541cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry, static_cast<PendingActivationStore::State>(-1)));
25641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_FALSE(store_.SetActivationState(
25741cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
2580a3e27994a45a9723f3867fe7f297e089bd2254bArman Uguray      kEntry, PendingActivationStore::kStateMax));
25941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_FALSE(store_.SetActivationState(
26041cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
26141cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry, PendingActivationStore::kStateUnknown));
26241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.SetActivationState(
26341cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
26441cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry,
26541cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStatePending));
26641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.SetActivationState(
26741cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kIdentifierICCID,
26841cc634bcf55c46e9ada7447403c01553152205fArman Uguray      kEntry,
26941cc634bcf55c46e9ada7447403c01553152205fArman Uguray      PendingActivationStore::kStateActivated));
27041cc634bcf55c46e9ada7447403c01553152205fArman Uguray}
27141cc634bcf55c46e9ada7447403c01553152205fArman Uguray
27241cc634bcf55c46e9ada7447403c01553152205fArman UgurayTEST_F(PendingActivationStoreTest, RemoveEntry) {
2733b30ca58d13cf66b75ba0729b222ddc42ae68b33Paul Stewart  MockStore* mock_store = mock_store_.get();
27441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  SetMockStore();
27541cc634bcf55c46e9ada7447403c01553152205fArman Uguray
27641cc634bcf55c46e9ada7447403c01553152205fArman Uguray  const char kEntry[] = "12345689";
27741cc634bcf55c46e9ada7447403c01553152205fArman Uguray
27841cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store, Flush()).WillRepeatedly(Return(true));
27941cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store, DeleteKey(PendingActivationStore::kIccidGroupId,
28041cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                     kEntry))
28141cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillOnce(Return(false));
28241cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_FALSE(store_.RemoveEntry(PendingActivationStore::kIdentifierICCID,
28341cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                  kEntry));
28441cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_CALL(*mock_store, DeleteKey(PendingActivationStore::kIccidGroupId,
28541cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                     kEntry))
28641cc634bcf55c46e9ada7447403c01553152205fArman Uguray      .WillOnce(Return(true));
28741cc634bcf55c46e9ada7447403c01553152205fArman Uguray  EXPECT_TRUE(store_.RemoveEntry(PendingActivationStore::kIdentifierICCID,
28841cc634bcf55c46e9ada7447403c01553152205fArman Uguray                                 kEntry));
28941cc634bcf55c46e9ada7447403c01553152205fArman Uguray}
29041cc634bcf55c46e9ada7447403c01553152205fArman Uguray
29141cc634bcf55c46e9ada7447403c01553152205fArman Uguray}  // namespace shill
292