blob: b8ba10f289d365d9d805e008882af88a29e7d2a4 [file] [log] [blame]
[email protected]e16e8732012-08-07 11:03:111// 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]aebcd0dd2012-10-05 17:48:588#include "base/ios/ios_util.h"
[email protected]e16e8732012-08-07 11:03:119#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
14namespace {
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
19typedef PlatformTest DeviceUtilTest;
20
21TEST_F(DeviceUtilTest, GetPlatform) {
22 GTEST_ASSERT_GT(ios::device_util::GetPlatform().length(), 0U);
23}
24
25TEST_F(DeviceUtilTest, IsRunningOnHighRamDevice) {
26 ios::device_util::IsRunningOnHighRamDevice();
27}
28
29TEST_F(DeviceUtilTest, IsSingleCoreDevice) {
30 ios::device_util::IsSingleCoreDevice();
31}
32
33TEST_F(DeviceUtilTest, GetMacAddress) {
34 GTEST_ASSERT_GT(ios::device_util::GetMacAddress("en0").length(), 0U);
35}
36
37TEST_F(DeviceUtilTest, GetRandomId) {
38 GTEST_ASSERT_GT(ios::device_util::GetRandomId().length(), 0U);
39}
40
41TEST_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]aebcd0dd2012-10-05 17:48:5851 if (base::ios::IsRunningOnIOS6OrLater())
52 EXPECT_EQ(default_id, new_default_id);
53 else
54 EXPECT_NE(default_id, new_default_id);
[email protected]e16e8732012-08-07 11:03:1155}
56
57} // namespace