| Index: remoting/ios/data_store_unittest.mm
|
| diff --git a/remoting/ios/data_store_unittest.mm b/remoting/ios/data_store_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f03df89ae803e6e72d326c3be7f51cd9a5cdc63f
|
| --- /dev/null
|
| +++ b/remoting/ios/data_store_unittest.mm
|
| @@ -0,0 +1,119 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#if !defined(__has_feature) || !__has_feature(objc_arc)
|
| +#error "This file requires ARC support."
|
| +#endif
|
| +
|
| +#import "data_store.h"
|
| +
|
| +#import "base/compiler_specific.h"
|
| +#import "testing/gtest_mac.h"
|
| +
|
| +namespace {
|
| +
|
| +NSString* kHostName = @"testHost";
|
| +NSString* kHostPin = @"testHostPin";
|
| +NSString* kPairId = @"testPairId";
|
| +NSString* kSecret = @"testSecret";
|
| +
|
| +} // namespace
|
| +
|
| +namespace remoting {
|
| +
|
| +class DataStoreTest : public ::testing::Test {
|
| + protected:
|
| + virtual void SetUp() OVERRIDE {
|
| + _store = [[DataStore allocWithZone:nil] init];
|
| + RemoveAllHosts();
|
| + EXPECT_EQ(0, HostCount());
|
| + }
|
| + virtual void TearDown() OVERRIDE { RemoveAllHosts(); }
|
| +
|
| + int HostCount() { return [[_store allHosts] count]; }
|
| +
|
| + void RemoveAllHosts() {
|
| + while (HostCount() > 0) {
|
| + [_store removeHost:[_store allHosts].firstObject];
|
| + }
|
| + [_store saveChanges];
|
| + }
|
| +
|
| + DataStore* _store;
|
| +};
|
| +
|
| +TEST(DataStoreTest_Static, IsSingleInstance) {
|
| + DataStore* firstStore = [DataStore sharedStore];
|
| +
|
| + ASSERT_NSEQ(firstStore, [DataStore sharedStore]);
|
| +}
|
| +
|
| +TEST(DataStoreTest_Static, RemoveAllHost) {
|
| + // Test this functionality independently before expecting the fixture to do
|
| + // this correctly during cleanup
|
| + DataStore* store = [DataStore sharedStore];
|
| +
|
| + while ([[store allHosts] count]) {
|
| + [store removeHost:[store allHosts].firstObject];
|
| + }
|
| +
|
| + ASSERT_EQ(0, [[store allHosts] count]);
|
| + store = nil;
|
| +}
|
| +
|
| +TEST_F(DataStoreTest, CreateHost) {
|
| +
|
| + const HostPreferences* host = [_store createHost:kHostName];
|
| + ASSERT_STREQ([kHostName UTF8String], [host.hostId UTF8String]);
|
| + ASSERT_EQ(1, HostCount());
|
| +}
|
| +
|
| +TEST_F(DataStoreTest, GetHostForId) {
|
| + const HostPreferences* host = [_store getHostForId:kHostName];
|
| + ASSERT_TRUE(host == nil);
|
| +
|
| + [_store createHost:kHostName];
|
| +
|
| + host = [_store getHostForId:kHostName];
|
| +
|
| + ASSERT_TRUE(host != nil);
|
| + ASSERT_STREQ([kHostName UTF8String], [host.hostId UTF8String]);
|
| +}
|
| +
|
| +TEST_F(DataStoreTest, SaveChanges) {
|
| +
|
| + const HostPreferences* newHost = [_store createHost:kHostName];
|
| +
|
| + ASSERT_EQ(1, HostCount());
|
| +
|
| + // Default values for a new host
|
| + ASSERT_TRUE([newHost.askForPin boolValue] == NO);
|
| + ASSERT_TRUE(newHost.hostPin == nil);
|
| + ASSERT_TRUE(newHost.pairId == nil);
|
| + ASSERT_TRUE(newHost.secret == nil);
|
| +
|
| + // Set new values and save
|
| + newHost.askForPin = [NSNumber numberWithBool:YES];
|
| + newHost.hostPin = kHostPin;
|
| + newHost.pairId = kPairId;
|
| + newHost.secret = kSecret;
|
| +
|
| + [_store saveChanges];
|
| +
|
| + // The next time the store is loaded the host will still be present, even
|
| + // though we are about to release and reinit a new object
|
| + _store = nil;
|
| + _store = [[DataStore allocWithZone:nil] init];
|
| + ASSERT_EQ(1, HostCount());
|
| +
|
| + const HostPreferences* host = [_store getHostForId:kHostName];
|
| + ASSERT_TRUE(host != nil);
|
| + ASSERT_STREQ([kHostName UTF8String], [host.hostId UTF8String]);
|
| + ASSERT_TRUE([host.askForPin boolValue] == YES);
|
| + ASSERT_STREQ([kHostPin UTF8String], [host.hostPin UTF8String]);
|
| + ASSERT_STREQ([kPairId UTF8String], [host.pairId UTF8String]);
|
| + ASSERT_STREQ([kSecret UTF8String], [host.secret UTF8String]);
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|