[email protected] | e16e873 | 2012-08-07 11:03:11 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #import <Foundation/Foundation.h> |
| 6 | |
| 7 | #include "base/ios/device_util.h" |
[email protected] | aebcd0dd | 2012-10-05 17:48:58 | [diff] [blame^] | 8 | #include "base/ios/ios_util.h" |
[email protected] | e16e873 | 2012-08-07 11:03:11 | [diff] [blame] | 9 | #include "base/sys_string_conversions.h" |
| 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | #include "testing/gtest_mac.h" |
| 12 | #include "testing/platform_test.h" |
| 13 | |
| 14 | namespace { |
| 15 | // The behavior of most of these utility functions depends on what they are run |
| 16 | // on, so there is not much to unittest them. The APIs are run to make sure they |
| 17 | // don't choke. Additional checks are added for particular APIs when needed. |
| 18 | |
| 19 | typedef PlatformTest DeviceUtilTest; |
| 20 | |
| 21 | TEST_F(DeviceUtilTest, GetPlatform) { |
| 22 | GTEST_ASSERT_GT(ios::device_util::GetPlatform().length(), 0U); |
| 23 | } |
| 24 | |
| 25 | TEST_F(DeviceUtilTest, IsRunningOnHighRamDevice) { |
| 26 | ios::device_util::IsRunningOnHighRamDevice(); |
| 27 | } |
| 28 | |
| 29 | TEST_F(DeviceUtilTest, IsSingleCoreDevice) { |
| 30 | ios::device_util::IsSingleCoreDevice(); |
| 31 | } |
| 32 | |
| 33 | TEST_F(DeviceUtilTest, GetMacAddress) { |
| 34 | GTEST_ASSERT_GT(ios::device_util::GetMacAddress("en0").length(), 0U); |
| 35 | } |
| 36 | |
| 37 | TEST_F(DeviceUtilTest, GetRandomId) { |
| 38 | GTEST_ASSERT_GT(ios::device_util::GetRandomId().length(), 0U); |
| 39 | } |
| 40 | |
| 41 | TEST_F(DeviceUtilTest, GetDeviceIdentifier) { |
| 42 | std::string default_id = ios::device_util::GetDeviceIdentifier(NULL); |
| 43 | std::string other_id = ios::device_util::GetDeviceIdentifier("ForTest"); |
| 44 | EXPECT_NE(default_id, other_id); |
| 45 | |
| 46 | NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 47 | [defaults removeObjectForKey:@"ChromiumClientID"]; |
| 48 | [defaults synchronize]; |
| 49 | |
| 50 | std::string new_default_id = ios::device_util::GetDeviceIdentifier(NULL); |
[email protected] | aebcd0dd | 2012-10-05 17:48:58 | [diff] [blame^] | 51 | if (base::ios::IsRunningOnIOS6OrLater()) |
| 52 | EXPECT_EQ(default_id, new_default_id); |
| 53 | else |
| 54 | EXPECT_NE(default_id, new_default_id); |
[email protected] | e16e873 | 2012-08-07 11:03:11 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } // namespace |